async def unverify(ctx: discord.Message, client: discord.Client): if not _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create( "Confirm Reply", "Verification is not enabled on this server!", "red") await ctx.channel.send(embed=replyEmbed) return if not _mongoFunctions.is_user_id_linked_to_verified_user_in_guild( ctx.guild.id, ctx.author.id): replyEmbed = _embedMessage.create("Unverify Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return else: user_id = ctx.author.id _mongoFunctions.remove_verified_user(ctx.guild.id, user_id) await ctx.channel.send(embed=_embedMessage.create( "Unverify Reply", "You have been unverified", "blue")) try: await ctx.author.remove_roles( discord.utils.get(ctx.guild.roles, name=_mongoFunctions.get_settings( ctx.guild.id)['verified_role'])) except: print("this didnt work LOL")
async def add_quote(ctx: discord.Message, client: discord.Client): if not _mongoFunctions.is_user_id_linked_to_verified_user_in_guild( ctx.guild.id, ctx.author.id) and _mongoFunctions.get_settings( ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create("AddQuote Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return args = _util.parse_message(ctx.content) if len(args) != 3: await ctx.channel.send(embed=_embedMessage.create( "AddQuote Reply", "Invalid Syntax! You need two arguments for this function!\nEx: $addquote \"Life is Good\" Bedi", "red")) return if len(args[1]) > embed_field_max_char: await ctx.channel.send(embed=_embedMessage.create( "AddQuote Reply", "Quote is too long! Please submit a quote that is 1024 characters or fewer", "red")) return embed = _embedMessage.create( "AddQuote Reply", "| \"" + args[1] + "\" by: " + args[2] + " submitted by: " + ctx.author.mention + " \nReact to Approve\nApproved by: ", "blue") message = await ctx.channel.send(embed=embed) await message.add_reaction( discord.utils.get(ctx.guild.emojis, name=_mongoFunctions.get_settings( ctx.guild.id)['reaction_emoji']))
async def set_due_date_channel(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role(ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("SetDueDateChannel Reply", "Invalid Permissions", "red") await ctx.channel.send(embed = replyEmbed) return if not _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled']: await ctx.channel.send(embed = _embedMessage.create("AddDueDate Reply", "Due Dates are not enabled on this server.", "red")) return _mongoFunctions.set_due_date_channel_id(ctx.guild.id, ctx.channel.id) await ctx.channel.purge(limit = None) dueDateEmbeds = {} dueDateMessages = {} for stream in _mongoFunctions.get_settings(ctx.guild.id)['streams']: dueDateEmbeds[stream] = _embedMessage.create("Stream {0} Due Dates Message".format(stream), "Temporary Message", "green") dueDateMessages[stream] = await ctx.channel.send(embed = dueDateEmbeds[stream]) await dueDateMessages[stream].pin() _mongoFunctions.set_due_date_message_id(ctx.guild.id, stream, dueDateMessages[stream].id) await _dueDateMessage.edit_due_date_message(client) # Purge all unpinned messages await ctx.channel.purge(limit = None, check = lambda msg: not msg.pinned)
async def send_morning_announcement(client: discord.Client, guild_id: int, channel_id: int): guild = client.get_guild(guild_id) quote = _mongoFunctions.random_quote(guild_id) if _mongoFunctions.get_settings(guild_id)['random_quote'] \ else _mongoFunctions.random_quote_from_person(guild_id, _mongoFunctions.get_settings(guild_id)['announcement_quoted_person']) await guild.get_channel(channel_id).send(embed = _embedMessage.create("Good Morning!", quote, "blue")) _mongoFunctions.set_last_announcement_time(guild_id, datetime.now())
async def quotes_reaction_handler( reaction_payload: discord.RawReactionActionEvent, message: discord.Message): # if isinstance(reaction.emoji, str): # i think this means its a discord emoji # await reaction.message.channel.send("string") if reaction_payload.emoji.is_custom_emoji: # await reaction.message.channel.send("emoji") # print(reaction.emoji.name) # emojis from this server if reaction_payload.emoji.id == discord.utils.get( message.guild.emojis, name=_mongoFunctions.get_settings( message.guild.id)['reaction_emoji']).id: if reaction_payload.member.mention not in message.embeds[ 0].description: embed = _embedMessage.create( "AddQuote Reply", message.embeds[0].description + " " + reaction_payload.member.mention, "blue") await message.edit(embed=embed) reaction_object = None for reaction in message.reactions: if reaction.emoji.id == reaction.emoji.id: reaction_object = reaction break if reaction_object.count >= _mongoFunctions.get_settings( message.guild.id)['required_quote_reactions']: args = _util.parse_message(message.embeds[0].description) quote = args[1] quotedPerson = args[3] res = _mongoFunctions.insert_quote(guild_id=message.guild.id, quoted_person=quotedPerson, quote=quote) contentArr = message.embeds[0].description.split(" ") newContent = " ".join(contentArr[1:]) if res: embed = _embedMessage.create("Quote Reply", "Approved: " + newContent, "blue") await message.edit(embed=embed) else: embed = _embedMessage.create( "Quote Reply", "Failed to Connect to DB: " + newContent, "blue") await message.edit(embed=embed)
async def schedule_jobs(client: discord.Client): guild_list = _mongoFunctions.get_guilds_information() for guild_dict in guild_list: guild_id = guild_list[guild_dict]['guild_id'] guild_timezone = guild_list[guild_dict]['timezone'] # Checks if channel actually exists in guild if guild_list[guild_dict]['due_dates_enabled']: try: due_date_channel_id = client.get_guild(guild_id).get_channel(int(_mongoFunctions.get_settings(guild_id)['due_date_channel_id'])).id # Purges (unpinned) messages in due date channel at end of day scheduler.add_job(_util.purge_messages_in_channel, 'cron', hour = 23, minute = 59, second = 0, timezone = guild_timezone, args = [client, guild_id, due_date_channel_id]) except: print("Error scheduling due dates for guild ID: {0}".format(guild_id)) if guild_list[guild_dict]['birthday_announcements_enabled']: try: birthday_channel_id = client.get_guild(guild_id).get_channel(int(_mongoFunctions.get_settings(guild_id)['birthday_channel_id'])).id birthday_time = guild_list[guild_dict]['birthday_time'].split(':') scheduler.add_job(_birthdayMessage.send_birthday_message, 'cron', hour = int(birthday_time[0]), minute = int(birthday_time[1]), second = 1, timezone = guild_timezone, args = [client, guild_id, birthday_channel_id]) except: print("Error scheduling birthdays for guild ID: {0}".format(guild_id)) if guild_list[guild_dict]['morning_announcements_enabled']: try: announcement_channel_id = client.get_guild(guild_id).get_channel(int(_mongoFunctions.get_settings(guild_id)['announcement_channel_id'])).id announcement_time = guild_list[guild_dict]['announcement_time'].split(':') announcement_time_object = datetime.today() announcement_time_object = announcement_time_object.replace(hour = int(announcement_time[0]), minute = int(announcement_time[1])) scheduler.add_job(_morningAnnouncement.send_morning_announcement, 'cron', hour = announcement_time_object.hour, minute = announcement_time_object.minute, second = 1, timezone = guild_timezone, args = [client, guild_id, announcement_channel_id]) # Does announcement check five minutes after announcement time (To handle edge case where bot goes offline during announcement time announcement_time_object += timedelta(minutes = 5) scheduler.add_job(_morningAnnouncement.check_if_morning_announcement_occurred_today, 'cron', hour = announcement_time_object.hour, minute = announcement_time_object.minute, second = 1, timezone = guild_timezone, args = [client, guild_id, announcement_channel_id]) except: print("Error scheduling morning announcements for guild ID: {0}".format(guild_id)) due_date_edit_interval = 10 scheduler.add_job(_dueDateMessage.edit_due_date_message, 'interval', minutes = due_date_edit_interval, args = [client]) scheduler.add_job(_setBotStatus.set_random_bot_status, 'interval', hours = 1, args = [client])
async def send_birthday_message(client: discord.Client, guild_id: int, channel_id: int): guild_id = int(guild_id) channel_id = int(channel_id) guild = client.get_guild(guild_id) birthday_role = discord.utils.get( guild.roles, name=_mongoFunctions.get_settings(guild_id)['birthday_role']) # Remove Birthday Role from all Members for member in guild.members: if birthday_role in member.roles: await member.remove_roles(birthday_role) birthday_mentions = [] user_documents = _mongoFunctions.get_all_birthdays_today() # Checks if member exists in guild, adds their mention to list of mentions, and gives them birthday role for document in user_documents: member = discord.utils.get(guild.members, id=document['user_id']) if member is None: continue birthday_mentions.append(member.mention) await member.add_roles(birthday_role) if len(birthday_mentions) != 0: await guild.get_channel(int(channel_id) ).send(embed=_embedMessage.create( "Happy Birthday!", "Happy birthday to:\n" + ' '.join(birthday_mentions), "blue"))
async def remove_quote(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("RemoveQuote Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return args = _util.parse_message(ctx.content) if len(args) != 3: await ctx.channel.send(embed=_embedMessage.create( "RemoveQuote Reply", "Invalid Syntax! You need two arguments for this function!", "red") ) return if len(args[1]) > embed_field_max_char: await ctx.channel.send(embed=_embedMessage.create( "RemoveQuote Reply", "Quote is too long! Please submit a quote that is 1024 characters or fewer", "red")) return embed = _embedMessage.create( "RemoveQuote Reply", "\"" + args[1] + "\" by: " + args[2] + " \n Removed by: " + ctx.author.mention, "blue") await ctx.channel.send(embed=embed) _mongoFunctions.delete_quote(ctx.guild.id, args[1], args[2])
async def force_announcement(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("ForceAnnouncement Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return await _morningAnnouncement.send_morning_announcement( client, ctx.guild.id, _mongoFunctions.get_settings(ctx.guild.id)['announcement_channel_id']) await ctx.channel.send(embed=_embedMessage.create( "ForceAnnouncement Reply", "Announcement has been **FORCED**", "blue")) return
async def admin_verify(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("AdminVerify Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return if not _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create( "AdminVerify Reply", "Verification is not enabled on this server!", "red") await ctx.channel.send(embed=replyEmbed) return message_contents = ctx.content.split(" ") if len(message_contents) != 2: await ctx.channel.send(embed=_embedMessage.create( "AdminVerify Reply", "The syntax is invalid! Make sure it is in the format $adminverify <User (Mention)>\nNote that this command does NOT assign a role, it only verifies them inside the database!", "red")) return mention = message_contents[1] # Removes special characters from mention to end up with the user id user_id = mention.replace("<", "").replace(">", "").replace("@", "").replace("!", "") _mongoFunctions.admin_add_user_to_verified_users(ctx.guild.id, user_id) await ctx.guild.get_member(user_id).add_roles( discord.utils.get(ctx.guild.roles, name=_mongoFunctions.get_settings( ctx.guild.id)['verified_role'])) await ctx.channel.send( embed=_embedMessage.create("AdminVerify reply", mention + "has been verified", "blue"))
async def say(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("Say Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return global target_channel args = _util.parse_message(ctx.content) if len(args) != 4: await ctx.channel.send(embed=_embedMessage.create( "Say Reply", "Invalid Syntax! You need three arguments for this function!\nSyntax: say title content channel", "red")) return title = args[1] content = args[2] channel_mention = args[3] channels = client.get_all_channels() for channel in channels: if channel.mention == channel_mention: target_channel = channel break if target_channel is None: await ctx.channel.send(embed=_embedMessage.create( "Say Reply", "Channel not Found!", "red")) return try: await ctx.delete() except: print("Missing Manage Messages permission in {0} on server ID: {1}". format(channel.mention, str(ctx.guild.id))) if not _util.author_is_bot_owner(ctx): embed = _embedMessage.create( title, content + "\n\n This message was sent by {}".format(ctx.author.mention), "green") else: embed = _embedMessage.create(title, content, "green") await target_channel.send(embed=embed)
async def on_message(ctx): if ctx.author == client.user: return prefix = _mongoFunctions.get_settings(ctx.guild.id)['prefix'] if ctx.content.startswith(prefix): # Checks if the first word of the message's content (with the prefix removed) is in the dict of commands command_string = ctx.content.split(" ")[0][len(prefix):].lower() if command_string in commands: await commands[command_string](ctx, client)
async def pins_reaction_handler(reaction: discord.Reaction, user: discord.Member, remove: bool): if not _mongoFunctions.get_settings(user.guild.id)['pins_enabled']: return if not remove: if str(reaction.emoji) == "📌": await reaction.message.pin() else: if reaction.emoji == "📌": if not ":pushpin:" in [ reaction.emoji for reaction in reaction.message.reactions ]: await reaction.message.unpin()
async def lockdown(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("Lockdown Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return args = parse_message(ctx.content) if len(args) == 1: for role in ctx.guild.roles: try: perms = ctx.channel.overwrites_for( role) # Use a permissions overwrite object perms.send_messages = False await ctx.channel.set_permissions(role, overwrite=perms) except: print("Unable to change permissions for {0}".format(role.name)) replyEmbed = _embedMessage.create( "Lockdown Reply", "Channel Locked for all possible roles", "green") await ctx.channel.send(embed=replyEmbed) elif len(args) == 2: role = get(ctx.guild.roles, name=args[1]) if role is None: replyEmbed = _embedMessage.create("Lockdown Reply", "Invalid Role", "red") await ctx.channel.send(embed=replyEmbed) return else: replyEmbed = _embedMessage.create( "Lockdown Reply", "Channel Locked for {}".format(args[1]), "green") await ctx.channel.send(embed=replyEmbed) # await ctx.channel.set_permissions(role, send_messages = False, read_messages = True) perms = ctx.channel.overwrites_for( role) # Use a permissions overwrite object perms.send_messages = False await ctx.channel.set_permissions(role, overwrite=perms) else: replyEmbed = _embedMessage.create( "Lockdown Reply", "This command needs can only take one argument.", "red") await ctx.channel.send(embed=replyEmbed)
async def set_birthday(ctx: discord.Message, client: discord.Client): if not _mongoFunctions.is_user_id_linked_to_verified_user_in_guild( ctx.guild.id, ctx.author.id) and _mongoFunctions.get_settings( ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create("SetBirthday Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return message_contents = ctx.content.split(" ") if len(message_contents) == 4: message_contents.pop(0) # Expected format is YYYY MM DD birth_year = message_contents[0] birth_month = message_contents[1] birth_day = message_contents[2] error_check = _dateFunctions.check_for_errors_in_date( birth_year, birth_month, birth_day) else: error_check = 1 if error_check == 1: await ctx.channel.send(embed=_embedMessage.create( "SetBirthday Reply", "The syntax is invalid! Make sure it is in the format YYYY MM DD\nEx: $setbirthday 2002 07 26", "red")) return if error_check == 2: await ctx.channel.send(embed=_embedMessage.create( "SetBirthday Reply", "The date is invalid, please ensure that this is a valid date.", "red")) return birth_date_string = '-'.join(message_contents) await ctx.channel.send(embed=_embedMessage.create( "SetBirthday Reply", "Your birthday has been set!", "blue")) await ctx.delete() _mongoFunctions.set_users_birthday( ctx.author.id, datetime.datetime.strptime(birth_date_string, "%Y-%m-%d"))
async def edit_due_date_embed(stream: int, courses: list, guild_id: int, guild: discord.Guild, channel_id: int): channel = guild.get_channel(channel_id) message_id = _mongoFunctions.get_settings(guild_id)['stream_' + str(stream) + '_message_id'] due_date_message = await channel.fetch_message(message_id) # Zero Width Space is used as embed body as field cannot be empty message_embed = _embedMessage.create("Upcoming Due Dates for Stream " + str(stream), "​", "blue") for course in courses: due_dates = _mongoFunctions.get_all_upcoming_due_dates(guild_id, stream, course) for due_date in due_dates: # Sets emojis for some generic due date types or uses :placard: by default if due_date['type'] == "Assignment": emoji = ":pushpin:" elif due_date['type'] == "Test": emoji = ":bulb:" elif due_date['type'] == "Exam": emoji = ":pen_ballpoint:" elif due_date['type'] == "Project": emoji = ":books:" elif due_date['type'] == "Quiz": emoji = ":pencil:" else: emoji = ":placard:" # Creates string to represent due date information if due_date['time_included']: current_due_date = " **Type:** " + due_date['type'].rjust(10) + " **Date:** " + due_date['date'].strftime("%m/%d/%Y, %H:%M:%S").rjust(10) + '\n​' else: current_due_date = " **Type:** " + due_date['type'].rjust(10) + " **Date:** " + due_date['date'].strftime("%m/%d/%Y").rjust(10) + '\n​' # Creates string to represent due date title, including course name if its the first due date for that course if due_date == due_dates[0]: title = "**" + course + "**\n" + emoji + " " + due_date['title'] else: title = emoji + " " + due_date['title'] message_embed.add_field(name = title, value = current_due_date, inline = False) await due_date_message.edit(embed = message_embed)
async def settings(ctx: discord.Message, client: discord.Client): # Checks if user is admin or bot owner if not (_checkrole.author_has_role( ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): replyEmbed = _embedMessage.create("Settings Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return settings_embed = _embedMessage.create( "Settings Reply", "Here are the settings for **" + ctx.guild.name + "**", "blue") _embedMessage.add_field( settings_embed, "Prefix", _mongoFunctions.get_settings(ctx.guild.id)['prefix'], False) _embedMessage.add_field( settings_embed, "Timezone", _mongoFunctions.get_settings(ctx.guild.id)['timezone'], False) _embedMessage.add_field( settings_embed, "Admin Role", _mongoFunctions.get_settings(ctx.guild.id)['admin_role'], False) _embedMessage.add_field( settings_embed, "Pins Enabled", _mongoFunctions.get_settings(ctx.guild.id)['pins_enabled'], False) await ctx.channel.send(embed=settings_embed) verification_embed = _embedMessage.create( "Verification Settings", "Here are the verification settings.", "blue") _embedMessage.add_field( verification_embed, "Verification Enabled?", _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled'], False) if _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: _embedMessage.add_field( verification_embed, "Verified Role", _mongoFunctions.get_settings(ctx.guild.id)['verified_role'], False) _embedMessage.add_field( verification_embed, "Verification Email Domain", _mongoFunctions.get_settings(ctx.guild.id)['email_domain'], False) await ctx.channel.send(embed=verification_embed) announcement_embed = _embedMessage.create( "Morning Announcement Settings", "Here are the morning announcement settings.", "blue") _embedMessage.add_field( announcement_embed, "Morning Announcements Enabled?", _mongoFunctions.get_settings( ctx.guild.id)['morning_announcements_enabled'], False) if _mongoFunctions.get_settings( ctx.guild.id)['morning_announcements_enabled']: try: channel_name = ctx.guild.get_channel( int( _mongoFunctions.get_settings( ctx.guild.id)['announcement_channel_id'])).mention except: channel_name = "Not set. Run {0}setup to set.".format( _mongoFunctions.get_settings(ctx.guild.id)['prefix']) _embedMessage.add_field(announcement_embed, "Morning Announcements Channel", channel_name, False) _embedMessage.add_field( announcement_embed, "Daily Announcement Time", _mongoFunctions.get_settings(ctx.guild.id)['announcement_time'], False) _embedMessage.add_field( announcement_embed, "Random Quote?", _mongoFunctions.get_settings(ctx.guild.id)['random_quote'], False) _embedMessage.add_field( announcement_embed, "Daily Announcement Quote Author", _mongoFunctions.get_settings( ctx.guild.id)['announcement_quoted_person'], False) await ctx.channel.send(embed=announcement_embed) birthday_embed = _embedMessage.create("Birthday Announcement Settings", "Here are the birthday settings.", "blue") _embedMessage.add_field( birthday_embed, "Birthday Announcements Enabled?", _mongoFunctions.get_settings( ctx.guild.id)['birthday_announcements_enabled'], False) if _mongoFunctions.get_settings( ctx.guild.id)['birthday_announcements_enabled']: try: channel_name = ctx.guild.get_channel( int( _mongoFunctions.get_settings( ctx.guild.id)['birthday_channel_id'])).mention except: channel_name = "Not set. Run {0}setup to set.".format( _mongoFunctions.get_settings(ctx.guild.id)['prefix']) _embedMessage.add_field(birthday_embed, "Birthday Announcements Channel", channel_name, False) _embedMessage.add_field( birthday_embed, "Birthday Announcement Time", _mongoFunctions.get_settings(ctx.guild.id)['birthday_time'], False) _embedMessage.add_field( birthday_embed, "Birthday Role", _mongoFunctions.get_settings(ctx.guild.id)['birthday_role'], False) await ctx.channel.send(embed=birthday_embed) due_date_embed = _embedMessage.create("Due Date Settings", "Here are the due date settings.", "blue") _embedMessage.add_field( due_date_embed, "Due Dates Enabled?", _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled'], False) if _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled']: try: channel_name = ctx.guild.get_channel( int( _mongoFunctions.get_settings( ctx.guild.id)['due_date_channel_id'])).mention except: channel_name = "Not set. Run {0}setduedatechannel in a channel to set.".format( _mongoFunctions.get_settings(ctx.guild.id)['prefix']) _embedMessage.add_field(due_date_embed, "Due Date Channel", channel_name, False) _embedMessage.add_field( due_date_embed, "Streams", ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['streams']), False) _embedMessage.add_field( due_date_embed, "Courses", ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['courses']), False) _embedMessage.add_field( due_date_embed, "Due Date Types", ', '.join( _mongoFunctions.get_settings(ctx.guild.id)['due_date_types']), False) await ctx.channel.send(embed=due_date_embed) quote_embed = _embedMessage.create("Quote Settings", "Here are the quote settings.", "blue") _embedMessage.add_field( quote_embed, "Quote Reaction Emoji Name", _mongoFunctions.get_settings(ctx.guild.id)['reaction_emoji'], False) _embedMessage.add_field( quote_embed, "Required Quote Reactions for Approval", _mongoFunctions.get_settings(ctx.guild.id)['required_quote_reactions'], False) await ctx.channel.send(embed=quote_embed)
async def check_if_morning_announcement_occurred_today(client: discord.Client, guild_id: int, channel_id: int): last_announcement_time = _mongoFunctions.get_settings(guild_id)['last_announcement_time'] if last_announcement_time is None or (last_announcement_time.date() != date.today()): await send_morning_announcement(client, guild_id, channel_id)
async def set_settings(ctx: discord.Message, client: discord.Client, response_message: discord.Message, stop_embed: discord.embeds, check): while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should Birthday Announcements be Enabled (y/n)?", "blue")) try: birthday_announcements_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: birthday_announcements_string = birthday_announcements_message.content.lower( ) if birthday_announcements_string == 'next': break if birthday_announcements_string == 'stop': await ctx.channel.send(embed=stop_embed) return if birthday_announcements_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting( ctx.guild.id, "birthday_announcements_enabled", True) else: _mongoFunctions.update_setting( ctx.guild.id, "birthday_announcements_enabled", False) break await asyncio.sleep(0.5) if _mongoFunctions.get_settings( ctx.guild.id)["birthday_announcements_enabled"]: while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the birthday announcement channel?", "blue")) try: birthday_channel_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: birthday_channel_string = birthday_channel_message.content if birthday_channel_string.lower() == 'next': break if birthday_channel_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return birthday_channel_id = discord.utils.get( ctx.guild.channels, mention=birthday_channel_string).id _mongoFunctions.update_setting(ctx.guild.id, "birthday_channel_id", birthday_channel_id) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the birthday announcement time (HH:MM)? Most would do 00:00 here.", "blue")) try: birthday_time_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: birthday_time_string = birthday_time_message.content if birthday_time_string.lower() == 'next': break if birthday_time_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "birthday_time", birthday_time_string) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the birthday announcement role? (This role must be below BediBot's highest role. " "You may want to display this role separately from online members.)", "blue")) try: birthday_role_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: birthday_role_string = birthday_role_message.content if birthday_role_string.lower() == 'next': break if birthday_role_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "birthday_role", birthday_role_string) break
async def remove_due_date(ctx: discord.Message, client: discord.Client): # This command is almost identical to $addduedate. Reference comments in that file. global course, due_date_type, stream, time, title, year, month, day wait_timeout = 60.0 sleep_time = 2 if not (_checkrole.author_has_role(ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx)): await ctx.channel.send(embed = _embedMessage.create("RemoveDueDate Reply", "Invalid Permissions", "red")) return if not _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled']: await ctx.channel.send(embed = _embedMessage.create("RemoveDueDate Reply", "Due Dates are not enabled on this server.", "red")) return def check(message): return message.author == ctx.author and message.channel == ctx.channel response_message = await ctx.channel.send( embed = _embedMessage.create("RemoveDueDate Reply", "What course is this due date for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['courses']), "blue")) while True: await response_message.edit( embed = _embedMessage.create("RemoveDueDate Reply", "What course is this due date for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['courses']), "blue")) try: course_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: course = course_message.content if course not in _mongoFunctions.get_settings(ctx.guild.id)['courses']: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "The course name is invalid!", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit( embed = _embedMessage.create("RemoveDueDate Reply", "What is the due date type?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['due_date_types']), "blue")) try: due_date_type_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: due_date_type = due_date_type_message.content if due_date_type not in _mongoFunctions.get_settings(ctx.guild.id)['due_date_types']: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "The due date type is invalid!", "red")) await asyncio.sleep(sleep_time) else: break if len(_mongoFunctions.get_settings(ctx.guild.id)['streams']) == 1: stream = _mongoFunctions.get_settings(ctx.guild.id)['streams'][0] else: while True: await response_message.edit( embed = _embedMessage.create("RemoveDueDate Reply", "Which stream is this for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['streams']), "blue")) try: stream_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: stream = stream_message.content if stream not in _mongoFunctions.get_settings(ctx.guild.id)['streams']: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "The stream is invalid!", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit( embed = _embedMessage.create("RemoveDueDate Reply", "What is the title?", "blue")) try: title_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: title = title_message.content break while True: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "What is the date? (YYYY MM DD)", "blue")) try: date_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: global error_check date = date_message.content.split(" ") if len(date) == 3: year = date[0] month = date[1] day = date[2] error_check = _dateFunctions.check_for_errors_in_date(year, month, day) else: error_check = 1 if error_check == 1: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Invalid syntax. Make sure it is in the format YYYY MM DD", "red")) await asyncio.sleep(sleep_time) elif error_check == 2: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "The date is invalid, please ensure that this is a valid date.", "red")) await asyncio.sleep(sleep_time) else: date_object = datetime.date(int(year), int(month), int(day)) if date_object < datetime.date.today(): await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "That due date has already passed.", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "What time is the due date? (HH:MM)\nEnter 'None' if there is no time.", "blue")) try: time_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "You took too long to respond.", "red")) return else: time = time_message.content match = re.match('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$', time) # Using regex to check if time format is valid if time == "None": break elif not match: await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Invalid syntax. Make sure it is in the format HH:MM or 'None'", "red")) await asyncio.sleep(sleep_time) else: time = time.split(':') time_object = datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])) if time_object < datetime.datetime.now(): await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "That due date has already passed.", "red")) await asyncio.sleep(sleep_time) else: break if time == "None": if not _mongoFunctions.does_assignment_exist_already(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day)), False): await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Your due date does not exist!", "red")) return _mongoFunctions.remove_due_date_from_upcoming_due_dates(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day)), False) await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Your due date has been removed!", "blue")) else: if type(time) is str: time = time.split(':') if not _mongoFunctions.does_assignment_exist_already(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])), True): await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Your due date does not exist!", "red")) return _mongoFunctions.remove_due_date_from_upcoming_due_dates(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])), True) await response_message.edit(embed = _embedMessage.create("RemoveDueDate Reply", "Your due date has been removed!", "blue")) await _dueDateMessage.edit_due_date_message(client)
async def add_due_date(ctx: discord.Message, client: discord.Client): if not _mongoFunctions.is_user_id_linked_to_verified_user_in_guild(ctx.guild.id, ctx.author.id) and _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create("AddDueDate Reply", "Invalid Permissions", "red") await ctx.channel.send(embed = replyEmbed) return global course, due_date_type, stream, time, title, year, month, day # How long to wait for user response before timeout wait_timeout = 60.0 # How long (seconds) the user has to read the response before the next question is asked sleep_time = 3 if not _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled']: await ctx.channel.send(embed = _embedMessage.create("AddDueDate Reply", "Due Dates are not enabled on this server.", "red")) return # Checking function to determine if responses are sent by initial user in initial channel def check(message): return message.author == ctx.author and message.channel == ctx.channel response_message = await ctx.channel.send( embed = _embedMessage.create("AddDueDate Reply", "What course is this due date for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['courses']), "blue")) while True: await response_message.edit( embed = _embedMessage.create("AddDueDate Reply", "What course is this due date for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['courses']), "blue")) try: course_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: course = course_message.content if course not in _mongoFunctions.get_settings(ctx.guild.id)['courses']: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "The course name is invalid!", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit( embed = _embedMessage.create("AddDueDate Reply", "What is the due date type?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['due_date_types']), "blue")) try: due_date_type_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: due_date_type = due_date_type_message.content if due_date_type not in _mongoFunctions.get_settings(ctx.guild.id)['due_date_types']: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "The due date type is invalid!", "red")) await asyncio.sleep(sleep_time) else: break # Doesn't bother asking for stream if the server only has one stream configured if len(_mongoFunctions.get_settings(ctx.guild.id)['streams']) == 1: stream = _mongoFunctions.get_settings(ctx.guild.id)['streams'][0] else: while True: await response_message.edit( embed = _embedMessage.create("AddDueDate Reply", "Which stream is this for?\nOptions: " + ', '.join(_mongoFunctions.get_settings(ctx.guild.id)['streams']), "blue")) try: stream_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: stream = stream_message.content if stream not in _mongoFunctions.get_settings(ctx.guild.id)['streams']: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "The stream is invalid!", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit( embed = _embedMessage.create("AddDueDate Reply", "What is the title?", "blue")) try: title_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: title = title_message.content break while True: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "What is the date? (YYYY MM DD)", "blue")) try: date_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: global error_check date = date_message.content.split(" ") if len(date) == 3: year = date[0] month = date[1] day = date[2] error_check = _dateFunctions.check_for_errors_in_date(year, month, day) else: error_check = 1 if error_check == 1: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Invalid syntax. Make sure it is in the format YYYY MM DD", "red")) await asyncio.sleep(sleep_time) elif error_check == 2: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "The date is invalid, please ensure that this is a valid date.", "red")) await asyncio.sleep(sleep_time) else: date_object = datetime.date(int(year), int(month), int(day)) if date_object < datetime.date.today(): await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "That due date has already passed.", "red")) await asyncio.sleep(sleep_time) else: break while True: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "What time is the due date? (HH:MM)\nEnter 'None' if there is no time.", "blue")) try: time_message = await client.wait_for('message', timeout = wait_timeout, check = check) except asyncio.TimeoutError: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "You took too long to respond.", "red")) return else: time = time_message.content # Using regex to check if time format is valid match = re.match('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$', time) if time == "None": break elif not match: await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Invalid syntax. Make sure it is in the format HH:MM or 'None'", "red")) await asyncio.sleep(sleep_time) else: time = time.split(':') time_object = datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])) if time_object < datetime.datetime.now(): await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "That due date has already passed.", "red")) await asyncio.sleep(sleep_time) else: break if time == "None": if _mongoFunctions.does_assignment_exist_already(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day)), False): await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Your due date already exists!", "red")) return _mongoFunctions.add_due_date_to_upcoming_due_dates(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day)), False) await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Your due date has been added!", "blue")) else: # Since its possible that the time object was already turned into a list, we do this check to only convert it to a list if its a string if type(time) is str: time = time.split(':') if _mongoFunctions.does_assignment_exist_already(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])), True): await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Your due date already exists!", "red")) return _mongoFunctions.add_due_date_to_upcoming_due_dates(ctx.guild.id, course, due_date_type, title, stream, datetime.datetime(int(year), int(month), int(day), int(time[0]), int(time[1])), True) await response_message.edit(embed = _embedMessage.create("AddDueDate Reply", "Your due date has been added!", "blue")) await _dueDateMessage.edit_due_date_message(client)
async def set_settings(ctx: discord.Message, client: discord.Client, response_message: discord.Message, stop_embed: discord.embeds, check): while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should Verification be Enabled (y/n)?", "blue")) try: verification_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: verification_string = verification_message.content.lower() if verification_string == 'next': break if verification_string == 'stop': await ctx.channel.send(embed=stop_embed) return if verification_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting(ctx.guild.id, "verification_enabled", True) else: _mongoFunctions.update_setting(ctx.guild.id, "verification_enabled", False) break await asyncio.sleep(0.5) if _mongoFunctions.get_settings(ctx.guild.id)["verification_enabled"]: while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the verified role?", "blue")) try: verified_role_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: verified_role_string = verified_role_message.content if verified_role_string.lower() == 'next': break if verified_role_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "verified_role", verified_role_string) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the verification email domain? (E.g. @uwaterloo.ca)", "blue")) try: email_domain_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: email_domain = email_domain_message.content if email_domain.lower() == 'next': break if email_domain.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "email_domain", email_domain) break
async def confirm(ctx: discord.Message, client: discord.Client): if not _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create( "Confirm Reply", "Verification is not enabled on this server!", "red") await ctx.channel.send(embed=replyEmbed) return # Verified users can't run $confirm. They are already verified (duh) if _mongoFunctions.is_user_id_linked_to_verified_user_in_guild( ctx.guild.id, ctx.author.id): replyEmbed = _embedMessage.create("Confirm Reply", "Invalid Permissions", "red") await ctx.channel.send(embed=replyEmbed) return message_contents = _util.parse_message(ctx.content) if len(message_contents) != 2: await ctx.channel.send(embed=_embedMessage.create( "Confirm Reply", "The syntax is invalid! Make sure it is in the format $confirm <confirmcode>", "red")) return uw_id = _mongoFunctions.get_uw_id_from_pending_user_id( ctx.guild.id, ctx.author.id) if uw_id is None: await ctx.channel.send(embed=_embedMessage.create( "Confirm Reply", "You have not run $verify yet!", "red")) return unique_key = message_contents[1] if unique_key == _email.verificationCodes.get(ctx.author.id): # Removing this stuff since V2 API is deprecated # department = uw_driver.directory_people_search(uw_id)['department'] # if department == "ENG/Mechanical & Mechatronics": # await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name = "Tron")) # else: # await ctx.author.add_roles(discord.utils.get(ctx.guild.roles, name = "Not Tron")) await ctx.author.add_roles( discord.utils.get(ctx.guild.roles, name=_mongoFunctions.get_settings( ctx.guild.id)['verified_role'])) _mongoFunctions.add_user_to_verified_users( ctx.guild.id, ctx.author.id, _hashingFunctions.hash_user_id(uw_id)) _mongoFunctions.remove_user_from_pending_verification_users( ctx.guild.id, ctx.author.id) reply_embed = _embedMessage.create("Confirm reply", "You have been verified", "blue") await ctx.channel.send(embed=reply_embed) await ctx.author.send(embed=reply_embed) else: await ctx.channel.send( embed=_embedMessage.create("Confirm reply", "Invalid Code!", "red") )
async def set_settings(ctx: discord.Message, client: discord.Client, response_message: discord.Message, stop_embed: discord.embeds, check): while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should Morning Announcements be Enabled (y/n)?", "blue")) try: morning_announcements_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: morning_announcements_string = morning_announcements_message.content.lower( ) if morning_announcements_string == 'next': break if morning_announcements_string == 'stop': await ctx.channel.send(embed=stop_embed) return if morning_announcements_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting( ctx.guild.id, "morning_announcements_enabled", True) else: _mongoFunctions.update_setting( ctx.guild.id, "morning_announcements_enabled", False) break await asyncio.sleep(0.5) if _mongoFunctions.get_settings( ctx.guild.id)["morning_announcements_enabled"]: while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the morning announcement channel?", "blue")) try: announcement_channel_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: announcement_channel_string = announcement_channel_message.content if announcement_channel_string.lower() == 'next': break if announcement_channel_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return announcement_channel_id = discord.utils.get( ctx.guild.channels, mention=announcement_channel_string).id _mongoFunctions.update_setting(ctx.guild.id, "announcement_channel_id", announcement_channel_id) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the morning announcement time (HH:MM)?", "blue")) try: announcement_time_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: announcement_time_string = announcement_time_message.content if announcement_time_string.lower() == 'next': break if announcement_time_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "announcement_time", announcement_time_string) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should the quote be random (y/n)?", "blue")) try: random_quote_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: random_quote_string = random_quote_message.content.lower() if random_quote_string == 'next': break if random_quote_string == 'stop': await ctx.channel.send(embed=stop_embed) return if random_quote_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting(ctx.guild.id, "random_quote", True) else: _mongoFunctions.update_setting(ctx.guild.id, "random_quote", False) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Who should be quoted in the morning announcement?", "blue")) try: announcement_quoted_person_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: announcement_quoted_person = announcement_quoted_person_message.content if announcement_quoted_person.lower() == 'next': break if announcement_quoted_person.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "announcement_quoted_person", announcement_quoted_person) break
async def help_command(ctx: discord.Message, client: discord.Client): commandPrefix2 = _mongoFunctions.get_settings(ctx.guild.id)['prefix'] help_embed = _embedMessage.create("General Commands", "Commands that can be run with BediBot. Each word represents an argument.", "green") _embedMessage.add_field(help_embed, commandPrefix2 + "help", "Allows you to view commands!", False) _embedMessage.add_field(help_embed, commandPrefix2 + "ping", "Returns Pong and some bot stats.", False) _embedMessage.add_field(help_embed, commandPrefix2 + "GitHub", "Shows the GitHub repository link", False) _embedMessage.add_field(help_embed, commandPrefix2 + "addquote \"quote with spaces\" Name", "Adds a quote from the individual of your choice\nEx: " + commandPrefix2 + "addquote \"Life is Good\" Bedi", False) _embedMessage.add_field(help_embed, commandPrefix2 + "getquotes person pagenumber", "Gets a persons quotes with a page number, with each page containing 5 quotes. Page number argument is optional.\nEx: " + commandPrefix2 + "getquotes Bedi 2", False) _embedMessage.add_field(help_embed, commandPrefix2 + "getrandomquote name", "Gets a random quote from a random or specified person. Name is optional.\nEx: " + commandPrefix2 + "getrandomquote Bedi", False) await ctx.channel.send(embed = help_embed) if _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: verification_embed = _embedMessage.create("Verification Commands", "Commands related to verification.", "green") _embedMessage.add_field(verification_embed, commandPrefix2 + "verify userID{0}".format(_mongoFunctions.get_settings(ctx.guild.id)['email_domain']), "Allows you to verify yourself as a UWaterloo Student and access the server\nEx: " + commandPrefix2 + "verify g0ose{0}".format( _mongoFunctions.get_settings(ctx.guild.id)['email_domain']), False) _embedMessage.add_field(verification_embed, commandPrefix2 + "unverify", "Unverifies you from the server.", False) _embedMessage.add_field(verification_embed, commandPrefix2 + "confirm code", "Allows you to enter in your 2FA verification code after you run the verify command\nEx: " + commandPrefix2 + "confirm 123456789", False) await ctx.channel.send(embed = verification_embed) if _mongoFunctions.get_settings(ctx.guild.id)['birthday_announcements_enabled']: birthday_embed = _embedMessage.create("Birthday Commands", "Commands related to birthdays.", "green") _embedMessage.add_field(birthday_embed, commandPrefix2 + "getbirthdays monthnumber", "Gets all birthdays for the specified month\nEx: " + commandPrefix2 + "getbirthdays 5", False) _embedMessage.add_field(birthday_embed, commandPrefix2 + "setbirthday YYYY MM DD", "Allows you to set your birthday and let the server know when to embarrass you :D\nEx: " + commandPrefix2 + "setbirthday 2001 01 01", False) await ctx.channel.send(embed = birthday_embed) if _mongoFunctions.get_settings(ctx.guild.id)['due_dates_enabled']: due_date_embed = _embedMessage.create("Due Date Commands", "Commands related to due dates.", "green") _embedMessage.add_field(due_date_embed, commandPrefix2 + "addduedate", "Add's an assignment's due date to be counted down to\nEx: " + commandPrefix2 + "addduedate", False) await ctx.channel.send(embed = due_date_embed) if _checkrole.author_has_role(ctx, _mongoFunctions.get_settings(ctx.guild.id)['admin_role']) or _util.author_is_bot_owner(ctx): admin_embed = _embedMessage.create("Admin Commands", "Commands that can only be run by those with the admin role.", "green") _embedMessage.add_field(admin_embed, commandPrefix2 + "removequote \"quote with spaces\" Name", "Removes a quote from the individual of your choice\nEx: " + commandPrefix2 + "removequote \"Life is Good\" Bedi", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "adminverify @Mention", "Manually verifies a user.\nEx: " + commandPrefix2 + "adminverify " + client.user.mention, False) _embedMessage.add_field(admin_embed, commandPrefix2 + "purge number_of_messages", "Purges a specified amount of messages in the channel that the command is executed in.\nEx: " + commandPrefix2 + "purge 10", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "removeduedate", "Remove's a due date\nEx: " + commandPrefix2 + "removeduedate", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "lockdown role", "Sets send message permissions to false for specified role in the current channel." "If role is not specified. Channel will be locked for all possible roles.\nEx: " + commandPrefix2 + "lockdown " + "Tron", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "unlock role", "Sets send message permissions to True for specified role." "If role is not specified. Channel will be unlocked for all possible roles.\nEx: " + commandPrefix2 + "unlock " + "Tron", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "say title content channel", "Sends a message inside an embed to the specified channel\nEx: " + commandPrefix2 + "say Hello world " + ctx.channel.mention, False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setduedatechannel", "Sets the channel which will be used for due dates\n**WARNING**: This clears the channel's history. Use with caution.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "settings", "Displays the guild's settings", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setup", "Command used to setup initial guild settings or change any settings.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setupannouncement", "Command used to setup initial guild settings or change all settings at once.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setupbirthdays", "Command used to setup birthday settings.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setupduedates", "Command used to setup due date settings.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setupquotes", "Command used to setup quote settings.", False) _embedMessage.add_field(admin_embed, commandPrefix2 + "setupverification", "Command used to setup verification settings.", False) await ctx.channel.send(embed = admin_embed)
async def set_settings(ctx: discord.Message, client: discord.Client, response_message: discord.Message, stop_embed: discord.embeds, check): while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should Due Dates be Enabled (y/n)?", "blue")) try: due_dates_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: due_dates_string = due_dates_message.content.lower() if due_dates_string == 'next': break if due_dates_string == 'stop': await ctx.channel.send(embed=stop_embed) return if due_dates_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting(ctx.guild.id, "due_dates_enabled", True) else: _mongoFunctions.update_setting(ctx.guild.id, "due_dates_enabled", False) break if _mongoFunctions.get_settings(ctx.guild.id)["due_dates_enabled"]: while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Which streams require due dates? (Must be integers separated by spaces." "E.g. 4 8)", "blue")) try: streams_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: streams_string = streams_message.content if streams_string.lower() == 'next': break if streams_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return streams = streams_string.split(' ') _mongoFunctions.update_setting(ctx.guild.id, "streams", streams) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What are the term's courses. (Or other deadline categories). " "(Must be strings separated by spaces. " "Use quotes around courses made of multiple words) " "E.g. \"MATH 115\" Physics)", "blue")) try: courses_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: courses_string = courses_message.content if courses_string.lower() == 'next': break if courses_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return courses = _util.parse_message(courses_string) _mongoFunctions.update_setting(ctx.guild.id, "courses", courses) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What are the due date types. " "(Must be strings separated by spaces. " "E.g. Assignment Test Quiz Exam Project Other)", "blue")) try: due_date_types_message = await client.wait_for( 'message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: due_date_types_string = due_date_types_message.content if due_date_types_string.lower() == 'next': break if due_date_types_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return due_date_types = due_date_types_string.split(' ') _mongoFunctions.update_setting(ctx.guild.id, "due_date_types", due_date_types) break
async def setup(ctx: discord.Message, client: discord.Client): # How long to wait for user response before timeout wait_timeout = 60.0 stop_embed = _embedMessage.create("Setup Reply", "Setup Stopped", "green") # Checks if user is admin or bot owner if not (ctx.author.guild_permissions.administrator or _util.author_is_bot_owner(ctx)): await ctx.channel.send(embed=_embedMessage.create( "Setup Reply", "Invalid Permissions", "red")) return try: _mongoFunctions.get_guilds_information()[str(ctx.guild.id)] except KeyError: _mongoFunctions.generate_default_settings(ctx.guild.id) # Checking function to determine if responses are sent by initial user in initial channel def check(message): return message.author == ctx.author and message.channel == ctx.channel response_message = await ctx.channel.send(embed=_embedMessage.create( "Setup Reply", "What should the prefix be (Default: $)? For any of these settings, if you wish to keep the current setting, type 'next'. " "If you wish to stop the command at any time, type 'stop'.", "blue")) while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What should the prefix be (Default: $)? For any of these settings, " "if you wish to keep the current setting, type 'next'.", "blue")) try: prefix_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: prefix = prefix_message.content if prefix.lower() == 'next': break if prefix.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "prefix", prefix) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "What is the admin role?", "blue")) try: admin_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: admin_role_string = admin_message.content if admin_role_string.lower() == 'next': break if admin_role_string.lower() == 'stop': await ctx.channel.send(embed=stop_embed) return _mongoFunctions.update_setting(ctx.guild.id, "admin_role", admin_role_string) break while True: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "Should reaction pinning be enabled (y/n)?", "blue") ) try: pinning_message = await client.wait_for('message', timeout=wait_timeout, check=check) except asyncio.TimeoutError: await response_message.edit(embed=_embedMessage.create( "Setup Reply", "You took too long to respond.", "red")) return else: pinning_string = pinning_message.content.lower() if pinning_string == 'next': break if pinning_string == 'stop': await ctx.channel.send(embed=stop_embed) return if pinning_string in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): _mongoFunctions.update_setting(ctx.guild.id, "pins_enabled", True) else: _mongoFunctions.update_setting(ctx.guild.id, "pins_enabled", False) break await setupverification.set_settings(ctx, client, response_message, stop_embed, check) await setupannouncement.set_settings(ctx, client, response_message, stop_embed, check) await setupbirthdays.set_settings(ctx, client, response_message, stop_embed, check) await setupduedates.set_settings(ctx, client, response_message, stop_embed, check) await setupquotes.set_settings(ctx, client, response_message, stop_embed, check) await ctx.channel.send(embed=_embedMessage.create( "Setup Reply", "Guild has been setup. Make sure to run {0}setduedatechannel in a view-only channel if needed." .format(_mongoFunctions.get_settings(ctx.guild.id)['prefix']), "blue")) await settings(ctx, client)
async def verify(ctx: discord.Message, client: discord.Client): await ctx.delete() if not _mongoFunctions.get_settings(ctx.guild.id)['verification_enabled']: replyEmbed = _embedMessage.create( "Verify Reply", "Verification is not enabled on this server!", "red") await ctx.channel.send(embed=replyEmbed) return # This checks if the user is verified in the current guild if _mongoFunctions.is_user_id_linked_to_verified_user_in_guild( ctx.guild.id, ctx.author.id): replyEmbed = _embedMessage.create( "Verify Reply", "Invalid Permissions - you are already verified! Run $unverify if you need to reverify yourself here.", "red") await ctx.channel.send(embed=replyEmbed) return # Checks if the user is verified in ANY guild with the same verification email domain if _mongoFunctions.is_user_id_linked_to_verified_user_anywhere( ctx.guild.id, ctx.author.id): user_doc = _mongoFunctions.get_user_doc_from_verified_user_id( ctx.guild.id, ctx.author.id) _mongoFunctions.add_user_to_verified_users(ctx.guild.id, ctx.author.id, user_doc['uw_id']) await ctx.author.add_roles( discord.utils.get(ctx.guild.roles, name=_mongoFunctions.get_settings( ctx.guild.id)['verified_role'])) replyEmbed = _embedMessage.create( "Verify Reply", "You are already verified on another server, so you've been automatically verified.", "blue") await ctx.channel.send(embed=replyEmbed) await ctx.author.send(embed=replyEmbed) return message_contents = ctx.content.split(" ") if len(message_contents) != 2: await ctx.channel.send(embed=_embedMessage.create( "Verify Reply", "The syntax is invalid! Make sure it is in the format $verify <emailaddress>", "red")) return email_address = message_contents[1] match = re.match( '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email_address) and email_address.endswith( _mongoFunctions.get_settings(ctx.guild.id)['email_domain']) uw_id = email_address[:email_address.rfind('@')] if not match: await ctx.channel.send( embed=_embedMessage.create("Verify Reply", "Invalid email!", "red") ) return # Commenting these lines since the V2 API will be deprecated # if uw_driver.directory_people_search(uw_id) == {}: # await ctx.channel.send(embed = _embedMessage.create("Verify Reply", "That's not a valid uWaterloo email!", "red")) # return # uw_id = uw_driver.directory_people_search(uw_id)['user_id'] if _mongoFunctions.is_uw_id_linked_to_verified_user(ctx.guild.id, uw_id): await ctx.channel.send(embed=_embedMessage.create( "Verify Reply", "That email is already linked to a user!", "red")) return if _mongoFunctions.is_uw_id_linked_to_pending_verification_user( ctx.guild.id, uw_id): await ctx.channel.send(embed=_embedMessage.create( "Verify Reply", "Someone is already using that email to verify! If this is an error, contact an admin", "red")) return _email.send_confirmation_email(email_address, ctx.author.id) _mongoFunctions.add_user_to_pending_verification_users( ctx.guild.id, ctx.author.id, uw_id) await ctx.channel.send(embed=_embedMessage.create( "Verify Reply", "Verification Email sent!", "blue"))