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
+1
View File
@@ -9,3 +9,4 @@ backup.json
temp.js temp.js
easySetup.js easySetup.js
meme.js
+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 { Constants } = require('discord.js');
const { CreateNewCollection } = require("../db/econ"); const { CreateNewCollection } = require("../db/econ");
const { checkRole } = require('./verify.js'); const { checkRole } = require('./verify.js');
const fetch = require('node-fetch'); // const fetch = require('node-fetch');
async function execute(interaction, Discord, Client, bot) { 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')}}); dbo.updateOne({_id: 'WELCOME'}, {$set: {welcomebanner: imgbfr.toString('base64')}});
interaction.reply({ content: "Banner updated!", ephemeral: true }); 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 reg = /^#[0-9A-F]{6}$/i;
const newCol = interaction.options.data[0].value; const newCol = interaction.options.data[0].value;
if (reg.test(newCol)) { if (reg.test(newCol)) {
@@ -120,6 +120,18 @@ async function execute(interaction, Discord, Client, bot) {
interaction.reply("Please chose a valid hex color"); 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 { else {
interaction.reply({content: "Please chose a valid option", ephemeral: true}); 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_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: '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: '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'}]} // {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); // return console.log(buffer.byteLength * 0.000001);
welcomeChannel.send({ welcomeChannel.send({
content: "content",
files: [buffer], 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 } 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...."); } if (!isNum(amt)) { return console.log("This isn't a number...."); }
dbo.find({"balance": {$exists: true}}).toArray(function(err, doc) { 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; let newmp = temp.mp + 5;
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank, hpmp: {maxhp: newhp, maxmp: newmp} }}); dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank, hpmp: {maxhp: newhp, maxmp: newmp}, xp: txp }});
interaction.channel.send('Congradulations <@' + interaction.user.id + '> for reaching rank ' + String(rank) + '!');
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 { } else {
interaction.reply("You've already reached max level!").catch((err) => { if (!noPing) {
interaction.channel.send("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}}); dbo.updateOne({balance: temp.balance}, { $set: { xp: txp}});
@@ -388,6 +399,6 @@ module.exports = {
}, },
//Battle Updating stuff //Battle Updating stuff
addxp, checkAndUpdateBal, CreateNewCollection, econHelp, addxp, BASE, STATE, addxp, checkAndUpdateBal, CreateNewCollection, econHelp, BASE, STATE,
options: [] options: []
} }
+1 -1
View File
@@ -31,7 +31,7 @@ function loseGame(user_dbo, xp_collection, interaction, bot = null) {
} }
//Update the player's xp //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 }}); 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); resolve(addbal);
+16 -7
View File
@@ -17,6 +17,7 @@ const { registerCommands } = require('./registerCommands.js');
const { backupLists, loadBotBackups } = require('./commands/dev only/backupBot.js'); const { backupLists, loadBotBackups } = require('./commands/dev only/backupBot.js');
const { setPresence } = require('./commands/dev only/setPresence.js'); const { setPresence } = require('./commands/dev only/setPresence.js');
const { exit } = require('process'); const { exit } = require('process');
const {textToLevels} = require('./commands/Selmer Specific/msgLevels.js');
//#endregion //#endregion
const BASE_LVL_XP = 20; const BASE_LVL_XP = 20;
@@ -172,6 +173,7 @@ bot.commands.set('game', temp_command);
//XP Table section //XP Table section
let xp_collection = new Map(); let xp_collection = new Map();
let items; let items;
var botIsReady = bot.inDebugMode;
bot.on('ready', async () => { bot.on('ready', async () => {
const startTime = new Date().getTime(); const startTime = new Date().getTime();
@@ -212,14 +214,19 @@ bot.on('ready', async () => {
bot.currencysymbolmmain = `${emj}`; bot.currencysymbolmmain = `${emj}`;
}).catch((err) => { }).catch((err) => {
console.log(err); console.log(err);
}).finally(() => { console.log(`Setting up Slash Commands took ${(new Date().getTime() - startTime) / 1000} seconds to complete!`); }); }).finally(() => {
botIsReady = true;
console.log(`Setting up Slash Commands took ${(new Date().getTime() - startTime) / 1000} seconds to complete!`);
});
}); });
//Button Section //Button Section
bot.on('interactionCreate', async interaction => { bot.on('interactionCreate', async interaction => {
const { commandName } = interaction; const { commandName } = interaction;
if (!botIsReady) {
return interaction.reply("The bot is still warming up. This is process can take up to 5 minutes. Please try again in a bit! \:(");
}
// console.log(bot.lockedChannels); // console.log(bot.lockedChannels);
//Slash commands //Slash commands
if (interaction.isApplicationCommand()) { if (interaction.isApplicationCommand()) {
@@ -364,7 +371,7 @@ bot.on('guildMemberAdd', async (member) => {
} }
if (welcomechannel == null) { if (welcomechannel == null) {
return console.log('No welcome channel detected'); return; // console.log('No welcome channel detected');
} }
await welcome(member, welcomechannel, docs[0].welcomemessage, docs[0].welcomebanner, (docs[0].welcometextcolor) ? docs[0].welcometextcolor : "#FFFFFF"); await welcome(member, welcomechannel, docs[0].welcomemessage, docs[0].welcomebanner, (docs[0].welcometextcolor) ? docs[0].welcometextcolor : "#FFFFFF");
@@ -392,11 +399,8 @@ bot.on('messageCreate', (message) => {
//Check if the prefix exists //Check if the prefix exists
if (message.author.bot) { return } if (message.author.bot) { return }
else if (!message.content.startsWith(prefix)) {
//Use for the leveling-by-interaction system
return;
} else {
if (message.content.startsWith(prefix)) {
//Game section (too complicated to move to Slash Commands) //Game section (too complicated to move to Slash Commands)
//Note: Slash commands do not register as valid replies //Note: Slash commands do not register as valid replies
const args = message.content.slice(prefix.length).split(' '); const args = message.content.slice(prefix.length).split(' ');
@@ -406,7 +410,12 @@ bot.on('messageCreate', (message) => {
} else if (command == 'rss' && bot.inDebugMode) { } else if (command == 'rss' && bot.inDebugMode) {
const rss = require('./side projects/RSSHandlers/rssFeed.js'); const rss = require('./side projects/RSSHandlers/rssFeed.js');
rss.execute(message, args, Discord, client, bot); rss.execute(message, args, Discord, client, bot);
} else {
textToLevels(bot, message, xp_collection);
} }
} else {
//Use for the leveling-by-interaction system
textToLevels(bot, message, xp_collection);
} }
}); });
+2 -1
View File
@@ -135,7 +135,8 @@ function registerCommands(bot) {
commands.create({ commands.create({
name: "Temp", name: "Temp",
type: 'USER' type: 'USER'
}); }).then(() => { resolve(true); });
//#endregion //#endregion
}).catch((err) => { reject(err); }); }).catch((err) => { reject(err); });