11# LaR: Learn and Reply
2- import typing
3-
42import qna
53import discord
64import logging
5+ from cogs .modmode import DeleteView , ModMode
76from cogs .config import Config
87from discord .ext import commands
98
@@ -12,8 +11,9 @@ class LaR(commands.Cog):
1211 def __init__ (self , client : commands .Bot ):
1312 self .client = client
1413 self .logger = logging .getLogger ("cogs.LaR" )
15- self .config : typing . Union [ Config , None ] = client .get_cog ("Config" )
14+ self .config : Config | None = client .get_cog ("Config" )
1615 self .logger .debug ("registered." )
16+ self .mod_mode : ModMode | None = self .client .get_cog ("ModMode" )
1717
1818 async def learn (self , message : discord .Message ):
1919 if message .author .id in self .config .config ["optout" ] or message .author .id in self .config .config ["blacklist" ]:
@@ -59,15 +59,21 @@ async def reply(self, message: discord.Message):
5959 placeholder = "I don't know what to say (give me some time to learn)"
6060 text = placeholder
6161 server_questions = [q for q in self .config .question_map .values () if q .guild == message .guild .id ]
62+ question = None
63+ response = None
6264 if len (server_questions ):
63- question = qna .helpers .get_closest_question (server_questions , content ,
64- message .guild .id )
65+ question = qna .helpers .get_closest_question (server_questions , content )
6566 response = qna .helpers .pick_response (question )
6667 text = response .text or placeholder
6768 if message .content .startswith (self .client .command_prefix ):
6869 text += "\n (psst, i don't listen to commands here! if you want to run a command, " \
6970 "go to another channel or use slash commands.)"
70- await message .reply (text )
71+ view = None
72+ if self .mod_mode .is_in_mod_mode (guild , message .author ):
73+ view = DeleteView (self .mod_mode , self .config )
74+ message_reply = await message .reply (text , view = view )
75+ if self .mod_mode .is_in_mod_mode (guild , message .author ):
76+ self .mod_mode .save_info (guild , message .author , message_reply , question , response )
7177 self .logger .debug (f"reply: { message .clean_content } -> { text } " )
7278
7379 @commands .Cog .listener ()
0 commit comments