Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #483

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions/guild/guildCreatePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = async (d) => {
const thread = await forum.threads.create({
name,
autoArchiveDuration,
message: content?.data,
message: content.data ? content.data : content,
appliedTags: parseTags,
reason
});
Expand Down
40 changes: 21 additions & 19 deletions src/functions/user/cacheMembers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module.exports = async (d) => {
const {code} = d.command;
const inside = d.unpack();
const [guildID = d.guild.Id, returnCount = "false"] = inside.splits;
let result;
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
const [guildID = d.guild.id, returnCount = "false"] = data.inside.splits;
let result;

const guild = await d.util.getGuild(d, guildID);
if (!guild) return d.aoiError.fnError(d, "guild", {inside});
const guild = await d.util.getGuild(d, guildID);
if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside });

if (guild.memberCount > guild.members.cache.size) {
result = await guild.members.fetch().catch((err) => {
d.aoiError.fnError(
d,
"custom",
{},
"Failed To Fetch Members With Reason :" + err,
);
});
}
if (guild.memberCount > guild.members.cache.size) {
result = await guild.members.fetch().catch((err) => {
d.aoiError.fnError(
d,
"custom",
{},
"Failed To Fetch Members With Reason :" + err
);
});
}

return {
code: d.util.setCode({function: d.func, code, inside, result}),
};
data.result = returnCount === "true" ? guild.members.cache.size.toString() : undefined;

return {
code: d.util.setCode(data),
};
};
37 changes: 20 additions & 17 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 @@ -14,39 +23,33 @@ module.exports = async (d) => {
key = `${variable.addBrackets()}_${`${id}_${
d.guild?.id === undefined ? "dm" : d.guild?.id
}`}`;
cache = await d.client.guilds.cache.get(id);
cache = await d.util.getGuild(d, id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.client.users.fetch(id)
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);
cache = await d.util.getGuild(d, id);
user =
typeof cache === "undefined" || Object.keys(cache).length === 0
? await d.client.users.fetch(id)
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}`;
} else {
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;
data.result = all.slice().sort((a, b) => b.value - a.value).findIndex((x) => x.key === key) + 1 || 0;
break;
case "value":
data.result = value;
data.result = all.find(x => x.key === key).value || 0;
break;
case "tag":
Faf4a marked this conversation as resolved.
Show resolved Hide resolved
data.result = user.tag || null;
case "id":
data.result = user.id || null;
break;
case "username":
data.result = user.username || null;
Expand Down