add leveling
This commit is contained in:
3
index.js
3
index.js
@@ -5,6 +5,7 @@ const sql = require("./src/functions/postgres");
|
|||||||
const { createClient } = require("redis");
|
const { createClient } = require("redis");
|
||||||
const { Client } = require("pg");
|
const { Client } = require("pg");
|
||||||
const colors = require("colors");
|
const colors = require("colors");
|
||||||
|
const { connect } = require("http2");
|
||||||
|
|
||||||
colors.setTheme({
|
colors.setTheme({
|
||||||
prompt: "grey",
|
prompt: "grey",
|
||||||
@@ -68,7 +69,7 @@ cl.on("messageCreate", async (msg) => {
|
|||||||
const cmd = cl.cmds.get(cmdName);
|
const cmd = cl.cmds.get(cmdName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cmd.execute(cl, msg, args);
|
cmd.execute(cl, msg, args, client);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`msgCommand error: ${cmdName} with args ${args} by ${msg.author.tag}\n--\n${error}\n--`
|
`msgCommand error: ${cmdName} with args ${args} by ${msg.author.tag}\n--\n${error}\n--`
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: "profil",
|
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" }
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,35 @@
|
|||||||
|
const { lvl } = require("./tools");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
messageCount: async function (connect, userID) {
|
messageCount: async function (connect, userID) {
|
||||||
query = `UPDATE users SET msg_count = msg_count + 1 WHERE users.user_id = '${userID}'`;
|
query = `UPDATE users SET msg_count = msg_count + 1 WHERE users.user_id = '${userID}'`;
|
||||||
await connect.query(query);
|
await connect.query(query);
|
||||||
},
|
},
|
||||||
addExp: async function (connect, userID) {
|
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);
|
const check = await connect.query(query);
|
||||||
if (check.rowCount == 0) {
|
if (check.rowCount == 0) {
|
||||||
query = `INSERT INTO users(user_id,msg_count,exp) VALUES ('${userID}',1,${Math.floor(
|
query = `INSERT INTO users(user_id,msg_count,exp) VALUES ('${userID}',1,${Math.floor(
|
||||||
Math.random() * 25
|
Math.random() * 25
|
||||||
)},)`;
|
)})`;
|
||||||
await connect.query(query);
|
await connect.query(query);
|
||||||
} else {
|
} else {
|
||||||
query = `UPDATE users SET exp = users.exp + ${Math.floor(
|
let exp = check.rows[0].exp + Math.floor(Math.random() * 25);
|
||||||
Math.random() * 25
|
console.debug(lvl(exp));
|
||||||
)},msg_count = msg_count + 1 WHERE users.user_id = '${userID}'`;
|
query =
|
||||||
|
query = `UPDATE users SET exp = ${exp},msg_count = msg_count + 1,lvl = ${lvl(
|
||||||
|
exp
|
||||||
|
)} WHERE users.user_id = '${userID}'`;
|
||||||
await connect.query(query);
|
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
5
src/functions/tools.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
lvl: function (exp) {
|
||||||
|
return Math.floor(Math.sqrt(exp) / 5);
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user