replace pg-promise with pg
This commit is contained in:
parent
1f194e8267
commit
8c5fb99cd3
@ -11,9 +11,9 @@
|
||||
"author": "Flummi & jkhsjdhjs",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"flumm-fetch-cookies": "git+https://gitfap.de/keinBot/flumm-fetch-cookies",
|
||||
"cuffeo": "git+https://gitfap.de/keinBot/cuffeo",
|
||||
"pg-promise": "^7.3.2",
|
||||
"flumm-fetch-cookies": "git+https://gitfap.de/keinBot/flumm-fetch-cookies",
|
||||
"pg": "^7.12.1",
|
||||
"stringify-object": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
import PG from "pg-promise";
|
||||
import { default as config } from "../../cfg/config.json";
|
||||
import PG from "pg";
|
||||
import config from "../../cfg/config.json";
|
||||
|
||||
//const pgp = new PG();
|
||||
const sql = (new PG())(config.sql);
|
||||
|
||||
export default sql;
|
||||
export default new PG.Pool(config.sql);
|
||||
|
@ -9,12 +9,10 @@ const data = {
|
||||
};
|
||||
|
||||
export default async bot => {
|
||||
Object.keys(data).forEach(cur => {
|
||||
sql.any("select data from useless where trigger = $1 limit 1", [cur])
|
||||
.then(rows => {
|
||||
data[cur] = JSON.parse(rows[0].data);
|
||||
});
|
||||
});
|
||||
for(const cur in data) {
|
||||
const rows = (await sql.query("select data from useless where trigger = $1 limit 1", [cur])).rows[0];
|
||||
data[cur] = JSON.parse(rows.data);
|
||||
}
|
||||
|
||||
return [{
|
||||
name: "cookie",
|
||||
|
@ -6,12 +6,10 @@ const data = {
|
||||
};
|
||||
|
||||
export default async bot => {
|
||||
Object.keys(data).forEach(cur => {
|
||||
sql.any("select data from useless where trigger = $1 limit 1", [cur])
|
||||
.then(rows => {
|
||||
data[cur] = JSON.parse(rows[0].data);
|
||||
});
|
||||
});
|
||||
for(const cur in data) {
|
||||
const rows = (await sql.query("select data from useless where trigger = $1 limit 1", [cur])).rows[0];
|
||||
data[cur] = JSON.parse(rows.data);
|
||||
}
|
||||
|
||||
return [{
|
||||
name: "dope",
|
||||
|
@ -19,7 +19,7 @@ export default async bot => {
|
||||
call: /Mc.*iaC/,
|
||||
set: "nxy",
|
||||
f: async e => {
|
||||
await sql.any(_query_add, [e.message.match(/(Mc\S+iaC?)/)[0]]);
|
||||
await sql.query(_query_add, [e.message.match(/(Mc\S+iaC?)/)[0]]);
|
||||
}
|
||||
}, {
|
||||
name: "mcmaniac_get",
|
||||
@ -50,7 +50,7 @@ export default async bot => {
|
||||
.split("{order}").join(order)
|
||||
.split("{offset}").join(offset);
|
||||
|
||||
const rows = await sql.any(query);
|
||||
const rows = (await sql.query(query)).rows;
|
||||
e.reply(`[${rows[0].rank}/${rows[0].total}] ${rows[0].item}`);
|
||||
}
|
||||
}];
|
||||
|
@ -29,19 +29,16 @@ export default async bot => {
|
||||
name: "qrnd",
|
||||
call: /^(\.|\/)q(rnd)?$/i,
|
||||
set: "all",
|
||||
f: e => {
|
||||
fetch("https://nxy.totally.rip/api/quotes.php?c=nick,item")
|
||||
.then(res => res.json())
|
||||
.then(res => {
|
||||
const quote = res.data.quotes[~~(Math.random() * res.data.quotes.length)];
|
||||
e.reply(`<[b]${quote.nick}[/b]> [i]${quote.item}[/i]`);
|
||||
}).catch(console.error);
|
||||
f: async e => {
|
||||
const res = await (await fetch("https://nxy.totally.rip/api/quotes.php?c=nick,item")).json();
|
||||
const quote = res.data.quotes[~~(Math.random() * res.data.quotes.length)];
|
||||
e.reply(`<[b]${quote.nick}[/b]> [i]${quote.item}[/i]`);
|
||||
}
|
||||
}, {
|
||||
name: "quotes",
|
||||
call: /^(\.|\/)q .*/i,
|
||||
set: "nxy",
|
||||
f: e => {
|
||||
f: async e => {
|
||||
let args = e.message.trim().substring(3).split(" ");
|
||||
const cmd = args[0].toLowerCase();
|
||||
let nick = "";
|
||||
@ -55,12 +52,11 @@ export default async bot => {
|
||||
args.shift();
|
||||
let quote = args.join(" ");
|
||||
|
||||
sql.any(_query_add, [ nick, quote, `${e.network}.${e.channel}`, e.user.nick ])
|
||||
.then(rows => { })
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
e.reply("duplicate!");
|
||||
});
|
||||
try {
|
||||
await sql.query(_query_add, [ nick, quote, `${e.network}.${e.channel}`, e.user.nick ]);
|
||||
} catch(e) {
|
||||
return e.reply("duplicate!");
|
||||
}
|
||||
break;
|
||||
default: // get quote
|
||||
nick = cmd;
|
||||
@ -93,31 +89,27 @@ export default async bot => {
|
||||
.replace("{limit}", limit)
|
||||
.replace("{order}", rand ? "random()" : order)
|
||||
.replace("{offset}", rand ? "" : `offset ${offset}`);
|
||||
sql.any(query, params)
|
||||
.then(rows => {
|
||||
if(!rows[0])
|
||||
return e.reply("index nicht vorhanden");
|
||||
if(rows.length > 1) {
|
||||
let rank = 1;
|
||||
let index = rank - 1;
|
||||
if (args[2] && !isNaN(args[2])) {
|
||||
rank = parseInt(args[2]);
|
||||
index = rank - 1;
|
||||
}
|
||||
if(rank < 0) {
|
||||
index = rows.length - Math.abs(rank);
|
||||
rank = index + 1;
|
||||
}
|
||||
if (!rows[index])
|
||||
return e.reply("index nicht vorhanden");
|
||||
else
|
||||
e.reply(`[${rank}/${rows.length}] <${rows[index].nick}> ${rows[index].item}`)
|
||||
}
|
||||
else
|
||||
e.reply(`[${rows[0].rank}/${rows[0].total}] <${rows[0].nick}> ${rows[0].item}`)
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
break;
|
||||
|
||||
const rows = (await sql.query(query, params)).rows;
|
||||
|
||||
if (!rows || rows.length === 0)
|
||||
return e.reply("index nicht vorhanden");
|
||||
|
||||
let rank = 1;
|
||||
index = rank - 1;
|
||||
if (args[2] && !isNaN(args[2])) {
|
||||
rank = parseInt(args[2]);
|
||||
index = rank - 1;
|
||||
}
|
||||
if (rank < 0) {
|
||||
index = rows.length - Math.abs(rank);
|
||||
rank = index + 1;
|
||||
}
|
||||
if (!rows[index])
|
||||
return e.reply("index nicht vorhanden");
|
||||
|
||||
e.reply(`[${rows[index].rank}/${rows[index].total}] <${rows[index].nick}> ${rows[index].item}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
@ -6,6 +6,7 @@ export default async bot => {
|
||||
name: "rape",
|
||||
call: /^(\.|\/)rape/i,
|
||||
set: "nxy",
|
||||
active: false,
|
||||
help: {
|
||||
text: "Rapes a nick and eventually charge for it",
|
||||
usage: "[b].rape[/b] [i](<nick>)[/i]"
|
||||
@ -21,7 +22,7 @@ export default async bot => {
|
||||
const fined = [e.user.nick, nick][rand];
|
||||
const reason = ["raping", "being too lewd and getting raped"][rand];
|
||||
|
||||
sql.any("insert into nxy_users (nick, fines) values (lower($1), $2) on conflict (nick) do update set fines = nxy_users.fines + excluded.fines returning fines", [fined, fine])
|
||||
sql.query("insert into nxy_users (nick, fines) values (lower($1), $2) on conflict (nick) do update set fines = nxy_users.fines + excluded.fines returning fines", [fined, fine])
|
||||
.then(rows => {
|
||||
e.replyAction(`fines [b]${nick}[/b] [b]$${fine}[/b] for ${reason}. You owe: [b]$${rows[0].fines}[/b].`);
|
||||
})
|
||||
@ -34,13 +35,14 @@ export default async bot => {
|
||||
name: "owe",
|
||||
call: /^(\.|\/)owe/i,
|
||||
set: "nxy",
|
||||
active: false,
|
||||
help: {
|
||||
text: "Shows how much a nick owes",
|
||||
usage: "[b].owe[/b] [i](<nick>)[/i]"
|
||||
},
|
||||
f: e => {
|
||||
const nick = e.args[0] || e.user.nick;
|
||||
sql.any("select fines from nxy_users where lower(nick) = lower($1) limit 1", [nick])
|
||||
sql.query("select fines from nxy_users where lower(nick) = lower($1) limit 1", [nick])
|
||||
.then(rows => {
|
||||
if(!rows[0])
|
||||
return e.reply("user not found");
|
||||
|
@ -8,7 +8,7 @@ import stringify from "stringify-object";
|
||||
let _contexts = new Map();
|
||||
|
||||
export default async bot => {
|
||||
sql.any("select prefix, sandbox from nxy_users where sandbox != 'NULL'")
|
||||
sql.query("select prefix, sandbox from nxy_users where sandbox != 'NULL'")
|
||||
.then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`)))
|
||||
.catch(err => console.log("nichts vorhanden lol", err));
|
||||
|
||||
@ -37,7 +37,7 @@ export default async bot => {
|
||||
.replace(/\n/g, "")
|
||||
.replace(/\t/g, "")
|
||||
.split("[native code]").join(""));
|
||||
sql.any("insert into nxy_users (nick, prefix, sandbox) values (lower($1), $3, $2) on conflict (prefix) do update set sandbox = $2, nick = lower($1)", [
|
||||
sql.query("insert into nxy_users (nick, prefix, sandbox) values (lower($1), $3, $2) on conflict (prefix) do update set sandbox = $2, nick = lower($1)", [
|
||||
(e.type === "tg" ? e.user.username || e.user.nick : e.user.nick), tmp, e.user.prefix
|
||||
]).then(() => e.reply(e.user.nick + ": " + output))
|
||||
.catch(err => console.log(err));
|
||||
|
@ -11,10 +11,10 @@ const data = {
|
||||
};
|
||||
|
||||
export default async bot => {
|
||||
|
||||
Object.keys(data).forEach(cur => sql.any("select data from useless where trigger = $1 limit 1", [cur])
|
||||
.then(rows => data[cur] = JSON.parse(rows[0].data))
|
||||
.catch(console.error));
|
||||
for(const cur in data) {
|
||||
const rows = (await sql.query("select data from useless where trigger = $1 limit 1", [cur])).rows[0];
|
||||
data[cur] = JSON.parse(rows.data);
|
||||
}
|
||||
|
||||
return [{
|
||||
name: "kiss",
|
||||
|
@ -13,10 +13,10 @@ const data = {
|
||||
};
|
||||
|
||||
export default async bot => {
|
||||
|
||||
Object.keys(data).forEach(cur => sql.any("select data from useless where trigger = $1 limit 1", [cur])
|
||||
.then(rows => data[cur] = JSON.parse(rows[0].data))
|
||||
.catch(console.error));
|
||||
for(const cur in data) {
|
||||
const rows = (await sql.query("select data from useless where trigger = $1 limit 1", [cur])).rows[0];
|
||||
data[cur] = JSON.parse(rows.data);
|
||||
}
|
||||
|
||||
return [{
|
||||
name: "abschieben",
|
||||
|
Loading…
Reference in New Issue
Block a user