2017-03-20 20:17:03 +01:00
|
|
|
module.exports = (lib) => {
|
2017-03-22 00:53:18 +01:00
|
|
|
lib.trigger.add({
|
|
|
|
name: 'f0ckrand',
|
|
|
|
call: /^gib f0ck/i,
|
|
|
|
level: 0,
|
|
|
|
active: 1,
|
|
|
|
func: (e) => {
|
2017-03-22 14:03:10 +01:00
|
|
|
let args = e.message.trim().split(" ").slice(2);
|
2017-03-22 01:33:57 +01:00
|
|
|
let params = {
|
2017-03-22 13:58:23 +01:00
|
|
|
inc: [],
|
|
|
|
exc: []
|
2017-03-22 01:33:57 +01:00
|
|
|
};
|
2017-03-22 14:06:09 +01:00
|
|
|
|
2017-03-22 01:46:31 +01:00
|
|
|
for(let i = 0; i < args.length; i++) {
|
|
|
|
let name = args[0];
|
|
|
|
if(name.charAt(0) === "!")
|
2017-03-22 13:58:23 +01:00
|
|
|
params.exc.push(name.slice(1));
|
2017-03-22 01:46:31 +01:00
|
|
|
else
|
2017-03-22 13:58:23 +01:00
|
|
|
params.inc.push(name);
|
2017-03-22 01:46:31 +01:00
|
|
|
}
|
2017-03-22 00:10:26 +01:00
|
|
|
|
2017-03-22 13:58:23 +01:00
|
|
|
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`;
|
2017-03-22 01:40:09 +01:00
|
|
|
|
2017-03-22 02:57:10 +01:00
|
|
|
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');
|
2017-03-20 20:17:03 +01:00
|
|
|
});
|
2017-03-22 00:53:18 +01:00
|
|
|
},
|
|
|
|
desc: 'Random-f0ck'
|
|
|
|
});
|
2017-03-20 20:17:03 +01:00
|
|
|
};
|