Filled out remove presence some more. Not currently working.
build_develop / build (push) Successful in 1m25s
build_develop / build (push) Successful in 1m25s
This commit is contained in:
@@ -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())
|
||||||
|
|||||||
+18
-10
@@ -4,7 +4,7 @@ Commands for removing information in the database.
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
from sqlalchemy import select
|
from sqlalchemy import delete, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from database_setup.sql_data_classes import Presences, engine
|
from database_setup.sql_data_classes import Presences, engine
|
||||||
@@ -33,21 +33,29 @@ class RemoveCog(commands.Cog, name="View Commands"):
|
|||||||
async def presence(
|
async def presence(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
presence: str = nextcord.SlashOption(
|
presence_str: str = nextcord.SlashOption(
|
||||||
description="The presence to remove", required=True
|
description="The presence to remove", required=True
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
_summary_
|
Deletes the given presence id from the database.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
presence (str): Is SlashOption. The presence to remove.
|
presence (str): Is SlashOption. The presence to remove. Is the ID of the presence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@remove.on_autocomplete("presence")
|
presence_id = int(presence_str)
|
||||||
async def election_autocomplete(
|
with Session(engine) as session:
|
||||||
self, interaction: nextcord.Interaction, presence: str
|
stmt = delete(Presences).where(Presences.Id == presence_id)
|
||||||
|
session.execute(stmt)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
await interaction.response.send_message("Presence deleted.", ephemeral=True)
|
||||||
|
|
||||||
|
@remove.on_autocomplete("presence_str")
|
||||||
|
async def presence_autocomplete(
|
||||||
|
self, interaction: nextcord.Interaction, presence_str: str
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Collects all presences that start with the presence string.
|
Collects all presences that start with the presence string.
|
||||||
@@ -55,7 +63,7 @@ class RemoveCog(commands.Cog, name="View Commands"):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Interaction with command.
|
interaction (nextcord.Interaction): Interaction with command.
|
||||||
presence (str): String to run autocomplete on.
|
presence_str (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
@@ -65,7 +73,7 @@ class RemoveCog(commands.Cog, name="View Commands"):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# if empty compare string
|
# if empty compare string
|
||||||
if not presence:
|
if not presence_str:
|
||||||
await interaction.response.send_autocomplete(
|
await interaction.response.send_autocomplete(
|
||||||
dict(list(presences_dict.items())[:25])
|
dict(list(presences_dict.items())[:25])
|
||||||
)
|
)
|
||||||
@@ -74,6 +82,6 @@ class RemoveCog(commands.Cog, name="View Commands"):
|
|||||||
autofilled_presences: "dict[str,str]" = {
|
autofilled_presences: "dict[str,str]" = {
|
||||||
pres: pres_id
|
pres: pres_id
|
||||||
for pres, pres_id in presences_dict.items()
|
for pres, pres_id in presences_dict.items()
|
||||||
if presence.lower() in pres.lower()
|
if presence_str.lower() in pres.lower()
|
||||||
}
|
}
|
||||||
await interaction.response.send_autocomplete(autofilled_presences[:25])
|
await interaction.response.send_autocomplete(autofilled_presences[:25])
|
||||||
|
|||||||
Reference in New Issue
Block a user