From 5a26b48fdacf6c360da4acddbedd081c8d171b74 Mon Sep 17 00:00:00 2001 From: Antoine Rybacki Date: Fri, 12 Mar 2021 23:57:56 +0100 Subject: [PATCH 1/4] [Chatter] Allow bot to reply to maintain conversation continuity --- chatter/chat.py | 34 ++++++++++++++++++++++++++++++++-- chatter/info.json | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index 41affb6..84e8fbb 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -53,7 +53,13 @@ class Chatter(Cog): self.bot = bot self.config = Config.get_conf(self, identifier=6710497116116101114) default_global = {} - default_guild = {"whitelist": None, "days": 1, "convo_delta": 15, "chatchannel": None} + default_guild = { + "whitelist": None, + "days": 1, + "convo_delta": 15, + "chatchannel": None, + "reply": False, + } path: pathlib.Path = cog_data_path(self) self.data_path = path / "database.sqlite3" @@ -213,6 +219,25 @@ class Chatter(Cog): await self.config.guild(ctx.guild).chatchannel.set(channel.id) await ctx.maybe_send_embed(f"Chat channel is now {channel.mention}") + @checks.admin() + @chatter.command(name="reply") + async def chatter_reply(self, ctx: commands.Context, toggle: Optional[bool] = None): + """ + Toggle bot reply to messages if conversation continuity is not present + + """ + reply = await self.config.guild(ctx.guild).reply() + if toggle is None: + toggle = not reply + await self.config.guild(ctx.guild).reply.set(toggle) + + if toggle: + await ctx.send("I will now respond to you if conversation continuity is not present") + else: + await ctx.send( + "I will not reply to your message if conversation continuity is not present, anymore" + ) + @checks.is_owner() @chatter.command(name="cleardata") async def chatter_cleardata(self, ctx: commands.Context, confirm: bool = False): @@ -493,7 +518,12 @@ class Chatter(Cog): async with channel.typing(): future = await self.loop.run_in_executor(None, self.chatbot.get_response, text) + replying = None + if await self.config.guild(guild).reply(): + if message != ctx.channel.last_message: + replying = message + if future and str(future): - await channel.send(str(future)) + await channel.send(str(future), reference=replying) else: await channel.send(":thinking:") diff --git a/chatter/info.json b/chatter/info.json index 85107ed..a3fe0da 100644 --- a/chatter/info.json +++ b/chatter/info.json @@ -2,7 +2,7 @@ "author": [ "Bobloy" ], - "min_bot_version": "3.4.0", + "min_bot_version": "3.4.6", "description": "Create an offline chatbot that talks like your average member using Machine Learning. See setup instructions at https://github.com/bobloy/Fox-V3/tree/master/chatter", "hidden": false, "install_msg": "Thank you for installing Chatter! Please make sure you check the install instructions at https://github.com/bobloy/Fox-V3/blob/master/chatter/README.md\nAfter that, get started ith `[p]load chatter` and `[p]help Chatter`", From f7dad0aa3f9d0e5a73778062314ba8621d490a4a Mon Sep 17 00:00:00 2001 From: Antoine Rybacki Date: Mon, 15 Mar 2021 14:25:46 +0100 Subject: [PATCH 2/4] [Chatter] Bot will respond to reply --- chatter/chat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/chatter/chat.py b/chatter/chat.py index 84e8fbb..ed8b49d 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -500,7 +500,15 @@ class Chatter(Cog): # Thank you Cog-Creators channel: discord.TextChannel = message.channel - if guild is not None and channel.id == await self.config.guild(guild).chatchannel(): + # is_reply = False # this is only useful with in_response_to + if ( + message.reference is not None + and isinstance(message.reference.resolved,discord.Message) + and message.reference.resolved.author.id == self.bot.user.id + ): + # is_reply = True # this is only useful with in_response_to + pass # this is a reply to the bot, good to go + elif guild is not None and channel.id == await self.config.guild(guild).chatchannel(): pass # good to go else: when_mentionables = commands.when_mentioned(self.bot, message) From 42bdc640289d82318229ca3de0b8cff3dfe070dc Mon Sep 17 00:00:00 2001 From: Antoine Rybacki Date: Mon, 15 Mar 2021 14:29:34 +0100 Subject: [PATCH 3/4] Black format fix --- chatter/chat.py | 2 +- launchlib/launchlib.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chatter/chat.py b/chatter/chat.py index ed8b49d..971492c 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -503,7 +503,7 @@ class Chatter(Cog): # is_reply = False # this is only useful with in_response_to if ( message.reference is not None - and isinstance(message.reference.resolved,discord.Message) + and isinstance(message.reference.resolved, discord.Message) and message.reference.resolved.author.id == self.bot.user.id ): # is_reply = True # this is only useful with in_response_to diff --git a/launchlib/launchlib.py b/launchlib/launchlib.py index 4994a1d..3d3eb0e 100644 --- a/launchlib/launchlib.py +++ b/launchlib/launchlib.py @@ -152,7 +152,9 @@ class LaunchLib(commands.Cog): if pad_name is not None: if location_url is not None: - location_url = re.sub("[^a-zA-Z0-9/:.'+\"°?=,-]", "", location_url) # Fix bad URLS + location_url = re.sub( + "[^a-zA-Z0-9/:.'+\"°?=,-]", "", location_url + ) # Fix bad URLS em.add_field(name="Launch Pad Name", value=f"[{pad_name}]({location_url})") else: em.add_field(name="Launch Pad Name", value=pad_name) From d32de1586ffb35c3b052d53044fdd89773ef41dc Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 15 Mar 2021 15:40:25 -0400 Subject: [PATCH 4/4] Reply enabled by default cause it's cool. --- chatter/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatter/chat.py b/chatter/chat.py index 971492c..1419bbf 100644 --- a/chatter/chat.py +++ b/chatter/chat.py @@ -58,7 +58,7 @@ class Chatter(Cog): "days": 1, "convo_delta": 15, "chatchannel": None, - "reply": False, + "reply": True, } path: pathlib.Path = cog_data_path(self) self.data_path = path / "database.sqlite3"