spool management and printer loading
This commit is contained in:
parent
492990f073
commit
0ed04fbc93
9 changed files with 320 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://1oww0utk77w7"]
|
[gd_scene load_steps=2 format=3 uid="uid://1oww0utk77w7"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://library.gd" id="1_gqcys"]
|
[ext_resource type="Script" uid="uid://bmni837s3wuee" path="res://library.gd" id="1_gqcys"]
|
||||||
|
|
||||||
[node name="Library" type="Node"]
|
[node name="Library" type="Node"]
|
||||||
script = ExtResource("1_gqcys")
|
script = ExtResource("1_gqcys")
|
||||||
|
|
|
||||||
170
application_cmds/printer-load.gd
Normal file
170
application_cmds/printer-load.gd
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
var endangered_spool : String = ""
|
||||||
|
|
||||||
|
func on_ready(main, bot: DiscordBot) -> void:
|
||||||
|
bot.interaction_create.connect(on_interaction_create)
|
||||||
|
pass
|
||||||
|
#
|
||||||
|
func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
print(options)
|
||||||
|
#interaction.respond_autocomplete(Library.printer_choies())
|
||||||
|
var result = []
|
||||||
|
# The part of string which the user is typing
|
||||||
|
var spool_part : String
|
||||||
|
if options.size() > 1:
|
||||||
|
spool_part = options[1].value
|
||||||
|
print("received spool autocomplete: ", spool_part)
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
result = []
|
||||||
|
for hint in Library.spool_choices_string():
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if spool_part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(spool_part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
|
else:
|
||||||
|
var part = options[0].value
|
||||||
|
print("received autocomplete: ", part)
|
||||||
|
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
result = []
|
||||||
|
for hint in Library.printer_choices_string():
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
print(options)
|
||||||
|
var printer_name = options[0].value
|
||||||
|
var printer_exists : bool = false
|
||||||
|
var spool_name = options[1].value
|
||||||
|
var spool_exists : bool = false
|
||||||
|
var printer_editing : Printer
|
||||||
|
var spool_editing : Spool
|
||||||
|
|
||||||
|
for printer in Library.save.printers:
|
||||||
|
if printer.name == printer_name:
|
||||||
|
printer_exists = true
|
||||||
|
printer_editing = printer
|
||||||
|
#Library.save.printers.erase(printer)
|
||||||
|
|
||||||
|
for spool in Library.save.spools:
|
||||||
|
if spool.name == spool_name:
|
||||||
|
spool_exists = true
|
||||||
|
spool_editing = spool
|
||||||
|
|
||||||
|
if spool_exists and printer_exists:
|
||||||
|
var printer_has_spool : bool = printer_editing.spool != null
|
||||||
|
if printer_has_spool:
|
||||||
|
endangered_spool = printer_editing.spool.name
|
||||||
|
printer_editing.spool = spool_editing
|
||||||
|
|
||||||
|
if printer_has_spool:
|
||||||
|
#ask the user if they want to delete the old one
|
||||||
|
var response : String = "Loaded `"+ spool_editing.name + "` into `" + printer_editing.name + "` and unloaded `" + endangered_spool + "` would you like to keep or delete the old spool: `" + endangered_spool + "` ?"
|
||||||
|
var embed = Embed.new().set_description(Library.list_printers())
|
||||||
|
var row = MessageActionRow.new()
|
||||||
|
var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
|
||||||
|
delete_button.set_custom_id('delete-oldspool')
|
||||||
|
delete_button.set_label("Yes, delete " + endangered_spool)
|
||||||
|
var keep_button = MessageButton.new().set_style(MessageButton.STYLES.DEFAULT)
|
||||||
|
keep_button.set_custom_id('keep-oldspool')
|
||||||
|
keep_button.set_label("No, keep the old spool")
|
||||||
|
row.add_component(delete_button)
|
||||||
|
row.add_component(keep_button)
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
"embeds":[embed],
|
||||||
|
"components":[row],
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
var response : String = "Loaded `"+ spool_editing.name + "` into `" + printer_editing.name + "`"
|
||||||
|
var embed = Embed.new().set_description(Library.list_printers())
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
"embeds":[embed],
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
interaction.reply({
|
||||||
|
"content" : "Invalid input"
|
||||||
|
})
|
||||||
|
return
|
||||||
|
|
||||||
|
#Library.save_data()
|
||||||
|
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
||||||
|
if not interaction.is_button():
|
||||||
|
return
|
||||||
|
|
||||||
|
print(interaction.data.custom_id)
|
||||||
|
|
||||||
|
if(interaction.data.custom_id == "delete-oldspool"):
|
||||||
|
#print("deleting: " + endangered_printer)
|
||||||
|
for spool in Library.save.spools:
|
||||||
|
if spool.name == endangered_spool:
|
||||||
|
Library.save.spools.erase(spool)
|
||||||
|
Library.save_data()
|
||||||
|
var embed = Embed.new().set_description(endangered_spool + " has been removed")
|
||||||
|
var new_embeds = interaction.message.embeds + [embed]
|
||||||
|
interaction.update({
|
||||||
|
"content": interaction.message.content,
|
||||||
|
"embeds": new_embeds,
|
||||||
|
"components": []
|
||||||
|
})
|
||||||
|
|
||||||
|
elif(interaction.data.custom_id == "keep-oldspool"):
|
||||||
|
endangered_spool = ""
|
||||||
|
var embed = Embed.new().set_description("cancelled removal")
|
||||||
|
var new_embeds = interaction.message.embeds + [embed]
|
||||||
|
interaction.update({
|
||||||
|
"content": interaction.message.content,
|
||||||
|
"embeds": new_embeds,
|
||||||
|
"components": []
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var data = ApplicationCommand.new()\
|
||||||
|
.set_name("printer-load")\
|
||||||
|
.set_description("load a new spool of fillament into a printer, optionally deleting the old spool")\
|
||||||
|
.add_option(ApplicationCommand.string_option("printer-name", "the printer to load",
|
||||||
|
{
|
||||||
|
"required":true,
|
||||||
|
"autocomplete":true,
|
||||||
|
#"choices" : Library.printer_choies()
|
||||||
|
}))\
|
||||||
|
.add_option(ApplicationCommand.string_option("spool-name", "the spool to load into the printer",
|
||||||
|
{
|
||||||
|
"required":true,
|
||||||
|
"autocomplete":true,
|
||||||
|
#"choices" : Library.printer_choies()
|
||||||
|
}))\
|
||||||
|
|
||||||
1
application_cmds/printer-load.gd.uid
Normal file
1
application_cmds/printer-load.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://iaebhu3ewk53
|
||||||
116
application_cmds/spool-delete.gd
Normal file
116
application_cmds/spool-delete.gd
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
var endangered_spool : String = ""
|
||||||
|
|
||||||
|
func on_ready(main, bot: DiscordBot) -> void:
|
||||||
|
bot.interaction_create.connect(on_interaction_create)
|
||||||
|
pass
|
||||||
|
#
|
||||||
|
func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
#print(options)
|
||||||
|
#interaction.respond_autocomplete(Library.printer_choies())
|
||||||
|
|
||||||
|
# The part of string which the user is typing
|
||||||
|
var part = options[0].value
|
||||||
|
#print("received autocomplete: ", part)
|
||||||
|
|
||||||
|
# The final Array of choices for the autocomplete response
|
||||||
|
var result = []
|
||||||
|
for hint in Library.spool_choices_string():
|
||||||
|
# If the user hasn't typed anything, add all the hints
|
||||||
|
if part == "":
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
else:
|
||||||
|
# If the user has typed some part of string,
|
||||||
|
# add only those hints which have the part as a substring
|
||||||
|
if hint.findn(part) > -1:
|
||||||
|
result.append(ApplicationCommand.choice(hint, hint))
|
||||||
|
|
||||||
|
# Limit the number of results to 25 (Discord's limit is 25)
|
||||||
|
if result.size() > 25:
|
||||||
|
result = result.slice(0, 24)
|
||||||
|
|
||||||
|
# Respond with the results
|
||||||
|
interaction.respond_autocomplete(result)
|
||||||
|
pass
|
||||||
|
|
||||||
|
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
print(options)
|
||||||
|
var spool_name = options[0].value
|
||||||
|
var spool_exists : bool = false
|
||||||
|
|
||||||
|
for spool in Library.save.spools:
|
||||||
|
if spool.name == spool_name:
|
||||||
|
spool_exists = true
|
||||||
|
endangered_spool = spool.name
|
||||||
|
#Library.save.printers.erase(printer)
|
||||||
|
|
||||||
|
#Library.save_data()
|
||||||
|
|
||||||
|
if not spool_exists:
|
||||||
|
interaction.reply({
|
||||||
|
"content" : "unable to find " + spool_name
|
||||||
|
})
|
||||||
|
return
|
||||||
|
|
||||||
|
var response : String = "Are you sure you want to delete: `" + spool_name + "`?\n"
|
||||||
|
var embed = Embed.new().set_description(Library.list_spools())
|
||||||
|
var row = MessageActionRow.new()
|
||||||
|
var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
|
||||||
|
delete_button.set_custom_id('delete-spool')
|
||||||
|
delete_button.set_label("Yes, delete " + spool_name)
|
||||||
|
var keep_button = MessageButton.new().set_style(MessageButton.STYLES.DEFAULT)
|
||||||
|
keep_button.set_custom_id('keep-spool')
|
||||||
|
keep_button.set_label("No, keep the spool")
|
||||||
|
row.add_component(delete_button)
|
||||||
|
row.add_component(keep_button)
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
"embeds":[embed],
|
||||||
|
"components":[row],
|
||||||
|
})
|
||||||
|
pass
|
||||||
|
|
||||||
|
func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
||||||
|
if not interaction.is_button():
|
||||||
|
return
|
||||||
|
|
||||||
|
print(interaction.data.custom_id)
|
||||||
|
|
||||||
|
if(interaction.data.custom_id == "delete-spool"):
|
||||||
|
#print("deleting: " + endangered_printer)
|
||||||
|
for spool in Library.save.spools:
|
||||||
|
if spool.name == endangered_spool:
|
||||||
|
Library.save.spools.erase(spool)
|
||||||
|
Library.save_data()
|
||||||
|
var embed = Embed.new().set_description(endangered_spool + " 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-spool"):
|
||||||
|
endangered_spool = ""
|
||||||
|
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": []
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var data = ApplicationCommand.new()\
|
||||||
|
.set_name("spool-delete")\
|
||||||
|
.set_description("remove a spool")\
|
||||||
|
.add_option(ApplicationCommand.string_option("name", "the name of the spool to remove",
|
||||||
|
{
|
||||||
|
"required":true,
|
||||||
|
"autocomplete":true,
|
||||||
|
#"choices" : Library.printer_choies()
|
||||||
|
}))\
|
||||||
|
|
||||||
1
application_cmds/spool-delete.gd.uid
Normal file
1
application_cmds/spool-delete.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d2r7pbnfynhdy
|
||||||
23
application_cmds/spool-list.gd
Normal file
23
application_cmds/spool-list.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
extends RefCounted
|
||||||
|
|
||||||
|
#func on_ready(main, bot: DiscordBot) -> void:
|
||||||
|
# pass
|
||||||
|
#
|
||||||
|
#func on_autocomplete(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Array) -> void:
|
||||||
|
|
||||||
|
var response : String = "Listing spools..."
|
||||||
|
var embed = Embed.new().set_description(Library.list_spools())
|
||||||
|
|
||||||
|
interaction.reply({
|
||||||
|
"content": response,
|
||||||
|
"embeds":[embed]
|
||||||
|
})
|
||||||
|
pass
|
||||||
|
|
||||||
|
var data = ApplicationCommand.new()\
|
||||||
|
.set_name("spool-list")\
|
||||||
|
.set_description("view all current spools")\
|
||||||
|
|
||||||
1
application_cmds/spool-list.gd.uid
Normal file
1
application_cmds/spool-list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d1elsfl2en0rm
|
||||||
|
|
@ -62,3 +62,9 @@ func printer_choices_string() -> Array[String]:
|
||||||
for printer : Printer in save.printers:
|
for printer : Printer in save.printers:
|
||||||
printer_names.append(printer.name)
|
printer_names.append(printer.name)
|
||||||
return printer_names
|
return printer_names
|
||||||
|
|
||||||
|
func spool_choices_string() -> Array[String]:
|
||||||
|
var spool_names : Array[String] = []
|
||||||
|
for spool : Spool in save.spools:
|
||||||
|
spool_names.append(spool.name)
|
||||||
|
return spool_names
|
||||||
|
|
|
||||||
1
library.gd.uid
Normal file
1
library.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bmni837s3wuee
|
||||||
Loading…
Add table
Add a link
Reference in a new issue