diff --git a/commands/items.js b/commands/items.js index db167a7..e59ba92 100644 --- a/commands/items.js +++ b/commands/items.js @@ -1,4 +1,4 @@ -const { saveItem, editItemPrice } = require("../services/items.js"); +const { saveItem, deleteItem, editItemPrice } = require("../services/items.js"); const { checkDataEdit } = require("../utils/discordutils.js"); async function addItem(message, args) { @@ -47,6 +47,21 @@ async function editItem(message, args) { return; } +async function removeItem(message, args) { + if (!(await checkDataEdit(message))) return; // No permission + + if (args.length != 1) { + await message.channel.send( + "The edititem command requires 1 parameter: the calling code of the item (3 characters please)"); + return; + } + + const output = deleteItem(args[0]); + + await message.channel.send(output); + return; +} + async function editPrice(message, args) { if (!(await checkDataEdit(message))) return; // No permission @@ -69,7 +84,10 @@ module.exports = { edititem: { execute: editItem }, + removeitem: { + execute: removeItem + }, editprice: { execute: editPrice } -} \ No newline at end of file +} diff --git a/commands/mine.js b/commands/mine.js index eac327d..fd418d1 100644 --- a/commands/mine.js +++ b/commands/mine.js @@ -111,7 +111,7 @@ async function mine(message, args) { energy_string = `${watts.toFixed(0)} Wh`; } - const message_string = `Your hashrate is ${hash_rate.toFixed(4)} TH/s, and your expected income each ${period} is ${(net_income).toFixed(8)} BTC. Using ${energy_string} costing ${(electricity_cost).toFixed(8)} BTC, your expected net is ${(net_income).toFixed(8)} BTC.`; + const message_string = `Your hashrate is ${hash_rate.toFixed(4)} TH/s, and your expected gross income each ${period} is ${(gross_income).toFixed(8)} BTC. Using ${energy_string} costing ${(electricity_cost).toFixed(8)} BTC, your expected net income is ${(net_income).toFixed(8)} BTC.`; message.channel.send(message_string); } @@ -123,4 +123,4 @@ module.exports = { mine: { execute: mine } -}; \ No newline at end of file +}; diff --git a/data/itemdict.json b/data/itemdict.json index aa20774..6e34c27 100644 --- a/data/itemdict.json +++ b/data/itemdict.json @@ -575,4 +575,4 @@ "single": true, "last_edited_by": "toxicmaximalist" } -} \ No newline at end of file +} diff --git a/services/items.js b/services/items.js index e3f9bfa..04d8268 100644 --- a/services/items.js +++ b/services/items.js @@ -56,6 +56,28 @@ function saveItem(code, name, price, mode, lastEditedBy, emoji = "", pricingType return `Successfully ${mode === "add" ? "added" : "edited"} item: ${name} with value $${cost}`; } +/** + * Removes an item. + * @param {string} code - The unique calling code (3-9 characters). + * @returns {string} Result message, either success or an error. + */ +function deleteItem(code) { + // Check if the memo exists + if (!code || code.length < 3 || code.length > 9) { + return "Please use a calling code that is 3-9 characters."; + } + + const itemExists = Object.prototype.hasOwnProperty.call(ITEM_DICT, code.toLowerCase()); + if (!itemExists) { + return `The calling code ${code} does not exist. Use the !additem command or an existing code.`; + } + + // Remove the memo from the store + delete ITEM_DICT[code.toLowerCase()]; + save(ITEM_DICT, FILEPATH); + return `Successfully removed item: ${code}`; +} + /** * Edits the price of an existing item. * @param {string} code - The calling code of the item. @@ -126,4 +148,4 @@ function getAllItems() { return Object.keys(ITEM_DICT); } -module.exports = { saveItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems } \ No newline at end of file +module.exports = { saveItem, deleteItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems }