diff --git a/.env.example b/.env.example index 702e09f..2fafc8f 100644 --- a/.env.example +++ b/.env.example @@ -7,3 +7,6 @@ DISABLED_COGS=general.context_menus # yt-dlp cookies (for media/download command) YTDLP_COOKIE_FILE=/bot/cogs/media/files/cookies.txt + +# User IDs for co ownership (comma seperated) +OWNER_FRIENDS=0000000000,000000000,000000000 diff --git a/bot.py b/bot.py index bc29256..5f64987 100644 --- a/bot.py +++ b/bot.py @@ -214,7 +214,7 @@ class DiscordBot(commands.Bot): split = full_command_name.split(" ") executed_command = str(split[0]) - if executed_command.lower() == "shutdown": + if executed_command.lower() in ["shutdown", "say", "embed"]: return if context.guild is not None: diff --git a/cogs/owner/invite.py b/cogs/owner/invite.py index 9ec15fa..e8b8a52 100644 --- a/cogs/owner/invite.py +++ b/cogs/owner/invite.py @@ -3,6 +3,7 @@ import discord from discord import app_commands from discord.ext import commands from discord.ext.commands import Context +from utils.checks import is_owner_or_friend class Invite(commands.Cog, name="invite"): @@ -25,7 +26,7 @@ class Invite(commands.Cog, name="invite"): ) @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) @app_commands.allowed_installs(guilds=True, users=True) - @commands.is_owner() + @is_owner_or_friend() async def invite(self, context: Context) -> None: """ Get the invite link of the bot to be able to invite it. @@ -43,7 +44,7 @@ class Invite(commands.Cog, name="invite"): await self.send_embed(context, embed, ephemeral=False) async def cog_command_error(self, context: Context, error) -> None: - if isinstance(error, commands.NotOwner): + if isinstance(error, (commands.NotOwner, commands.CheckFailure)): embed = discord.Embed( title="Permission Denied", description="You are not the owner of this bot.", diff --git a/cogs/owner/logs.py b/cogs/owner/logs.py index 93a2008..2666c05 100644 --- a/cogs/owner/logs.py +++ b/cogs/owner/logs.py @@ -4,6 +4,7 @@ from discord import app_commands from discord.ext import commands from discord.ext.commands import Context from utils.ascii_art import ascii_plain +from utils.checks import is_owner_or_friend class Logs(commands.Cog, name="logs"): @@ -27,7 +28,7 @@ class Logs(commands.Cog, name="logs"): @app_commands.describe(lines="Number of lines to read from the end of the log file (default: 50, max: 200)") @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) @app_commands.allowed_installs(guilds=True, users=True) - @commands.is_owner() + @is_owner_or_friend() async def logs(self, context: Context, lines: int = 50) -> None: if lines > 200: lines = 200 @@ -98,7 +99,7 @@ class Logs(commands.Cog, name="logs"): await self.send_embed(context, embed, ephemeral=True) async def cog_command_error(self, context: Context, error) -> None: - if isinstance(error, commands.NotOwner): + if isinstance(error, (commands.NotOwner, commands.CheckFailure)): embed = discord.Embed( title="Permission Denied", description="You are not the owner of this bot!", diff --git a/cogs/owner/say.py b/cogs/owner/say.py index f79e968..9b93ebd 100644 --- a/cogs/owner/say.py +++ b/cogs/owner/say.py @@ -2,21 +2,22 @@ import discord from discord import app_commands from discord.ext import commands from discord.ext.commands import Context +from utils.checks import is_owner_or_friend class Say(commands.Cog, name="say"): def __init__(self, bot) -> None: self.bot = bot - async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None: + async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False, allowed_mentions: discord.AllowedMentions = None) -> None: interaction = getattr(context, "interaction", None) if interaction is not None: if interaction.response.is_done(): - await interaction.followup.send(embed=embed, ephemeral=ephemeral) + await interaction.followup.send(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions) else: - await interaction.response.send_message(embed=embed, ephemeral=ephemeral) + await interaction.response.send_message(embed=embed, ephemeral=ephemeral, allowed_mentions=allowed_mentions) else: - await context.send(embed=embed) + await context.send(embed=embed, allowed_mentions=allowed_mentions) @commands.hybrid_command( name="say", @@ -25,7 +26,7 @@ class Say(commands.Cog, name="say"): @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) @app_commands.allowed_installs(guilds=True, users=True) @app_commands.describe(message="The message that should be repeated by the bot") - @commands.is_owner() + @is_owner_or_friend() async def say(self, context: Context, *, message: str) -> None: """ The bot will say anything you want. @@ -33,7 +34,26 @@ class Say(commands.Cog, name="say"): :param context: The hybrid command context. :param message: The message that should be repeated by the bot. """ - await context.send(message) + if context.guild is not None: + self.bot.logger.info( + f"Say command used in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id}): {message}" + ) + else: + self.bot.logger.info( + f"Say command used in DMs by {context.author} (ID: {context.author.id}): {message}" + ) + + allowed_mentions = discord.AllowedMentions.none() + + interaction = getattr(context, "interaction", None) + if interaction is not None: + await context.channel.send(message, allowed_mentions=allowed_mentions) + else: + try: + await context.message.delete() + except: + pass + await context.send(message, allowed_mentions=allowed_mentions) @commands.hybrid_command( name="embed", @@ -42,7 +62,7 @@ class Say(commands.Cog, name="say"): @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) @app_commands.allowed_installs(guilds=True, users=True) @app_commands.describe(message="The message that should be repeated by the bot") - @commands.is_owner() + @is_owner_or_friend() async def embed(self, context: Context, *, message: str) -> None: """ The bot will say anything you want, but using embeds. @@ -50,17 +70,36 @@ class Say(commands.Cog, name="say"): :param context: The hybrid command context. :param message: The message that should be repeated by the bot. """ + if context.guild is not None: + self.bot.logger.info( + f"Embed command used in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id}): {message}" + ) + else: + self.bot.logger.info( + f"Embed command used in DMs by {context.author} (ID: {context.author.id}): {message}" + ) + + allowed_mentions = discord.AllowedMentions.none() embed = discord.Embed( title="Say", description=message, color=0x7289DA, ) embed.set_author(name="Owner", icon_url="https://yes.nighty.works/raw/zReOib.webp") - await self.send_embed(context, embed) + + interaction = getattr(context, "interaction", None) + if interaction is not None: + await context.channel.send(embed=embed, allowed_mentions=allowed_mentions) + else: + try: + await context.message.delete() + except: + pass + await context.send(embed=embed, allowed_mentions=allowed_mentions) async def cog_command_error(self, context: Context, error) -> None: - if isinstance(error, commands.NotOwner): + if isinstance(error, (commands.NotOwner, commands.CheckFailure)): embed = discord.Embed( title="Permission Denied", description="You are not the owner of this bot!", diff --git a/utils/checks.py b/utils/checks.py new file mode 100644 index 0000000..4b57965 --- /dev/null +++ b/utils/checks.py @@ -0,0 +1,15 @@ +import os +from discord.ext import commands + +def get_owner_friend_ids(): + owner_friends = os.getenv("OWNER_FRIENDS", "") + if not owner_friends.strip(): + return [] + return [int(id.strip()) for id in owner_friends.split(",") if id.strip().isdigit()] + +def is_owner_or_friend(): + async def predicate(ctx): + owner_friend_ids = get_owner_friend_ids() + return ctx.author.id in owner_friend_ids or await ctx.bot.is_owner(ctx.author) + return commands.check(predicate) +