104 lines
3.5 KiB
JavaScript
104 lines
3.5 KiB
JavaScript
const { EmbedBuilder } = require('discord.js');
|
|
const { Bank, addBank } = require('../structures/bank');
|
|
|
|
module.exports = {
|
|
name: "fine",
|
|
debug: false,
|
|
global: false,
|
|
description: "Fine a user for an offense",
|
|
usage: "[user] [amount]",
|
|
permissions: {
|
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
member: [],
|
|
},
|
|
options: [
|
|
{
|
|
name: "user",
|
|
description: "The user to fine",
|
|
value: "user",
|
|
type: 6,
|
|
required: true,
|
|
},
|
|
{
|
|
name: "amount",
|
|
description: "Amount the fine totals to",
|
|
value: "amount",
|
|
type: 10,
|
|
min_value: 0.01,
|
|
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) });
|
|
}
|
|
|
|
if (!GuildDB.officerRole) {
|
|
const embed = EmbedBuilder()
|
|
.setColor(client.config.Colors.Yellow)
|
|
.setDescription("**Notice:** The admins have not set an officer role.")
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
|
|
if (!interaction.member.roles.includes(GuildDB.officerRole)) {
|
|
const embed = EmbedBuilder()
|
|
.setColor(client.config.Colors.Yellow)
|
|
.setDescription(`**Notice:** You require the <@&${GuildDB.officerRole}>`)
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
|
|
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
|
let banking = await client.dbo.collection("banks").findOne({"banking.userID": targetUserID}).then(banking => banking);
|
|
|
|
if (!banking) {
|
|
banking = {
|
|
userID: targetUserID,
|
|
guilds: {
|
|
[GuildDB.serverID]: {
|
|
account: {
|
|
balance: GuildDB.startingBalance,
|
|
cash: 0.00,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Register inventory for user
|
|
let newBank = new Bank();
|
|
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance, 0);
|
|
newBank.save().catch(err => {
|
|
if (err) return client.sendInternalError(interaction, err);
|
|
});
|
|
|
|
} else banking = banking.banking;
|
|
|
|
if (!client.exists(banking.guilds[GuildDB.serverID])) {
|
|
const success = addBank(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
|
|
if (!success) return client.sendInternalError(interaction, 'Failed to add bank');
|
|
}
|
|
|
|
const newTargetBalance = banking.guilds[GuildDB.serverID].account.balance - args[0].options[1].value;
|
|
|
|
client.dbo.collection("banks").updateOne({"banking.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newTargetBalance}}, function(err, res) {
|
|
if (err) return client.sendInternalError(interaction, err);
|
|
});
|
|
|
|
const successEmbed = new EmbedBuilder()
|
|
.setTitle('Bank Notice:')
|
|
.setDescription(`Successfully fined <@${targetUserID}> $${args[0].options[1].value.toFixed(2)}`)
|
|
.setColor(client.config.Colors.Green);
|
|
|
|
return interaction.send({ embeds: [successEmbed] });
|
|
},
|
|
},
|
|
} |