diff --git a/actions/add_item_to_object_MOD.js b/actions/add_item_to_object_MOD.js new file mode 100644 index 00000000..55cc56cd --- /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 Item to 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..6c2b7759 --- /dev/null +++ b/actions/add_items_to_object_MOD.js @@ -0,0 +1,147 @@ +module.exports = { + // --------------------------------------------------------------------- + // Action Name + // + // This is the name of the action displayed in the editor. + // --------------------------------------------------------------------- + + name: 'Add Items to 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..62f1bae7 --- /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() {}, +}; diff --git a/docs/mods.json b/docs/mods.json index 65b273db..8c05aa72 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 Item to Object", + "section": "JSON Things" + }, + "add_items_to_object_MOD.js": { + "description": "Adds or edits multiple entries in an object", + "name": "Add Items to 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",