def get(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) postId = self.request.get("postId") if user_id: q = BlogEntry.get_by_id(int(postId)) title = q.title body = q.body created = q.created last_mod = q.last_mod author = q.author_id logging.warning(author + " = " + user_id) # ONLY AUTHOR CAN EDIT: check that user_id matches the AUTHOR if author == user_id: self.render("delete.html", title=title, body=body, created=created, last_mod=last_mod, author=author, postId=postId) else: error = "Only the author can delete." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "Please signup and login to edit posts." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def post(self): user_id = None commentId = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) commentId = self.request.get("commentId") comment = self.request.get("comment") postId = self.request.get("postId") q = BlogEntry.get_by_id(int(postId)) k = q.key() if user_id: commentId = int(commentId) comEntity = Comments.get_by_id(commentId, parent=k) if user_id == comEntity.author_id: q = BlogEntry.get_by_id(int(postId)) if q: k = q.key() c = Comments.get_by_id(int(commentId), parent=k) if c: c.comment = comment c.put() error = "" self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "You must be the author to edit the comment." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "You must be loggen in to edit the comment." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def post(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) postId = self.request.get("postId") # must be logged in if user_id: q = BlogEntry.get_by_id(int(postId)) title = q.title body = q.body created = q.created last_mod = q.last_mod author = q.author_id # ONLY AUTHOR CAN EDIT: check that user_id matches the AUTHOR if author == user_id: q = BlogEntry.get_by_id(int(postId)) q.delete() error = "Post deleted" self.redirect("/welcome?error=%s" % error) else: error = "Only the author can delete." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "Please signup and login to edit posts." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def post(self): # AUTHENTICATE user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) title = self.request.get("title") body = self.request.get("body") like = 0 if user_id: if title and body: u = Users.get_by_id(int(user_id)) b = BlogEntry(title=title, body=body, author_name=u.userName, likes=like, author_id=user_id) b.put() self.redirect("/welcome") else: error = "Please provide BOTH a title and body." # must include all the parameters below to preserve user # entered data self.render_newpost(title=title, body=body, error=error) else: self.redirect("/login")
def post(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) postId = self.request.get("postId") if user_id: try: u = Users.get_by_id(int(user_id)) q = BlogEntry.get_by_id(int(postId)) except: pass if q: title = q.title body = q.body created = q.created last_mod = q.last_mod author = q.author_id k = q.key() try: comments = Comments.all().ancestor(k) except: pass # check again if user is the author.. if user_id == author: title = self.request.get("title") body = self.request.get("body") postId = self.request.get("postId") # if field is left empty if title == "": error = "You must enter a new title." self.redirect("/editpost?postId=%s&error=%s" % (postId, error)) if body == "": error = "You must enter new content." self.redirect("/editpost?postId=%s&error=%s" % (postId, error)) else: if q: q.title = title q.body = body q.put() error = "Updated post." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "error updating post" self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "You must be author to edit." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "Please signup and login to edit posts." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def get(self): # AUTHENTICATE check for valid cookie user_id = None user_id = auth(self.request.cookies.get('user_id')) if not user_id: error = "Please log in." self.redirect("/login?error=%s" % error) # if the cookie is authentic, then also check username against the db else: self.render_newpost()
def get(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) # get the blog post id from the get request postId = self.request.get("postId") if user_id: q = BlogEntry.get_by_id(int(postId)) title = q.title body = q.body self.render("comment.html", title=title, body=body, postId=postId) else: error = "Please signup and login to edit comments." # if you are not logged in, you must sign up and login. self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def get(self): commentId = None user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) commentId = self.request.get("commentId") postId = self.request.get("postId") q = BlogEntry.get_by_id(int(postId)) k = q.key() # must be logged in if user_id: commentId = int(commentId) comment = Comments.get_by_id(commentId, parent=k) # must be the author to edit the comment if user_id == comment.author_id: c = Comments.get_by_id(commentId, parent=k) if c: comment = c.comment created = c.created author_id = c.author_id u = Users.get_by_id(int(author_id)) user_name = u.userName self.render("edit-comment.html", author=user_name, comment=comment, created=created, commentId=commentId, postId=postId) else: error = "error" self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "You must be the author to edit the comment." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "You must be loggen in to edit the comment." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
def post(self): # AUTHENTICATE user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) u = Users.get_by_id(int(user_id)) user_name = u.userName if user_id: comment = None comment = self.request.get("comment") postId = self.request.get("postId") q = BlogEntry.get_by_id(int(postId)) if comment: if comment != "": c = Comments(parent=q, comment=comment, author_id=user_id, author_name=user_name) c.put() error = "Comment saved." self.redirect( "/focus?postId=%s&error=%s&user_name=%s" % (postId, error, user_name)) else: error = "Please add content for the comment or cancel." self.redirect( "/comment?postId=%s&error=%s&user_name=%s" % (postId, error, user_name)) else: error = "Please add a comment." # must include all the parameters below to preserve user # entered data self.redirect( "/comment?postId=%s&error=%s&user_name=%s" % (postId, error, user_name)) else: error = "Please signup and login to add a comment." self.redirect("/focus?postId=%s&error=%s&user_name=%s" % (postId, error, user_name))
def get(self): user_id = None u = None error = "" post = "" # GET ALL BLOG POSTS TO LIST THEM try: posts = BlogEntry.all().order('-created') except: pass # AUTHENTICATE: check for valid cookie user_id = auth(self.request.cookies.get('user_id')) if user_id: try: # check db to verify that the username exists even though \ # browser has a cookie. Maybe this user was deleted from the\ # db by the admin. u = Users.get_by_id(int(user_id)) except: pass if u: user_name = u.userName try: error = self.request.get("error") except: pass self.render("blogMain.html", user_name=user_name, posts=posts, error=error) else: # if user is NOT in the db error = "Could not verify username." self.redirect("/login?error=%s" % error) else: error = "Please log in." self.redirect("/login?error=%s" % error)
def get(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) postId = self.request.get("postId") if user_id: try: u = Users.get_by_id(int(user_id)) q = BlogEntry.get_by_id(int(postId)) except: pass if q: title = q.title body = q.body created = q.created last_mod = q.last_mod author = q.author_id k = q.key() try: comments = Comments.all().ancestor(k) except: pass # if user is the author then ok to edit if user_id == author: self.render("edit-post.html", body=body, title=title, postId=postId) else: error = "You must be author to edit." self.redirect("/focus?postId=%s&error=%s" % (postId, error)) else: error = "Please signup and login to edit posts." self.redirect("/focus?postId=%s&error=%s" % (postId, error))
class Dev(commands.Cog): def __init__(self, bot): set_commanders() self.bot = bot # Events @commands.Cog.listener() async def on_ready(self): print(f'Cog {self.qualified_name} is ready.') # Commands # Echo what you said @commands.command(name='echo', aliases=['repeat', 'say'], pass_context=True, description='Says what you tell it') @commands.check(auth(1)) async def echo(self, ctx, *, message): """Have the bot repeat your message. Requires: Auth level 1 Message: The message to repeat""" await ctx.message.delete() # delete the command await ctx.send(message) print( f'Echo command used by {ctx.author} at {now()} with message {message}' ) # Have the bot send a dm to someone with your message @commands.command(name='sendmsg', aliases=['dm', 'tell', 'message'], pass_context=True, description='DM an unsuspecting user') @commands.check(auth(2)) async def send(self, ctx, user: discord.User, *, message=None): """Sends a DM to a user of your choice Requires: Auth level 2 User: The user to message Message: The message to send""" message = message or 'Someone is pranking you bro.' await ctx.message.delete() # delete the command await ctx.send('Message sent.', delete_after=deltime) await user.send(message) print( f'Send command used by {ctx.author} at {now()} to user {user} with message {message}' ) # Check someone's auth level @commands.group(name='auth', aliases=['who', 'check', 'authorize'], description='Check the Auth Level of a user') @commands.check(auth(1)) async def autho(self, ctx): """auth check returns the auth level of a given user Requires: Auth level 1 Member: The discord member to check the auth level of You can use auth set <user> <level> if you have auth level 7""" # await ctx.send('Use auth check, auth set or auth all') print(f'Auth command used by {ctx.author} at {now()}') pass # Checks a user's auth level @autho.command(name='check') async def check(self, ctx, user: discord.User = None, detail=''): if not user: user = ctx.author auth_level = get_commanders().get(str(user.id), default_auth) embed = discord.Embed(title='', description='', color=user.color) embed.set_author(icon_url=user.avatar_url, name=f'{user} is ' f'authorized at level {auth_level}') if detail != '': perms = '' for perm in sorted(perms_info.keys(), reverse=True): if perm <= auth_level: perms += str(perm) + ': ' + perms_info.get(perm) + '\n' embed.add_field(name='The Details:', value=perms) embed.set_footer(text=embed_footer(ctx.author)) await ctx.send(content=None, embed=embed, delete_after=deltime * 5) await ctx.message.delete(delay=deltime) # delete the command print( f'Auth check command used by {ctx.author} at {now()}, {user} is authorized at level {auth_level}.' ) # sets a user's auth level @commands.command(name='authset') @commands.check(auth(7)) async def authset(self, ctx, level, user: discord.User): commanders = get_commanders() level = int(level) if commanders[str(ctx.author.id)] > level and commanders.get( user.id, 0) < commanders[str(ctx.author.id)]: with open('auths.json', 'r') as f: auths = json.load(f) print(f'Changing {user} auth level to {level}') auths[str(user.id)] = level with open('auths.json', 'w') as f: json.dump(auths, f, indent=4) set_commanders( ) # update variable in memory after having written to disc new perms await ctx.send( f'Changed {user} auth level to {auths[str(user.id)]}', delete_after=deltime) elif commanders[str(ctx.author.id)] <= level: await ctx.send( f"I'm sorry, but you can't set someone's auth level higher than your own." ) else: await ctx.send( f"I'm sorry, but you can't change the auth level of someone with an auth level equal to or " f"higher than you.") print( f'Authset command used by {ctx.author} at {now()} to set {user}\'s auth level to {level}' ) # lists all bot commanders and their auth levels @autho.command(name='all') @commands.check(auth(4)) async def set(self, ctx): commanders = get_commanders() embed = discord.Embed(title='', description='', color=ctx.author.color) embed.set_author(icon_url=ctx.author.avatar_url, name='Here you go:') message = '' for c in commanders: message += (str(await self.bot.fetch_user(c)) + ': ' + str(commanders[c]) + '\n') embed.add_field(name='Bot Commanders:', value=message) embed.set_footer(text=embed_footer(ctx.author)) await ctx.send(content=None, embed=embed) print(f'Auth All command used by {ctx.author} at {now()}') # Unload a cog @commands.command(name='unload', pass_context=True, description='Unload a cog') @commands.check(auth(4)) async def unload(self, ctx, extension): """Unload a cog Requires: Auth level 4 Extension: The cog to unload""" self.bot.unload_extension(f'cogs.{extension}') print(f'Unloaded {extension}') await ctx.send(f'Unloaded {extension}.', delete_after=deltime) await ctx.message.delete(delay=deltime) # delete the command print( f'Unload command used by {ctx.author} at {now()} on cog {extension}' ) # Reload a cog @commands.command(name='reload', description='Reload a cog') @commands.check(auth(3)) async def reload(self, ctx, extension): """Reload a cog Requires: Auth level 4 Extension: The cog to reload""" self.bot.unload_extension(f'cogs.{extension}') self.bot.load_extension(f'cogs.{extension}') print(f'Reloaded {extension}') await ctx.send(f'Reloaded {extension}', delete_after=deltime) await ctx.message.delete(delay=deltime) # delete the command print( f'Reload command used by {ctx.author} at {now()} on cog {extension}' ) # Update bot status @commands.command(name='status', description='Change what the bot is playing') @commands.check(auth(5)) async def status(self, ctx, *, message=''): """Change the bot's "playing" status Requires: Auth level 5 Message: The message to change it to""" await self.bot.change_presence(activity=discord.Game(message)) print(f'Updated status to {message}.') await ctx.send(f'Updated status to {message}.', delete_after=deltime) await ctx.message.delete(delay=deltime) # delete the command print( f'Status command used by {ctx.author} at {now()} to set bot status to {message}' ) @commands.command(name='eval', description='Evaluates input.') @commands.check(auth(9)) async def eval_fn(self, ctx, *, cmd): """Evaluates input. This command requires Auth 9 for obvious reasons. """ starttime = time.time_ns() fn_name = "_eval_expr" cmd = cmd.strip("` ") if cmd[0:2] == 'py': # Cut out py for ```py``` built in code blocks cmd = cmd[2:] # add a layer of indentation cmd = "\n".join(f" {i}" for i in cmd.splitlines()) # wrap in async def body body = f"async def {fn_name}():\n{cmd}" parsed = ast.parse(body) body = parsed.body[0].body insert_returns(body) env = { 'bot': ctx.bot, 'discord': discord, 'commands': commands, 'ctx': ctx, 'guild': ctx.guild, 'self': self, '__import__': __import__ } exec(compile(parsed, filename="<ast>", mode="exec"), env) result = (await eval(f"{fn_name}()", env)) endtime = time.time_ns() await ctx.send( f'Command took {(endtime - starttime) / 1000000}ms to run.\nResult: {result}' ) @commands.command(name='delete', description='Delete a single message by ID') @commands.check(auth(6)) async def delete(self, ctx, message_id: int): """ Deletes a single message. Requires: Auth 6. Used for cleaning up bot mistakes. """ await (await ctx.channel.fetch_message(message_id)).delete() await ctx.message.delete(delay=deltime) # delete the command print( f'Deleted message {message_id} in channel {ctx.channel} for user {ctx.author} at {now()}' )
class Database(commands.Cog): def __init__(self, bot): self.bot = bot # Events @commands.Cog.listener() async def on_ready(self): print(f'Loading Cog {self.qualified_name}...') connect() # cursor.execute("SHOW DATABASES") # databases = cursor.fetchall() # print(f"Databases: {databases}") # cursor.execute("DROP TABLE users") cursor.execute("SHOW TABLES") tables = cursor.fetchall() if 'users' not in str(tables): print('Users table not found. Creating a new one...') cursor.execute( "CREATE TABLE users " "(id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, " "name VARCHAR(255), " "user_name VARCHAR(255), " "rsi VARCHAR(255), " "rsi_link VARCHAR(255), " "languages VARCHAR(255), " "location VARCHAR(255), " "joined_rsi VARCHAR(255), " "rsi_number INT(10), " "joined VARCHAR(255), " "hr_rep VARCHAR(255))") print(f'I have the following tables:\n{pquery("SHOW TABLES")}') print(f'My Users table is configured thusly:\n{pquery("DESC users")}') print(f'Users:\n{pquery("SELECT * FROM users")}') # ALTER TABLE table_name DROP column_name # ALTER TABLE table_name ADD PRIMARY KEY(column_name) print(f'Cog {self.qualified_name} is ready.') def cog_unload(self): print(f"Closing {self.qualified_name} cog.") disconnect() @commands.command(name='listusers', description='Prints the list of users to the console.') @commands.check(auth(4)) async def listusers(self, ctx): users = pquery("SELECT * FROM users") print(f'Users: {users}') names = [user[1] for user in users] numUsers = len(users) await ctx.send( f'The list of {numUsers} users has been printed to the console. Here are their names only:\n{names}' ) @commands.command(name='directq', description='Does a direct database querry.') @commands.check(auth(8)) async def directq(self, ctx, *, query): """ Does a direct database query. Not quite as dangerous as eval, but still restricted to Auth 8. """ result = pquery(query) print( f'{ctx.author} executed a direct database query at {now()}:\n{query}\nResult was:\n{result}' ) try: await ctx.send(pquery(query)) except InterfaceError: await ctx.send("Okay. There's no result from that query.")
def authenticate(email, pw): logger.debug('checking email: %s, pw: %s' % (email, pw)) user = functions.auth(email, pw) logger.debug(user) if user != -1: return user
x = 1 while x == 1: os.system('clear') answer = input("Are you a New User? (Y/N) -->> ").upper() if answer != 'Y' and answer != 'N': print("""I am sorry, that is not a valid option. Try again...""") time.sleep(3) os.system('clear') elif answer == 'Y': functions.newUser() x = 0 elif answer == 'N': if functions.auth(): break else: x = 1 #while loop to see the main menu x = 1 while x == 1: os.system('clear') print(""" **** PLEASE SELECT AN OPTION: **** 1. Make a Reservation
def post(self): def render_focus(title, body, created, last_mod, author, comments, count, error, postId, user_name): self.render("focus.html", title=title, body=body, created=created, last_mod=last_mod, author=author, comments=comments, count=count, error=error, postId=postId, user_name=user_name) postId = self.request.get("postId") user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) # get the logged in user to get username if user_id: try: u = Users.get_by_id(int(user_id)) except: pass if u: user_name = u.userName # query for the usual blogPost entity properties try: q = BlogEntry.get_by_id(int(postId)) if q: title = q.title body = q.body created = q.created last_mod = q.last_mod author = u.userName author_id = q.author_id # k is the key to the blog post. k = q.key() except: pass try: # get all comments for for the blogpost - that means get # all comments who are ancestors of K (the blogpost). comments = Comments.all().ancestor(k) except: pass # check if user has already liked this post # all Likes have a user_id property which corresponds to the # User who LIKED the post, so query Likes filtered by user_id # to get ALL the likes for this user try: z = Likes.all().filter("user_id =", user_id) except: pass # then get the ONE (if theres is one) that is an ancestor # of the blog post if z: try: alreadyLiked = z.ancestor(k).get() except: pass # set flag default = go flag = "go" # if there are ZERO likes in the db, you'll get an error bc # the query gets nothing. To prevent the error, use try/except try: if alreadyLiked.user_id: flag = "nogo" except: pass # initialize the counter count = 0 # If the logged in user is the author then error if user_id == author_id: # repaint page likes = Likes.all().ancestor(k) count = 0 for like in likes: try: if like.user_id: count += 1 except: pass error = "You can't like your own posts." render_focus(title, body, created, last_mod, author, comments, count, error, postId, user_name) else: # if the logged in user has already liked this post then error if flag == "nogo": error = "Stop it....You already liked this post." likes = Likes.all().ancestor(k) count = 0 if likes: for like in likes: if like.user_id: count += 1 # repaint page render_focus(title, body, created, last_mod, author, comments, count, error, postId, user_name) else: # if tests are passed....record the LIKE; # record the userIDKEY in LIKES as a CHILD of the BLOGPOST # increment the like so it updates the display (not the db) # record like in the db - user_id is the only property and # it's ancestor is the blogpost k. try: l = Likes(parent=k, user_id=user_id) except: pass if l: l.put() error = "The Like was recorded." # count ALL the existing LIKES to update display \ # on VIEW post # filter by ancestor bc ALL likes are recorded as an \ # ancestor of ONE blogPost likes = Likes.all().ancestor(k) count = 0 if likes: for like in likes: if like.user_id: count += 1 # repaint page render_focus(title, body, created, last_mod, author, comments, count, error, postId, user_name) else: error = "Please signup and login to like a post." # if you are not logged in, you must sign up and login. self.redirect("/focus?postId=%s&error=%s" % (postId, error))
class Corp(commands.Cog): def __init__(self, bot): self.bot = bot # Events @commands.Cog.listener() async def on_ready(self): print(f'Cog {self.qualified_name} is ready.') def cog_unload(self): print("Closing Corp cog...") session.close() # Commands @commands.command(name='register', description='Register for The Corporation!') async def corp_register(self, ctx): """ Register for the Corporation! """ # If already registered, don't let them register again if ctx.guild.get_role( 667268366456717332) in ctx.author.roles or ctx.guild.get_role( corp_tag_id) in ctx.author.roles: await ctx.send('It looks like you already have a Corporateer tag.') return # Make sure they understand await ctx.send(welcome_david_msg.format(author=ctx.author.mention)) try: response = await self.bot.wait_for('message', check=check_ok(ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return if response.content.casefold() == 'help'.casefold(): await ctx.guild.get_channel(log_channel).send( help_david_msg.format(ctx.author)) await ctx.send(get_a_person) return # Get RSI handle, can get link from this. flag = False handle_e = "" while not flag: await ctx.send( content=understand_david_msg, file=discord.File('rsi_register_helper_image_3.png')) try: rsi_handle = await self.bot.wait_for('message', check=check_author( ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return if response.content.casefold() == 'help'.casefold(): await ctx.guild.get_channel(log_channel).send( f'@Recruiter, {ctx.author} has requested a personal touch ' f'for assistance with their application.') await ctx.send(get_a_person) return if rsi_handle.content.casefold() == 'how'.casefold(): await ctx.send( "\n\n\nHere's a more detailed description of how to do that.\n```\n" f"1) Go to https://robertsspaceindustries.com\n" f"2) Log in to your account.\n" f"3) Find and click the Account button in the top right.\n" f"4) Copy the large/top name beside your picture, and paste it as a reply here.\n```" f"As an example, for someone with the RSI handle `Vyryn`, it would look something like" f" this:", file=discord.File('rsi_register_helper_image.png')) await ctx.send( "When you're ready, please post your RSI handle here.") try: rsi_handle = await self.bot.wait_for('message', check=check_author( ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return if rsi_handle.content.casefold() == 'help'.casefold(): await ctx.guild.get_channel(log_channel).send( f'@Recruiter, {ctx.author} has requested a personal touch ' f'for assistance with their application.') await ctx.send(get_a_person) return split = rsi_handle.content.split('/') handle_e = split[len(split) - 1] # Confirm RSI handle flag2 = False while not flag2: await ctx.send( f"I'd just like to confirm: Your RSI handle is **`{handle_e}`** ?\n" f"**__Confirm with__** \n```\nok```\n, or type it again if you made a mistake." ) try: response = await self.bot.wait_for('message', check=check_author( ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return if response.content.casefold() == 'help'.casefold(): await ctx.guild.get_channel(log_channel).send( f'@Recruiter, {ctx.author} has requested a personal touch ' f'for assistance with their application.') await ctx.send(get_a_person) return if response.content.casefold() == 'ok'.casefold(): flag = True flag2 = True else: split = response.content.split('/') handle_e = split[len(split) - 1] # Confirm profile is theirs # one_time_code = random.randint(min_rand, min_rand * 10) await ctx.send( content= f"Great. Next I need to check your profile actually belongs to you.\n The way I'd like to do " f"that is by having you **__add the phrase__** \n\nI am {ctx.author} on Discord\n\n**__ to your" f" RSI profile__** and then type `ok` and I'll take a look at your profile. Or, " f"if you're not sure how to do that, **__type__** `how`.") try: response = await self.bot.wait_for('message', check=check_author(ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return if response.content.casefold() == 'help'.casefold(): await ctx.guild.get_channel(log_channel).send( f'@Recruiter, {ctx.author} has requested a personal touch ' f'for assistance with their application.') await ctx.send(get_a_person) return if response.content.casefold() == 'how'.casefold(): await ctx.send( content= f"Here's a more detailed description of how to do that.\n```\n" f"1) Go to https://robertsspaceindustries.com/account/profile" f" and scroll down to where it says 'Short Bio'\n" f"2) Add 'I am {ctx.author} on Discord.' to the 'Short Bio' and then Click " f"'APPLY ALL CHANGES'\n" f"3) Check that you are in The Corporation on RSI and it is visible on your profile.\n" f"4) Tell me 'ok' and I'll check your profile.```", file=discord.File('rsi_register_helper_image_2.png')) try: ok_check = await self.bot.wait_for('message', check=check_ok(ctx.author), timeout=deltime) except asyncio.TimeoutError: await ctx.send(timeout_msg) return await ctx.send(f"Checking your RSI profile...") citizen = fetch_citizen(handle_e) print(citizen) # await ctx.send("Here's what I found.") message = "" ready = False try: bio = citizen['bio'] except KeyError: await ctx.send( "Hmm, I wasn't able to find your profile. **__Are you sure you spelled your handle " "correctly?__** Please double check and try this command again. It is also possible the " "RSI site is down for the moment, try again in a few minutes.") return orgnames = [i['name'] for i in citizen['orgs']] if f'I am {ctx.author}' in citizen['bio'] and citizen['handle'].casefold() == handle_e.casefold() and \ 'The Corporation' in orgnames: message += "Great news! I was able to confirm you put the phrase in your bio *and* that you are in the" \ " Corporation. I'll go ahead and assign your Corporateer tag." ready = True else: if citizen['handle'].casefold() == handle_e.casefold(): message += "Good news. I was able to find your profile. " flag = True else: message += "Hmm, I wasn't able to find your profile. **__Are you sure you spelled your handle " \ "correctly?__** Please double check and try again." if 'The Corporation' in orgnames: if flag: message += "Plus, " else: message += "Good news. " message += "I was able to confirm you're in The Corporation. " flag2 = True else: message += "I wasn't able to confirm you're in The Corporation. **__Please make sure The " \ "Corporation is set as your main org and visible__**, and try again. " if f'I am {ctx.author}' in citizen['bio']: if not flag and not flag2: message += "Good news. " else: message += "Plus, " message += "I was able to find the phrase in your bio. " else: message += f"I wasn't able to find `I am {ctx.author} on Discord.` in your bio. **__Please add that" \ f" to your bio and then re-run this command.__** " await ctx.send(message) # Yay! Feedback time hr_rep = "N/A" if ready: joined = now() rsi_number = citizen['citizen_record'] languages = citizen.get('languages', '') location = citizen.get('location', '') joined_rsi = citizen['enlisted'] hr_rep = random.choice(hr_reps(ctx.guild)) adduser(ctx.author, handle_e, languages, location, joined_rsi, rsi_number, joined, hr_rep) # Get display name so it can be changed to RSI name. disp = None if ctx.author.nick is not None: disp = ctx.author.nick else: disp = ctx.author.display_name try: await ctx.author.add_roles(ctx.guild.get_role(corp_tag_id)) if ctx.guild.get_role(visitor_role) in ctx.author.roles: await ctx.author.remove_roles( ctx.guild.get_role(visitor_role)) await ctx.send(f'Removed {ctx.author}\'s @Visitor role.', delete_after=10) if disp != handle_e: await ctx.author.edit( reason='Bot change to match RSI handle', nick=handle_e) await ctx.send( 'I have changed your nickname on this server to match your RSI handle so that games' ' nights can be done more easily.') except PermissionError: await ctx.send( "Hmm, the bot seems to be configured incorrectly. Make sure I have all required perms " "and my role is high enough in the role list.") return assign_language_tags(ctx, citizen['languages']) else: prefix = await self.bot.get_prefix(ctx.message) await ctx.send( f"I'm sorry you weren't able to complete the process this time. " f"When you're ready to try again, use `{prefix}register` again." ) return await ctx.send( content= f"Welcome! Enjoy your time here at Corp. Your HR rep is `{hr_rep}`. If you" f" have any questions I'm not able to answer, please do contact them. This is our new members " f"guide, it may be of use to you. Read at your leisure. :smiley:", file=discord.File('New_Members_Guide_V2.1.pdf')) prefix = await self.bot.get_prefix(ctx.message) await ctx.send( "The next step is to join some divisions. Much of the content of the Corporation is hidden and" " visible only to division members. You can choose one or several that you are interested in." f" When you're ready to join some divisions, type `{prefix}reqdiv division`. Be sure to do so " f"to see all the fun content!") await ctx.send( f"If you'd like some training, type `{prefix}trainme` to let our trainers know you want to " "participate in the next M1 training session.") # Log for HR/bookkeeping await self.bot.get_channel(registration_channel).send( f"**{ctx.author.mention}** has successfully become a Corporateer at {now()}. Their RSI link is:\n" f"```{profiles_url + handle_e}```") embed = discord.Embed(title='New Corporateer!', description='', color=ctx.author.color) embed.add_field(name="User:"******"Citizen Number #", value=citizen['citizen_record'], inline=False) embed.add_field(name="RSI URL:", value=profiles_url + handle_e, inline=False) embed.add_field(name="Languages:", value=f"{citizen['languages']}.", inline=False) embed.add_field(name="Location:", value=f"{citizen['location']}.", inline=False) embed.add_field(name="Joined CORP:", value=joined, inline=False) embed.add_field(name="Joined RSI:", value=citizen['enlisted'], inline=False) embed.add_field(name="Assigned HR Rep:", value=hr_rep, inline=False) app = await self.bot.get_channel(log_channel).send(content=None, embed=embed) # str(feedback.content) await self.bot.get_channel(log_channel).send( f"Please give them" f" a warm welcome in #lobby then mark this post with :corpyes:") @commands.command(name='verify', description='Verify someone\'s registration!') async def corp_verify(self, ctx, member: typing.Optional[discord.Member] = None, *, handle_e=None): """ Verify someone's Corporateer registration. Usage: verify [@mention or id] [rsi handle] If and only if discord username is exactly RSI handle, you can omit RSI handle here. If you are registering yourself, you can omit member: register RSI_handle """ if member is None: member = ctx.author # If already registered, don't let them register again if ctx.guild.get_role( 667268366456717332) in member.roles or ctx.guild.get_role( corp_tag_id) in member.roles: # await ctx.send('User already has Corporateer tag. Proceeding anyways.') pass # return # Commented out due to proceeding anyways. Likely temporary. # Assume RSI handle is discord nick or username if there is none if handle_e is None: if member.nick is not None: handle_e = member.nick else: handle_e = member.display_name await ctx.send(f"Checking RSI profile...") citizen = fetch_citizen(handle_e) print(citizen) # await ctx.send("Here's what I found.") message = "" ready = False # Verify user is meaningful try: bio = citizen['bio'] except KeyError: await ctx.send("Unable to find user profile.") return orgnames = [i['name'] for i in citizen['orgs']] # Verify user is correct user if not citizen['handle'].casefold() == handle_e.casefold(): return await ctx.send("Profile not found.") # Verify user in org if 'The Corporation' not in orgnames: return await ctx.send("User not in The Corporation.") # Verify phrase in user bio if f'I am {member}' not in citizen['bio']: prefix = await self.bot.get_prefix(ctx.message) return await ctx.send( f"I didn't find 'I am {member} on Discord' in that user's bio. If you aren't sure " f"how to fix this, consider using {prefix}register instead for a step by step " f"process.") await ctx.send( "User in The Corporation. Phrase found in bio. Adding Corporateer tag." ) # Complete paperwork hr_rep = ctx.author.display_name joined = now() rsi_number = citizen['citizen_record'] languages = citizen.get('languages', '') location = citizen.get('location', '') joined_rsi = citizen['enlisted'] hr_rep = random.choice(hr_reps(ctx.guild)) adduser(member, handle_e, languages, location, joined_rsi, rsi_number, joined, hr_rep) await assign_language_tags(ctx, languages) # Get display name so it can be changed to RSI name. disp = None if member.nick is not None: disp = member.nick else: disp = member.display_name try: # Add Corporateer tag if ctx.guild.get_role(corp_tag_id) not in member.roles: await member.add_roles(ctx.guild.get_role(corp_tag_id)) # Remove Visitor tag if ctx.guild.get_role(visitor_role) in member.roles: await member.remove_roles(ctx.guild.get_role(visitor_role)) if disp != handle_e: try: await member.edit(reason='Bot change to match RSI handle', nick=handle_e) await ctx.send( f"{member}'s nickname changed to match their RSI handle." ) except (discord.Forbidden, discord.HTTPException): await ctx.guild.get_member(81980368688779264).send( f"I was unable to update {member}'s nickname" f" to match their rsi handle of {handle_e} due" f" to role ordering.") await ctx.send( f"Due to the way discord role lists work, I can't change {member}'s nickname" f" to {handle_e}. Only Weyland can. I have messaged him with the " f"request, and he will probably update it within a few hours. " ) except PermissionError: await ctx.send( "Hmm, the bot seems to be configured incorrectly. Make sure I have all required perms " "and my role is high enough in the role list.") # Send success info prefix = await self.bot.get_prefix(ctx.message) await ctx.send( content= f"User {handle_e} successfully added/updated. HR rep is `{hr_rep}`. New members guide attached." f" Next steps are:" f"\nJoin 2 or more divisions with `{prefix}reqdiv`," f"\nJoin the influence system with `~influence login` " f"(note website MOTHER provides is out of date, use https://influence.thecorporateer.com instead)," f"\nAttend weekly meetings," f"\nJoin us on the forums with the username and password pinned in #announcements," f"\nPerhaps sign up for M1 with `{prefix}trainme`," f"\nAnd of course join us in game :)", file=discord.File('New_Members_Guide_V2.1.pdf')) # Log for HR/bookkeeping await self.bot.get_channel(registration_channel).send( f"**{member.mention}** has successfully become a Corporateer or updated their RSI handle at {now()}. " f"Their RSI link is:\n```{profiles_url + handle_e}```") embed = discord.Embed(title='New Corporateer!', description='', color=member.color) embed.add_field(name="User:"******"Citizen Number #", value=citizen['citizen_record'], inline=False) embed.add_field(name="RSI URL:", value=profiles_url + handle_e, inline=False) embed.add_field(name="Languages:", value=f"{citizen['languages']}.", inline=False) embed.add_field(name="Location:", value=f"{citizen['location']}.", inline=False) embed.add_field(name="Joined CORP:", value=joined, inline=False) embed.add_field(name="Joined RSI:", value=citizen['enlisted'], inline=False) embed.add_field(name="Assigned HR Rep:", value=hr_rep, inline=False) app = await self.bot.get_channel(log_channel).send(content=None, embed=embed) await self.bot.get_channel(log_channel).send( f"{ctx.guild.get_role(recruiter_role).mention}, please say " f"hello!") @commands.command(name='checkrsi', aliases=['fetch_cit, rsi'], description='Check citizen\'s rsi profile') async def fetch_citizen_cmd(self, ctx, user): """ Check someone's RSI profile """ try: name = str(user.name) if user.nick is not None: name = str(user.nick) except: name = user # citizen = fetch_citizen(name) # print(citizen) await ctx.send(f'{DEFAULT_RSI_URL}/citizens/{name}') @commands.command( name='listlinks', description='List all the RSI links for everyone in your voice chat.') async def list_rsi_links(self, ctx, *, channel=None): """ Print a list of the RSI handles of everyone in the selected voice channel. """ if channel is None: if ctx.author.voice is None or ctx.author.voice.channel is None: await ctx.send( f"{ctx.author}, you aren't currently in a voice channel. Either join one or specify " f"one with the command.") return else: channel = ctx.author.voice.channel else: for try_channel in ctx.guild.voice_channels: if try_channel.name.casefold() == channel.casefold(): channel = try_channel break try: if len(channel.members) < 1: await ctx.send(f'I see no one in that channel.') return except AttributeError: await ctx.send( 'It looks like you may have misspelled that channel name. Try again.' ) return members = [] for member in channel.members: link = get_rsi(member.id) rsi = link[link.rfind('/') + 1:len(link)] members.append((rsi, str(member), link)) members = sorted(members) message = [''] i = 0 for member in members: try: message[int( i / 10 )] += f'I see {member[1]} in that channel, their link is {member[2]}.\n' except IndexError: message.append('') message[int( i / 10 )] += f'I see {member[1]} in that channel, their link is {member[2]}.\n' i += 1 for mes in message: await ctx.send(mes) @commands.command( name='listdivs', description= 'List all the divisons of members in your voice channel or target voice channel.' ) async def list_divs(self, ctx, num=0, *, channel=None): """ Print a list of the division tags of everyone in the selected voice channel. Add a number to list the top that many, defaults to 10. """ if num < 1: num = 10 if channel is None: if ctx.author.voice is None or ctx.author.voice.channel is None: await ctx.send( f"{ctx.author}, you aren't currently in a voice channel. Either join one or specify " f"one with the command.") return else: channel = ctx.author.voice.channel else: for try_channel in ctx.guild.voice_channels: if try_channel.name.casefold() == channel.casefold(): channel = try_channel break try: if len(channel.members) < 1: await ctx.send(f'I see no one in that channel.') return except AttributeError: await ctx.send( 'It looks like you may have misspelled that channel name. Try again.' ) return divs_in_channel = Counter() for member in channel.members: for div in member.roles: if div.name.casefold() in divs.keys(): divs_in_channel[div.name] += 1 print(divs_in_channel) print((divs_in_channel.most_common(num))) message = '' counter = 0 for div in divs_in_channel.most_common(num): counter += 1 message += f'{counter}) {div[1]} x {div[0]}\n' await ctx.send(f'I found the following divs:\n{message}') @commands.command(name='reqdiv', description="Request a division tag.") async def reqdiv(self, ctx, *, div: str = None): """ Request a division tag for any divs in divs """ if div is None: return await ctx.send( f"Our divisions are all in the picture below. I recommend using this command again with a division to " f"request 2-3 divisions of your choice :smile: \n" f"{div_pic}") return # If not yet registered, don't allow use of reqdiv if not ctx.guild.get_role(corp_tag_id) in ctx.author.roles: prefix = await self.bot.get_prefix(ctx.message) await ctx.send( f'I\'m sorry, you need to get a Corporateer tag first. Use `{prefix}register`.' ) return # Find reporting channel for channel in ctx.guild.channels: if channel.name.casefold() == div_req_notif_ch.casefold(): management = channel div = div_alternative_names.get(div.casefold(), div) dept = divs.get(div.casefold(), 'none') # If not a valid division if dept == 'none': return await ctx.send( f"Hmm, I didn't find {div} in our list of divisions. Our divisions are all in the picture below.\n" f"{div_pic}") return if div.casefold() == 'Diplomacy'.casefold(): return await ctx.send( "Thank you for your interest in Diplomacy. This division is a bit unique, and due " "to the nature of diplomacy it generally requires at least S2 security clearance. I " "recommend joining some other divisions first, getting to know some members of the " "organization. If you are still interested in Diplomacy, contact Weyland directly." ) elif div.casefold() == 'Training'.casefold(): author_role_ids = [role.id for role in ctx.author.roles] if self.bot.mtags.isdisjoint( author_role_ids): # If member has no M tag prefix = await self.bot.get_prefix(ctx.message) return await ctx.send( "Thank you for your interest in Training. Joining this division requires an M-1 " "or higher certification. You can earn an M-1 tag by participating in an M-1 " f"training: Sign up for an M-1 training with `{prefix}trainme`. Good luck! " ) print(f'{ctx.author} used reqdiv to request to join {div} at {now()}.') # Find DH and DL roles for role in ctx.guild.roles: if role.name.casefold() == f'DL {div.casefold()}'.casefold(): dl_role = role elif role.name.casefold( ) == f'DH {divs[div.casefold()].casefold()}'.casefold(): dh_role = role await management.send( f'{dl_role.mention}, {dh_role.mention}, {ctx.author} is interested in joining {div}! ' f'Please contact them at your convenience to help them with that.') await ctx.send( f"Okay, I have informed the division leader and department head that you're interested " f"in joining {div}.") @commands.command(name='adduser', description='Adds a user to the database.') @commands.check(auth(1)) async def adduser(self, ctx, user: discord.User, rsi): """ Insert a user into the users database Requires Auth 1 """ citizen = fetch_citizen(rsi) joined = now() try: # can check if the citizen call was valid by trying to get the first key from it rsi_number = citizen['citizen_record'] except KeyError: await ctx.send('I think you mis-typed their rsi handle.') return languages = citizen['languages'] location = citizen['location'] joined_rsi = citizen['enlisted'] hr_rep = random.choice(hr_reps(ctx.guild)) result = adduser(user, rsi, languages, location, joined_rsi, rsi_number, joined, hr_rep) await ctx.send(result) print(result) @commands.command( name='checkorgs', description='Checks what organizations someone is a part of.') @commands.check(auth(1)) async def checkorgs(self, ctx, rsi): """ Lists user's orgs, location and languages. Test command for upcoming automatic adding of these. Requires Auth 1 """ citizen = fetch_citizen(rsi) try: # can check if the citizen call was valid by trying to get the first key from it rsi_number = citizen['citizen_record'] except KeyError: await ctx.send('I think you mis-typed their rsi handle.') return languages = ', '.join([language for language in citizen['languages']]) orgs = ', '.join([org['name'] for org in citizen['orgs']]) to_send = f"I found some information on that person's RSI profile.\n**Orgs:**\n{orgs}\n" \ f"**Languages:**\n{languages}" await ctx.send(to_send) @commands.command(name='remove_corp', description='Removes someone\'s Corporateer tag') @commands.check(auth(1)) async def remove_corp(self, ctx, user: discord.Member): """ Removes a corporateer tag. Requires Auth 1. """ try: await user.remove_roles(ctx.guild.get_role(corp_tag_id)) print( f'Removed corp tag from {user} by request from {ctx.author}.') await ctx.send( f'Removed corp tag from {user} by request from {ctx.author}.') except PermissionError: await ctx.send( "Hmm, the bot seems to be configured incorrectly. Make sure I have all required perms " "and my role is high enough in the role list.") @commands.command(description='Add someone to the HR Rep list') @commands.check(auth(1)) async def add_hr(self, ctx, member: discord.User): add_hr(member) return await ctx.send(f'{member} added to the HR rep list.') @commands.command(description='Remove someone from the HR Rep list') @commands.check(auth(1)) async def remove_hr(self, ctx, member: discord.User): del_hr(member) return await ctx.send(f'{member} removed from the HR rep list.')
def get(self): user_id = None # AUTHENTICATE check for valid cookie user_id = auth(self.request.cookies.get('user_id')) if user_id: # get the logged in user try: u2 = Users.get_by_id(int(user_id)) except: pass if u2: # get the username NOT the id user_name = u2.userName postId = self.request.get("postId") error = self.request.get("error") q = None # querie BlogEntry for the blog entity filtered by title try: q = BlogEntry.get_by_id(int(postId)) title = q.title body = q.body created = q.created last_mod = q.last_mod author_id = q.author_id k = q.key() except: pass if q: # get the user who is the author of the blogpost try: u = Users.get_by_id(int(author_id)) except: pass if u: # get the authors username NOT id author = u.userName comments = None # get all comments for this blogpost try: comments = Comments.all().ancestor(k) except: pass # if there are no comments.... if not comments: commentError = "No comments" else: commentError = "" else: error = "Could not access the blog post." self.redirect("/welcome?error=%s" % error) # count likes in the database for display, all relevant likes are\ # ancestors of the blog post with title count = 0 likes = None try: likes = Likes.all().ancestor(k) except: pass if likes: # iterate through all likes for this post to count them for like in likes: if like.user_id: count += 1 self.render("focus.html", postId=postId, title=title, body=body, created=created, last_mod=last_mod, author=author, comments=comments, error=error, count=count, commentError=commentError, user_name=user_name) else: self.redirct("/login")
# Checks if a user has the requested authorization level or not, is a coroutine for async operation @bot.check_once def channel_check(ctx): async def channel_perm_check(*args): no_command_channels = get_ignored_channels() for channel in no_command_channels: if int(channel) == ctx.channel.id: return False return True return channel_perm_check() # Commands @bot.command(name='load', description='Load a cog') @commands.check(auth(4)) async def load(ctx, extension): """The command to load a cog Requires: Auth level 4 Extension: the cog to load""" bot.load_extension(f'cogs.{extension}') print(f'Loaded {extension}.') await ctx.send(f'Loaded {extension}.', delete_after=deltime) await ctx.message.delete(delay=deltime) # delete the command @bot.command( name='ignorech', description='Make the bot ignore commands in the channel this is used in.') @commands.check(auth(4)) async def ignorech(ctx):
class Moderation(commands.Cog): def __init__(self, bot): self.bot = bot # Events @commands.Cog.listener() async def on_ready(self): print(f'Cog {self.qualified_name} is ready.') # Commands @commands.command(aliases=['clear', 'del'], description='Delete a number of messages') @commands.has_permissions(manage_messages=True) async def purge(self, ctx, amount): """Delete a bunch of messages Requires: Manage Message perms on your server Amount: The number of messages to purge. Typically limited to 100. People with Auth level 4 can delete more messages at once.""" if int(amount) <= 100: await ctx.channel.purge(limit=int(amount) + 1) return print( f'{ctx.author} deleted {amount} messages in channel {ctx.channel} in guild {ctx.guild}.' ) elif await auth(4)(ctx): await ctx.channel.purge(limit=int(amount) + 1) return print( f'{ctx.author} deleted {amount} messages in channel {ctx.channel} in guild {ctx.guild}.' ) else: await ctx.send('You may only delete up to 100 messages', delete_after=deltime) @commands.command(name='forcepurge', description='Delete a number of messages') @commands.check(auth(6)) async def purge(self, ctx, amount): """Delete a bunch of messages Requires: Auth 6. This is meant for use only in cases where the bot has caused spam that it shouldn't have. Amount: The number of messages to purge. Typically limited to 100. People with Auth level 4 can delete more messages at once.""" if int(amount) <= 100: await ctx.channel.purge(limit=int(amount) + 1) return print( f'{ctx.author} deleted {amount} messages in channel {ctx.channel} in guild {ctx.guild}.' ) elif await auth(4)(ctx): await ctx.channel.purge(limit=int(amount) + 1) return print( f'{ctx.author} deleted {amount} messages in channel {ctx.channel} in guild {ctx.guild}.' ) else: await ctx.send('You may only delete up to 100 messages', delete_after=deltime) @commands.command(name='kick', description='Kick em out!') @commands.has_permissions(kick_members=True) async def kick(self, ctx, member: discord.Member, *, reason='No reason provided.'): """Kick someone out of the server Requires: Kick Members permission Member: the person to kick Reason: the reason why, defaults to 'No reason provided.'""" reason = f'{ctx.author} kicked {member} for reason {reason}' await member.kick(reason=reason) @commands.command(name='ban', description='The Banhammer!') @commands.has_permissions(ban_members=True) async def ban(self, ctx, member: discord.Member, *, reason='No reason provided.'): """Ban someone from the server Requires: Ban Members permission Member: the person to ban Reason: the reason why, defaults to 'No reason provided.'""" reason = f'{ctx.author} banned {member} for reason {reason}' await member.ban(reason=reason) await ctx.send(f'Banned {member.mention} for {reason}.') @commands.command(name='unban', description='I am merciful, sometimes.') @commands.has_permissions(manage_guild=True) async def unban(self, ctx, *, member): """Unban someone from the server Requires: Manage Server permission Member: the person to unban""" banned_users = await ctx.guild.bans() member_name, member_discriminator = member.split('#') for ban_entry in banned_users: user = ban_entry.user if (user.name, user.discriminator) == (member_name, member_discriminator): await ctx.guild.unban(user) await ctx.send(f'Unbanned {user.name}#{user.discriminator}') print( f'Unban command used by {ctx.author} at {now()} on user {member}.') @commands.command(name='clearpins', description='Remove *all* the pins from a channel') @commands.has_permissions(manage_messages=True) async def clearpins(self, ctx): """Clear all the pinned messages from a channel. Requires: Manage Messages permission Note: It is highly recommended to be absolutely sure before using this command.""" if confirmed_ids.get(ctx.author.id, 0) > 0: i = 0 for pin in await ctx.channel.pins(): await pin.unpin() i += 1 await ctx.send(f'Okay {ctx.author}, {i} pins have been cleared.') confirmed_ids[ctx.author.id] = 0 await ctx.message.delete() # delete the command else: await ctx.send( "Are you certain you wish to clear all the pins from this channel? This can not be undone. " "If so, use this command again.", delete_after=deltime) confirmed_ids[ctx.author.id] = 1 await ctx.message.delete() # delete the command self.bg_task = self.bot.loop.create_task( self.confirmation_on(ctx.author.id)) print( f'Clearpins command used by {ctx.author} at {now()} in channel {ctx.channel.name}.' ) async def confirmation_on(self, user): await asyncio.sleep(deltime * 2) confirmed_ids[user] = 0 return