diff --git a/bot/__main__.py b/bot/__main__.py index cfdf28d..d81e269 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -6,6 +6,7 @@ import discord intents = discord.Intents.default() intents.members = True +intents.message_content = True from discord.ext import commands from bot.baconpatroll_cog import BaconpaTrollCog @@ -51,7 +52,7 @@ async def process_commands(self, message): await self.invoke(ctx) -def main(): +async def main(): parser = argparse.ArgumentParser() parser.add_argument("--debug", action="store_true") parser.add_argument("--config", help="JSON file containing the required configuration", @@ -61,14 +62,10 @@ def main(): with open(args.config, "rb") as f: settings = json.load(f) - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - gvrd_grunt = BadBot( command_prefix=commands.when_mentioned_or(settings["command_prefix"]), case_insensitive=True, description="A grunt worker for the GVRD servers' needs", - loop=loop, intents=intents, ) @@ -109,9 +106,9 @@ def main(): # These have been converted to check bot perms under the new scheme. logging_cog = GuildLoggingCog(gvrd_grunt, logging_db, bot_perms_db) - gvrd_grunt.add_cog(logging_cog) - gvrd_grunt.add_cog(BotPermsCog(gvrd_grunt, bot_perms_db)) - gvrd_grunt.add_cog( + await gvrd_grunt.add_cog(logging_cog) + await gvrd_grunt.add_cog(BotPermsCog(gvrd_grunt, bot_perms_db)) + await gvrd_grunt.add_cog( RaidFYICog( gvrd_grunt, raid_fyi_db, @@ -127,20 +124,16 @@ def main(): logging_cog=logging_cog, ) ) - gvrd_grunt.add_cog(VerificationCog(gvrd_grunt, verification_db, bot_perms_db)) + await gvrd_grunt.add_cog(VerificationCog(gvrd_grunt, verification_db, bot_perms_db)) # These are the old-style cogs. - gvrd_grunt.add_cog(EXGateCog(gvrd_grunt, ex_db, logging_cog=logging_cog)) - gvrd_grunt.add_cog(RoleReactionSubscriptionCog(gvrd_grunt, role_reaction_subscription_db, logging_cog=logging_cog)) - gvrd_grunt.add_cog(BaconpaTrollCog(gvrd_grunt)) - gvrd_grunt.add_cog(NoCommandSubscriptionCog(gvrd_grunt, no_command_subscription_db, logging_cog=logging_cog)) - gvrd_grunt.add_cog(RoleSetOperationsCog(gvrd_grunt)) - gvrd_grunt.add_cog(PurgeChannelsCog(gvrd_grunt)) - gvrd_grunt.add_cog(RoleReminderCog(gvrd_grunt, role_reminder_db, logging_cog=logging_cog)) - - - # For testing only -- *do not install on a production bot!* - # gvrd_grunt.add_cog(SpamCog()) + await gvrd_grunt.add_cog(EXGateCog(gvrd_grunt, ex_db, logging_cog=logging_cog)) + await gvrd_grunt.add_cog(RoleReactionSubscriptionCog(gvrd_grunt, role_reaction_subscription_db, logging_cog=logging_cog)) + await gvrd_grunt.add_cog(BaconpaTrollCog(gvrd_grunt)) + await gvrd_grunt.add_cog(NoCommandSubscriptionCog(gvrd_grunt, no_command_subscription_db, logging_cog=logging_cog)) + await gvrd_grunt.add_cog(RoleSetOperationsCog(gvrd_grunt)) + await gvrd_grunt.add_cog(PurgeChannelsCog(gvrd_grunt)) + await gvrd_grunt.add_cog(RoleReminderCog(gvrd_grunt, role_reminder_db, logging_cog=logging_cog)) @gvrd_grunt.event async def on_command_error(ctx, error): @@ -169,8 +162,9 @@ async def on_command_error(ctx, error): logging.getLogger("discord").setLevel(logging.WARNING) logging.getLogger("websockets.protocol").setLevel(logging.INFO) - gvrd_grunt.run(settings["token"], bot=True) + async with gvrd_grunt: + await gvrd_grunt.start(settings["token"]) if __name__ == "__main__": - main() + asyncio.run(main()) diff --git a/bot/bot_perms_cog.py b/bot/bot_perms_cog.py index 9b17aca..31e71f8 100644 --- a/bot/bot_perms_cog.py +++ b/bot/bot_perms_cog.py @@ -25,7 +25,7 @@ def can_configure_bot(self, ctx): :param ctx: :return: """ - caller_permissions = ctx.author.permissions_in(ctx.channel) + caller_permissions = ctx.channel.permissions_for(ctx.author) if caller_permissions.administrator: return True diff --git a/bot/raid_fyi_cog.py b/bot/raid_fyi_cog.py index f6557fd..40e5f89 100644 --- a/bot/raid_fyi_cog.py +++ b/bot/raid_fyi_cog.py @@ -786,9 +786,9 @@ async def deactivate_fyi( if cancellation: # Strike out any relay messages that are remaining. - for relay_message in [x for x in [relay_message, chat_relay_message] if x is not None]: - prior_content = relay_message.content - await relay_message.edit(content="~~{}~~".format(prior_content)) + for relay_msg in [x for x in [relay_message, chat_relay_message] if x is not None]: + prior_content = relay_msg.content + await relay_msg.edit(content="~~{}~~".format(prior_content)) # Add the guild's "cancelled" emoji to any messages that are remaining. for fyi_message in [x for x in [command_message, relay_message, chat_relay_message] if x is not None]: diff --git a/bot/role_set_operations_cog.py b/bot/role_set_operations_cog.py index 68989e0..bac4dcb 100644 --- a/bot/role_set_operations_cog.py +++ b/bot/role_set_operations_cog.py @@ -2,7 +2,7 @@ from discord.ext.commands import command, has_permissions, Cog import discord import asyncio -from datetime import datetime +from datetime import datetime, timezone from bot.convert_using_guild import role_converter_from_name @@ -134,8 +134,8 @@ def evaluate_role_statement(self, guild, role_statement, start_datetime_str=None result = parser.parseString(role_statement) if start_datetime_str is not None and end_datetime_str is not None: - start_datetime = datetime.strptime(start_datetime_str, "%Y-%m-%dT%H:%M:%S") - end_datetime = datetime.strptime(end_datetime_str, "%Y-%m-%dT%H:%M:%S") + start_datetime = datetime.strptime(start_datetime_str, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=timezone.utc) + end_datetime = datetime.strptime(end_datetime_str, "%Y-%m-%dT%H:%M:%S").replace(tzinfo=timezone.utc) members_list = [x for x in result[0] if start_datetime <= x.joined_at <= end_datetime] else: members_list = result[0] diff --git a/bot/verification_cog.py b/bot/verification_cog.py index 6105154..f84cfbb 100644 --- a/bot/verification_cog.py +++ b/bot/verification_cog.py @@ -682,7 +682,7 @@ async def on_reaction_add(self, reaction, user): reacting_member = reaction.message.guild.get_member(user.id) if reacting_member == reaction.message.guild.get_member(self.bot.user.id): return - reactor_permissions = reacting_member.permissions_in(reaction.message.channel) + reactor_permissions = reaction.message.channel.permissions_for(reacting_member) if not reactor_permissions.manage_roles or not reactor_permissions.manage_nicknames: return if reaction.message not in self.screenshot_to_member: diff --git a/bot/verification_db.py b/bot/verification_db.py index 4a92b8a..25522d9 100644 --- a/bot/verification_db.py +++ b/bot/verification_db.py @@ -102,7 +102,7 @@ def set_channel(self, guild, channel: discord.TextChannel, type): :return: """ if type not in ("screenshot", "help"): - raise discord.InvalidArgument('channel type must be one of "screenshot", or "help"') + raise ValueError('channel type must be one of "screenshot", or "help"') self.table.update_item( Key={"guild_id": guild.id}, UpdateExpression=f"SET {type}_channel = :channel", @@ -139,13 +139,13 @@ def set_welcome_role(self, guild, welcome_role: discord.Role): def team_name_validator(self, team): """ - Raises discord.InvalidArgument if team is not one of "instinct", "mystic", or "valor", case-insensitive. + Raises ValueError if team is not one of "instinct", "mystic", or "valor", case-insensitive. :param team: :return: """ if team.lower() not in self.TEAMS: - raise discord.InvalidArgument('team must be one of "instinct", "mystic", or "valor" (case-insensitive)') + raise ValueError('team must be one of "instinct", "mystic", or "valor" (case-insensitive)') def set_team_role(self, guild, team, role: discord.Role): """ diff --git a/requirements.txt b/requirements.txt index db1a27b..5768371 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ # yarl == 1.1.1 # seems to break otherwise # multidict == 4.5.2 # subsequent versions break as of Nov 23, 2019 -discord.py == 1.6.0 +discord.py == 2.1.0 pyparsing awscli boto3