Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2596b9fa7b | ||
|
|
8c654612a9 | ||
|
|
e836ead399 | ||
|
|
fa691ced5d | ||
|
|
81f4c7741b | ||
|
|
2cde9f7109 | ||
|
|
2632bb883f | ||
|
|
2f75f0cdcb | ||
|
|
deb405f02b | ||
|
|
ee7cbaf2f6 | ||
|
|
39746123f1 | ||
|
|
c69adb8374 | ||
|
|
f722a6a87b | ||
|
|
b3550bbf55 |
@@ -4,6 +4,7 @@ Cog loader. Adds all command cogs to the bot.
|
|||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from cogs.commands.remove import RemoveCog
|
||||||
from cogs.commands.request import RequestCog
|
from cogs.commands.request import RequestCog
|
||||||
from cogs.commands.set import setCog
|
from cogs.commands.set import setCog
|
||||||
from cogs.commands.test import TestCog
|
from cogs.commands.test import TestCog
|
||||||
@@ -17,7 +18,8 @@ def setup(bot: commands.Bot):
|
|||||||
Adds all command classes to bot.
|
Adds all command classes to bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
bot.add_cog(RemoveCog())
|
||||||
bot.add_cog(RequestCog(bot))
|
bot.add_cog(RequestCog(bot))
|
||||||
bot.add_cog(TestCog(bot))
|
bot.add_cog(TestCog(bot))
|
||||||
bot.add_cog(setCog())
|
|
||||||
bot.add_cog(ViewCog())
|
bot.add_cog(ViewCog())
|
||||||
|
bot.add_cog(setCog())
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
"""
|
||||||
|
Commands for removing information in the database.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import delete, select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from database_setup.sql_data_classes import Presences, engine
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveCog(commands.Cog, name="Remove Commands"):
|
||||||
|
"""
|
||||||
|
Holds the view commands.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for RemoveCog class. Does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@nextcord.slash_command(
|
||||||
|
default_member_permissions=nextcord.Permissions(administrator=True),
|
||||||
|
)
|
||||||
|
async def remove(self, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Parent slash command for set. Never called.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@remove.subcommand(description="Remove a presence from the database.")
|
||||||
|
async def presence(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
presence_str: str = nextcord.SlashOption(
|
||||||
|
description="The presence to remove", required=True
|
||||||
|
),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Deletes the given presence id from the database.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
presence (str): Is SlashOption. The presence to remove. Is the ID of the presence.
|
||||||
|
"""
|
||||||
|
|
||||||
|
presence_id = int(presence_str)
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = delete(Presences).where(Presences.Id == presence_id)
|
||||||
|
session.execute(stmt)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
await interaction.response.send_message("Presence deleted.", ephemeral=True)
|
||||||
|
|
||||||
|
@presence.on_autocomplete("presence_str")
|
||||||
|
async def presence_autocomplete(
|
||||||
|
self, interaction: nextcord.Interaction, presence_str: str
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Collects all presences that start with the presence string.
|
||||||
|
Sends autocomplete dict {Presence Name, Presence Id}
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
|
presence_str (str): String to run autocomplete on.
|
||||||
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = select(Presences)
|
||||||
|
presences_dict: "dict[str,str]" = {
|
||||||
|
pres.Presence: str(pres.Id) for pres in session.scalars(stmt)
|
||||||
|
}
|
||||||
|
|
||||||
|
# if empty compare string
|
||||||
|
if not presence_str:
|
||||||
|
await interaction.response.send_autocomplete(
|
||||||
|
dict(list(presences_dict.items())[:25])
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
autofilled_presences: "dict[str,str]" = {
|
||||||
|
pres: pres_id
|
||||||
|
for pres, pres_id in presences_dict.items()
|
||||||
|
if presence_str.lower() in pres.lower()
|
||||||
|
}
|
||||||
|
await interaction.response.send_autocomplete(autofilled_presences[:25])
|
||||||
@@ -25,7 +25,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
Default constructor for ViewCog class. Does nothing.
|
Default constructor for ViewCog class. Does nothing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@nextcord.slash_command(guild_ids=[1000247361639030804]) # TODO remove guild ids
|
@nextcord.slash_command()
|
||||||
async def view(self, interaction: nextcord.Interaction):
|
async def view(self, interaction: nextcord.Interaction):
|
||||||
"""
|
"""
|
||||||
Parent slash command for set. Never called.
|
Parent slash command for set. Never called.
|
||||||
@@ -126,7 +126,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
|
|
||||||
# if empty compare string
|
# if empty compare string
|
||||||
if not election_name:
|
if not election_name:
|
||||||
await interaction.response.send_autocomplete(elections)
|
await interaction.response.send_autocomplete(list(elections)[:25])
|
||||||
return
|
return
|
||||||
|
|
||||||
autofilled_elections: "list[str]" = [
|
autofilled_elections: "list[str]" = [
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ def get_datetime(day: str) -> datetime:
|
|||||||
if datetime.today().month == 12 and month < 12:
|
if datetime.today().month == 12 and month < 12:
|
||||||
year += 1
|
year += 1
|
||||||
|
|
||||||
|
if datetime.today().month == 1 and month > 1:
|
||||||
|
year -= 1
|
||||||
|
|
||||||
return datetime(year, month, day)
|
return datetime(year, month, day)
|
||||||
|
|
||||||
|
|
||||||
@@ -88,7 +91,7 @@ def get_current_cycle(config: DakinyConfig) -> int:
|
|||||||
config (DakinyConfig): Config object to use
|
config (DakinyConfig): Config object to use
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: cycle index for active election. -1 for no active cycle
|
int: cycle index for active election. None for no active cycle
|
||||||
"""
|
"""
|
||||||
|
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
@@ -100,7 +103,7 @@ def get_current_cycle(config: DakinyConfig) -> int:
|
|||||||
):
|
):
|
||||||
return cycle
|
return cycle
|
||||||
|
|
||||||
return -1
|
return None
|
||||||
|
|
||||||
|
|
||||||
def build_votes_str(config: DakinyConfig) -> str:
|
def build_votes_str(config: DakinyConfig) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user