Postgres is alive
This commit is contained in:
2
cfg.json
2
cfg.json
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"prefix": ".",
|
"prefix": "&",
|
||||||
"hexBlue": "61f2ea",
|
"hexBlue": "61f2ea",
|
||||||
"hexRed": "fb636b",
|
"hexRed": "fb636b",
|
||||||
"iconurl": "https://i.imgur.com/4AmRDyX.png",
|
"iconurl": "https://i.imgur.com/4AmRDyX.png",
|
||||||
|
|||||||
32
index.js
32
index.js
@@ -1,8 +1,19 @@
|
|||||||
const discordjs = require("discord.js");
|
const discordjs = require("discord.js");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const redis = require("./src/functions/redis");
|
const redis = require("./src/functions/redis");
|
||||||
|
const sql = require("./src/functions/postgres");
|
||||||
const { createClient } = require("redis");
|
const { createClient } = require("redis");
|
||||||
const { connect } = require("http2");
|
const { Client } = require("pg");
|
||||||
|
const colors = require("colors");
|
||||||
|
|
||||||
|
colors.setTheme({
|
||||||
|
prompt: "grey",
|
||||||
|
info: "green",
|
||||||
|
warn: "yellow",
|
||||||
|
debug: "blue",
|
||||||
|
error: "red",
|
||||||
|
});
|
||||||
|
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
const cl = new discordjs.Client({
|
const cl = new discordjs.Client({
|
||||||
@@ -13,10 +24,22 @@ const cl = new discordjs.Client({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//redis connect
|
||||||
const redisConnection = createClient({
|
const redisConnection = createClient({
|
||||||
url: process.env.REDIS_TOKEN,
|
url: process.env.REDIS_TOKEN,
|
||||||
});
|
});
|
||||||
redisConnection.connect();
|
redisConnection
|
||||||
|
.connect()
|
||||||
|
.then(() => console.log("✔️ redis connected".info))
|
||||||
|
.catch((err) => console.error(err.stack.red));
|
||||||
|
|
||||||
|
//postgresql connect
|
||||||
|
const client = new Client();
|
||||||
|
client
|
||||||
|
.connect()
|
||||||
|
.then(() => console.log("✔️ postgres connected".info))
|
||||||
|
.catch((err) => console.error(err.stack.red));
|
||||||
|
|
||||||
cl.cfg = require("./cfg.json");
|
cl.cfg = require("./cfg.json");
|
||||||
cl.cmds = new discordjs.Collection();
|
cl.cmds = new discordjs.Collection();
|
||||||
|
|
||||||
@@ -33,6 +56,9 @@ cl.on("messageCreate", async (msg) => {
|
|||||||
if (msg.author.bot) return;
|
if (msg.author.bot) return;
|
||||||
if (!msg.content.startsWith(cl.cfg.prefix)) {
|
if (!msg.content.startsWith(cl.cfg.prefix)) {
|
||||||
if (await redis.expCheck(msg.author.id, redisConnection)) {
|
if (await redis.expCheck(msg.author.id, redisConnection)) {
|
||||||
|
sql.addExp(client, msg.author.id);
|
||||||
|
} else {
|
||||||
|
sql.messageCount(client, msg.author.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const args = msg.content.slice(cl.cfg.prefix.length).trim().split(/ +/);
|
const args = msg.content.slice(cl.cfg.prefix.length).trim().split(/ +/);
|
||||||
@@ -57,7 +83,7 @@ cl.on("messageCreate", async (msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cl.once("ready", () => {
|
cl.once("ready", () => {
|
||||||
console.log(`bot ready; logged in as ${cl.user.tag}\n--`);
|
console.log(`bot ready; logged in as ${cl.user.tag}\n--`.info);
|
||||||
cl.user.setActivity(".pomoc", { type: "LISTENING" });
|
cl.user.setActivity(".pomoc", { type: "LISTENING" });
|
||||||
});
|
});
|
||||||
cl.login(process.env.TOKEN); // here comes the boooy
|
cl.login(process.env.TOKEN); // here comes the boooy
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "^0.5.3",
|
"@discordjs/opus": "^0.5.3",
|
||||||
"@discordjs/voice": "^0.7.5",
|
"@discordjs/voice": "^0.7.5",
|
||||||
|
"colors": "^1.4.0",
|
||||||
"daemon": "^1.1.0",
|
"daemon": "^1.1.0",
|
||||||
"discord.js": "^13.1.0",
|
"discord.js": "^13.1.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
@@ -637,6 +638,14 @@
|
|||||||
"color-support": "bin.js"
|
"color-support": "bin.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/colors": {
|
||||||
|
"version": "1.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||||
|
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.1.90"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/combined-stream": {
|
"node_modules/combined-stream": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
@@ -2819,6 +2828,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
|
||||||
"integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg=="
|
"integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg=="
|
||||||
},
|
},
|
||||||
|
"colors": {
|
||||||
|
"version": "1.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||||
|
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
|
||||||
|
},
|
||||||
"combined-stream": {
|
"combined-stream": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "^0.5.3",
|
"@discordjs/opus": "^0.5.3",
|
||||||
"@discordjs/voice": "^0.7.5",
|
"@discordjs/voice": "^0.7.5",
|
||||||
|
"colors": "^1.4.0",
|
||||||
"daemon": "^1.1.0",
|
"daemon": "^1.1.0",
|
||||||
"discord.js": "^13.1.0",
|
"discord.js": "^13.1.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
|
|||||||
@@ -1 +1,21 @@
|
|||||||
module.exports = {};
|
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}'`;
|
||||||
|
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}'`;
|
||||||
|
await connect.query(query);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user