Transitioned all Misc, audio, Selmer Specific, admin, anime/manga, and inventory commands to Slash Command format. The RSS and reactionrole commands are still broken and all game commands are still in message format due to compications

This commit is contained in:
ION606
2022-09-27 16:45:50 -04:00
parent a190a250a6
commit e1002d748d
45 changed files with 1951 additions and 1058 deletions
+109 -83
View File
@@ -1,6 +1,6 @@
const { MongoClient, ServerApiVersion } = require('mongodb');
// const { update } = require('apt');
const { Collection, Client, Formatters, Intents } = require('discord.js');
const { Collection, Client, Formatters, Intents, Interaction } = require('discord.js');
const { CLIENT_ODBC } = require('mysql/lib/protocol/constants/client');
const { time } = require('@discordjs/builders');
@@ -31,14 +31,14 @@ function isNum(arg) {
};
function CreateNewCollection(message, client, server, id, opponent = null, game = null) {
function CreateNewCollection(interaction, client, server, id, opponent = null, game = null) {
const db = client.db(String(server));
const dbo = db.collection(id);
db.listCollections({name: id})
.next(function(err, collinfo) {
if (!collinfo) {
message.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
interaction.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
let hp_mp = {maxhp: BASE.HP, hp: BASE.HP, maxmp: BASE.MP, mp: BASE.MP}
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, gamesettings: {battle: {class: 'none', ultimate: true}}, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
}
@@ -46,7 +46,7 @@ function CreateNewCollection(message, client, server, id, opponent = null, game
}
function addxp(message, dbo, amt, xp_list) {
function addxp(interaction, dbo, amt, xp_list) {
if (!isNum(amt)) { return console.log("This isn't a number...."); }
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) {
@@ -76,10 +76,12 @@ function addxp(message, dbo, amt, xp_list) {
let newmp = temp.mp + 5;
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank, hpmp: {maxhp: newhp, maxmp: newmp} }});
message.channel.send('Congradulations <@' + message.author.id + '> for reaching rank ' + String(rank) + '!');
interaction.channel.send('Congradulations <@' + interaction.user.id + '> for reaching rank ' + String(rank) + '!');
}
} else {
message.reply("You've already reached max level!");
interaction.reply("You've already reached max level!").catch((err) => {
interaction.channel.send("You've already reached max level!");
});
}
dbo.updateOne({balance: temp.balance}, { $set: { xp: txp}});
@@ -87,25 +89,28 @@ function addxp(message, dbo, amt, xp_list) {
}
function getBalance(dbo, message) {
function getBalance(dbo, interaction) {
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) {
let bal = 0;
if (doc[0] && doc[0].balance) {
bal = doc[0].balance;
}
return message.reply(`<@${message.author.id}>, your current balance is ${currencySymbol}${bal}`);
return interaction.reply(`<@${interaction.user.id}>, your current balance is ${currencySymbol}${bal}`)
.catch((err) => {
interaction.channel.send(`<@${interaction.user.id}>, your current balance is ${currencySymbol}${bal}`);
});
});
}
function rank(dbo, message, xp_list) {
function rank(dbo, interaction, xp_list) {
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) {
if (!String(doc)) { return console.log("ERROR!\nThis account does not exist!"); }
let next = doc[0].rank + 1;
let needed = xp_list.get(next);
message.channel.send('<@' + message.author.id + '> you are currently at rank ' + String(next-1) + ' and have ' + String(doc[0].xp) + 'xp. You need ' + String(needed - doc[0].xp) + ' more xp to get to rank ' + String(next));
interaction.channel.send(`<@${interaction.user.id}'> you are currently at rank ${next-1} and have ${doc[0].xp}xp. You need ${needed - doc[0].xp} more xp to get to rank ${next}`);
});
}
@@ -115,22 +120,27 @@ function convertCurrency(id, amt, dbo) {
}
function checkAndUpdateBal(dbo, item, message, args) {
function checkAndUpdateBal(dbo, item, interaction, amt) {
return new Promise(function(resolve, reject) {
dbo.find({"balance": {$exists: true}}).toArray(b = function(err, doc) {
if (!String(doc)) {
message.reply("Your account doesn't exist, please contact the mods for support");
interaction.reply("Your account doesn't exist, please contact the mods for support").catch(() => {
interaction.channel.send("Your account doesn't exist, please contact the mods for support");
});
return false;
}
const icost = args[0] * item.cost;
const icost = amt * item.cost;
if (doc[0].balance < icost) {
message.reply("Insufficient funds!");
interaction.reply("Insufficient funds!").catch(() => { interaction.channel.send("Insufficient funds!"); });
resolve(false);
} else {
let temp = doc[0];
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { balance: doc[0].balance -= icost }});
message.reply(`You have bought ${item.name} for ${currencySymbol}${icost}!`);
interaction.reply(`You have bought ${item.name} for ${currencySymbol}${icost}!`).catch(() => {
interaction.channel.send(`You have bought ${item.name} for ${currencySymbol}${icost}!`);
});
resolve(true);
}
});
@@ -138,46 +148,51 @@ function checkAndUpdateBal(dbo, item, message, args) {
}
function buy(id, message, args, dbo, shop, xp_list) {
if (args.length < 2) { return; }
if (!isNum(args[0])) { return message.reply("Please enter a number for query 2"); }
function buy(id, interaction, dbo, shop, xp_list) {
const args = interaction.options.data;
let query = args[1];
//REAPPLY THIS TO OTHER FUNCTIONS
let query = args.filter((arg) => { return (arg.name == 'item'); })[0].value;
let amt = args.filter((arg) => { return (arg.name == 'amount'); })[0].value;
let item = shop.filter(function (item) { return item.name.toLowerCase() == query.toLowerCase(); })[0];
if (!String(item)) { return message.reply("This item does not exist!"); }
if (!String(item)) { return interaction.reply("This item does not exist!").catch(() => { interaction.channel.send("This item does not exist!"); }); }
// let success = Boolean(checkAndUpdateBal(dbo, item, message, args));
checkAndUpdateBal(dbo, item, message, args).then((success) => {
if (!success) { return } //The message is handled in the CheckAndUpdateBal() function
checkAndUpdateBal(dbo, item, interaction, amt).then((success) => {
//The message is handled in the CheckAndUpdateBal() function
if (!success) { return }
var newObj = { name: item.name, cost: item.cost, icon: item.icon, sect: item.sect};
addxp(message, dbo, Math.ceil(item.cost * 1.2), xp_list);
addxp(interaction, dbo, Math.ceil(item.cost * 1.2), xp_list);
dbo.find(newObj, {$exists: true}).toArray(function(err, doc) {
if(String(doc)) {
let newnum = doc[0].num + Number(args[0]);
let newnum = doc[0].num + amt;
dbo.updateOne({ name: item.name }, {$set: {num: newnum}});
} else {
item.num = amt;
// dbo.insertOne({ name: item.name, cost: item.cost, icon: item.icon, sect: item.sect, num: Number(args[0])}); //Causes "cyclic dependancy"
dbo.insertOne(item);
dbo.updateOne(item, { $set: {num: Number(args[0]) }});
dbo.updateOne(item, { $set: {num: amt }});
}
});
})
};
function sell(id, message, args, dbo, shop, xp_list) {
if (args.length < 2) { return; }
if (!isNum(args[0])) { return message.reply("Please enter a number for query 1"); }
let query = args[1];
var newObj = { name: query };
//FIXME
function sell(id, interaction, dbo, shop, xp_list) {
const args = interaction.options.data;
const query = args.filter((arg) => { return (arg.name == 'item'); })[0].value;
var num = args.filter((arg) => { return (arg.name == 'amount'); })[0].value;
let item = shop.filter(function (titem) { return titem.name.toLowerCase() == query.toLowerCase(); });
if (!String(item)) { return message.reply("This item does not exist!"); }
if (!String(item)) {
return interaction.reply("This item does not exist!").catch((err) => {
interaction.channel.send("This item does not exist!");
});
}
item[0] = {name: item[0].name, cost: item[0].cost, icon: item[0].icon, sect: item[0].sect};
@@ -187,7 +202,6 @@ function sell(id, message, args, dbo, shop, xp_list) {
if(String(doc)) {
//Make sure you don't sell more than you have
let num = Number(args[0]);
if (num < doc[0].num) {
let newNum = doc[0].num - num;
dbo.updateOne({ name: item[0].name }, {$set: {num: newNum}});
@@ -204,23 +218,34 @@ function sell(id, message, args, dbo, shop, xp_list) {
dbo.updateOne({"balance": {$exists: true}}, { $set: { balance: currentBal + amountSoldFor }});
});
addxp(message, dbo, Math.ceil(functional_item.cost * 1.2), xp_list);
addxp(interaction, dbo, Math.ceil(functional_item.cost * 1.2), xp_list);
message.reply(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`);
interaction.reply(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`)
.catch((err) => {
interaction.channel.send(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`);
});
} else {
message.reply("You don't own this item!");
interaction.reply("You don't own this item!").catch((err) => {
interaction.channel.send(`You've sold ${num} ${String(functional_item.name)} for ${currencySymbol}${amountSoldFor}`);
});
}
});
}
function work(dbo, message, xp_list) {
function work(dbo, interaction, xp_list) {
let fulldate = new Date();
let date = fulldate.getDate();
dbo.find({"lastdayworked": {$exists: true}}).toArray(function(err, doc) {
if (!String(doc)) { return message.reply("Your account doesn't exist, please contact the mods for support"); }
if (!String(doc)) {
return interaction.reply("Your account doesn't exist, please contact the mods for support").catch((err) => {
interaction.channel.send("Your account doesn't exist, please contact the mods for support");
});
}
if (doc[0].lastdayworked == date) {//date
message.reply("You've already worked today, try again tomorrow!");
interaction.reply("You've already worked today, try again tomorrow!").catch((err) => {
interaction.channel.send("You've already worked today, try again tomorrow!");
});
} else {
//Amount to be paid
let amt = 0;
@@ -229,14 +254,16 @@ function work(dbo, message, xp_list) {
//Update the amount to the new TOTAL balance
dbo.updateOne({"balance": {$exists: true}}, { $set: { balance: doc[0].balance + amt, lastdayworked: date }});
addxp(message, dbo, xp_earned, xp_list);
message.channel.send(`<@${message.author.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`);
addxp(interaction, dbo, xp_earned, xp_list);
interaction.reply(`<@${interaction.user.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`).catch((err) => {
interaction.channel.send(`<@${interaction.user.id}> worked and earned ${currencySymbol}${amt} and ${xp_earned} xp!`)
});
}
});
}
function printInventory(dbo, message) {
function printInventory(dbo, interaction) {
let tempstring = "";
dbo.find().toArray(function(err, docs){
docs.forEach(val => {
@@ -246,44 +273,50 @@ function printInventory(dbo, message) {
});
if (tempstring == "") { tempstring += "You have nothing in your inventory!"; }
message.reply(tempstring);
interaction.reply(tempstring).catch((err) => {
interaction.channel.send(tempstring);
});
});
}
function getShop(message, args, items, bot) {
if (args.length == 0) {
let temp = Formatters.codeBlock(items.map(i => `${i.sect}`).join(' '));
temp = [...new Set(temp.split(' '))];
function getShop(interaction, items, bot) {
const args = interaction.options.data;
const type = args.filter((arg) => { return (arg.name == 'type'); })[0].value.toLowerCase();
return message.reply(`Please use the format ${bot.prefix}shop [type] [page number]\nTypes are: ${temp}`);
}
// if (args.length == 0) {
// let temp = Formatters.codeBlock(items.map(i => `${i.sect}`).join(' '));
// temp = [...new Set(temp.split(' '))];
// return message.reply(`Please use the format ${bot.prefix}shop [type] [page number]\nTypes are: ${temp}`);
// }
let ind = 1;
let noinp = false;
if (args.length > 1) {
if (args[1] < (items.length / 9)) {
ind = Number(args[1]);
const amt = args.filter((arg) => { return (arg.name == 'page'); })[0].value;
if (amt.value < (items.length / 9)) {
ind = Number(amt);
} else {
return message.reply("That number is too large");
return interaction.reply("That number is too large").catch(() => { interaction.channel.send("That number is too large"); });
}
} else {
noinp = true;
}
const items2 = items.filter(function(f) { return (f.sect.toLowerCase() == args[0].toLowerCase()) }).slice((ind - 1)*10, (ind - 1)*10+10);
const items2 = items.filter(function(f) { return (f.sect.toLowerCase() == type) }).slice((ind - 1)*10, (ind - 1)*10+10);
newText = Formatters.codeBlock(items2.map(i => `${i.icon} (${i.name}): $${i.cost}`).join('\n')); //${currencySymbol} doesn't owrk for some reason
if (noinp) {
newText += `(Use ${bot.prefix}shop [type] [page number] to access other pages)`;
}
return message.reply(newText);
return interaction.reply(newText).catch(() => { interaction.channel.send(newtext); });
}
function econHelp() {
let l = ["buy", 'shop', 'work', 'rank', 'inventory', 'balance', 'sell']
let l = ["buy", 'shop', 'work', 'rank', 'inventory', 'balance', 'sell'];
return l.join(", ");
}
@@ -293,10 +326,11 @@ function econHelp() {
module.exports = {
name: 'econ',
description: 'ECON',
async execute(bot, message, args, command, Discord, mongouri, items, xp_list) {
async execute(bot, interaction, Discord, mongouri, items, xp_list) {
//Set Discord vars
const id = message.author.id;
const server = message.guild.id;
const id = interaction.user.id;
const server = interaction.guildId;
const command = interaction.commandName;
// const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
// if (client.writeConcern || client.writeConcern) {
@@ -308,14 +342,14 @@ module.exports = {
bot.mongoconnection.then(async (client) => {
//Initialize if necessary
CreateNewCollection(message, client, server, id);
CreateNewCollection(interaction, client, server, id);
const db = client.db(String(server));
const dbo = db.collection(id);
currencySymbol = bot.currencysymbolmmain;
//test area
/*/test area
if (command == 'xp' || command == 'adbal') {
//Selmer Dev only command
if (message.member.roles.cache.has('944048889038774302')) {
@@ -323,7 +357,7 @@ module.exports = {
return addxp(message, dbo, Number(args[0]), xp_list);
}
}
}
}*/
//Command Area
if(command == 'init') {
@@ -331,37 +365,29 @@ module.exports = {
// init.execute(bot, message, args, command, dbo, Discord, connect);
return;
} else if (command == 'buy') {
buy(id, message, args, dbo, items, xp_list);
buy(id, interaction, dbo, items, xp_list);
} else if (command == 'shop') {
getShop(message, args, items, bot);
getShop(interaction, items, bot);
} else if (command == 'work') {
work(dbo, message, xp_list);
work(dbo, interaction, xp_list);
} else if (command == 'rank') {
rank(dbo, message, xp_list);
rank(dbo, interaction, xp_list);
} else if (command == 'inventory') {
printInventory(dbo, message);
printInventory(dbo, interaction);
} else if (command == 'balance') {
getBalance(dbo, message);
getBalance(dbo, interaction);
} else if (command == 'sell') {
sell(id, message, args, dbo, items, xp_list);
sell(id, interaction, dbo, items, xp_list);
} else {
message.channel.send("'" + message.content + "' is not a command!");
interaction.reply(`${command} is not a command`).catch((err) => {
interaction.channel.send(`${command} is not a command`);
});
}
});
},
//Battle Updating stuff
addxp, checkAndUpdateBal, CreateNewCollection, econHelp, addxp, BASE, STATE
}
/*
?????????????? What did I need this for?
else if (command == 'checkinv') {
const req = dbo.findOne({ id: message.guild.id });
if (!req) { return message.reply("Doc doesn't exist!"); }
}
*/
addxp, checkAndUpdateBal, CreateNewCollection, econHelp, addxp, BASE, STATE,
options: []
}