Added verify and submission register subcommands. Removed bot argument from Register class.

This commit is contained in:
alwayscompiling
2022-08-06 22:21:08 -04:00
parent ff07787a9a
commit 0eb332aefd
+59 -57
View File
@@ -20,8 +20,10 @@ class Register(commands.Cog, name="Register"):
name (str, optional): Name of Cog. Defaults to "Register". name (str, optional): Name of Cog. Defaults to "Register".
""" """
def __init__(self, bot: commands.Bot) -> None: def __init__(self) -> None:
self.bot = bot """
Default constructor for Register class. Does nothing.
"""
@nextcord.slash_command(default_member_permissions=Permissions(administrator=True)) @nextcord.slash_command(default_member_permissions=Permissions(administrator=True))
async def register(self): async def register(self):
@@ -29,7 +31,7 @@ class Register(commands.Cog, name="Register"):
Parent slash command, never called. Parent slash command, never called.
""" """
@register.subcommand(description="highscore") @register.subcommand(description="Registers the channel for perminent highscores messages.")
async def highscore( async def highscore(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
@@ -41,73 +43,73 @@ class Register(commands.Cog, name="Register"):
), ),
) -> None: ) -> None:
""" """
_summary_ Command function to register the highscore printing channel.
Args: Args:
interaction (nextcord.Interaction): _description_ interaction (nextcord.Interaction): Interaction that invoked the command
channel (nextcord.abc.GuildChannel, optional): _description_. channel (nextcord.abc.GuildChannel, optional): Channel to register
Is a SlashOption. Limited to text channels, Defaults to None.
Defaults to SlashOption( description="Channel to register",
required=False,
channel_types=[nextcord.ChannelType.text],
default=None,
).
""" """
if not channel: if not channel:
channel = interaction.channel channel = interaction.channel
channel_id = channel.id channel_id = channel.id
guild = highscores_data.get_guild(interaction.guild_id) guild = highscores_data.get_guild(interaction.guild_id)
await interaction.send( await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
f"Registered <#{channel_id}> as channel to post highscores in.", ephemeral=True
)
guild.highscore_channel = channel_id guild.highscore_channel = channel_id
highscores_data.save_guild_data(guild) highscores_data.save_guild_data(guild)
@commands.command(name="register") @register.subcommand(description="Registers the channel for submission messages.")
# @commands.has_permissions(administrator=True) async def submission(
async def register_highscores(self, ctx: commands.Context, registration_type: str) -> None: self,
"""A command which registers current channel as for various uses. interaction: nextcord.Interaction,
Usage: channel: nextcord.abc.GuildChannel = SlashOption(
``` description="Channel to register",
?register verify (Use in channel you want to verify submissions in.) required=False,
?register highscore (Use in channel you want to show highscore messages in.) channel_types=[nextcord.ChannelType.text],
?register submission (Use in channel you want submission messages to be send it.) default=None,
?register help (Shows help message.) ),
``` ) -> None:
""" """
# respond to the message Command function to register the submission message channel.
channel_id = ctx.channel.id
guild = highscores_data.get_guild(ctx.guild.id)
if registration_type == "verify": Args:
await ctx.send(f"Registered <#{channel_id}> as channel to post verifications in.") interaction (nextcord.Interaction): Interaction that invoked the command
guild.verification_channel = channel_id channel (nextcord.abc.GuildChannel, optional): Channel to register
elif registration_type == "highscore": Is a SlashOption. Limited to text channels, Defaults to None.
await ctx.send(f"Registered <#{channel_id}> as channel to post highscores in.") """
guild.highscore_channel = channel_id if not channel:
elif registration_type == "submission": channel = interaction.channel
await ctx.send(f"Registered <#{channel_id}> as channel to post submissions in.") channel_id = channel.id
guild = highscores_data.get_guild(interaction.guild_id)
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
guild.submission_channel = channel_id guild.submission_channel = channel_id
else: highscores_data.save_guild_data(guild)
embed = Embed(
title="Register command help", description="How to use the register command."
)
embed.add_field(
name="?register verify", value="Use in channel you want to verify submissions in."
)
embed.add_field(
name="?register highscore",
value="Use in channel you want to show highscore messages in.",
)
embed.add_field(
name="?register submission",
value="Use in channel you want submission messages to be send it.",
)
embed.add_field(name="?register help", value="Use to show this message.")
await ctx.reply(embed=embed)
# return, don't need to save data
return
@register.subcommand(description="Registers the channel for verification messages.")
async def verify(
self,
interaction: nextcord.Interaction,
channel: nextcord.abc.GuildChannel = SlashOption(
description="Channel to register",
required=False,
channel_types=[nextcord.ChannelType.text],
default=None,
),
) -> None:
"""
Command function to register the verification message channel.
Args:
interaction (nextcord.Interaction): Interaction that invoked the command
channel (nextcord.abc.GuildChannel, optional): Channel to register
Is a SlashOption. Limited to text channels, Defaults to None.
"""
if not channel:
channel = interaction.channel
channel_id = channel.id
guild = highscores_data.get_guild(interaction.guild_id)
await interaction.send(f"Registered <#{channel_id}>.", ephemeral=True)
guild.verification_channel = channel_id
highscores_data.save_guild_data(guild) highscores_data.save_guild_data(guild)
@@ -115,4 +117,4 @@ class Register(commands.Cog, name="Register"):
# It is necessary to add these functions to the bot. # It is necessary to add these functions to the bot.
def setup(bot: commands.Bot) -> None: def setup(bot: commands.Bot) -> None:
"""Adds function to bot""" """Adds function to bot"""
bot.add_cog(Register(bot)) bot.add_cog(Register())