add /checkin_all command

This commit is contained in:
greyweather committed 2026-11-03 00:16:08 +00:00
1 parent 427d9fbf75
commit 781e063469
1 file changed
+36
+36
View File
@@ -46,6 +46,22 @@ async def checkin(interaction: discord.Interaction) -> None:
else:
await interaction.response.send_message("The current channel does not have a ledger, either run `/register_channel` or move to a different channel and try again...", ephemeral=True)
@tree.command(name="checkin_all", description="Allows the user to check in every single checked-out file at once")
async def checkin_all(interaction: discord.Interaction) -> None:
if db_table_exists(interaction.channel_id):
if db_user_exists(interaction.channel_id, interaction.user):
files_by_user = db_get_files_by_user(interaction.channel_id, interaction.user)
if len(files_by_user) > 1:
await interaction.response.send_modal(CheckinAllConfirmationModal(interaction.channel_id))
elif len(files_by_user) == 1:
await interaction.response.send_modal(CheckinConfirmationModal(channel_id=interaction.channel_id,file=files_by_user[0]))
else:
await interaction.response.send_modal(CheckinModal(channel_id=interaction.channel_id,user=interaction.user))
else:
await interaction.response.send_message("You haven't checked out any files in this channel yet!", ephemeral=True)
else:
await interaction.response.send_message("The current channel does not have a ledger, either run `/register_channel` or move to a different channel and try again...", ephemeral=True)
@client.event
async def on_ready():
await tree.sync()
@@ -199,4 +215,24 @@ class CheckinConfirmationModal(discord.ui.Modal, title='Please confirm this is c
db_delete_row_by_file(channel_id=self.channel_id,file=self.file)
return await interaction.response.send_message(f"Successfully checked in file '{self.file}'!", ephemeral=True)
class CheckinAllConfirmationModal(discord.ui.Modal, title='Please confirm this is correct...'):
text = discord.ui.TextDisplay("hello world")
channel_id = 0
file = ""
def __init__(self, channel_id: int) -> None:
self.text.content = f"Do you want to check in all files in this channel?"
self.channel_id = channel_id
super().__init__()
async def on_submit(self, interaction):
channel = await client.fetch_channel(self.channel_id)
files = db_get_files_by_user(self.channel_id,interaction.user)
for file in files:
message_id = db_get_message_id_by_file(channel_id=self.channel_id,file=file)
if message_id != 0:
message = await channel.fetch_message(message_id)
await message.delete()
db_delete_row_by_file(channel_id=self.channel_id,file=file)
return await interaction.response.send_message(f"Successfully checked in all files!", ephemeral=True)
client.run(token)