r-Techsupport / TechSupportBot

A powerful discord bot primarily used in the r/TS discord server
GNU General Public License v3.0
7 stars 14 forks source link

Make an automute function based on a list of key words #1020

Open ajax146 opened 1 month ago

ajax146 commented 1 month ago

@TheKrol

Improve upon this code, and make the timeout a configurable list of strings instead of a hardcoded item

import munch
from core import auxiliary, cogs
from discord.ext import commands
from datetime import timedelta

async def setup(bot):
    await bot.add_cog(AutoMute(bot=bot, extension_name="automute"))

class AutoMute(cogs.MatchCog):
    """Class for the autoreact to make it to discord."""

    async def match(
        self, config: munch.Munch, _: commands.Context, content: str
    ) -> bool:
        """A match function to determine if somehting should be reacted to

        Args:
            config (munch.Munch): The guild config for the running bot
            content (str): The string content of the message

        Returns:
            bool: True if there needs to be a reaction, False otherwise
        """
        if content.startswith("?8350"):
            return True

    async def response(
        self, config: munch.Munch, ctx: commands.Context, content: str, _: bool
    ):
        """The function to generate and add reactions

        Args:
            config (munch.Munch): The guild config for the running bot
            ctx (commands.Context): The context in which the message was sent in
            content (str): The string content of the message
        """
        await ctx.author.timeout(timedelta(seconds=60))
SaintTheAce commented 1 month ago

if i may suggest changing the string ?8350 to something more relevant, whatever that might be? and maybe make a list of different timeout strings if thats needed?

ajax146 commented 1 month ago

This is made entirely as a joke, with the explicit purpose of ?8350 being a timeout. The improvements requested include making a configurable list instead of hard coding a single string.

This will also very likely be rolled into protect whenever I get around to completing the rewrite.

SaintTheAce commented 1 month ago

Well thanks for making me feel like a complete moron >.> <.< should of known better by now of course... MunchMunch (shoulda gave it away)