Merge branch 'f0ckdev' into 'master'

mrhanky <3

See merge request !100
This commit is contained in:
Flummi 2017-03-22 13:06:47 +00:00
commit 127fe6f3a6

View File

@ -5,28 +5,26 @@ module.exports = (lib) => {
level: 0, level: 0,
active: 1, active: 1,
func: (e) => { func: (e) => {
let args = lib.sql.escape(e.message).trim().split(" ").slice(2); let args = e.message.trim().split(" ").slice(2);
let params = { let params = {
"in": [], inc: [],
"not": [] exc: []
}; };
for(let i = 0; i < args.length; i++) { for(let i = 0; i < args.length; i++) {
let name = args[0]; let name = args[0];
if(name.charAt(0) === "!") if(name.charAt(0) === "!")
params.not.push(name.slice(1)); params.exc.push(name.slice(1));
else else
params.in.push(name); params.inc.push(name);
} }
let vars = params.in.concat(params.not); let vars = params.inc.concat(params.inc.length == 0 ? params.exc : []);
params.inc = new Array(params.inc.length).fill('username LIKE ?');
params.exc = new Array(params.inc.length == 0 ? params.exc.length : 0).fill('username NOT LIKE ?');
let where = params.inc.concat(params.exc).join(' || ');
let query = `SELECT id, username FROM f0ck.items ${where.length > 0 ? `WHERE ${where}` : ''} ORDER BY rand() LIMIT 1`;
params.in = new Array(params.in.length).fill('username LIKE ?');
params.not = params.in.length > 0 ? [] : new Array(params.not.length).fill('username NOT LIKE ?');
let where = params.in.concat(params.not);
let query = `SELECT id, username FROM f0ck.items ${where.length > 0 ? `WHERE ${where.join(' || ')}` : ''} ORDER BY rand() LIMIT 1`;
console.log( query );
lib.sql.query(query, vars, (err, rows) => { lib.sql.query(query, vars, (err, rows) => {
e.reply(!err && rows.length > 0 ? `f0ckrnd: ${lib.cfg.main.url}/${rows[0].id} by: ${rows[0].username}` : 'nothing found, f0cker'); e.reply(!err && rows.length > 0 ? `f0ckrnd: ${lib.cfg.main.url}/${rows[0].id} by: ${rows[0].username}` : 'nothing found, f0cker');
}); });