diff --git a/bob/__init__.py b/bob/__init__.py index 4772c8f..7593a04 100644 --- a/bob/__init__.py +++ b/bob/__init__.py @@ -1,7 +1,7 @@ """ Constants used by bob. """ -__version__ = "2.7.4" +__version__ = "2.8.0" import random diff --git a/cogs/config.py b/cogs/config.py index ccff3e9..96d6d92 100644 --- a/cogs/config.py +++ b/cogs/config.py @@ -40,7 +40,7 @@ def __init__(self, client: commands.Bot): for question in questions: self.question_map.update({question.text + str(question.guild): question}) del questions - self.logger.debug("loaded %d questions.", len(self.question_map.keys())) + self.logger.debug("loaded %d questions.", len(self.question_map)) if os.path.exists("config.json"): self.logger.debug("loading config...") diff --git a/cogs/configuration.py b/cogs/configuration.py index b5f8523..e026f9b 100644 --- a/cogs/configuration.py +++ b/cogs/configuration.py @@ -16,8 +16,6 @@ def __init__(self, client: commands.Bot): @commands.has_permissions(manage_channels=True) @commands.hybrid_command(brief="Sets the channel that bob will talk in.") async def channel(self, ctx: commands.Context, channel: discord.TextChannel): - if not ctx.author.resolved_permissions.manage_channels: - return await ctx.reply("You're not allowed to use this command!") self.logger.debug(f"setting guild {ctx.guild.id}'s channel to {channel.id}") if str(ctx.guild.id) not in self.config.config["guilds"].keys(): self.config.config["guilds"].update({str(ctx.guild.id): {"channel": channel.id}}) diff --git a/cogs/lar.py b/cogs/lar.py index dbdf8e2..781128b 100644 --- a/cogs/lar.py +++ b/cogs/lar.py @@ -1,9 +1,8 @@ # LaR: Learn and Reply -import typing - import qna import discord import logging +from cogs.modmode import DeleteView, ModMode from cogs.config import Config from discord.ext import commands @@ -12,8 +11,9 @@ class LaR(commands.Cog): def __init__(self, client: commands.Bot): self.client = client self.logger = logging.getLogger("cogs.LaR") - self.config: typing.Union[Config, None] = client.get_cog("Config") + self.config: Config | None = client.get_cog("Config") self.logger.debug("registered.") + self.mod_mode: ModMode | None = self.client.get_cog("ModMode") async def learn(self, message: discord.Message): 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): placeholder = "I don't know what to say (give me some time to learn)" text = placeholder server_questions = [q for q in self.config.question_map.values() if q.guild == message.guild.id] + question = None + response = None if len(server_questions): - question = qna.helpers.get_closest_question(server_questions, content, - message.guild.id) + question = qna.helpers.get_closest_question(server_questions, content) response = qna.helpers.pick_response(question) text = response.text or placeholder if message.content.startswith(self.client.command_prefix): text += "\n(psst, i don't listen to commands here! if you want to run a command, " \ "go to another channel or use slash commands.)" - await message.reply(text) + view = None + if self.mod_mode.is_in_mod_mode(guild, message.author): + view = DeleteView(self.mod_mode, self.config) + message_reply = await message.reply(text, view=view) + if self.mod_mode.is_in_mod_mode(guild, message.author): + self.mod_mode.save_info(guild, message.author, message_reply, question, response) self.logger.debug(f"reply: {message.clean_content} -> {text}") @commands.Cog.listener() diff --git a/cogs/usercommands.py b/cogs/usercommands.py index 1a49d19..d1d8d34 100644 --- a/cogs/usercommands.py +++ b/cogs/usercommands.py @@ -44,8 +44,7 @@ async def debug(self, ctx: commands.Context, *, prompt: str): response = None server_questions = [q for q in self.config.question_map.values() if q.guild == message.guild.id] if len(server_questions): - question = qna.helpers.get_closest_question(server_questions, content, - message.guild.id) + question = qna.helpers.get_closest_question(server_questions, content) response = qna.helpers.pick_response(question) text = response.text or placeholder embed = None diff --git a/main.py b/main.py index 1ab80b9..19c06d9 100644 --- a/main.py +++ b/main.py @@ -88,6 +88,7 @@ async def on_command_error(ctx: commands.Context, error): async def on_ready(): cogs = [ "cogs.config", + "cogs.modmode", "cogs.lar", "cogs.configuration", "cogs.optin", diff --git a/qna/helpers.py b/qna/helpers.py index f75718d..91e454e 100644 --- a/qna/helpers.py +++ b/qna/helpers.py @@ -26,7 +26,7 @@ def pick_response(question: Question) -> Response: return response -def get_closest_question(questions: typing.List[Question], message: str, guild_id: int) -> Question: +def get_closest_question(questions: typing.List[Question], message: str) -> Question: lowest = None target = None for question in questions: