spool system redo nearly done
still need to fix unload
This commit is contained in:
parent
0ed04fbc93
commit
b83ef6b77b
12 changed files with 286 additions and 46 deletions
|
|
@ -1,4 +1,8 @@
|
|||
# FabsocBot
|
||||
|
||||
## Todo
|
||||
- [ ] Write todo
|
||||
- [x] want to redo spool management so when a spool is in a printer it leaves leaves the library - only exists in one place at a time
|
||||
- [x] spool list should show loaded spools in printer, then unloaded and available spools
|
||||
- [X] unloading a spool returns it to the library
|
||||
- [ ] job management?
|
||||
- [ ] shoot some of the printers can hold multiple fillaments: endermixer 2, ams: 4
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
extends RefCounted
|
||||
|
||||
var endangered_spool : String = ""
|
||||
var endangered_spool : Spool
|
||||
|
||||
func on_ready(main, bot: DiscordBot) -> void:
|
||||
bot.interaction_create.connect(on_interaction_create)
|
||||
|
|
@ -78,19 +78,24 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
|||
spool_editing = spool
|
||||
|
||||
if spool_exists and printer_exists:
|
||||
var printer_has_spool : bool = printer_editing.spool != null
|
||||
if printer_editing.spool_slots <= 1:
|
||||
var printer_has_spool : bool = printer_editing.spools.size() > 0
|
||||
if printer_has_spool:
|
||||
endangered_spool = printer_editing.spool.name
|
||||
printer_editing.spool = spool_editing
|
||||
endangered_spool = printer_editing.spools[0]
|
||||
Library.save.spools.append(endangered_spool)
|
||||
printer_editing.spools.clear()
|
||||
printer_editing.spools.append(spool_editing)
|
||||
Library.save.spools.erase(spool_editing)
|
||||
Library.save_data()
|
||||
|
||||
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 response : String = "Loaded `"+ spool_editing.name + "` into `" + printer_editing.name + "` and unloaded `" + endangered_spool.name + "` would you like to keep or delete the old spool: `" + endangered_spool.name + "` ?"
|
||||
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)
|
||||
delete_button.set_label("Yes, delete " + endangered_spool.name)
|
||||
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")
|
||||
|
|
@ -109,6 +114,27 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
|||
"content": response,
|
||||
"embeds":[embed],
|
||||
})
|
||||
|
||||
else: #printer has multiple slots, we can only handle it if there are empty slots
|
||||
if (printer_editing.spools.size() < printer_editing.spool_slots):
|
||||
printer_editing.spools.append(spool_editing)
|
||||
Library.save.spools.erase(spool_editing)
|
||||
Library.save_data()
|
||||
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: #its full!!
|
||||
|
||||
interaction.reply({
|
||||
"content": "This printer has multiple slots and they are all full, I don't know which one to replace! use `/printer-unload` to unload a spool first",
|
||||
})
|
||||
pass
|
||||
|
||||
else:
|
||||
interaction.reply({
|
||||
"content" : "Invalid input"
|
||||
|
|
@ -129,10 +155,11 @@ func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
|||
if(interaction.data.custom_id == "delete-oldspool"):
|
||||
#print("deleting: " + endangered_printer)
|
||||
for spool in Library.save.spools:
|
||||
if spool.name == endangered_spool:
|
||||
if spool == endangered_spool:
|
||||
Library.save.spools.erase(spool)
|
||||
Library.save_data()
|
||||
var embed = Embed.new().set_description(endangered_spool + " has been removed")
|
||||
var embed = Embed.new().set_description(endangered_spool.name + " has been removed")
|
||||
endangered_spool = null
|
||||
var new_embeds = interaction.message.embeds + [embed]
|
||||
interaction.update({
|
||||
"content": interaction.message.content,
|
||||
|
|
@ -141,7 +168,7 @@ func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
|||
})
|
||||
|
||||
elif(interaction.data.custom_id == "keep-oldspool"):
|
||||
endangered_spool = ""
|
||||
endangered_spool = null
|
||||
var embed = Embed.new().set_description("cancelled removal")
|
||||
var new_embeds = interaction.message.embeds + [embed]
|
||||
interaction.update({
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
|||
|
||||
var data = ApplicationCommand.new()\
|
||||
.set_name("printer-nozzle")\
|
||||
.set_description("chnage the nozzle attached to a printer")\
|
||||
.set_description("change the nozzle attached to a printer")\
|
||||
.add_option(ApplicationCommand.string_option("name", "the printers name",
|
||||
{
|
||||
"required":true,
|
||||
|
|
|
|||
81
application_cmds/printer-slots.gd
Normal file
81
application_cmds/printer-slots.gd
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
extends RefCounted
|
||||
|
||||
|
||||
#func on_ready(main, bot: DiscordBot) -> void:
|
||||
#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.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 new_slots : int = options[1].value
|
||||
var printer_exists : bool = false
|
||||
|
||||
for printer in Library.save.printers:
|
||||
if printer.name == printer_name:
|
||||
printer_exists = true
|
||||
printer.spool_slots = new_slots
|
||||
#Library.save.printers.erase(printer)
|
||||
|
||||
Library.save_data()
|
||||
|
||||
if not printer_exists:
|
||||
interaction.reply({
|
||||
"content" : "unable to find " + printer_name
|
||||
})
|
||||
return
|
||||
|
||||
var response : String = printer_name + " now has `" + str(new_slots) + "` spool slots\n"
|
||||
var embed = Embed.new().set_description(Library.list_printers())
|
||||
|
||||
|
||||
interaction.reply({
|
||||
"content": response,
|
||||
"embeds":[embed],
|
||||
})
|
||||
pass
|
||||
|
||||
|
||||
var data = ApplicationCommand.new()\
|
||||
.set_name("printer-slots")\
|
||||
.set_description("change the amount of spool slots the printer has")\
|
||||
.add_option(ApplicationCommand.string_option("name", "the printers name",
|
||||
{
|
||||
"required":true,
|
||||
"autocomplete":true,
|
||||
#"choices" : Library.printer_choies()
|
||||
}))\
|
||||
.add_option(ApplicationCommand.integer_option("slots","number of spool slots the printer should have",
|
||||
{
|
||||
"required" : true,
|
||||
}))\
|
||||
|
||||
|
||||
## lesson learnt: option name must not have spaces
|
||||
1
application_cmds/printer-slots.gd.uid
Normal file
1
application_cmds/printer-slots.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cil50lh15obcb
|
||||
98
application_cmds/printer-unload.gd
Normal file
98
application_cmds/printer-unload.gd
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
extends RefCounted
|
||||
|
||||
|
||||
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.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 : String = ""
|
||||
|
||||
for printer in Library.save.printers:
|
||||
if printer.name == printer_name:
|
||||
printer_exists = true
|
||||
spool_name = printer.spool.name
|
||||
Library.save.spools.append(printer.spool)
|
||||
printer.spool = null
|
||||
#Library.save.printers.erase(printer)
|
||||
|
||||
#Library.save_data()
|
||||
|
||||
if not printer_exists:
|
||||
interaction.reply({
|
||||
"content" : "unable to find " + printer_name
|
||||
})
|
||||
return
|
||||
|
||||
|
||||
|
||||
var response : String = "returned `" + spool_name + "` to the library"
|
||||
#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-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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var data = ApplicationCommand.new()\
|
||||
.set_name("printer-unload")\
|
||||
.set_description("unload the spool from a printer and return it to the library")\
|
||||
.add_option(ApplicationCommand.string_option("name", "the printers name",
|
||||
{
|
||||
"required":true,
|
||||
"autocomplete":true,
|
||||
#"choices" : Library.printer_choies()
|
||||
}))\
|
||||
|
||||
1
application_cmds/printer-unload.gd.uid
Normal file
1
application_cmds/printer-unload.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://k8kxljysyux2
|
||||
|
|
@ -13,6 +13,13 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
|||
if options.size() > 1:
|
||||
spool_link = options[1].value
|
||||
|
||||
## some sort of logic to name duplicated spool differently?
|
||||
#var match_count : int = 0
|
||||
#for spool : Spool in Library.save.spools:
|
||||
#if spool.name.find(spool_name):
|
||||
#match_count += 1
|
||||
|
||||
|
||||
var new_spool : Spool = Spool.new()
|
||||
new_spool.name = spool_name
|
||||
if spool_link:
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func execute(main, bot: DiscordBot, interaction: DiscordInteraction, options: Ar
|
|||
return
|
||||
|
||||
var response : String = "Are you sure you want to delete: `" + spool_name + "`?\n"
|
||||
var embed = Embed.new().set_description(Library.list_spools())
|
||||
var embed = Embed.new().set_description(Library.list_spools(spool_name))
|
||||
var row = MessageActionRow.new()
|
||||
var delete_button = MessageButton.new().set_style(MessageButton.STYLES.DANGER)
|
||||
delete_button.set_custom_id('delete-spool')
|
||||
|
|
@ -83,6 +83,7 @@ func on_interaction_create(bot: DiscordBot, interaction : DiscordInteraction):
|
|||
for spool in Library.save.spools:
|
||||
if spool.name == endangered_spool:
|
||||
Library.save.spools.erase(spool)
|
||||
break
|
||||
Library.save_data()
|
||||
var embed = Embed.new().set_description(endangered_spool + " has been deleted")
|
||||
var new_embeds = interaction.message.embeds + [embed]
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ extends Resource
|
|||
class_name Printer
|
||||
|
||||
@export var name : String
|
||||
@export var spool : Spool
|
||||
@export var spools : Array[Spool] = []
|
||||
@export var nozzle : String = "0.4mm"
|
||||
@export var spool_slots : int = 1
|
||||
|
||||
static var nozzles : Array[String] = [
|
||||
"0.6mm",
|
||||
|
|
@ -15,13 +16,15 @@ static var nozzles : Array[String] = [
|
|||
func list_string() -> String:
|
||||
var result = name + ": "
|
||||
|
||||
if spool:
|
||||
result += spool.name + " "
|
||||
if spool.link:
|
||||
result += "[Link]("+spool.link+")"
|
||||
if spools.size() > 0:
|
||||
for i : int in spools.size():
|
||||
result += spools[i].list_string()
|
||||
if i < spools.size() - 1:
|
||||
result += ", "
|
||||
else:
|
||||
result += "***Unloaded***"
|
||||
|
||||
result += " (Slots: "+ str(spools.size()) +"/"+ str(spool_slots) +")"
|
||||
result += " (Nozzle: "+nozzle+")"
|
||||
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ class_name Spool
|
|||
@export var link : String
|
||||
# tags?
|
||||
|
||||
func list_string() -> String:
|
||||
func list_string(bold : bool = false) -> String:
|
||||
var result : String = name
|
||||
if bold:
|
||||
result = "**" + result + "**"
|
||||
if link:
|
||||
result = "[" + result +"]("+link+")"
|
||||
return result
|
||||
|
|
|
|||
21
library.gd
21
library.gd
|
|
@ -45,10 +45,25 @@ func list_printers() -> String:
|
|||
response += "\n- " + printer.list_string()
|
||||
return response
|
||||
|
||||
func list_spools() -> String:
|
||||
var response : String = "Current Spools:"
|
||||
func list_spools(search : String = "") -> String:
|
||||
var response : String = "Loaded Spools:"
|
||||
var unloaded_printers : int = 0
|
||||
for printer : Printer in save.printers:
|
||||
if printer.spools.size() > 0:
|
||||
response += "\n- " + printer.list_string()
|
||||
else:
|
||||
unloaded_printers += 1
|
||||
if unloaded_printers > 0:
|
||||
response += "\n-# +" + str(unloaded_printers) + " unloaded printers"
|
||||
|
||||
response += "\n\nAvailable Spools: "
|
||||
var found_search_match = false
|
||||
for spool : Spool in save.spools:
|
||||
response += "\n- " + spool.list_string()
|
||||
var bold : bool = false
|
||||
if spool.name == search and not found_search_match:
|
||||
bold = true
|
||||
found_search_match = true
|
||||
response += "\n- " + spool.list_string(bold)
|
||||
return response
|
||||
|
||||
func printer_choies() -> Array[Dictionary]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue