Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apollo.py
Comment thread
lunazeta marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"cogs.database",
"cogs.irc",
"cogs.parallelism",
"cogs.welcome",
"cogs.welcome"
]


Expand Down
20 changes: 11 additions & 9 deletions cogs/bot_moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
import discord
from discord import Color, Embed
from discord.ext.commands import Bot, Cog
from pytz import timezone

from config import CONFIG

LONDON = timezone("Europe/London")

class Database(Cog):
class BotModeration(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()
joined_recently = message.author.joined_at > datetime.now(LONDON) - 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_title = f"@{message.author.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
title=embed_title, color=embed_colour, description=embed_description
)

await message.delete()
await channel.send(f'<@&{CONFIG.UWCS_EXEC_ROLE_IDS[1]}>', embed=embed)
await channel.send(f"<@&{CONFIG.UWCS_BOT_PING_ROLE_ID}>", embed=embed)
await message.author.timeout(timedelta(days=1))

async def setup(bot: Bot):
await bot.add_cog(Database(bot))
await bot.add_cog(BotModeration(bot))
2 changes: 2 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ config:
UWCS_bot_log_channel_id: 1234
# IRC bridge bot ID
UWCS_discord_bridge_bot_id: 1337
# Role ID for bot pings
UWCS_bot_ping_role_id: 1234213
# API Key for chatgpt integration
openai_api_key: openai
# Whether to include usernames as part of a prompt
Expand Down
3 changes: 2 additions & 1 deletion config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ 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_BOT_LOG_CHANNEL_ID: int = parsed.get("UWCS_bot_log_channel_id")
self.UWCS_DISCORD_BRIDGE_BOT_ID: int = parsed.get("UWCS_discord_bridge_bot_id")
self.UWCS_BOT_PING_ROLE_ID: int = parsed.get("UWCS_bot_ping_role_id")
self.OPENAI_API_KEY: str = parsed.get("openai_api_key")
self.AI_INCLUDE_NAMES: bool = parsed.get("ai_include_names")
self.AI_CHAT_CHANNELS: list[int] = parsed.get("ai_chat_channels")
Expand Down
Loading