154 lines
5.7 KiB
JavaScript
154 lines
5.7 KiB
JavaScript
const { EmbedBuilder } = require('discord.js');
|
|
const { Inventory, addInventory } = require('../structures/inventory');
|
|
|
|
module.exports = {
|
|
name: "wallet",
|
|
debug: false,
|
|
global: false,
|
|
description: "manage your wallet",
|
|
usage: "[cmd] [opt]",
|
|
permissions: {
|
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
member: [],
|
|
},
|
|
options: [
|
|
{
|
|
name: "view",
|
|
description: "view your wallet",
|
|
value: "view",
|
|
type: 1,
|
|
},
|
|
{
|
|
name: "id-set",
|
|
description: "set values on your id",
|
|
value: "id-set",
|
|
type: 1,
|
|
options: [
|
|
{
|
|
name: "alter",
|
|
description: "value to alter",
|
|
value: "alter",
|
|
type: 3,
|
|
required: true,
|
|
choices: [
|
|
{ name: "firstname", value: "firstname" }, { name: "lastname", value: "lastname" },
|
|
{ name: "date of birth", value: "dob" }, { name: "address", value: "addr" },
|
|
{ name: "eye color", value: "eyeColor" }, { name: "height", value: "height" },
|
|
{ name: "weight", value: "weight" }, { name: "sex", value: "sex" },
|
|
{ name: "hair color", value: "hairColor" },
|
|
]
|
|
},
|
|
{
|
|
name: "value",
|
|
description: "New value of what you'd like to change",
|
|
value: "value",
|
|
type: 3,
|
|
required: true,
|
|
},
|
|
]
|
|
}
|
|
],
|
|
SlashCommand: {
|
|
/**
|
|
*
|
|
* @param {require("../structures/QuarksBot")} client
|
|
* @param {import("discord.js").Message} message
|
|
* @param {string[]} args
|
|
* @param {*} param3
|
|
*/
|
|
run: async (client, interaction, args, { GuildDB }) => {
|
|
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
|
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
|
|
}
|
|
|
|
let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory);
|
|
|
|
if (!inventory) {
|
|
inventory = {
|
|
userID: interaction.member.user.id,
|
|
guilds: {
|
|
[GuildDB.serverID]: {
|
|
items: [{
|
|
name: 'Wallet',
|
|
type: 'wallet',
|
|
description: '`/inventory wallet` to view wallet',
|
|
cash: 0.00,
|
|
ID: {
|
|
firstname: '',
|
|
lastname: '',
|
|
dob: '',
|
|
addr: '',
|
|
height: '',
|
|
weight: '',
|
|
eyeColor: '',
|
|
hairColor: '',
|
|
sex: '',
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
|
|
// Register inventory for user
|
|
let newInventory = new Inventory();
|
|
newInventory.createInventory(interaction.member.user.id, GuildDB.serverID);
|
|
newInventory.save().catch(err => {
|
|
if (err) return client.sendInternalError(interaction, err);
|
|
});
|
|
} else inventory = inventory.inventory
|
|
|
|
if (!client.exists(inventory.guilds[GuildDB.serverID])) {
|
|
const success = addInventory(inventory.guilds, GuildDB.serverID, interaction.member.user.id, client);
|
|
if (!success) return client.sendInternalError(interaction, 'Failed to add inventory');
|
|
}
|
|
|
|
if (args[0].name == "view") {
|
|
// Display wallet
|
|
|
|
let item = inventory.guilds[GuildDB.serverID].items[0];
|
|
let ID = `**FN** ${client.exists(item.ID.firstname) ? `${item.ID.firstname}` : '...'} **LN** ${client.exists(item.ID.lastname) ? item.ID.lastname : '...'} **DOB** ${client.exists(item.ID.dob) ? item.ID.dob : 'N/A'}\n**Address** ${client.exists(item.ID.addr) ? item.ID.addr : 'N/A'} **Height** ${client.exists(item.ID.height) ? item.ID.height : 'N/A'} **Weight** ${client.exists(item.ID.weight) ? item.ID.weight : 'N/A'}\n**Eye Color** ${client.exists(item.ID.eyeColor) ? item.ID.eyeColor : 'N/A'} **Hair Color** ${client.exists(item.ID.hairColor) ? item.ID.hairColor : 'N/A'} **Sex** ${client.exists(item.ID.sex) ? item.ID.sex : 'N/A'}`
|
|
|
|
let walletEmbed = new EmbedBuilder()
|
|
.setTitle(`Your Wallet`)
|
|
.setColor(client.config.Colors.Default)
|
|
.addFields(
|
|
{ name: '**Cash**', value: `$${item.cash.toFixed(2)}`, inline: true },
|
|
{ name: '**ID**', value: ID, inline: false });
|
|
|
|
return interaction.send({ embeds: [walletEmbed] });
|
|
|
|
} else if (args[0].name == "id-set") {
|
|
const query = {"inventory.userID":interaction.member.user.id, [`inventory.guilds.${GuildDB.serverID}.items.type`]:"wallet"};
|
|
|
|
let update = {$set: {[`inventory.guilds.${GuildDB.serverID}.items.$.ID.${args[0].options[0].value}`]: args[0].options[1].value}};
|
|
let updateAction = args[0].options[0].name;
|
|
|
|
if (args[0].options[0].value == "dob") {
|
|
const isDate = (date) => {
|
|
return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date));
|
|
}
|
|
|
|
if (!isDate(args[0].options[1].value)) {
|
|
let embed = new EmbedBuilder()
|
|
.setTitle("Invalid Date of Birth")
|
|
.setColor(client.config.Colors.Red);
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
}
|
|
|
|
client.dbo.collection("inventories").updateOne(query, update, function (err, res) {
|
|
if (err) return client.sendInternalError(interaction, err);
|
|
});
|
|
|
|
let successEmbed = new EmbedBuilder()
|
|
.setTitle('Success')
|
|
.setDescription(`Successfully set ${updateAction}\nUse \`/inventory wallet\` to view your updated ID`)
|
|
.setColor(client.config.Colors.Green);
|
|
|
|
return interaction.send({ embeds: [successEmbed] });
|
|
|
|
}
|
|
},
|
|
},
|
|
} |