add bal command
This commit is contained in:
3 files changed
+121
-11
No files matched your search
+102
@@ -0,0 +1,102 @@
|
||||
const { MessageEmbed, Guild } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "bal",
|
||||
description: "View balance",
|
||||
usage: "[user]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
SlashCommand: {
|
||||
options: [
|
||||
{
|
||||
name: "user",
|
||||
description: "user to view ballance",
|
||||
value: "user",
|
||||
type: 6,
|
||||
required: false,
|
||||
}
|
||||
],
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/QuarksBot")} client
|
||||
* @param {import("discord.js").MessageCreate} 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(`You are not allowed to use the bot in this channel.`);
|
||||
}
|
||||
|
||||
let balanceEmbed = new MessageEmbed()
|
||||
.setColor(client.config.EmbedColor);
|
||||
|
||||
if (args&&args[0]) {
|
||||
// Show target users balance
|
||||
|
||||
let targetUserID = args[0].value.replace('<@!', '').replace('>', '');
|
||||
let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID":targetUserID}).then(inventory => inventory);
|
||||
|
||||
if (!targetUserBanking) {
|
||||
targetUserBanking = {
|
||||
account: {
|
||||
userID: interaction.member.user.id,
|
||||
ballance: GuildDB.startingBalance,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(targetUserBanking, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This lame line of code to get username without ping on discord
|
||||
const User = client.users.cache.get(targetUserID);
|
||||
|
||||
balanceEmbed.setTitle(`${User.tag}'s Balance`);
|
||||
balanceEmbed.setDescription(`**Bank:** $${targetUserBanking.account.ballance}\n**Cash:** $${targetUserBanking.account.cash}`);
|
||||
|
||||
} else {
|
||||
// Show command authors balance
|
||||
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking);
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
account: {
|
||||
userID: interaction.member.user.id,
|
||||
ballance: GuildDB.startingBalance,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(banking, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
balanceEmbed.setTitle('Your Balance');
|
||||
balanceEmbed.setDescription(`**Bank:** $${banking.account.ballance}\n**Cash:** $${banking.account.cash}`);
|
||||
}
|
||||
|
||||
return interaction.send({ embeds: [balanceEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -113,8 +113,11 @@ module.exports = {
|
||||
.catch(err => {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
const channel = interaction.guild.channels.cache.find(channel => channel.id === GuildDB.tweetChannel);
|
||||
return client.sendError(channel, err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
} else inventory = inventory.inventory;
|
||||
|
||||
+14
-9
@@ -119,8 +119,10 @@ class QuarksBot extends Client {
|
||||
}
|
||||
|
||||
async GetGuild(GuildId) {
|
||||
let serverID = GuildId;
|
||||
let customChannelStatus, allowedChannels;
|
||||
let actionChannel, tweetChannel;
|
||||
let startingBalance;
|
||||
let guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild);
|
||||
|
||||
// If guild not found, generate guild default
|
||||
@@ -129,31 +131,34 @@ class QuarksBot extends Client {
|
||||
server: {
|
||||
serverID: GuildId,
|
||||
hasCustomChannels: false,
|
||||
allowedChannels: [],
|
||||
actionChannel: null,
|
||||
tweetChannel: null
|
||||
tweetChannel: null,
|
||||
startingBalance: 1000.00,
|
||||
}
|
||||
}
|
||||
this.dbo.collection("guilds").insertOne(newGuild, function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
customChannelStatus = newGuild.server.hasCustomChannels;
|
||||
allowedChannels = null;
|
||||
actionChannel = null;
|
||||
tweetChannel = null;
|
||||
allowedChannels = newGuild.server.allowedChannels;
|
||||
actionChannel = newGuild.server.actionChannel;
|
||||
tweetChannel = newGuild.server.tweetChannel;
|
||||
startingBalance = newGuild.server.startingBalance;
|
||||
} else {
|
||||
customChannelStatus = guild.server.hasCustomChannels;
|
||||
allowedChannels = guild.server.allowedChannels;
|
||||
actionChannel = guild.server.actionChannel;
|
||||
tweetChannel = guild.server.tweetChannel;
|
||||
if (this.exists(guild.server.allowedChannels) && guild.server.allowedChannels.length>0) {
|
||||
allowedChannels = guild.server.allowedChannels;
|
||||
} else allowedChannels = null;
|
||||
startingBalance = guild.server.startingBalance;
|
||||
}
|
||||
let guildData = {
|
||||
allowedChannels: allowedChannels,
|
||||
serverID: serverID,
|
||||
customChannelStatus: customChannelStatus,
|
||||
allowedChannels: allowedChannels,
|
||||
actionChannel: actionChannel,
|
||||
tweetChannel: tweetChannel,
|
||||
serverID: GuildId
|
||||
startingBalance: startingBalance
|
||||
}
|
||||
return guildData;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user