From ffda1f7069065fd4ce2b2fe781fbcb5793406f99 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Tue, 31 Aug 2021 15:01:10 +0200 Subject: Migrate to Discord.py 2.0a0 Since the Discord.py repository has been archived, we can switch to the latest commit of 2.0a0, knowing no breaking change will occur (still pinned to the commit just in case). This commit also solves two small problems due to that fix, the avatar interface changing and Embed.name disappearing. Quite a painless migration. --- bot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index b8de97aa..8e82d0c4 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -120,7 +120,7 @@ class Bot(commands.Bot): return if not icon: - icon = self.user.avatar_url_as(format="png") + icon = self.user.display_avatar.url embed = Embed(description=details) embed.set_author(name=title, icon_url=icon) -- cgit v1.2.3 From 9c02adc04a7949b1ed8a979420e513531d46e384 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Tue, 31 Aug 2021 15:10:01 +0200 Subject: Trigger the bot on mentions Since it is the only way to add bots to threads, it would make sense to be able to execute that command. --- bot/bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 8e82d0c4..b877233e 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -8,6 +8,7 @@ from aiohttp import AsyncResolver, ClientSession, TCPConnector from async_rediscache import RedisSession from discord import DiscordException, Embed from discord.ext import commands +from discord.ext.commands import when_mentioned_or from bot import constants @@ -203,7 +204,7 @@ loop.run_until_complete(redis_session.connect()) bot = Bot( redis_session=redis_session, - command_prefix=constants.Client.prefix, + command_prefix=when_mentioned_or(constants.Client.prefix), activity=discord.Game(name=f"Commands: {constants.Client.prefix}help"), allowed_mentions=discord.AllowedMentions(everyone=False, roles=_allowed_roles), intents=_intents, -- cgit v1.2.3 From 3f90389d76b4666868cbb24e7958d5cf236207c5 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Tue, 31 Aug 2021 15:23:26 +0200 Subject: Make the bot automatically join threads This is just a QoL of life thing, avoiding having us to check if the bot is here or not before issuing a command Co-authored-by: ChrisJL --- bot/bot.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index b877233e..c7b87a65 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,14 +1,15 @@ import asyncio import logging import socket +from contextlib import suppress from typing import Optional import discord from aiohttp import AsyncResolver, ClientSession, TCPConnector from async_rediscache import RedisSession -from discord import DiscordException, Embed +from discord import DiscordException, Embed, Forbidden, Thread from discord.ext import commands -from discord.ext.commands import when_mentioned_or +from discord.ext.commands import Cog, when_mentioned_or from bot import constants @@ -46,6 +47,21 @@ class Bot(commands.Bot): return None return guild.me + @Cog.listener() + async def on_thread_join(self, thread: Thread) -> None: + """ + Try to join newly created threads. + + Despite the event name being misleading, this is dispatched when new threads are created. + We want our bots to automatically join threads in order to answer commands using their prefixes. + """ + if thread.me: + # Already in this thread, return early + return + + with suppress(Forbidden): + await thread.join() + async def close(self) -> None: """Close Redis session when bot is shutting down.""" await super().close() -- cgit v1.2.3