Added the framework for the message-leveling system

This commit is contained in:
ION606
2022-11-18 11:01:15 -05:00
parent 1b1932015e
commit 6ae725d211
8 changed files with 97 additions and 31 deletions
+39
View File
@@ -0,0 +1,39 @@
const { addxp, BASE } = require('../db/econ.js');
async function setCard(bot, interaction) {
bot.mongoconnection.then(async (client) => {
const dbo = client.db(interaction.guildId).collection('SETUP');
dbo.findOne({_id: "LEVELING"}).then((doc) => {
const bkBuffer = Buffer.from(doc.card, 'base64');
});
});
}
function textToLevels(bot, message, xp_list) {
const author = message.author;
// doc.xp + (BASE.XP * doc.rank)
bot.mongoconnection.then((client) => {
const serverOpts = client.db(message.guild.id).collection('SETUP');
serverOpts.findOne({_id: "LEVELING"}).then((doc) => {
if (!doc) {
doc.insertOne({_id: "LEVELING", enabled: false, card: undefined, text: undefined});
const server = bot.guilds.cache.get(message.guild.id);
server.members.fetch(guild.ownerId).then(function(owner) {
// Implement `setup leveling enable`
owner.send("Interactive Leveling has been added to your server!\nTo enable it, use `/setup leveling enable`");
});
} else if (doc.enabled) {
const dbo = client.db(message.guild.id).collection(author.id);
dbo.findOne({"balance": {$exists: true}}).then((doc) => {
const newXp = doc.xp + Math.ceil((BASE.XP * doc.rank) / 4);
addxp(message, dbo, newXp, xp_list, true);
});
}
});
});
}
module.exports = {textToLevels};
+18 -3
View File
@@ -3,7 +3,7 @@ const { MongoClient, ServerApiVersion } = require('mongodb');
const { Constants } = require('discord.js');
const { CreateNewCollection } = require("../db/econ");
const { checkRole } = require('./verify.js');
const fetch = require('node-fetch');
// const fetch = require('node-fetch');
async function execute(interaction, Discord, Client, bot) {
@@ -110,7 +110,7 @@ async function execute(interaction, Discord, Client, bot) {
dbo.updateOne({_id: 'WELCOME'}, {$set: {welcomebanner: imgbfr.toString('base64')}});
interaction.reply({ content: "Banner updated!", ephemeral: true });
}
else if ("welcome_text_color") {
else if (command == "welcome_text_color") {
const reg = /^#[0-9A-F]{6}$/i;
const newCol = interaction.options.data[0].value;
if (reg.test(newCol)) {
@@ -120,6 +120,18 @@ async function execute(interaction, Discord, Client, bot) {
interaction.reply("Please chose a valid hex color");
}
}
else if (command == "toggle_leveling") {
dbo.updateOne({_id: 'LEVELING'}, {$set: {enabled: interaction.options.data[0].value}});
}
else if (command == "leveling_banner") {
const response = await fetch(interaction.options.data[0].attachment.attachment);
const arrayBuffer = await response.arrayBuffer();
const imgbfr = Buffer.from(arrayBuffer);
dbo.updateOne({_id: 'LEVELING'}, {$set: {card: imgbfr.toString('base64')}});
}
else if (command == "leveling_text") {
dbo.updateOne({_id: 'LEVELING'}, {$set: {text: interaction.options.data[0].value}});
}
else {
interaction.reply({content: "Please chose a valid option", ephemeral: true});
}
@@ -164,7 +176,10 @@ module.exports = {
{name: 'announcement_role', description: 'Sets the role to be pinged for reminders', type: Constants.ApplicationCommandOptionTypes.ROLE},
{name: 'announcement_channel', description: 'Sets the channel for reminders', type: Constants.ApplicationCommandOptionTypes.CHANNEL},
{name: 'add_mod_role', description: 'Make a role into an admin role for Selmer Bot, able to execute ALL Selmer Bot commands', type: Constants.ApplicationCommandOptionTypes.ROLE},
{name: 'remove_mod_role', description: 'Remove a Selmer Bot moderation role', type: Constants.ApplicationCommandOptionTypes.ROLE}
{name: 'remove_mod_role', description: 'Remove a Selmer Bot moderation role', type: Constants.ApplicationCommandOptionTypes.ROLE},
{name: 'toggle_leveling', description: 'Enable or Disable the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN},
{name: 'leveling_banner', description: 'Set the card background for the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN},
{name: 'leveling_text', description: 'Set the card text for the leveling system', type: Constants.ApplicationCommandOptionTypes.BOOLEAN},
// {name: 'help', description: 'gets help with setup commands', type: Constants.ApplicationCommandOptionTypes.STRING, choices: [{name: 'welcome', value: 'welcome'}, {name: 'logs', value: 'logs'}, {name: 'announcement', value: 'announcement'}]}
]
}
-10
View File
@@ -94,21 +94,11 @@ async function welcome(member, welcomeChannel, welcomemessage, welcomebanner, we
// return console.log(buffer.byteLength * 0.000001);
welcomeChannel.send({
content: "content",
files: [buffer],
});
});
});
});
// .toFile("./events/output.jpeg", (err, info) => {
// if (err) throw err;
// const attachment = new DJS.MessageAttachment("./events/output.jpeg");
// welcomeChannel.send({
// content: content,
// files: [attachment],
// });*/
// });
}
module.exports = { welcome }
+18 -7
View File
@@ -46,7 +46,7 @@ function CreateNewCollection(interaction, client, server, id, opponent = null, g
}
function addxp(interaction, dbo, amt, xp_list) {
function addxp(interaction, dbo, amt, xp_list, noPing = false) {
if (!isNum(amt)) { return console.log("This isn't a number...."); }
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) {
@@ -75,13 +75,24 @@ function addxp(interaction, 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} }});
interaction.channel.send('Congradulations <@' + interaction.user.id + '> for reaching rank ' + String(rank) + '!');
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank, hpmp: {maxhp: newhp, maxmp: newmp}, xp: txp }});
var user;
if (interaction.user) {
user = interaction.user;
} else {
// This is a message
user = interaction.author;
}
interaction.channel.send('Congradulations <@' + user.id + '> for reaching rank ' + String(rank) + '!');
}
} else {
interaction.reply("You've already reached max level!").catch((err) => {
interaction.channel.send("You've already reached max level!");
});
if (!noPing) {
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}});
@@ -388,6 +399,6 @@ module.exports = {
},
//Battle Updating stuff
addxp, checkAndUpdateBal, CreateNewCollection, econHelp, addxp, BASE, STATE,
addxp, checkAndUpdateBal, CreateNewCollection, econHelp, BASE, STATE,
options: []
}
+1 -1
View File
@@ -31,7 +31,7 @@ function loseGame(user_dbo, xp_collection, interaction, bot = null) {
}
//Update the player's xp
addxp(interaction, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection)
addxp(interaction, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection);
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, 'hpmp.hp': doc.hpmp.maxhp, 'hpmp.mp': doc.hpmp.maxmp }});
resolve(addbal);