This commit is contained in:
parent
caac1a2c3f
commit
5cd6b4cf58
3 changed files with 90 additions and 16 deletions
95
art/art.py
95
art/art.py
|
@ -5,9 +5,12 @@
|
|||
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
||||
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
||||
|
||||
import re
|
||||
|
||||
import discord
|
||||
from redbot.core import app_commands, config, checks, commands, data_manager
|
||||
from redbot.core.app_commands import Choice
|
||||
from redbot.core import app_commands, checks, commands
|
||||
|
||||
from .config import config, register_config
|
||||
|
||||
|
||||
class Art(commands.Cog):
|
||||
|
@ -18,13 +21,11 @@ class Art(commands.Cog):
|
|||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.config = config.Config.get_conf(
|
||||
self, identifier=2347831296542324
|
||||
)
|
||||
self.config.register_guild(
|
||||
art_channel=None,
|
||||
art_submission_channel=None
|
||||
)
|
||||
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):
|
||||
|
@ -36,11 +37,15 @@ class Art(commands.Cog):
|
|||
Upload your art submission here.
|
||||
"""
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
art_submission_channel = interaction.guild.get_channel(await self.config.guild(interaction.guild).art_submission_channel())
|
||||
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
|
||||
await art_submission_channel.send(f"Art submission from {interaction.user.mention} ({interaction.user.id}):", file=await art.to_file())
|
||||
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()
|
||||
|
@ -51,20 +56,20 @@ class Art(commands.Cog):
|
|||
@artset.command()
|
||||
async def submission(self, ctx: commands.Context, channel: discord.TextChannel):
|
||||
"""Set the art submission channel."""
|
||||
await self.config.guild(ctx.guild).art_submission_channel.set(channel.id)
|
||||
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 self.config.guild(ctx.guild).art_channel.set(channel.id)
|
||||
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 self.config.guild(ctx.guild).art_channel())
|
||||
art_submission_channel = ctx.guild.get_channel(await self.config.guild(ctx.guild).art_submission_channel())
|
||||
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:
|
||||
|
@ -74,3 +79,63 @@ class Art(commands.Cog):
|
|||
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}).*")
|
||||
|
|
9
art/config.py
Normal file
9
art/config.py
Normal file
|
@ -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
|
||||
)
|
|
@ -5,6 +5,6 @@
|
|||
"short" : "TODO",
|
||||
"description" : "TODO",
|
||||
"end_user_data_statement" : "This cog does not store end user data.",
|
||||
"hidden": false,
|
||||
"hidden": true,
|
||||
"disabled": false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue