async def setup_birthdays(ctx: discord.Message, client: discord.Client): stop_embed = _embedMessage.create("SetupBirthdays 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( "SetupBirthdays 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( "SetupBirthdays Reply", "Should Birthday Announcements be Enabled (y/n)?", "blue")) await set_settings(ctx, client, response_message, stop_embed, check) await ctx.channel.send(embed=_embedMessage.create( "SetupBirthdays Reply", "Birthdays Setup has been Completed", "blue"))
async def setup_quotes(ctx: discord.Message, client: discord.Client): stop_embed = _embedMessage.create("SetupQuotes 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( "SetupQuotes 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( "SetupQuotes Reply", "What is the quote reaction emoji name? " "(Must be a custom emoji, enter the name without the : characters)", "blue")) await set_settings(ctx, client, response_message, stop_embed, check) await ctx.channel.send(embed=_embedMessage.create( "SetupQuotes Reply", "Quotes Setup has been Completed", "blue"))
async def edit_due_date_message(client: discord.Client): guild_list = _mongoFunctions.get_guilds_information() for guild_dict in guild_list: guild_id = guild_list[guild_dict]['guild_id'] # Updates due dates if due dates are enabled if guild_list[guild_dict]['due_dates_enabled']: update_due_dates(guild_id) guild_object = client.get_guild(guild_id) courses = guild_list[guild_dict]['courses'] channel_id = guild_list[guild_dict]['due_date_channel_id'] try: channel = guild_object.get_channel(channel_id) for stream in guild_list[guild_dict]['streams']: try: await edit_due_date_embed(stream, courses, guild_id, guild_object, channel_id) except: print("Error in edit_schedule_embed") print("server id: " + str(guild_dict)) except: print("Error in edit_schedule_embed") print("server id: " + str(guild_dict))
async def schedule_jobs(client): guild_list = _mongoFunctions.get_guilds_information() for guild in guild_list: guild_id = guild['guild_id'] channel_id = guild['channel_id'] guild_timezone = guild['timezone'] scheduler.add_job(_util.purge_messages_in_channel, 'cron', hour=23, minute=59, second=0, timezone=guild_timezone, args=[client, guild_id, channel_id]) birthday_time = _mongoFunctions.get_birthday_time(guild_id).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, channel_id]) announcement_time = _mongoFunctions.get_announcement_time( guild_id).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, channel_id]) 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, channel_id]) scheduler.add_job(_dueDateMessage.edit_due_date_message, 'interval', minutes=1, args=[client]) scheduler.start()
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 edit_due_date_message(client): guild_list = _mongoFunctions.get_guilds_information() for guild in guild_list: global guild_id, channel_id for key, value in guild.items(): if key == 'guild_id': guild_id = value if key == 'channel_id': channel_id = value update_due_dates(guild_id) guild = client.get_guild(guild_id) courses = _mongoFunctions.get_list_of_courses(guild_id) for stream in _mongoFunctions.get_list_of_streams(guild_id): await edit_schedule_embed(stream, courses, guild_id, guild, channel_id)
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)