Skip to content

Commit d454fcb

Browse files
authored
Fix mine command and modify item entries (#11)
* Update itemdict.json by modifying entries Removed 'mata' entry and renamed 'miat' to 'miata' in item dictionary. * Update income message to reflect gross income Also changed text to be more specific * Revert previous item changes * wrong spot :P * Add deleteItem function to remove items by code * Implement deleteItem function in items.js Add deleteItem function to handle item deletion. * Rename deleteItem function to removeItem, add import * Add removeitem command to module exports * Add deleteItem to module exports in items.js * fixed docstring for deleteitem * empty commit?
1 parent f4b2055 commit d454fcb

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

commands/items.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { saveItem, editItemPrice } = require("../services/items.js");
1+
const { saveItem, deleteItem, editItemPrice } = require("../services/items.js");
22
const { checkDataEdit } = require("../utils/discordutils.js");
33

44
async function addItem(message, args) {
@@ -47,6 +47,21 @@ async function editItem(message, args) {
4747
return;
4848
}
4949

50+
async function removeItem(message, args) {
51+
if (!(await checkDataEdit(message))) return; // No permission
52+
53+
if (args.length != 1) {
54+
await message.channel.send(
55+
"The edititem command requires 1 parameter: the calling code of the item (3 characters please)");
56+
return;
57+
}
58+
59+
const output = deleteItem(args[0]);
60+
61+
await message.channel.send(output);
62+
return;
63+
}
64+
5065
async function editPrice(message, args) {
5166
if (!(await checkDataEdit(message))) return; // No permission
5267

@@ -69,7 +84,10 @@ module.exports = {
6984
edititem: {
7085
execute: editItem
7186
},
87+
removeitem: {
88+
execute: removeItem
89+
},
7290
editprice: {
7391
execute: editPrice
7492
}
75-
}
93+
}

commands/mine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async function mine(message, args) {
111111
energy_string = `${watts.toFixed(0)} Wh`;
112112
}
113113

114-
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.`;
114+
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.`;
115115

116116
message.channel.send(message_string);
117117
}
@@ -123,4 +123,4 @@ module.exports = {
123123
mine: {
124124
execute: mine
125125
}
126-
};
126+
};

data/itemdict.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,4 @@
575575
"single": true,
576576
"last_edited_by": "toxicmaximalist"
577577
}
578-
}
578+
}

services/items.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ function saveItem(code, name, price, mode, lastEditedBy, emoji = "", pricingType
5656
return `Successfully ${mode === "add" ? "added" : "edited"} item: ${name} with value $${cost}`;
5757
}
5858

59+
/**
60+
* Removes an item.
61+
* @param {string} code - The unique calling code (3-9 characters).
62+
* @returns {string} Result message, either success or an error.
63+
*/
64+
function deleteItem(code) {
65+
// Check if the memo exists
66+
if (!code || code.length < 3 || code.length > 9) {
67+
return "Please use a calling code that is 3-9 characters.";
68+
}
69+
70+
const itemExists = Object.prototype.hasOwnProperty.call(ITEM_DICT, code.toLowerCase());
71+
if (!itemExists) {
72+
return `The calling code ${code} does not exist. Use the !additem command or an existing code.`;
73+
}
74+
75+
// Remove the memo from the store
76+
delete ITEM_DICT[code.toLowerCase()];
77+
save(ITEM_DICT, FILEPATH);
78+
return `Successfully removed item: ${code}`;
79+
}
80+
5981
/**
6082
* Edits the price of an existing item.
6183
* @param {string} code - The calling code of the item.
@@ -126,4 +148,4 @@ function getAllItems() {
126148
return Object.keys(ITEM_DICT);
127149
}
128150

129-
module.exports = { saveItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems }
151+
module.exports = { saveItem, deleteItem, editItemPrice, getItemPrice, isSingleItem, formatItem, getAllItems }

0 commit comments

Comments
 (0)