Files
Syntrel/cogs/events/__init__.py

96 lines
3.2 KiB
Python
Raw Normal View History

2025-11-02 18:57:40 -05:00
import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
from .baitbot import baitbot_command, BaitBotListener, has_protected_role
from .mention import MentionListener
2025-12-29 17:56:33 -05:00
from .stickybot import (
stickybot_command,
StickyBotListener,
has_allowed_role as has_sticky_role,
)
2025-11-02 18:57:40 -05:00
def _require_group_prefix(context: Context) -> bool:
if getattr(context, "interaction", None):
return True
group = getattr(getattr(context, "cog", None), "qualified_name", "").lower()
if not group:
return True
prefix = context.prefix or ""
content = context.message.content.strip().lower()
return content.startswith(f"{prefix}{group} ")
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@app_commands.allowed_installs(guilds=True, users=True)
class Events(commands.GroupCog, name="events"):
def __init__(self, bot) -> None:
self.bot = bot
super().__init__()
@commands.group(name="events", invoke_without_command=True)
async def events_group(self, context: Context):
embed = discord.Embed(
title="Events Commands",
description="Use `.events <subcommand>` or `/events <subcommand>`.",
2025-11-02 23:32:52 -05:00
color=0x7289DA,
)
embed.set_author(
name="Events", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
2025-11-02 18:57:40 -05:00
)
2025-12-29 17:56:33 -05:00
embed.add_field(name="Available", value="baitbot, stickybot", inline=False)
2025-11-02 18:57:40 -05:00
await context.send(embed=embed)
async def _invoke_hybrid(self, context: Context, name: str, **kwargs):
command = self.bot.get_command(name)
if command is not None:
await context.invoke(command, **kwargs)
else:
await context.send(f"Unknown events command: {name}")
@events_group.command(name="baitbot")
@has_protected_role()
async def events_group_baitbot(self, context: Context):
await self._invoke_hybrid(context, "baitbot")
2025-11-02 23:32:52 -05:00
2025-12-29 17:56:33 -05:00
@events_group.command(name="stickybot")
@has_sticky_role()
async def events_group_stickybot(self, context: Context):
await self._invoke_hybrid(context, "stickybot")
2025-11-02 18:57:40 -05:00
@commands.check(_require_group_prefix)
@has_protected_role()
@commands.hybrid_command(
2025-11-02 23:32:52 -05:00
name="baitbot", description="View bait bot configuration and status."
2025-11-02 18:57:40 -05:00
)
async def baitbot(self, context):
return await baitbot_command()(self, context)
2025-12-29 17:56:33 -05:00
@commands.check(_require_group_prefix)
@has_sticky_role()
@commands.hybrid_command(
name="stickybot", description="View sticky bot configuration and status."
)
async def stickybot(self, context):
return await stickybot_command()(self, context)
2025-11-02 18:57:40 -05:00
async def setup(bot) -> None:
cog = Events(bot)
await bot.add_cog(cog)
2025-11-02 23:32:52 -05:00
2025-11-02 18:57:40 -05:00
listener = BaitBotListener(bot)
await bot.add_cog(listener)
2025-11-02 23:32:52 -05:00
mention_listener = MentionListener(bot)
await bot.add_cog(mention_listener)
2025-12-29 17:56:33 -05:00
sticky_bot = StickyBotListener(bot)
await bot.add_cog(sticky_bot)
2025-11-02 18:57:40 -05:00
bot.logger.info("Loaded extension 'events.baitbot'")
bot.logger.info("Loaded extension 'events.mention'")
2025-12-29 17:56:33 -05:00
bot.logger.info("Loaded extension 'events.stickybot'")