add leveling

This commit is contained in:
Stanislaw
2022-03-15 12:10:15 +01:00
parent f2371974cd
commit 4af3c0adfa
4 changed files with 45 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ const sql = require("./src/functions/postgres");
const { createClient } = require("redis");
const { Client } = require("pg");
const colors = require("colors");
const { connect } = require("http2");
colors.setTheme({
prompt: "grey",
@@ -68,7 +69,7 @@ cl.on("messageCreate", async (msg) => {
const cmd = cl.cmds.get(cmdName);
try {
cmd.execute(cl, msg, args);
cmd.execute(cl, msg, args, client);
} catch (error) {
console.error(
`msgCommand error: ${cmdName} with args ${args} by ${msg.author.tag}\n--\n${error}\n--`

View File

@@ -1,4 +1,22 @@
module.exports = {
name: "profil",
execute(cl, msg) {},
execute(cl, msg, args, connect) {
const { profil } = require("../functions/postgres");
const { MessageEmbed } = require("discord.js");
async () => {
const user = profil(connect, msg.author.id);
};
console.debug(user);
/*if (user) {
const embed = new MessageEmbed()
.setColor("#F5F5F5")
.setTitle(msg.author.name)
.addFields(
{ name: "Regular field title", value: "Some value here" },
{ name: "Regular field title", value: "Some value here" },
{ name: "Regular field title", value: "Some value here" },
{ name: "Regular field title", value: "Some value here" }
);
}*/
},
};

View File

@@ -1,21 +1,35 @@
const { lvl } = require("./tools");
module.exports = {
messageCount: async function (connect, userID) {
query = `UPDATE users SET msg_count = msg_count + 1 WHERE users.user_id = '${userID}'`;
await connect.query(query);
},
addExp: async function (connect, userID) {
let query = `SELECT users.user_id FROM users WHERE users.user_id = '${userID}'`;
let query = `SELECT users.user_id, users.exp FROM users WHERE users.user_id = '${userID}'`;
const check = await connect.query(query);
if (check.rowCount == 0) {
query = `INSERT INTO users(user_id,msg_count,exp) VALUES ('${userID}',1,${Math.floor(
Math.random() * 25
)},)`;
)})`;
await connect.query(query);
} else {
query = `UPDATE users SET exp = users.exp + ${Math.floor(
Math.random() * 25
)},msg_count = msg_count + 1 WHERE users.user_id = '${userID}'`;
let exp = check.rows[0].exp + Math.floor(Math.random() * 25);
console.debug(lvl(exp));
query =
query = `UPDATE users SET exp = ${exp},msg_count = msg_count + 1,lvl = ${lvl(
exp
)} WHERE users.user_id = '${userID}'`;
await connect.query(query);
}
},
profil: async function (connect, userID) {
let query = `SELECT * FROM users WHERE users.user_id = '${userID}'`;
const check = await connect.query(query);
if (check.rowCount == 0) {
query = `INSERT INTO users(user_id) VALUES ('${userID}')`;
await connect.query(query);
}
return check.rows;
},
};

5
src/functions/tools.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
lvl: function (exp) {
return Math.floor(Math.sqrt(exp) / 5);
},
};