Merge pull request #172 from Lifeismana/master
[Chatter] Allow bot to reply to maintain conversation continuity and will respond to reply
This commit is contained in:
		
						commit
						11eb4a9dbf
					
				| @ -53,7 +53,13 @@ class Chatter(Cog): | |||||||
|         self.bot = bot |         self.bot = bot | ||||||
|         self.config = Config.get_conf(self, identifier=6710497116116101114) |         self.config = Config.get_conf(self, identifier=6710497116116101114) | ||||||
|         default_global = {} |         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": True, | ||||||
|  |         } | ||||||
|         path: pathlib.Path = cog_data_path(self) |         path: pathlib.Path = cog_data_path(self) | ||||||
|         self.data_path = path / "database.sqlite3" |         self.data_path = path / "database.sqlite3" | ||||||
| 
 | 
 | ||||||
| @ -213,6 +219,25 @@ class Chatter(Cog): | |||||||
|             await self.config.guild(ctx.guild).chatchannel.set(channel.id) |             await self.config.guild(ctx.guild).chatchannel.set(channel.id) | ||||||
|             await ctx.maybe_send_embed(f"Chat channel is now {channel.mention}") |             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() |     @checks.is_owner() | ||||||
|     @chatter.command(name="cleardata") |     @chatter.command(name="cleardata") | ||||||
|     async def chatter_cleardata(self, ctx: commands.Context, confirm: bool = False): |     async def chatter_cleardata(self, ctx: commands.Context, confirm: bool = False): | ||||||
| @ -475,7 +500,15 @@ class Chatter(Cog): | |||||||
|         # Thank you Cog-Creators |         # Thank you Cog-Creators | ||||||
|         channel: discord.TextChannel = message.channel |         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 |             pass  # good to go | ||||||
|         else: |         else: | ||||||
|             when_mentionables = commands.when_mentioned(self.bot, message) |             when_mentionables = commands.when_mentioned(self.bot, message) | ||||||
| @ -493,7 +526,12 @@ class Chatter(Cog): | |||||||
|         async with channel.typing(): |         async with channel.typing(): | ||||||
|             future = await self.loop.run_in_executor(None, self.chatbot.get_response, text) |             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): |             if future and str(future): | ||||||
|                 await channel.send(str(future)) |                 await channel.send(str(future), reference=replying) | ||||||
|             else: |             else: | ||||||
|                 await channel.send(":thinking:") |                 await channel.send(":thinking:") | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ | |||||||
|   "author": [ |   "author": [ | ||||||
|     "Bobloy" |     "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", |   "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, |   "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`", |   "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`", | ||||||
|  | |||||||
| @ -152,7 +152,9 @@ class LaunchLib(commands.Cog): | |||||||
| 
 | 
 | ||||||
|             if pad_name is not None: |             if pad_name is not None: | ||||||
|                 if location_url 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})") |                     em.add_field(name="Launch Pad Name", value=f"[{pad_name}]({location_url})") | ||||||
|                 else: |                 else: | ||||||
|                     em.add_field(name="Launch Pad Name", value=pad_name) |                     em.add_field(name="Launch Pad Name", value=pad_name) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 bobloy
						bobloy