FabcatBot/application_cmds/printer-delete.gd

112 lines
3.3 KiB
GDScript3
Raw Permalink Normal View History

2025-10-30 01:42:52 +11:00
extends RefCounted
2025-10-30 15:10:21 +11:00
var endangered_printer : String = ""
func on_ready(main, bot: DiscordBot) -> void:
bot.interaction_create.connect(on_interaction_create)
pass
2025-10-30 01:42:52 +11:00
#
2025-10-30 12:16:57 +11:00
func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
2025-10-30 15:10:21 +11:00
#print(options)
#interaction.respond_autocomplete(Library.printer_choies())
# The part of string which the user is typing
var part = options[0].value
2025-11-02 14:55:36 +11:00
AutocompleteTools.printer_autocomplete(part, interaction)
2025-10-30 12:16:57 +11:00
pass
2025-10-30 01:42:52 +11:00
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
2025-11-02 14:55:36 +11:00
if not Tools.check_perms(interaction): #limit access to technicians only
2025-11-02 13:24:43 +11:00
return
2025-10-30 01:42:52 +11:00
print(options)
var printer_name = options[0].value
2025-10-30 15:10:21 +11:00
var printer_exists : bool = false
2025-10-30 01:42:52 +11:00
for printer in Library.save.printers:
if printer.name == printer_name:
2025-10-30 15:10:21 +11:00
printer_exists = true
endangered_printer = printer.name
#Library.save.printers.erase(printer)
#Library.save_data()
2025-10-30 01:42:52 +11:00
2025-10-30 15:10:21 +11:00
if not printer_exists:
interaction.reply({
"content" : "unable to find " + printer_name
})
return
2025-10-30 01:42:52 +11:00
2025-10-30 15:10:21 +11:00
var response : String = "Are you sure you want to delete: `" + printer_name + "`?\n"
2025-10-30 01:42:52 +11:00
var embed = Embed.new().set_description(Library.list_printers())
2025-10-30 15:10:21 +11:00
var row = MessageActionRow.new()
var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
delete_button.set_custom_id('delete-printer')
delete_button.set_label("Yes, delete " + printer_name)
var keep_button = MessageButton.new().set_style(MessageButton.STYLES.DEFAULT)
keep_button.set_custom_id('keep-printer')
keep_button.set_label("No, keep the printer")
row.add_component(delete_button)
row.add_component(keep_button)
2025-10-30 01:42:52 +11:00
interaction.reply({
"content": response,
2025-10-30 15:10:21 +11:00
"embeds":[embed],
"components":[row],
2025-10-30 01:42:52 +11:00
})
pass
2025-10-30 15:10:21 +11:00
func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
2025-11-02 13:24:43 +11:00
2025-10-30 15:10:21 +11:00
if not interaction.is_button():
return
print(interaction.data.custom_id)
if(interaction.data.custom_id == "delete-printer"):
2025-11-02 14:55:36 +11:00
if not Tools.check_perms(interaction): #limit access to technicians only
2025-11-02 13:24:43 +11:00
return
2025-10-30 15:10:21 +11:00
#print("deleting: " + endangered_printer)
for printer in Library.save.printers:
if printer.name == endangered_printer:
2025-11-02 13:24:43 +11:00
for spool : Spool in printer.spools:
Library.save.spools.append(spool)
#dont need to erase, the whole printers about to get obilierated
2025-10-30 15:10:21 +11:00
Library.save.printers.erase(printer)
Library.save_data()
var embed = Embed.new().set_description(endangered_printer + " has been deleted")
var new_embeds = interaction.message.embeds + [embed]
interaction.update({
"content": interaction.message.content,
"embeds": new_embeds,
"components": []
})
elif(interaction.data.custom_id == "keep-printer"):
2025-11-02 14:55:36 +11:00
if not Tools.check_perms(interaction): #limit access to technicians only
2025-11-02 13:24:43 +11:00
return
2025-10-30 15:10:21 +11:00
endangered_printer = ""
var embed = Embed.new().set_description("cancelled deletion")
var new_embeds = interaction.message.embeds + [embed]
interaction.update({
"content": interaction.message.content,
"embeds": new_embeds,
"components": []
})
2025-10-30 01:42:52 +11:00
var data = ApplicationCommand.new()\
.set_name("printer-delete")\
.set_description("remove a printer")\
.add_option(ApplicationCommand.string_option("name", "the printers name",
{
"required":true,
2025-10-30 12:16:57 +11:00
"autocomplete":true,
#"choices" : Library.printer_choies()
2025-10-30 01:42:52 +11:00
}))\