From 492990f0731ac5414f7f4cf5f4779d313d6a76d5 Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Thu, 30 Oct 2025 22:32:42 +1100 Subject: [PATCH] printer nozzle edits, spool creation --- Library.gd.uid | 1 - Library.tscn | 2 +- README.md | 3 + application_cmds/printer-nozzle.gd | 81 ++++++++++++++++++++++++++ application_cmds/printer-nozzle.gd.uid | 1 + application_cmds/spool-create.gd | 37 ++++++++++++ application_cmds/spool-create.gd.uid | 1 + datatypes/spool.gd | 8 ++- library.gd | 6 ++ 9 files changed, 137 insertions(+), 3 deletions(-) delete mode 100644 Library.gd.uid create mode 100644 application_cmds/printer-nozzle.gd create mode 100644 application_cmds/printer-nozzle.gd.uid create mode 100644 application_cmds/spool-create.gd create mode 100644 application_cmds/spool-create.gd.uid diff --git a/Library.gd.uid b/Library.gd.uid deleted file mode 100644 index 8b97b82..0000000 --- a/Library.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://ow8cfjxy4fio diff --git a/Library.tscn b/Library.tscn index 79abcde..e658873 100644 --- a/Library.tscn +++ b/Library.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://1oww0utk77w7"] -[ext_resource type="Script" uid="uid://hkh1ewsuji8m" path="res://library.gd" id="1_gqcys"] +[ext_resource type="Script" path="res://library.gd" id="1_gqcys"] [node name="Library" type="Node"] script = ExtResource("1_gqcys") diff --git a/README.md b/README.md index 766f804..654e33c 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ # FabsocBot + +## Todo +- [ ] Write todo diff --git a/application_cmds/printer-nozzle.gd b/application_cmds/printer-nozzle.gd new file mode 100644 index 0000000..83405dd --- /dev/null +++ b/application_cmds/printer-nozzle.gd @@ -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_nozzle = options[1].value + var printer_exists : bool = false + + for printer in Library.save.printers: + if printer.name == printer_name: + printer_exists = true + printer.nozzle = new_nozzle + #Library.save.printers.erase(printer) + + Library.save_data() + + if not printer_exists: + interaction.reply({ + "content" : "unable to find " + printer_name + }) + return + + var response : String = new_nozzle + " nozzle applied to `" + printer_name + "`\n" + var embed = Embed.new().set_description(Library.list_printers()) + + + interaction.reply({ + "content": response, + "embeds":[embed], + }) + pass + + +var data = ApplicationCommand.new()\ + .set_name("printer-nozzle")\ + .set_description("chnage the nozzle attached to a printer")\ + .add_option(ApplicationCommand.string_option("name", "the printers name", + { + "required":true, + "autocomplete":true, + #"choices" : Library.printer_choies() + }))\ + .add_option(ApplicationCommand.string_option("new_nozzle","new nozzle to apply to the printer", + { + "required" : true, + }))\ + + +## lesson learnt: option name must not have spaces diff --git a/application_cmds/printer-nozzle.gd.uid b/application_cmds/printer-nozzle.gd.uid new file mode 100644 index 0000000..65e9ff0 --- /dev/null +++ b/application_cmds/printer-nozzle.gd.uid @@ -0,0 +1 @@ +uid://dblj3uerl5km2 diff --git a/application_cmds/spool-create.gd b/application_cmds/spool-create.gd new file mode 100644 index 0000000..8f9e14b --- /dev/null +++ b/application_cmds/spool-create.gd @@ -0,0 +1,37 @@ +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: + print(options) + var spool_name : String = options[0].value + var spool_link : String + if options.size() > 1: + spool_link = options[1].value + + var new_spool : Spool = Spool.new() + new_spool.name = spool_name + if spool_link: + new_spool.link = spool_link + Library.save.spools.append(new_spool) + Library.save_data() + + var response : String = "Created new spool: `" + spool_name + "`\n" + var embed = Embed.new().set_description(Library.list_spools()) + + interaction.reply({ + "content": response, + "embeds":[embed] + }) + pass + +var data = ApplicationCommand.new()\ + .set_name("spool-create")\ + .set_description("create a new spool")\ + .add_option(ApplicationCommand.string_option("name", "the printers name",{"required":true}))\ + .add_option(ApplicationCommand.string_option("link", "optional link to the fillaments page", {"required" : false})) + diff --git a/application_cmds/spool-create.gd.uid b/application_cmds/spool-create.gd.uid new file mode 100644 index 0000000..75a84f2 --- /dev/null +++ b/application_cmds/spool-create.gd.uid @@ -0,0 +1 @@ +uid://0c0a4lu0fwga diff --git a/datatypes/spool.gd b/datatypes/spool.gd index 9a5db1d..3213493 100644 --- a/datatypes/spool.gd +++ b/datatypes/spool.gd @@ -2,6 +2,12 @@ extends Resource class_name Spool @export var name : String -@export var material : String +#@export var material : String @export var link : String # tags? + +func list_string() -> String: + var result : String = name + if link: + result = "[" + result +"]("+link+")" + return result diff --git a/library.gd b/library.gd index eb97d3c..bc37690 100644 --- a/library.gd +++ b/library.gd @@ -45,6 +45,12 @@ func list_printers() -> String: response += "\n- " + printer.list_string() return response +func list_spools() -> String: + var response : String = "Current Spools:" + for spool : Spool in save.spools: + response += "\n- " + spool.list_string() + return response + func printer_choies() -> Array[Dictionary]: var printer_names : Array[Dictionary] = [] for printer : Printer in save.printers: