142 lines
6.1 KiB
Python
142 lines
6.1 KiB
Python
|
# _____ _
|
||
|
# / ____| (_)
|
||
|
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
|
||
|
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
|
||
|
# ____) | __/ (_| \__ \\ 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<id>[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<id>[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}).*")
|