Enhance reaction handling in TextBot to support removal of reactions and improve logging for reaction events
This commit is contained in:
parent
2027e02cf4
commit
07613ed4cb
1 changed files with 28 additions and 3 deletions
|
@ -34,6 +34,7 @@ class TextBot:
|
|||
def init_events(self) -> None:
|
||||
self.bot.add_listener(self.on_message, "on_message")
|
||||
self.bot.add_listener(self.add_more_reaction, "on_reaction_add")
|
||||
self.bot.add_listener(self.add_more_reaction, "on_reaction_remove")
|
||||
self.bot.add_listener(self.react_message_edit, "on_message_edit")
|
||||
self.bot.add_listener(self.rando_shuffle, "on_message")
|
||||
self.bot.add_application_command(
|
||||
|
@ -140,6 +141,9 @@ class TextBot:
|
|||
await message.reply(answer)
|
||||
|
||||
async def react(self, message: discord.Message) -> None:
|
||||
logger.info(
|
||||
f"React to message from <{message.author}> in channel <{message.channel}>."
|
||||
)
|
||||
emojis: tuple[str | discord.Emoji, ...] = self.uni_emojis
|
||||
if message.guild is not None and random.random() < 50 / 100:
|
||||
emojis = message.guild.emojis
|
||||
|
@ -165,9 +169,30 @@ class TextBot:
|
|||
async def add_more_reaction(
|
||||
self, reaction: discord.Reaction, user: discord.Member | discord.User
|
||||
) -> None:
|
||||
if random.random() < 20 / 100:
|
||||
logger.info(f"Copy reaction from {user}")
|
||||
await reaction.message.add_reaction(reaction.emoji)
|
||||
if user == self.bot.user:
|
||||
return
|
||||
|
||||
message = reaction.message
|
||||
guild = message.guild
|
||||
for reaction in message.reactions:
|
||||
if random.random() < 50 / 100:
|
||||
if random.random() < 50 / 100:
|
||||
if (
|
||||
self.bot.user is not None
|
||||
and self.bot.user in await reaction.users().flatten()
|
||||
and guild is not None
|
||||
and isinstance(
|
||||
member := guild.get_member(self.bot.user.id),
|
||||
discord.Member,
|
||||
)
|
||||
):
|
||||
logger.info(f"Remove reaction <{reaction}>.")
|
||||
await message.remove_reaction(reaction, member)
|
||||
else:
|
||||
logger.info(f"Copy reaction <{reaction}> from <{user}>.")
|
||||
await reaction.message.add_reaction(reaction.emoji)
|
||||
if random.random() < 10 / 100:
|
||||
await self.react(message)
|
||||
|
||||
async def react_message_edit(
|
||||
self, before: discord.Message, after: discord.Message
|
||||
|
|
Loading…
Add table
Reference in a new issue