Implement webhook support for message replies and enhance reaction handling

This commit is contained in:
Edgar P. Burkhart 2025-03-22 17:01:57 +01:00
parent 5c7a6f8ab0
commit 93077e7d49
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -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"))