querybuilder intensifies

This commit is contained in:
Flummi
2021-05-16 13:24:31 +02:00
parent 3bc0a74932
commit 04d4787232
16 changed files with 244 additions and 410 deletions

View File

@ -9,31 +9,22 @@ export default async bot => {
call: /^gib f0ck/i,
active: true,
f: async e => {
let args = e.args.slice(2);
let params = {
inc: [],
exc: []
};
let args = e.args.slice(1);
let rows = sql("items").select("id", "username", "mime", "size");
for(let i = 0; i < args.length; i++) {
let name = args[0];
if(name.charAt(0) === "!")
params.exc.push(name.slice(1));
if(args[i].charAt(0) === "!")
rows = rows.where("username", "not like", args[i].slice(1));
else
params.inc.push(name);
rows = rows.where("username", "like", args[i]);
}
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 ?");
const where = params.inc.concat(params.exc).join(" || ");
const query = `select id, username, mime, size from items ${where.length > 0 ? `where ${where}` : ""} order by rand() limit 1`;
const rows = await sql.query(query, vars);
rows = await rows.orderByRaw("rand()").limit(1);
if(rows.length === 0)
return e.reply("nothing found, f0cker");
e.reply(`f0ckrnd: ${cfg.main.url}/${rows[0].id} by: ${rows[0].username} (${rows[0].mime}, ~${lib.formatSize(rows[0].size)})`);
return e.reply(`f0ckrnd: ${cfg.main.url}/${rows[0].id} by: ${rows[0].username} (${rows[0].mime}, ~${lib.formatSize(rows[0].size)})`);
}
}];
};