replace pg-promise with pg

This commit is contained in:
Flummi
2019-08-22 09:56:16 +00:00
parent 1f194e8267
commit 8c5fb99cd3
10 changed files with 60 additions and 73 deletions

View File

@@ -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;
}
}
}];