Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to discord.py v2.1.0 #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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())
2 changes: 1 addition & 1 deletion bot/bot_perms_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions bot/raid_fyi_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions bot/role_set_operations_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion bot/verification_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions bot/verification_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down