Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions commands/items.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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

Expand All @@ -69,7 +84,10 @@ module.exports = {
edititem: {
execute: editItem
},
removeitem: {
execute: removeItem
},
editprice: {
execute: editPrice
}
}
}
4 changes: 2 additions & 2 deletions commands/mine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -123,4 +123,4 @@ module.exports = {
mine: {
execute: mine
}
};
};
2 changes: 1 addition & 1 deletion data/itemdict.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,4 @@
"single": true,
"last_edited_by": "toxicmaximalist"
}
}
}
24 changes: 23 additions & 1 deletion services/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -126,4 +148,4 @@ function getAllItems() {
return Object.keys(ITEM_DICT);
}

module.exports = { saveItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems }
module.exports = { saveItem, deleteItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems }
Loading