mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-20 07:01:39 +01:00
add balance,donate,admindonate commands and minor bugfixes
This commit is contained in:
26
bot/commands/getinventory.ts
Normal file
26
bot/commands/getinventory.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Command, sendMessage } from ".";
|
||||
import { getUserRecord } from "../db/dbUser";
|
||||
import parseCommandArgs from "../lib/parseCommandArgs";
|
||||
import { User } from "../user";
|
||||
import items from "../items";
|
||||
|
||||
export default new Command('inventory', ['inv', 'inventory'], 'chatter', async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
let target: User = user;
|
||||
if (args[0]) {
|
||||
const obj = await User.initUsername(args[0].toLowerCase());
|
||||
if (!obj) { await sendMessage(`User ${args[0]} doesn't exist`, msg.messageId); return; };
|
||||
target = obj;
|
||||
};
|
||||
|
||||
const data = await getUserRecord(target);
|
||||
const messagedata: string[] = [];
|
||||
for (const [key, amount] of Object.entries(data.inventory)) {
|
||||
if (amount === 0) continue;
|
||||
const itemselection = items.get(key);
|
||||
messagedata.push(`${itemselection?.prettyName}${amount === 1 ? '' : itemselection?.plural}: ${amount}`);
|
||||
};
|
||||
|
||||
if (messagedata.length === 0) { await sendMessage(`${target.displayName} has no items`, msg.messageId); return; };
|
||||
await sendMessage(`Inventory of ${target.displayName}: ${messagedata.join(', ')}`, msg.messageId);
|
||||
});
|
||||
Reference in New Issue
Block a user