From 93077e7d4942e06e32924db7c4bd17ffa429457e Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" <git@edgarpierre.fr> Date: Sat, 22 Mar 2025 17:01:57 +0100 Subject: [PATCH] Implement webhook support for message replies and enhance reaction handling --- botbotbot/__main__.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/botbotbot/__main__.py b/botbotbot/__main__.py index d3dd071..237296f 100644 --- a/botbotbot/__main__.py +++ b/botbotbot/__main__.py @@ -60,9 +60,18 @@ async def reply(message): f"{random.choice(word_list)}", ) ) - fct = random.choice((message.reply, message.channel.send)) - await fct(content) + if random.random() < 0.1: + await send_as_webhook( + message.channel, + message.author.display_name, + message.author.avatar.url, + content, + ) + else: + fct = random.choice((message.reply, message.channel.send)) + + await fct(content) async def ai_reply(message): @@ -82,6 +91,8 @@ async def ai_reply(message): async def react(message: discord.Message) -> None: + if message.guild is None: + return await message.add_reaction(random.choice(message.guild.emojis)) @@ -301,4 +312,22 @@ async def chan(ctx, file: discord.Attachment): logger.info("FIN CHAN") +async def send_as_webhook( + channel: discord.TextChannel, + name: str, + avatar_url: str, + content: str, + embed: discord.Embed = None, +): + webhooks = await channel.webhooks() + webhook = discord.utils.get(webhooks, name="BotbotbotHook") + + if webhook is None: + webhook = await channel.create_webhook(name="BotbotbotHook") + + await webhook.send( + content=content, username=name, avatar_url=avatar_url, embed=embed + ) + + bot.run(config.get("token"))