From 6c8a1c2411fe6365141aa32f3dcf86c53c2ddabe Mon Sep 17 00:00:00 2001 From: TCMine <32180878+TCMine@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:26:30 -0500 Subject: [PATCH 1/5] object actions --- actions/add_item_to_object_MOD.js | 137 ++++++++++++++++++++++++++ actions/add_items_to_object_MOD.js | 145 ++++++++++++++++++++++++++++ actions/create_object_MOD.js | 120 +++++++++++++++++++++++ actions/get_item_from_object_MOD.js | 138 ++++++++++++++++++++++++++ 4 files changed, 540 insertions(+) create mode 100644 actions/add_item_to_object_MOD.js create mode 100644 actions/add_items_to_object_MOD.js create mode 100644 actions/create_object_MOD.js create mode 100644 actions/get_item_from_object_MOD.js diff --git a/actions/add_item_to_object_MOD.js b/actions/add_item_to_object_MOD.js new file mode 100644 index 00000000..d3ed3551 --- /dev/null +++ b/actions/add_item_to_object_MOD.js @@ -0,0 +1,137 @@ +module.exports = { + // --------------------------------------------------------------------- + // Action Name + // + // This is the name of the action displayed in the editor. + // --------------------------------------------------------------------- + + name: 'Add/Edit Item in Object', + + // --------------------------------------------------------------------- + // Action Section + // + // This is the section the action will fall into. + // --------------------------------------------------------------------- + + section: 'JSON Things', + + // --------------------------------------------------------------------- + // Action Subtitle + // + // This function generates the subtitle displayed next to the name. + // --------------------------------------------------------------------- + + subtitle(data, presets) { + const storage = presets.variables; + if (!data.value) return `Clear key "${data.key}" in ${storage[parseInt(data.storage, 10)]} (${data.varName})`; + return `Add "${data.value}" to key "${data.key}" in ${storage[parseInt(data.storage, 10)]} (${data.varName})`; + }, + + // --------------------------------------------------------------------- + // Action Meta Data + // + // Helps check for updates and provides info if a custom mod. + // If this is a third-party mod, please set "author" and "authorUrl". + // + // It's highly recommended "preciseCheck" is set to false for third-party mods. + // This will make it so the patch version (0.0.X) is not checked. + // --------------------------------------------------------------------- + + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/add_item_to_object_MOD.js', + }, + + // --------------------------------------------------------------------- + // Action Fields + // + // These are the fields for the action. These fields are customized + // by creating elements with corresponding IDs in the HTML. These + // are also the names of the fields stored in the action's JSON data. + // --------------------------------------------------------------------- + + fields: ['storage', 'varName', 'key', 'value'], + + // --------------------------------------------------------------------- + // Command HTML + // + // This function returns a string containing the HTML used for + // editing actions. + // + // The "isEvent" parameter will be true if this action is being used + // for an event. Due to their nature, events lack certain information, + // so edit the HTML to reflect this. + // --------------------------------------------------------------------- + + html(isEvent, data) { + return ` + + +


+ +
+
+ Key
+
+
+
+ Value
+ +
+
`; + }, + + // --------------------------------------------------------------------- + // Action Editor Init Code + // + // When the HTML is first applied to the action editor, this code + // is also run. This helps add modifications or setup reactionary + // functions for the DOM elements. + // --------------------------------------------------------------------- + + init() {}, + + // --------------------------------------------------------------------- + // Action Bot Function + // + // This is the function for the action within the Bot's Action class. + // Keep in mind event calls won't have access to the "msg" parameter, + // so be sure to provide checks for variable existence. + // --------------------------------------------------------------------- + + action(cache) { + const data = cache.actions[cache.index]; + const storage = parseInt(data.storage, 10); + const varName = this.evalMessage(data.varName, cache); + const key = this.evalMessage(data.key, cache); + const list = this.getVariable(storage, varName, cache); + + let val = this.evalMessage(data.value, cache); + if (!val) { + delete list[key]; + } else { + try { + val = this.eval(val, cache); + } catch (e) { + this.displayError(data, cache, e); + } + list[key] = val; + }; + + this.callNextAction(cache); + }, + + // --------------------------------------------------------------------- + // Action Bot Mod + // + // Upon initialization of the bot, this code is run. Using the bot's + // DBM namespace, one can add/modify existing functions if necessary. + // In order to reduce conflicts between mods, be sure to alias + // functions you wish to overwrite. + // --------------------------------------------------------------------- + + mod() {}, +}; diff --git a/actions/add_items_to_object_MOD.js b/actions/add_items_to_object_MOD.js new file mode 100644 index 00000000..def35efd --- /dev/null +++ b/actions/add_items_to_object_MOD.js @@ -0,0 +1,145 @@ +module.exports = { + // --------------------------------------------------------------------- + // Action Name + // + // This is the name of the action displayed in the editor. + // --------------------------------------------------------------------- + + name: 'Add/Edit Items in Object', + + // --------------------------------------------------------------------- + // Action Section + // + // This is the section the action will fall into. + // --------------------------------------------------------------------- + + section: 'JSON Things', + + // --------------------------------------------------------------------- + // Action Subtitle + // + // This function generates the subtitle displayed next to the name. + // --------------------------------------------------------------------- + + subtitle(data, presets) { + const storage = presets.variables; + return `Add ${Object.entries(data.entriess).length} item${Object.entries(data.entriess).length === 1 ? '' : 's'} entries to ${storage[parseInt(data.storage, 10)]} (${data.varName})`; + }, + + // --------------------------------------------------------------------- + // Action Meta Data + // + // Helps check for updates and provides info if a custom mod. + // If this is a third-party mod, please set "author" and "authorUrl". + // + // It's highly recommended "preciseCheck" is set to false for third-party mods. + // This will make it so the patch version (0.0.X) is not checked. + // --------------------------------------------------------------------- + + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/add_items_to_object_MOD.js', + }, + + // --------------------------------------------------------------------- + // Action Fields + // + // These are the fields for the action. These fields are customized + // by creating elements with corresponding IDs in the HTML. These + // are also the names of the fields stored in the action's JSON data. + // --------------------------------------------------------------------- + + fields: ['storage', 'varName', 'entriess'], + + // --------------------------------------------------------------------- + // Command HTML + // + // This function returns a string containing the HTML used for + // editing actions. + // + // The "isEvent" parameter will be true if this action is being used + // for an event. Due to their nature, events lack certain information, + // so edit the HTML to reflect this. + // --------------------------------------------------------------------- + + html(isEvent, data) { + return ` + + +



+ + +
+
+ Key
+
+
+
+ Value
+ +
+
+
+ + +`; + }, + + // --------------------------------------------------------------------- + // Action Editor Init Code + // + // When the HTML is first applied to the action editor, this code + // is also run. This helps add modifications or setup reactionary + // functions for the DOM elements. + // --------------------------------------------------------------------- + + init() {}, + + // --------------------------------------------------------------------- + // Action Bot Function + // + // This is the function for the action within the Bot's Action class. + // Keep in mind event calls won't have access to the "msg" parameter, + // so be sure to provide checks for variable existence. + // --------------------------------------------------------------------- + + action(cache) { + const data = cache.actions[cache.index]; + const storage = parseInt(data.storage, 10); + const varName = this.evalMessage(data.varName, cache); + const list = this.getVariable(storage, varName, cache); + + for (let i = 0; i < data.entriess.length; i++) { + const key = this.evalMessage(data.entriess[i].key, cache); + let val = this.evalMessage(data.entriess[i].value, cache); + if (!key) continue; + if (!val) { + delete list[key]; + continue; + } else { + try { + val = this.eval(val, cache); + } catch (e) { + this.displayError(data, cache, e); + } + list[key] = val; + }; + }; + + this.callNextAction(cache); + }, + + // --------------------------------------------------------------------- + // Action Bot Mod + // + // Upon initialization of the bot, this code is run. Using the bot's + // DBM namespace, one can add/modify existing functions if necessary. + // In order to reduce conflicts between mods, be sure to alias + // functions you wish to overwrite. + // --------------------------------------------------------------------- + + mod() {}, +}; diff --git a/actions/create_object_MOD.js b/actions/create_object_MOD.js new file mode 100644 index 00000000..e7bb91f9 --- /dev/null +++ b/actions/create_object_MOD.js @@ -0,0 +1,120 @@ +module.exports = { + // --------------------------------------------------------------------- + // Action Name + // + // This is the name of the action displayed in the editor. + // --------------------------------------------------------------------- + + name: 'Create Object', + + // --------------------------------------------------------------------- + // Action Section + // + // This is the section the action will fall into. + // --------------------------------------------------------------------- + + section: 'JSON Things', + + // --------------------------------------------------------------------- + // Action Subtitle + // + // This function generates the subtitle displayed next to the name. + // --------------------------------------------------------------------- + + subtitle(data, presets) { + const storage = presets.variables; + return `${storage[parseInt(data.storage, 10)]} (${data.varName})`; + }, + + // --------------------------------------------------------------------- + // Action Storage Function + // + // Stores the relevant variable info for the editor. + // --------------------------------------------------------------------- + + variableStorage(data, varType) { + const type = parseInt(data.storage, 10); + if (type !== varType) return; + return [data.varName, 'Object']; + }, + + // --------------------------------------------------------------------- + // Action Meta Data + // + // Helps check for updates and provides info if a custom mod. + // If this is a third-party mod, please set "author" and "authorUrl". + // + // It's highly recommended "preciseCheck" is set to false for third-party mods. + // This will make it so the patch version (0.0.X) is not checked. + // --------------------------------------------------------------------- + + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/create_object_MOD.js', + }, + + // --------------------------------------------------------------------- + // Action Fields + // + // These are the fields for the action. These fields are customized + // by creating elements with corresponding IDs in the HTML. These + // are also the names of the fields stored in the action's JSON data. + // --------------------------------------------------------------------- + + fields: ['storage', 'varName'], + + // --------------------------------------------------------------------- + // Command HTML + // + // This function returns a string containing the HTML used for + // editing actions. + // + // The "isEvent" parameter will be true if this action is being used + // for an event. Due to their nature, events lack certain information, + // so edit the HTML to reflect this. + // --------------------------------------------------------------------- + + html(isEvent, data) { + return ``; + }, + + // --------------------------------------------------------------------- + // Action Editor Init Code + // + // When the HTML is first applied to the action editor, this code + // is also run. This helps add modifications or setup reactionary + // functions for the DOM elements. + // --------------------------------------------------------------------- + + init() {}, + + // --------------------------------------------------------------------- + // Action Bot Function + // + // This is the function for the action within the Bot's Action class. + // Keep in mind event calls won't have access to the "msg" parameter, + // so be sure to provide checks for variable existence. + // --------------------------------------------------------------------- + + action(cache) { + const data = cache.actions[cache.index]; + const varName = this.evalMessage(data.varName, cache); + const storage = parseInt(data.storage, 10); + this.storeValue({}, storage, varName, cache); + this.callNextAction(cache); + }, + + // --------------------------------------------------------------------- + // Action Bot Mod + // + // Upon initialization of the bot, this code is run. Using the bot's + // DBM namespace, one can add/modify existing functions if necessary. + // In order to reduce conflicts between mods, be sure to alias + // functions you wish to overwrite. + // --------------------------------------------------------------------- + + mod() {}, +}; diff --git a/actions/get_item_from_object_MOD.js b/actions/get_item_from_object_MOD.js new file mode 100644 index 00000000..e2b5b34c --- /dev/null +++ b/actions/get_item_from_object_MOD.js @@ -0,0 +1,138 @@ +module.exports = { + // --------------------------------------------------------------------- + // Action Name + // + // This is the name of the action displayed in the editor. + // --------------------------------------------------------------------- + + name: 'Get Item from Object', + + // --------------------------------------------------------------------- + // Action Section + // + // This is the section the action will fall into. + // --------------------------------------------------------------------- + + section: 'JSON Things', + + // --------------------------------------------------------------------- + // Action Subtitle + // + // This function generates the subtitle displayed next to the name. + // --------------------------------------------------------------------- + + subtitle(data, presets) { + return `Get Item from ${presets.variables[parseInt(data.storage1, 10)]} (${data.varName})`; + }, + + // --------------------------------------------------------------------- + // Action Storage Function + // + // Stores the relevant variable info for the editor. + // --------------------------------------------------------------------- + + variableStorage(data, varType) { + const type = parseInt(data.storage, 10); + if (type !== varType) return; + + return [data.varName2, 'Unknown Type']; + }, + + // --------------------------------------------------------------------- + // Action Meta Data + // + // Helps check for updates and provides info if a custom mod. + // If this is a third-party mod, please set "author" and "authorUrl". + // + // It's highly recommended "preciseCheck" is set to false for third-party mods. + // This will make it so the patch version (0.0.X) is not checked. + // --------------------------------------------------------------------- + + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/get_item_from_object_MOD.js', + }, + + // --------------------------------------------------------------------- + // Action Fields + // + // These are the fields for the action. These fields are customized + // by creating elements with corresponding IDs in the HTML. These + // are also the names of the fields stored in the action's JSON data. + // --------------------------------------------------------------------- + + fields: ['storage1', 'varName', 'key', 'storage', 'varName2'], + + // --------------------------------------------------------------------- + // Command HTML + // + // This function returns a string containing the HTML used for + // editing actions. + // + // The "isEvent" parameter will be true if this action is being used + // for an event. Due to their nature, events lack certain information, + // so edit the HTML to reflect this. + // --------------------------------------------------------------------- + + html(isEvent, data) { + return ` + + +



+ +
+ Key
+
+
+ +


+ +`; + }, + + // --------------------------------------------------------------------- + // Action Editor Init Code + // + // When the HTML is first applied to the action editor, this code + // is also run. This helps add modifications or setup reactionary + // functions for the DOM elements. + // --------------------------------------------------------------------- + + init() {}, + + // --------------------------------------------------------------------- + // Action Bot Function + // + // This is the function for the action within the Bot's Action class. + // Keep in mind event calls won't have access to the "msg" parameter, + // so be sure to provide checks for variable existence. + // --------------------------------------------------------------------- + + async action(cache) { + const data = cache.actions[cache.index]; + const object = this.getVariable(data.storage1, data.varName, cache); + + const result = object[data.key]; + if (result) { + const varName2 = this.evalMessage(data.varName2, cache); + const storage2 = parseInt(data.storage, 10); + this.storeValue(result, storage2, varName2, cache); + }; + + this.callNextAction(cache); + }, + + // --------------------------------------------------------------------- + // Action Bot Mod + // + // Upon initialization of the bot, this code is run. Using the bot's + // DBM namespace, one can add/modify existing functions if necessary. + // In order to reduce conflicts between mods, be sure to alias + // functions you wish to overwrite. + // --------------------------------------------------------------------- + + mod() {}, +}; From 7f9d9eb3ffa61a9ab14c27e51d083bffc46babb8 Mon Sep 17 00:00:00 2001 From: TCMine <32180878+TCMine@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:34:23 -0500 Subject: [PATCH 2/5] Update mods.json --- docs/mods.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/mods.json b/docs/mods.json index 65b273db..2d2ed2fd 100644 --- a/docs/mods.json +++ b/docs/mods.json @@ -9,6 +9,16 @@ "name": "Comment", "section": "Other Stuff" }, + "add_item_to_object_MOD.js": { + "description": "Adds or edits an entry in an object", + "name": "Add/Edit Item in Object", + "section": "JSON Things" + }, + "add_items_to_object_MOD.js": { + "description": "Adds or edits multiple entries in an object", + "name": "Add/Edit Items in Object", + "section": "JSON Things" + }, "add_member_to_thread_MOD.js": { "description": "Add Member To Thread", "name": "Add Member To Private Thread", @@ -269,6 +279,11 @@ "name": "Create GIF", "section": "Image Editing" }, + "create_object_MOD.js": { + "description": "Creates an object", + "name": "Create Object", + "section": "JSON Things" + }, "create_permission_MOD.js": { "description": "Create specified permissions", "name": "Create Permissions", @@ -449,6 +464,11 @@ "name": "Get Current Timestamp", "section": "Other Stuff" }, + "get_item_from_object_MOD.js": { + "description": "Stores the value of an entry from an object", + "name": "Get Item from Object", + "section": "JSON Things" + }, "get_lyrics_MOD.js": { "description": "Get song lyrics", "name": "Get Song Lyrics", From 8b51b85646e5b514a556a055f5e2325439d025bf Mon Sep 17 00:00:00 2001 From: TCMine <32180878+TCMine@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:41:13 -0500 Subject: [PATCH 3/5] remove semicolons whoops --- actions/add_item_to_object_MOD.js | 2 +- actions/add_items_to_object_MOD.js | 4 ++-- actions/get_item_from_object_MOD.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/add_item_to_object_MOD.js b/actions/add_item_to_object_MOD.js index d3ed3551..e3e58766 100644 --- a/actions/add_item_to_object_MOD.js +++ b/actions/add_item_to_object_MOD.js @@ -119,7 +119,7 @@ module.exports = { this.displayError(data, cache, e); } list[key] = val; - }; + } this.callNextAction(cache); }, diff --git a/actions/add_items_to_object_MOD.js b/actions/add_items_to_object_MOD.js index def35efd..078e059f 100644 --- a/actions/add_items_to_object_MOD.js +++ b/actions/add_items_to_object_MOD.js @@ -126,8 +126,8 @@ module.exports = { this.displayError(data, cache, e); } list[key] = val; - }; - }; + } + } this.callNextAction(cache); }, diff --git a/actions/get_item_from_object_MOD.js b/actions/get_item_from_object_MOD.js index e2b5b34c..62f1bae7 100644 --- a/actions/get_item_from_object_MOD.js +++ b/actions/get_item_from_object_MOD.js @@ -120,7 +120,7 @@ module.exports = { const varName2 = this.evalMessage(data.varName2, cache); const storage2 = parseInt(data.storage, 10); this.storeValue(result, storage2, varName2, cache); - }; + } this.callNextAction(cache); }, From 87da34be28e324d60cb24e9aa8a79673275c64fd Mon Sep 17 00:00:00 2001 From: TCMine <32180878+TCMine@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:43:05 -0500 Subject: [PATCH 4/5] Update add_items_to_object_MOD.js can we fix this stupid prettier rule that makes template literals look like a mess?? --- actions/add_items_to_object_MOD.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/actions/add_items_to_object_MOD.js b/actions/add_items_to_object_MOD.js index 078e059f..5fc06c41 100644 --- a/actions/add_items_to_object_MOD.js +++ b/actions/add_items_to_object_MOD.js @@ -23,7 +23,9 @@ module.exports = { subtitle(data, presets) { const storage = presets.variables; - return `Add ${Object.entries(data.entriess).length} item${Object.entries(data.entriess).length === 1 ? '' : 's'} entries to ${storage[parseInt(data.storage, 10)]} (${data.varName})`; + return `Add ${Object.entries(data.entriess).length} item${ + Object.entries(data.entriess).length === 1 ? '' : 's' + } entries to ${storage[parseInt(data.storage, 10)]} (${data.varName})`; }, // --------------------------------------------------------------------- From 14515621fd531cf2e652e417b6b57b5dda49716e Mon Sep 17 00:00:00 2001 From: TCMine <32180878+TCMine@users.noreply.github.com> Date: Thu, 5 Sep 2024 04:47:45 -0500 Subject: [PATCH 5/5] change names --- actions/add_item_to_object_MOD.js | 2 +- actions/add_items_to_object_MOD.js | 2 +- docs/mods.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/actions/add_item_to_object_MOD.js b/actions/add_item_to_object_MOD.js index e3e58766..55cc56cd 100644 --- a/actions/add_item_to_object_MOD.js +++ b/actions/add_item_to_object_MOD.js @@ -5,7 +5,7 @@ module.exports = { // This is the name of the action displayed in the editor. // --------------------------------------------------------------------- - name: 'Add/Edit Item in Object', + name: 'Add Item to Object', // --------------------------------------------------------------------- // Action Section diff --git a/actions/add_items_to_object_MOD.js b/actions/add_items_to_object_MOD.js index 5fc06c41..6c2b7759 100644 --- a/actions/add_items_to_object_MOD.js +++ b/actions/add_items_to_object_MOD.js @@ -5,7 +5,7 @@ module.exports = { // This is the name of the action displayed in the editor. // --------------------------------------------------------------------- - name: 'Add/Edit Items in Object', + name: 'Add Items to Object', // --------------------------------------------------------------------- // Action Section diff --git a/docs/mods.json b/docs/mods.json index 2d2ed2fd..8c05aa72 100644 --- a/docs/mods.json +++ b/docs/mods.json @@ -11,12 +11,12 @@ }, "add_item_to_object_MOD.js": { "description": "Adds or edits an entry in an object", - "name": "Add/Edit Item in Object", + "name": "Add Item to Object", "section": "JSON Things" }, "add_items_to_object_MOD.js": { "description": "Adds or edits multiple entries in an object", - "name": "Add/Edit Items in Object", + "name": "Add Items to Object", "section": "JSON Things" }, "add_member_to_thread_MOD.js": {