From c88295f8aa6d59245fe4cc0006cb67e1620c247b Mon Sep 17 00:00:00 2001 From: Ereiarrus Date: Sun, 4 Feb 2024 22:58:29 +0000 Subject: [PATCH] !complement separated into two --- src/complements_bot/bot.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/complements_bot/bot.py b/src/complements_bot/bot.py index 79fe048..c08631d 100644 --- a/src/complements_bot/bot.py +++ b/src/complements_bot/bot.py @@ -288,6 +288,19 @@ async def complement(self, ctx: commands.Context) -> None: The user of this command is allowed to prepend an optional '@' to the user's name with no change to the behaviour of the command. """ + to_send = await self.complement_h(ctx) + if to_send: + await ctx.channel.send(to_send) + custom_log( + f"In {ctx.channel.name} at {ctx.message.timestamp}, {ctx.message.author.name} " + f"was complemented (by command) with: {to_send}", + ComplementsBot.SHOULD_LOG + ) + + async def complement_h(self, ctx: commands.Context) -> Optional[str]: + """ + helper for complement() + """ who: str = self.isolate_args(ctx.message.content) if len(who) > 0: @@ -315,15 +328,16 @@ async def complement(self, ctx: commands.Context) -> None: if is_user_ignored or not cmd_complement_enabled: return - comp_msg, exists = await self.complement_msg( - who, ctx.channel.name, await database.is_cmd_complement_muted(userid=channel_id)) - if exists: - await ctx.channel.send(comp_msg) - custom_log( - f"In channel {ctx.channel.name}, at {ctx.message.timestamp}, {ctx.message.author.name} " - f"was complemented (by command) with: {comp_msg}", - ComplementsBot.SHOULD_LOG - ) + comp_msg: Optional[str] + comp_msg: bool + comp_msg, complement_exists = await self.complement_msg( + who, + ctx.channel.name, + await database.is_cmd_complement_muted(userid=channel_id) + ) + if complement_exists: + comp_msg = None if not complement_exists else comp_msg + return comp_msg @commands.command() async def compunignoreme(self, ctx: commands.Context) -> None: