From 770cf8d23371d25777b0199b7e5116d305e9eb9e Mon Sep 17 00:00:00 2001 From: Flummi Date: Tue, 28 Nov 2017 16:39:36 +0100 Subject: [PATCH] postkrebs :/ --- src/inc/cfg.js | 18 ++++++++++++------ src/inc/trigger/quotes.js | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/inc/cfg.js b/src/inc/cfg.js index 14dee99..e3b7f51 100644 --- a/src/inc/cfg.js +++ b/src/inc/cfg.js @@ -39,24 +39,30 @@ const write = (kat, key, value, type, cb) => { value = JSON.stringify(value); console.log(kat, key, value, type); - sql.any("select * from cfg where class = ? && key = ? limit 1", [kat, key], (err, rows) => { - console.log(rows); + sql.any("select * from cfg where class = $1 && key = $2 limit 1", [kat, key]).then(rows => { if (rows.length > 0) { - sql.any("update cfg set value = ? where class = ? && key = ?", [value, kat, key], (err) => { - console.log("updated", err); + sql.any("update cfg set value = $1 where class = $2 && key = $3", [value, kat, key]).then(rows => { read().then(() => { if(cb) cb(); }); + }) + .catch(err => { + console.log("on update", err); }); } else { - sql.any("insert into cfg (class, key, value, type) values (?, ?, ?, ?)", [kat, key, value, type], (err) => { - console.log("inserted", err); + sql.any("insert into cfg (class, key, value, type) values ($1, $2, $3, $4)", [kat, key, value, type]).then(rows => { read().then(() => { if (cb) cb(); }); + }) + .catch(err => { + console.log("on insert", err); }); } + }) + .then(err => { + console.log("on select", err); }); }; diff --git a/src/inc/trigger/quotes.js b/src/inc/trigger/quotes.js index 326619f..ce809c4 100644 --- a/src/inc/trigger/quotes.js +++ b/src/inc/trigger/quotes.js @@ -4,8 +4,8 @@ let _query_get = ` with ranked_quotes as ( select nick, item, - rank() over (partition by nick order by id), - count(*) over (partition by nick) as total + rank() over (partition by lower(nick) order by id), + count(*) over (partition by lower(nick)) as total from nxy_quotes ) select * @@ -43,6 +43,7 @@ module.exports = bot => { sql.any(_query_add, [ nick, quote, `${e.network}.${e.channel}`, e.user.nick ]) .then(rows => { }) .catch(err => { + console.log(err); e.reply("duplicate!"); }); break;