diff --git a/apollo.py b/apollo.py index 93b5af95..c0ee7a66 100644 --- a/apollo.py +++ b/apollo.py @@ -51,6 +51,7 @@ "cogs.commands.xkcd", "cogs.commands.market", "cogs.commands.auction", + "cogs.bot_moderation", "cogs.channel_checker", "cogs.database", "cogs.irc", diff --git a/cogs/bot_moderation.py b/cogs/bot_moderation.py new file mode 100644 index 00000000..6cc3351e --- /dev/null +++ b/cogs/bot_moderation.py @@ -0,0 +1,37 @@ +from datetime import datetime, timedelta + +import discord +from discord import Color, Embed +from discord.ext.commands import Bot, Cog + +from config import CONFIG + + +class Database(Cog): + def __init__(self, bot: Bot): + self.bot = bot + + @Cog.listener() + async def on_message(self, message: discord.Message): + joined_recently = message.author.joined_at > datetime.now() - timedelta(days=7) + contains_everyone = '@everyone' in message.content + is_giving_away = 'giving away' in message.content.lower() + + if not joined_recently or not (contains_everyone or is_giving_away): + return + + channel = self.bot.get_channel(CONFIG.UWCS_BOT_LOG_CHANNEL_ID) + + embed_colour = Color.from_rgb(61, 83, 255) + embed_title = f'@{message.author.global_name}, ID: {message.author.id}' + embed_description = f'User suspected to be a bot, joined_recently: {joined_recently}, contains_everyone: {contains_everyone}, is_giving_away: {is_giving_away}' + embed = Embed( + title=embed_title, color=embed_colour, embed_description=embed_description + ) + + await message.delete() + await channel.send(f'<@&{CONFIG.UWCS_EXEC_ROLE_IDS[1]}>', embed=embed) + await message.author.timeout(timedelta(days=1)) + +async def setup(bot: Bot): + await bot.add_cog(Database(bot)) \ No newline at end of file diff --git a/config.example.yaml b/config.example.yaml index 9b2e9060..b210a57b 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -20,6 +20,8 @@ config: UWCS_roles_channel_id: 123 # Channel for the channel movement checker UWCS_exec_spam_channel_id: 1234 + # Channel for message logs + UWCS_bot_log_channel_id: 1234 # IRC bridge bot ID UWCS_discord_bridge_bot_id: 1337 # API Key for chatgpt integration diff --git a/config/config.py b/config/config.py index 64cc34ab..430beec8 100644 --- a/config/config.py +++ b/config/config.py @@ -20,6 +20,7 @@ def __init__(self, filepath: str): self.UWCS_WELCOME_CHANNEL_ID: int = parsed.get("UWCS_welcome_channel_id") self.UWCS_ROLES_CHANNEL_ID: int = parsed.get("UWCS_roles_channel_id") self.UWCS_EXEC_SPAM_CHANNEL_ID: int = parsed.get("UWCS_exec_spam_channel_id") + self.UWCS_BOT_LOG_CHANNEL_ID: int = parsed.get("UWCS_message_log_channel_id") self.UWCS_DISCORD_BRIDGE_BOT_ID: int = parsed.get("UWCS_discord_bridge_bot_id") self.OPENAI_API_KEY: str = parsed.get("openai_api_key") self.AI_INCLUDE_NAMES: bool = parsed.get("ai_include_names")