Finish up smells in the commands directory.
Add a discord max message length constant. Move boolean argument to not be positional.
This commit is contained in:
+62
-38
@@ -1,51 +1,50 @@
|
||||
"""
|
||||
Commands for testing.
|
||||
"""
|
||||
"""Commands for testing."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import nextcord
|
||||
from nextcord.ext import application_checks, commands
|
||||
from nextcord.ext.application_checks.core import AC
|
||||
|
||||
from classes.election_cycle import ElectionCycle
|
||||
from config import DakinyConfig
|
||||
from utils import get_current_election_cycle
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from config import DakinyConfig
|
||||
|
||||
def is_me():
|
||||
"""
|
||||
predicate that makes sure only I can run the test commands.
|
||||
"""
|
||||
|
||||
def predicate(interaction: nextcord.Interaction):
|
||||
return interaction.user.id == 206602713511886849
|
||||
ME = 206602713511886849
|
||||
GUILDS = [1000247361639030804]
|
||||
|
||||
|
||||
def is_me() -> AC:
|
||||
"""Predicate that makes sure only I can run the test commands."""
|
||||
|
||||
def predicate(interaction: nextcord.Interaction) -> bool:
|
||||
return interaction.user.id == ME
|
||||
|
||||
return application_checks.check(predicate)
|
||||
|
||||
|
||||
class TestCog(commands.Cog, name="Test commands."):
|
||||
"""
|
||||
Class holds commands for testing.
|
||||
"""
|
||||
"""Class holds commands for testing."""
|
||||
|
||||
def __init__(self, bot) -> None:
|
||||
"""
|
||||
Default constructor for HelpCog class. Does nothing.
|
||||
"""
|
||||
self.bot = bot
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
"""Default constructor for HelpCog class. Does nothing."""
|
||||
self.bot: commands.Bot = bot
|
||||
|
||||
@nextcord.slash_command(guild_ids=[1000247361639030804])
|
||||
async def test(self, interaction: nextcord.Interaction):
|
||||
"""
|
||||
Parent slash command for help. Never called.
|
||||
"""
|
||||
@nextcord.slash_command(guild_ids=GUILDS)
|
||||
async def test(self, interaction: nextcord.Interaction) -> None:
|
||||
"""Parent slash command for help. Never called."""
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def election_start(self, interaction: nextcord.Interaction):
|
||||
async def election_start(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
idc
|
||||
Force starts election.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): _description_
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
@@ -54,15 +53,16 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.election_start_action()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def voting_start(self, interaction: nextcord.Interaction):
|
||||
async def voting_start(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
tests the voting start action
|
||||
Force starts voting.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): _description_
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
@@ -71,15 +71,16 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.voting_start_action()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def voting_end(self, interaction: nextcord.Interaction):
|
||||
async def voting_end(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
tests the voting start action
|
||||
Force ends voting.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): _description_
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
@@ -88,15 +89,16 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.voting_end_action()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def highcouncil_vote(self, interaction: nextcord.Interaction):
|
||||
async def highcouncil_vote(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
tests the voting start action
|
||||
Force starts highcouncil voting.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): _description_
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
@@ -105,10 +107,17 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.highcouncil_election_start_action()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def election_reminder(self, interaction: nextcord.Interaction):
|
||||
async def election_reminder(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
Forces election reminder.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
get_current_election_cycle(config),
|
||||
@@ -116,10 +125,17 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.election_reminder()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def daily(self, interaction: nextcord.Interaction):
|
||||
async def daily(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
Forces daily function.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
get_current_election_cycle(config),
|
||||
@@ -127,10 +143,17 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.check_date()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
@test.subcommand()
|
||||
@is_me()
|
||||
async def term_start(self, interaction: nextcord.Interaction):
|
||||
async def term_start(self, interaction: nextcord.Interaction) -> None:
|
||||
"""
|
||||
Forces term start.
|
||||
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
get_current_election_cycle(config),
|
||||
@@ -138,3 +161,4 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
)
|
||||
await cycle.term_start_action()
|
||||
await interaction.send("Test command sent.")
|
||||
|
||||
Reference in New Issue
Block a user