From e9471f85dfda05f73923ab4c757506bc4de10d85 Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:10:26 +0100 Subject: [PATCH 1/6] test xD --- src/trigger/f0ckrand.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index d8ca230..5ab45f7 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -1,11 +1,21 @@ module.exports = (lib) => { lib.trigger.add({ name: 'f0ckrand', - call: /^gib f0ck$/i, + call: /^gib f0ck/i, level: 0, active: 1, func: (e) => { - lib.sql.query("select `id`,`username` from `f0ck`.`items` order by rand() limit 1", (err, rows, fields) => { + let args = e.message.split(" "); + args.shift().shift(); + + let query = "select `id`,`username` from `f0ck`.`items` order by rand() "; + + if(args.length > 0) { + query += "where `username` = ? ".repeat(args.length); + } + + query += "limit 1"; + lib.sql.query(query, args, (err, rows, fields) => { if(!err) e.reply("f0ckrnd: "+lib.cfg.main.url+"/"+rows[0].id+" by: "+rows[0].username); }); From 36da6b94fc28b3a4ac39f7ede76177d618ce2266 Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:11:18 +0100 Subject: [PATCH 2/6] muh --- src/trigger/f0ckrand.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index 5ab45f7..442ccf2 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -6,7 +6,8 @@ module.exports = (lib) => { active: 1, func: (e) => { let args = e.message.split(" "); - args.shift().shift(); + args.shift(); + args.shift(); let query = "select `id`,`username` from `f0ck`.`items` order by rand() "; From c530db8959bacf7f86dd60bdc77a123111c09b3b Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:12:26 +0100 Subject: [PATCH 3/6] muh --- src/trigger/f0ckrand.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index 442ccf2..db89e7c 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -16,6 +16,8 @@ module.exports = (lib) => { } query += "limit 1"; + + console.log(query); lib.sql.query(query, args, (err, rows, fields) => { if(!err) e.reply("f0ckrnd: "+lib.cfg.main.url+"/"+rows[0].id+" by: "+rows[0].username); From 0dd192bdb6de64b42a2002ad8c24df4ab576102b Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:27:19 +0100 Subject: [PATCH 4/6] muh --- src/trigger/f0ckrand.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index db89e7c..6f05ef6 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -5,20 +5,16 @@ module.exports = (lib) => { level: 0, active: 1, func: (e) => { - let args = e.message.split(" "); + let args = lib.sql.escape(e.message).split(" "); args.shift(); args.shift(); let query = "select `id`,`username` from `f0ck`.`items` order by rand() "; - - if(args.length > 0) { - query += "where `username` = ? ".repeat(args.length); - } - + if(args.length > 0) + query += "where `username` = '" + args.join("' || `username` = '"); query += "limit 1"; - console.log(query); - lib.sql.query(query, args, (err, rows, fields) => { + lib.sql.query(query, (err, rows, fields) => { if(!err) e.reply("f0ckrnd: "+lib.cfg.main.url+"/"+rows[0].id+" by: "+rows[0].username); }); From 8c99039312ffc16d894b90c6c1650e47cf23f15b Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:28:44 +0100 Subject: [PATCH 5/6] debuggsen --- src/trigger/f0ckrand.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index 6f05ef6..10afda6 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -11,9 +11,10 @@ module.exports = (lib) => { let query = "select `id`,`username` from `f0ck`.`items` order by rand() "; if(args.length > 0) - query += "where `username` = '" + args.join("' || `username` = '"); + query += "where `username` like '" + args.join("' || `username` like '"); query += "limit 1"; + console.log( query ); lib.sql.query(query, (err, rows, fields) => { if(!err) e.reply("f0ckrnd: "+lib.cfg.main.url+"/"+rows[0].id+" by: "+rows[0].username); From d52e4249a142e27b04bdceebd25ca4db6e5c5903 Mon Sep 17 00:00:00 2001 From: Flummi Date: Wed, 22 Mar 2017 00:31:30 +0100 Subject: [PATCH 6/6] debuggsen --- src/trigger/f0ckrand.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trigger/f0ckrand.js b/src/trigger/f0ckrand.js index 10afda6..2f813af 100644 --- a/src/trigger/f0ckrand.js +++ b/src/trigger/f0ckrand.js @@ -9,10 +9,10 @@ module.exports = (lib) => { args.shift(); args.shift(); - let query = "select `id`,`username` from `f0ck`.`items` order by rand() "; + let query = "select `id`,`username` from `f0ck`.`items` "; if(args.length > 0) query += "where `username` like '" + args.join("' || `username` like '"); - query += "limit 1"; + query += "order by rand() limit 1"; console.log( query ); lib.sql.query(query, (err, rows, fields) => {