Skip to content

Commit

Permalink
merge conflict system sucks!
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a committed Sep 17, 2023
1 parent 5d0ea79 commit 0bc0204
Showing 1 changed file with 44 additions and 38 deletions.
82 changes: 44 additions & 38 deletions src/functions/variables/getLeaderboardInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [variable, id, type = "guild", format, table = d.client.db.tables[0]] = data.inside.splits;
const [variable, id, type = "guild", format, table = d.client.db.tables[0]] =
data.inside.splits;

if (!d.client.variableManager.has(variable, table))
return d.aoiError.fnError(
d,
"custom",
{},
`Variable "${variable}" Not Found`
);

let key = null;
let cache = null;
Expand All @@ -11,51 +20,48 @@ module.exports = async (d) => {
const all = await d.client.db.all(table, variable);

if (type === "guild") {
key = `${variable.addBrackets()}_${`${id}_${
d.guild?.id === undefined ? "dm" : d.guild?.id
}`}`;
cache = await d.client.guilds.cache.get(id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.client.users.fetch(id)
: undefined;
key = `${variable.addBrackets()}_${`${id}_${
d.guild?.id === "undefined" ? "dm" : d.guild?.id
}`}`;
cache = await d.util.getGuild(d, id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.util.getUser(d, id)
: undefined;
} else if (type === "global") {
key = `${variable.addBrackets()}_${id}`;
cache = await d.client.guilds.cache.get(id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.client.users.fetch(id)
: undefined;
key = `${variable.addBrackets()}_${id}`;
cache = await d.util.getGuild(d, id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.util.getUser(d, id)
: undefined;
} else if (type === "message" || type === "channel") {
key = `${variable.addBrackets()}_${id}`;
key = `${variable.addBrackets()}_${id}`;
} else {
d.aoiError.fnError(d, "custom", {inside: data.inside}, `type`);
d.aoiError.fnError(d, "custom", { inside: data.inside }, `type`);
}

const foundData = all.find((x) => x.key === key);
const foundDataMap = all
.map((x, pos) => ({value: x.value, key: x.key, pos: pos + 1}))
.sort((a, b) => a.value - b.value);
let value = foundData?.value ?? 0;

switch (format) {
case "top":
data.result = foundDataMap.find((x) => x.key === key)?.pos || null;
break;
case "value":
data.result = value;
break;
case "tag":
data.result = user.tag || null;
break;
case "username":
data.result = user.username || null;
break;
default:
data.result = null;
case "top":
data.result = all.slice().sort((a, b) => b.value - a.value).findIndex((x) => x.key === key) + 1 || 0;
break;
case "value":
data.result = all.find(x => x.key === key).value || 0;
break;
case "id":
data.result = user.id || null;
break;
case "username":
data.result = user.username || null;
break;
case "tag":
data.result = user.tag || '0000';
break;
default:
data.result = null;
}

return {
code: d.util.setCode(data),
code: d.util.setCode(data),
};
};

0 comments on commit 0bc0204

Please sign in to comment.