fix random

This commit is contained in:
Flummi 2022-01-02 14:37:44 +01:00
parent d781290430
commit 0a983b140e
2 changed files with 36 additions and 20 deletions

View File

@ -107,7 +107,8 @@ export default {
.limit(cfg.websrv.eps);
}
if(tag) rows = rows
if(tag) {
rows = rows
.innerJoin(
sql("tags")
.select("tags_assign.item_id", "tags.tag")
@ -117,7 +118,8 @@ export default {
.as("st"),
"st.item_id", "items.id"
)
.groupBy('st.item_id');
.groupBy('st.item_id', 'items.id', 'tags_assign.tag_id');
}
rows = await rows;
@ -183,7 +185,6 @@ export default {
.leftJoin('user', 'user.id', 'favorites.user_id')
.whereRaw(modequery)
.andWhere('user.user', 'ilike', user)
.groupBy('items.id');
}
else {
items = sql("items")
@ -282,7 +283,22 @@ export default {
const modequery = mime == "audio" ? lib.getMode(0) : lib.getMode(o.mode ?? 0);
let item = sql("items").select("*").orderByRaw("random()").whereRaw(modequery);
let item;
if(o.fav) {
item = sql("favorites")
.select('items.*')
.leftJoin('items', 'items.id', 'favorites.item_id')
.leftJoin('user', 'user.id', 'favorites.user_id')
.whereRaw(modequery)
.orderByRaw("random()")
.andWhere('user.user', 'ilike', user);
}
else {
item = sql("items")
.select("*")
.orderByRaw("random()")
.whereRaw(modequery);
}
if(tag) {
item = item.innerJoin(
@ -290,11 +306,11 @@ export default {
.select("tags_assign.item_id", "tags.tag")
.leftJoin("tags_assign", "tags_assign.tag_id", "tags.id")
.where("tags.tag", "ilike", "%"+tag+"%")
.groupBy("tags_assign.item_id")
.groupBy("tags_assign.item_id", "tags.tag")
.as("st"),
"st.item_id", "items.id"
)
.groupBy('st.item_id');
.groupBy('st.item_id', 'st.tag', 'items.id');
}
if(user)
item = item.andWhere("username", "ilike", "%" + user + "%");
@ -310,7 +326,7 @@ export default {
};
}
const link = lib.genLink({ user, tag, mime });
const link = lib.genLink({ user, tag, mime, type: o.fav ? 'favs' : 'f0cks' });
return {
success: true,

View File

@ -14,12 +14,12 @@ export default async bot => {
for(let i = 0; i < args.length; i++) {
if(args[i].charAt(0) === "!")
rows = rows.where("username", "not like", args[i].slice(1));
rows = rows.where("username", "not ilike", args[i].slice(1));
else
rows = rows.where("username", "like", args[i]);
rows = rows.where("username", "ilike", args[i]);
}
rows = await rows.orderByRaw("rand()").limit(1);
rows = await rows.orderByRaw("random()").limit(1);
if(rows.length === 0)
return e.reply("nothing found, f0cker");