querybuilder intensifies
This commit is contained in:
@ -14,14 +14,14 @@ export default async bot => {
|
||||
if(id <= 0)
|
||||
return false;
|
||||
|
||||
const f0ck = await sql.query("select dest from items where id = ? limit 1", [ id ]);
|
||||
const f0ck = await sql("items").select("dest").where("id", id).limit(1);
|
||||
if(f0ck.length === 0)
|
||||
return false;
|
||||
|
||||
await fs.unlink(`./public/b/${f0ck[0].dest}`).catch(_=>{});
|
||||
await fs.unlink(`./public/t/${id}`).catch(_=>{});
|
||||
|
||||
await sql.query("delete from items where id = ? limit 1", [ id ]);
|
||||
await sql("items").where("id", id).del().limit(1);
|
||||
|
||||
return id;
|
||||
}))).filter(d => d);
|
||||
@ -29,7 +29,7 @@ export default async bot => {
|
||||
if(ret.length > 0)
|
||||
e.reply(`deleted ${ret.length}/${e.args.length} (${ret.join(",")}) f0cks`);
|
||||
else
|
||||
e.reply(`oof`)
|
||||
e.reply(`oof`);
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ export default async bot => {
|
||||
case "limit":
|
||||
return e.reply(`up to ${lib.formatSize(cfg.main.maxfilesize)} (${lib.formatSize(cfg.main.maxfilesize * 2.5)} for admins)`);
|
||||
case "thumb":
|
||||
const rows = await sql.query("select id from items");
|
||||
const rows = await sql("items").select("id");
|
||||
const dir = (await fs.readdir("./public/t")).filter(d => d.endsWith(".png")).map(e => +e.split(".")[0]);
|
||||
const tmp = [];
|
||||
for(let row of rows)
|
||||
|
@ -2,7 +2,6 @@ import cfg from "../../../config.json";
|
||||
import sql from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
|
||||
const _query = "select id, mime, size, username, userchannel, usernetwork, stamp from items where ";
|
||||
const regex = /(https\:\/\/f0ck\.me|http\:\/\/fockmoonsb24iczs7odozzy5uktlzbcgp337nabrgffzxv5ihabgpvyd\.onion)(\/(video|image|audio))?\/(\d+|(?:b\/)(\w{8})\.(jpg|webm|gif|mp4|png|mov|mp3|ogg|flac))/gi;
|
||||
|
||||
export default async bot => {
|
||||
@ -13,18 +12,14 @@ export default async bot => {
|
||||
active: true,
|
||||
f: async e => {
|
||||
const dat = e.message.match(regex)[0].split(/\//).pop();
|
||||
let query, arg;
|
||||
let query = sql("items").select("id", "mime", "size", "username", "userchannel", "usernetwork", "stamp");
|
||||
|
||||
if(dat.includes(".")) {
|
||||
query = _query + "dest like ?";
|
||||
arg = `%${dat}%`;
|
||||
}
|
||||
else {
|
||||
query = _query + "id = ?";
|
||||
arg = dat;
|
||||
}
|
||||
if(dat.includes("."))
|
||||
query = query.where("dest", "like", `%${dat}%`);
|
||||
else
|
||||
query = query.where("id", dat);
|
||||
|
||||
const rows = await sql.query(query, [ arg ]);
|
||||
const rows = await query;
|
||||
if(rows.length === 0)
|
||||
return e.reply("no f0cks given! lol D:");
|
||||
|
||||
|
@ -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)})`);
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
@ -8,7 +8,8 @@ import { exec as _exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
const exec = promisify(_exec);
|
||||
|
||||
const regex = /https?:\/\/[\w\S(\.|:|/)]+/gi;
|
||||
//const regex = /https?:\/\/[\w\S(\.|:|/)]+/gi;
|
||||
const regex = /https?:\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?/gi;
|
||||
|
||||
export default async bot => {
|
||||
|
||||
@ -35,12 +36,12 @@ export default async bot => {
|
||||
|
||||
links.forEach(async link => {
|
||||
// check repost (link)
|
||||
const q_repost = await sql.query("select id from items where src = ?", [ link ]);
|
||||
const q_repost = await sql("items").select("id").where("src", link);
|
||||
if(q_repost.length > 0)
|
||||
return e.reply(`repost motherf0cker (link): ${cfg.main.url}/${q_repost[0].id}`);
|
||||
|
||||
// generate uuid
|
||||
const uuid = (await sql.query("select left(uuid(), 8) as uuid"))[0].uuid;
|
||||
const uuid = (await sql.select(sql.raw("left(uuid(), 8) as uuid")))[0].uuid;
|
||||
|
||||
const maxfilesize = (getLevel(e.user).level > 50 ? cfg.main.maxfilesize * 2.5 : cfg.main.maxfilesize) / 1024;
|
||||
|
||||
@ -48,7 +49,6 @@ export default async bot => {
|
||||
// read metadata
|
||||
try {
|
||||
meta = JSON.parse((await exec(`youtube-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
//meta = JSON.parse((await exec(`youtube-dl -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --skip-download --dump-json "${link}"`)).stdout);
|
||||
}
|
||||
catch(err) {
|
||||
//e.reply("(╯° °)╯︵ ┻━┻)");
|
||||
@ -56,6 +56,9 @@ export default async bot => {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!cfg.ext.includes(meta.ext.toLowerCase()))
|
||||
return;
|
||||
|
||||
let filename = `${uuid}.${meta.ext}`;
|
||||
|
||||
//e.reply(`downloading ${uuid}...`);
|
||||
@ -65,18 +68,14 @@ export default async bot => {
|
||||
const start = new Date();
|
||||
let source;
|
||||
if(meta.ext === "mp4") {
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
|
||||
source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" --merge-output-format mp4 -o ./tmp/${filename}`)).stdout.trim();
|
||||
console.log("mp4 lol");
|
||||
//console.log("mp4 lol");
|
||||
}
|
||||
else {
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=${meta.ext},filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[ext=${meta.ext},width<2000][height<=1200]/best" --merge-output-format ${meta.ext} -o ./tmp/${filename}`)).stdout.trim();
|
||||
source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[filesize<${maxfilesize}k][width<2000][height<=1200][ext=${meta.ext}]+bestaudio[filesize<${maxfilesize}k][ext=${meta.ext}]/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k][width<2000][height<=1200]+bestaudio[ext=m4a,filesize<${maxfilesize}k]/bestvideo[width<2000][height<=1200]+bestaudio/best[width<2000][height<=1200]/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
//source = (await exec(`youtube-dl "${link}" --max-filesize ${maxfilesize}k -f "bestvideo[ext=mp4,filesize<${maxfilesize}k]+bestaudio/best" -o ./tmp/${filename}`)).stdout.trim();
|
||||
console.log("alles andere lol");
|
||||
//console.log("alles andere lol");
|
||||
}
|
||||
console.log(source);
|
||||
//console.log(source);
|
||||
|
||||
if(source.match(/larger than/))
|
||||
return e.reply("too large lol");
|
||||
@ -115,17 +114,25 @@ export default async bot => {
|
||||
}
|
||||
|
||||
// check repost (checksum)
|
||||
const q_repostc = await sql.query("select id from items where checksum = ?", [ checksum ]);
|
||||
const q_repostc = await sql("items").select("id").where("checksum", checksum);
|
||||
if(q_repostc.length > 0)
|
||||
return e.reply(`repost motherf0cker (checksum): ${cfg.main.url}/${q_repostc[0].id}`);
|
||||
|
||||
await fs.promises.copyFile(`./tmp/${filename}`, `./public/b/${filename}`);
|
||||
await fs.promises.unlink(`./tmp/${filename}`).catch(_=>{});
|
||||
|
||||
const insertq = await sql.query(
|
||||
"insert into items (src, dest, mime, size, checksum, username, userchannel, usernetwork, stamp, active) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
[ e.photo ? "" : link, filename, mime, size, checksum, e.user.nick || e.user.username, e.channel, e.network, ~~(new Date() / 1000), 1 ]
|
||||
);
|
||||
const insertq = (await sql("items").insert({
|
||||
src: e.photo ? "" : link,
|
||||
dest: filename,
|
||||
mime: mime,
|
||||
size: size,
|
||||
checksum: checksum,
|
||||
username: e.user.nick || e.user.username,
|
||||
userchannel: e.channel,
|
||||
usernetwork: e.network,
|
||||
stamp: ~~(new Date() / 1000),
|
||||
active: 1
|
||||
}))[0];
|
||||
|
||||
// generate thumbnail
|
||||
try {
|
||||
@ -134,17 +141,17 @@ export default async bot => {
|
||||
if(mime.startsWith("image") && mime !== "image/gif")
|
||||
thumb_orig = `./public/b/${filename}`;
|
||||
else if(!mime.startsWith("audio")) {
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq.insertId}`);
|
||||
thumb_orig = `./tmp/${insertq.insertId}`;
|
||||
await exec(`ffmpegthumbnailer -i./public/b/${filename} -s1024 -o./tmp/${insertq}`);
|
||||
thumb_orig = `./tmp/${insertq}`;
|
||||
}
|
||||
else if(mime.startsWith("audio")) {
|
||||
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${insertq.insertId}.png`)
|
||||
await exec(`cp ./tmp/${insertq.insertId}.png ./public/ca/${insertq.insertId}.png`)
|
||||
thumb_orig = `./tmp/${insertq.insertId}.png`;
|
||||
await exec(`ffmpeg -i ./public/b/${filename} -update 1 -map 0:v -map 0:1 -c copy ./tmp/${insertq}.png`)
|
||||
await exec(`cp ./tmp/${insertq}.png ./public/ca/${insertq}.png`)
|
||||
thumb_orig = `./tmp/${insertq}.png`;
|
||||
}
|
||||
}
|
||||
await exec(`convert "${thumb_orig}" -resize "200x200^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq.insertId}.png`);
|
||||
await fs.promises.unlink(`./tmp/${insertq.insertId}`).catch(_=>{});
|
||||
await exec(`convert "${thumb_orig}" -resize "200x200^" -gravity center -crop 128x128+0+0 +repage ./public/t/${insertq}.png`);
|
||||
await fs.promises.unlink(`./tmp/${insertq}`).catch(_=>{});
|
||||
} catch(err) {
|
||||
e.reply("\x033>no thumb lol");
|
||||
console.error(err);
|
||||
@ -155,8 +162,8 @@ export default async bot => {
|
||||
|
||||
e.reply([
|
||||
//`title: ${meta.fulltitle}`,
|
||||
`link: ${cfg.main.url}/${insertq.insertId} | size: ${lib.formatSize(size)} | speed: ${speed}`
|
||||
//`link: ${cfg.main.url}/${insertq.insertId}`
|
||||
`link: ${cfg.main.url}/${insertq} | size: ${lib.formatSize(size)} | speed: ${speed}`
|
||||
//`link: ${cfg.main.url}/${insertq}`
|
||||
]);
|
||||
|
||||
});
|
||||
|
@ -2,14 +2,10 @@ import sql from "../sql.mjs";
|
||||
import cfg from "../config.mjs";
|
||||
import { getLevel } from "../admin.mjs";
|
||||
|
||||
const queries = {
|
||||
getTags: "select tags.id, tags.tag from tags_assign left join tags on tags.id = tags_assign.tag_id where tags_assign.item_id = ?",
|
||||
assignTag: "insert into tags_assign (tag_id, item_id, prefix) values (?, ?, ?)"
|
||||
};
|
||||
|
||||
const getTags = async itemid => {
|
||||
return await sql.query(queries.getTags, [ itemid ]);
|
||||
};
|
||||
const getTags = async itemid => await sql("tags_assign")
|
||||
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
||||
.where("tags_assign.item_id", itemid)
|
||||
.select("tags.id", "tags.tag");
|
||||
|
||||
export default async bot => {
|
||||
return [{
|
||||
@ -21,7 +17,7 @@ export default async bot => {
|
||||
const id = +e.args[1];
|
||||
if(!id)
|
||||
return e.reply("lol no");
|
||||
const tags = await getTags(id).map(t => t.tag);
|
||||
const tags = (await getTags(id)).map(t => t.tag);
|
||||
if(tags.length === 0)
|
||||
return e.reply(`item ${cfg.main.url}/${id} has no tags!`);
|
||||
return e.reply(`item ${cfg.main.url}/${id} is tagged as: ${tags.join(', ')}`);
|
||||
@ -48,13 +44,20 @@ export default async bot => {
|
||||
await Promise.all(newtags.map(async ntag => {
|
||||
try {
|
||||
let tagid;
|
||||
const tag_exists = (await sql.query(`select id, tag from tags where tag = ?`, [ ntag ]));
|
||||
if(tag_exists.length === 0) // create new tag
|
||||
tagid = (await sql.query("insert into tags (tag) values (?)", [ ntag ])).insertId;
|
||||
else
|
||||
const tag_exists = await sql("tags").select("id", "tag").where("tag", ntag);
|
||||
if(tag_exists.length === 0) { // create new tag
|
||||
tagid = (await sql("tags").insert({
|
||||
tag: ntag
|
||||
}))[0];
|
||||
}
|
||||
else {
|
||||
tagid = tag_exists[0].id;
|
||||
|
||||
return await sql.query(queries.assignTag, [ tagid, id, `${e.user.prefix}${e.channel}` ]);
|
||||
}
|
||||
return await sql("tags_assign").insert({
|
||||
tag_id: tagid,
|
||||
item_id: id,
|
||||
prefix: `${e.user.prefix}${e.channel}`
|
||||
});
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
@ -94,14 +97,12 @@ export default async bot => {
|
||||
};
|
||||
}
|
||||
|
||||
let q;
|
||||
if(getLevel(e.user).level > 50)
|
||||
q = !!(await sql.query("delete from tags_assign where tag_id = ? and item_id = ? limit 1", [ tagid, id ])).affectedRows;
|
||||
else
|
||||
q = !!(await sql.query("delete from tags_assign where tag_id = ? and item_id = ? and prefix = ? limit 1", [ tagid, id, `${e.user.prefix}${e.channel}` ])).affectedRows;
|
||||
|
||||
let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", id).del();
|
||||
if(getLevel(e.user).level < 50)
|
||||
q = q.andWhere("prefix", `${e.user.prefix}${e.channel}`);
|
||||
|
||||
return {
|
||||
success: q,
|
||||
success: !!(await q),
|
||||
tag: rtag,
|
||||
tagid: tagid
|
||||
};
|
||||
|
Reference in New Issue
Block a user