Trying my hardest not to die
This commit is contained in:
parent
d785cf72ad
commit
9bc1f81695
|
@ -36,5 +36,25 @@
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "removexp",
|
||||||
|
"description": "Remove XP from a user",
|
||||||
|
"type": 1,
|
||||||
|
"default_member_permissions": 0,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"name": "user",
|
||||||
|
"description": "The user you want to remove XP from",
|
||||||
|
"type": 6,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "amount",
|
||||||
|
"description": "The amount of XP you want to remove",
|
||||||
|
"type": 4,
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -3,7 +3,8 @@
|
||||||
"token": "",
|
"token": "",
|
||||||
"errorChannel": "",
|
"errorChannel": "",
|
||||||
"levels": {
|
"levels": {
|
||||||
"lvlUpEquation": "Math.floor(5 / 6 * lvl * (2 * lvl * lvl + 27 * lvl + 91))",
|
"lvlUpEquation": "30",
|
||||||
|
"lvlUpMessage": "{user}, you have leveled up to level {lvl}!",
|
||||||
"cooldownMinutes": 1
|
"cooldownMinutes": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
47
index.js
47
index.js
|
@ -94,23 +94,14 @@ client.on("messageCreate", async message => {
|
||||||
data.lvl++;
|
data.lvl++;
|
||||||
data.xp -= lvlUpXp;
|
data.xp -= lvlUpXp;
|
||||||
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
|
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
|
||||||
message.channel.send(`${message.author}, you have leveled up to level ${data.lvl}!`).then(msg => {
|
// use config.discord.levels.lvlUpMessage to send a message when the user levels up
|
||||||
|
message.channel.send(config.discord.levels.lvlUpMessage.replace("{user}", message.author).replace("{lvl}", data.lvl)).then(msg => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
msg.delete();
|
msg.delete();
|
||||||
}, 10000);
|
}, 10000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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}'`);
|
||||||
}
|
}
|
||||||
|
@ -229,25 +220,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
if (!row) {
|
if (!row) return interaction.reply({ content: "This user has not sent any messages yet.", ephemeral: true });
|
||||||
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) {
|
if (row) {
|
||||||
var data = row;
|
var data = row;
|
||||||
let lvl = data.lvl;
|
let lvl = data.lvl;
|
||||||
|
@ -261,11 +234,6 @@ client.on("interactionCreate", async interaction => {
|
||||||
data.lvl++;
|
data.lvl++;
|
||||||
data.xp -= lvlUpXp;
|
data.xp -= lvlUpXp;
|
||||||
lvlUpXp = eval(config.discord.levels.lvlUpEquation);
|
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
|
// Update database
|
||||||
|
@ -293,7 +261,6 @@ process.on('SIGINT', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Global error handler
|
// Global error handler
|
||||||
/*
|
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
await console.error(`${colors.red("[ERROR]")} Uncaught Exception: ${error}`);
|
await console.error(`${colors.red("[ERROR]")} Uncaught Exception: ${error}`);
|
||||||
if (client.user.tag) {
|
if (client.user.tag) {
|
||||||
|
@ -306,16 +273,8 @@ process.on('uncaughtException', async (error) => {
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await client.user.setPresence({
|
|
||||||
status: "invisible",
|
|
||||||
activities: []
|
|
||||||
});
|
|
||||||
await client.destroy();
|
|
||||||
}
|
}
|
||||||
await process.exit(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
*/
|
|
||||||
// Global Variables
|
// Global Variables
|
||||||
var cooldowns = {};
|
var cooldowns = {};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue