diff --git a/art/__init__.py b/art/__init__.py new file mode 100644 index 00000000..3705628b --- /dev/null +++ b/art/__init__.py @@ -0,0 +1,5 @@ +from .art import Art + + +async def setup(bot): + await bot.add_cog(Art(bot)) diff --git a/art/art.py b/art/art.py new file mode 100644 index 00000000..09afa0cd --- /dev/null +++ b/art/art.py @@ -0,0 +1,141 @@ +# _____ _ +# / ____| (_) +# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __ +# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__| +# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ | +# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_| + +import re + +import discord +from redbot.core import app_commands, checks, commands + +from .config import config, register_config + + +class Art(commands.Cog): + """TODO. Broken until Discord.py 2.4 is released.""" + + __author__ = "SeaswimmerTheFsh" + __version__ = "0.1.0" + + def __init__(self, bot): + self.bot = bot + register_config(config) + + async def cog_load(self) -> None: + self.add_dynamic_items(ApproveButton) + self.add_dynamic_items(DenyButton) + + @app_commands.command() + async def art(self, interaction: discord.Interaction, art: discord.Attachment): + """Submit art. + + Parameters + ----------- + art: discord.Attachment + Upload your art submission here. + """ + await interaction.response.defer(ephemeral=True) + art_submission_channel = interaction.guild.get_channel(await config.guild(interaction.guild).art_submission_channel()) + if art_submission_channel is None: + await interaction.followup.send("Art submission channel not set. Report this error to the server administrators.", ephemeral=True) + return + msg = await art_submission_channel.send(f"Art submission from {interaction.user.mention} ({interaction.user.id}):", file=await art.to_file()) + view = discord.ui.View(timeout=None) + view.add_item(ApproveButton(interaction.id, msg, self.bot)) + view.add_item(DenyButton(interaction.id, msg, self.bot)) + msg.edit(view=view) + await interaction.followup.send("Art submitted.", ephemeral=True) + + @commands.group() + @checks.admin_or_permissions(manage_guild=True) + async def artset(self, ctx: commands.Context): + """Art submission settings.""" + + @artset.command() + async def submission(self, ctx: commands.Context, channel: discord.TextChannel): + """Set the art submission channel.""" + await config.guild(ctx.guild).art_submission_channel.set(channel.id) + await ctx.send(f"Art submission channel set to {channel.mention}.") + + @artset.command() + async def result(self, ctx: commands.Context, channel: discord.TextChannel): + """Set the art channel.""" + await config.guild(ctx.guild).art_channel.set(channel.id) + await ctx.send(f"Art channel set to {channel.mention}.") + + @artset.command() + async def list(self, ctx: commands.Context): + """List all settings.""" + art_channel = ctx.guild.get_channel(await config.guild(ctx.guild).art_channel()) + art_submission_channel = ctx.guild.get_channel(await config.guild(ctx.guild).art_submission_channel()) + if art_channel: + response_str = f"Art channel: {art_channel.mention}\n" + else: + response_str = "Art channel not set.\n" + if art_submission_channel: + response_str += f"Art submission channel: {art_submission_channel.mention}" + else: + response_str += "Art submission channel not set." + await ctx.send(response_str) + +class ApproveButton(discord.ui.DynamicItem[discord.ui.Button], template=r'button:interaction:(?P[0-9]+)'): + def __init__(self, interaction_id: int, msg: discord.Message, bot) -> None: + super().__init__( + discord.ui.Button( + label='Approve', + style=discord.ButtonStyle.green, + custom_id=f'art:approve:interaction:{interaction_id}', + emoji='\N{THUMBS UP SIGN}', + ) + ) + self.interaction_id: int = interaction_id + self.msg = msg + self.bot = bot + + @classmethod + async def from_custom_id(cls, interaction: discord.Interaction, item: discord.ui.Button, match: re.Match[str], /): + interaction_id = int(match['id']) + return cls(interaction_id) + + async def interaction_check(self, interaction: discord.Interaction) -> bool: + return self.bot.is_mod(interaction.user) + + async def callback(self, interaction: discord.Interaction): + art_channel = interaction.guild.get_channel(await config.guild(interaction.guild).art_channel()) + if art_channel is None: + await interaction.followup.send("Art channel not set. Report this error to the server administrators.", ephemeral=True) + return + content = self.msg.content + await self.msg.edit(content=content + f"\n\n*This art submission was approved by {interaction.user.mention} ({interaction.user.id}).*") + msg: discord.Message = await art_channel.send(f"Art submission from {interaction.user.mention} ({interaction.user.id}):", file=self.msg.attachments[0]) + await msg.add_reaction('\N{THUMBS UP SIGN}') + await msg.add_reaction('\N{THUMBS DOWN SIGN}') + + +class DenyButton(discord.ui.DynamicItem[discord.ui.Button], template=r'button:interaction:(?P[0-9]+)'): + def __init__(self, interaction_id: int, msg: discord.Message, bot) -> None: + super().__init__( + discord.ui.Button( + label='Deny', + style=discord.ButtonStyle.red, + custom_id=f'art:deny:interaction:{interaction_id}', + emoji='\N{THUMBS DOWN SIGN}', + ) + ) + self.interaction_id: int = interaction_id + self.msg = msg + self.bot = bot + + @classmethod + async def from_custom_id(cls, interaction: discord.Interaction, item: discord.ui.Button, match: re.Match[str], /): + interaction_id = int(match['id']) + return cls(interaction_id) + + async def interaction_check(self, interaction: discord.Interaction) -> bool: + return self.bot.is_mod(interaction.user) + + async def callback(self, interaction: discord.Interaction): + content = self.msg.content + await self.msg.edit(content=content + f"\n\n*This art submission was denied by {interaction.user.mention} ({interaction.user.id}).*") diff --git a/art/config.py b/art/config.py new file mode 100644 index 00000000..5a6ec07e --- /dev/null +++ b/art/config.py @@ -0,0 +1,9 @@ +from redbot.core import Config + +config: Config = Config.get_conf(None, identifier=2347831296542324, cog_name="Art") + +def register_config(config_obj: Config): + config_obj.register_guild( + art_channel=None, + art_submission_channel=None + ) diff --git a/art/info.json b/art/info.json new file mode 100644 index 00000000..54364595 --- /dev/null +++ b/art/info.json @@ -0,0 +1,10 @@ +{ + "author" : ["SeaswimmerTheFsh"], + "install_msg" : "Thank you for installing Art!\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).", + "name" : "Art", + "short" : "TODO", + "description" : "TODO", + "end_user_data_statement" : "This cog does not store end user data.", + "hidden": true, + "disabled": true + } diff --git a/aurora/aurora.py b/aurora/aurora.py index 8fa72eec..7bb59d57 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -1289,6 +1289,13 @@ class Aurora(commands.Cog): await config.guild(ctx.guild).log_channel.set(" ") await ctx.send("Logging channel disabled.") + @auroraset.command(name="showmoderator") + @checks.admin() + async def auroraset_showmoderator(self, ctx: commands.Context): + """Toggle if the cog should show the moderator in the case embed when dming a user.""" + await config.guild(ctx.guild).show_moderator.set(not await config.guild(ctx.guild).show_moderator()) + await ctx.send(f"Show moderator setting set to {await config.guild(ctx.guild).show_moderator()}") + @auroraset.group(autohelp=True, name='import') @checks.admin() async def auroraset_import(self, ctx: commands.Context): diff --git a/aurora/utilities/config.py b/aurora/utilities/config.py index 05343d80..ee5f080d 100644 --- a/aurora/utilities/config.py +++ b/aurora/utilities/config.py @@ -4,6 +4,7 @@ config: Config = Config.get_conf(None, identifier=481923957134912, cog_name="Aur def register_config(config_obj: Config): config_obj.register_guild( + show_moderator = True, use_discord_permissions = True, ignore_other_bots = True, dm_users = True, diff --git a/aurora/utilities/embed_factory.py b/aurora/utilities/embed_factory.py index 6a0c3ea7..a80ff3f5 100644 --- a/aurora/utilities/embed_factory.py +++ b/aurora/utilities/embed_factory.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta import humanize from discord import Color, Embed, Guild, Interaction, InteractionMessage +from .config import config from .utils import fetch_channel_dict, fetch_user_dict, get_next_case_number @@ -51,11 +52,17 @@ async def embed_factory(embed_type: str, color: Color, /, interaction: Interact embed_desc = "been" embed = Embed(title=str.title(moderation_type), description=f"You have {embed_desc} {moderation_type}{embed_duration} in {guild_name}.", color=color, timestamp=datetime.now()) - embed.add_field(name='Reason', value=f"`{reason}`") + + if await config.guild(guild).show_moderator(): + embed.add_field(name='Moderator', value=f"`{interaction.user.name} ({interaction.user.id})`", inline=False) + + embed.add_field(name='Reason', value=f"`{reason}`", inline=False) + if guild.icon.url is not None: embed.set_author(name=guild.name, icon_url=guild.icon.url) else: embed.set_author(name=guild.name) + embed.set_footer(text=f"Case #{await get_next_case_number(guild.id):,}", icon_url="https://cdn.discordapp.com/attachments/1070822161389994054/1159469476773904414/arrow-right-circle-icon-512x512-2p1e2aaw.png?ex=65312319&is=651eae19&hm=3cebdd28e805c13a79ec48ef87c32ca532ffa6b9ede2e48d0cf8e5e81f3a6818&") return embed