This is ass, will fix spam later

This commit is contained in:
Christopher Cookman 2023-04-20 09:40:39 -06:00
parent 758b27f01f
commit 6390f718fa
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
2 changed files with 93 additions and 1 deletions

View file

@ -16,5 +16,25 @@
"name": "leaderboard", "name": "leaderboard",
"description": "Get the top 10 users", "description": "Get the top 10 users",
"type": 1 "type": 1
},
{
"name": "givexp",
"description": "Give XP to a user",
"type": 1,
"default_member_permissions": 0,
"options": [
{
"name": "user",
"description": "The user you want to give XP to",
"type": 6,
"required": true
},
{
"name": "amount",
"description": "The amount of XP you want to give",
"type": 4,
"required": true
}
]
} }
] ]

View file

@ -88,9 +88,12 @@ client.on("messageCreate", async message => {
// If user is in database, and xp is greater than or equal to the calculated level up XP, add 1 to lvl and add the remainder to xp // If user is in database, and xp is greater than or equal to the calculated level up XP, add 1 to lvl and add the remainder to xp
let lvlUpXp = eval(config.discord.levels.lvlUpEquation); let lvlUpXp = eval(config.discord.levels.lvlUpEquation);
if (data.xp >= lvlUpXp) {
// Keep running level up equation until xp is less than the calculated level up xp
while (data.xp >= lvlUpXp) {
data.lvl++; data.lvl++;
data.xp -= lvlUpXp; data.xp -= lvlUpXp;
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
message.channel.send(`${message.author}, you have leveled up to level ${data.lvl}!`).then(msg => { message.channel.send(`${message.author}, you have leveled up to level ${data.lvl}!`).then(msg => {
setTimeout(() => { setTimeout(() => {
msg.delete(); msg.delete();
@ -98,6 +101,16 @@ client.on("messageCreate", async message => {
}); });
} }
// if (data.xp >= lvlUpXp) {
// data.lvl++;
// data.xp -= lvlUpXp;
// message.channel.send(`${message.author}, you have leveled up to level ${data.lvl}!`).then(msg => {
// setTimeout(() => {
// msg.delete();
// }, 10000);
// });
// }
// Update database // Update database
await db.run(`UPDATE levels SET xp = ${data.xp}, lvl = ${data.lvl}, totalXp = ${data.totalXp}, msgCount = ${data.msgCount} WHERE id = '${message.author.id}'`); await db.run(`UPDATE levels SET xp = ${data.xp}, lvl = ${data.lvl}, totalXp = ${data.totalXp}, msgCount = ${data.msgCount} WHERE id = '${message.author.id}'`);
} }
@ -185,6 +198,65 @@ client.on("interactionCreate", async interaction => {
} }
}); });
break; break;
case "givexp":
// Dont gotta check perms, done on discord
// Dont gotta check arguments, done on discord
// Get user data
await db.get(`SELECT * FROM levels WHERE id = '${interaction.options.getUser("user").id}'`, async (err, row) => {
if (err) {
console.error(err);
}
if (!row) {
await db.run(`INSERT INTO levels (id, xp, lvl, totalXp, msgCount) VALUES ('${interaction.options.getUser("user").id}', ${interaction.options.getInteger("amount")}, 1, ${interaction.options.getInteger("amount")}, 0)`);
// Run level up equation
var lvl = 1;
let lvlUpXp = eval(config.discord.levels.lvlUpEquation);
// Keep running level up equation until xp is less than the calculated level up xp
while (interaction.options.getInteger("amount") >= lvlUpXp) {
lvl++;
interaction.options.getInteger("amount") -= lvlUpXp;
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
interaction.channel.send(`${interaction.options.getUser("user")}, you have leveled up to level ${lvl}!`).then(msg => {
setTimeout(() => {
msg.delete();
}, 10000);
});
}
return;
}
if (row) {
var data = row;
let lvl = data.lvl;
data.xp += interaction.options.getInteger("amount");
data.totalXp += interaction.options.getInteger("amount");
// If user is in database, and xp is greater than or equal to the calculated level up XP, add 1 to lvl and add the remainder to xp
let lvlUpXp = eval(config.discord.levels.lvlUpEquation);
// Keep running level up equation until xp is less than the calculated level up xp
while (data.xp >= lvlUpXp) {
data.lvl++;
data.xp -= lvlUpXp;
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
interaction.channel.send(`${interaction.options.getUser("user")}, you have leveled up to level ${data.lvl}!`).then(msg => {
setTimeout(() => {
msg.delete();
}, 10000);
});
}
// Update database
await db.run(`UPDATE levels SET xp = ${data.xp}, lvl = ${data.lvl}, totalXp = ${data.totalXp}, msgCount = ${data.msgCount} WHERE id = '${interaction.options.getUser("user").id}'`);
interaction.reply({
content: `Gave ${interaction.options.getInteger("amount")} XP to ${interaction.options.getUser("user").tag}!`,
ephemeral: true
});
}
}
);
break;
}; };
}); });