Skip to content

Commit

Permalink
fix(lowest/highestRole): returning error when user has no roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a committed Nov 29, 2023
1 parent 5d2d887 commit 2c7a408
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
20 changes: 10 additions & 10 deletions src/functions/guild/guildHighestRole.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = async d => {
const data = d.util.aoiFunc(d);
module.exports = async (d) => {
const data = d.util.aoiFunc(d);

const [guildID = d.guild?.id, option = 'id'] = data.inside.splits;
const [guildID = d.guild?.id, option = "id"] = data.inside.splits;

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

data.result = option === "mention" ? guild.roles.highest.toString() : guild.roles.highest[option];
data.result = option === "mention" ? member.roles.highest.toString() : member.roles.highest[option];

return {
code: d.util.setCode(data)
}
}
return {
code: d.util.setCode(data),
};
};
24 changes: 14 additions & 10 deletions src/functions/guild/guildLowestRole.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
module.exports = async d => {
const data = d.util.aoiFunc(d);
module.exports = async (d) => {
const data = d.util.aoiFunc(d);

const [guildID = d.guild?.id] = data.inside.splits;
const [guildID = d.guild?.id, option = "id"] = data.inside.splits;

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

data.result = [...guild.roles.cache.sort((a, b) => a.position - b.position)][1]?.[0];
const role = guild.roles.cache.filter((role) => role.id !== guild.id).sort((a, b) => a.position - b.position) .first();

return {
code: d.util.setCode(data)
}
}
data.result = !role
? guild?.roles.everyone.id
: role === undefined
? guild.id
: role?.[option.toLowerCase()];

return { code: d.util.setCode(data) };
};
25 changes: 13 additions & 12 deletions src/functions/user/userHighestRole.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module.exports = async d => {
const data = d.util.aoiFunc(d);
module.exports = async (d) => {
const data = d.util.aoiFunc(d);

const [userID = d.author?.id, guildID = d.guild?.id, option = 'id'] = data.inside.splits;
const [userID = d.author?.id, guildID = d.guild?.id, option = "id"] = data.inside.splits;

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

const member = await d.util.getMember(guild, userID);
if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside});
const member = await d.util.getMember(guild, userID);
if (!member) return d.aoiError.fnError(d, "member", { inside: data.inside });

data.result = option === "mention" ? member.roles.highest.toString() : member.roles.highest[option];
data.result =
option === "mention"
? member.roles.highest.toString()
: member.roles.highest[option];

return {
code: d.util.setCode(data)
}
}
return { code: d.util.setCode(data) };
};
29 changes: 16 additions & 13 deletions src/functions/user/userLowestRole.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
module.exports = async d => {
const data = d.util.aoiFunc(d);
module.exports = async (d) => {
const data = d.util.aoiFunc(d);

const [userID = d.author?.id, guildID = d.guild?.id] = data.inside.splits;
const [userID = d.author?.id, guildID = d.guild?.id, option = "id"] = data.inside.splits;

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

const member = await d.util.getMember(guild, userID);
if (!member) return d.aoiError.fnError(d, 'member', {inside: data.inside});
const role = [...member.roles.cache.sort((a, b) => a.position - b.position)][1];
const member = await d.util.getMember(guild, userID);
if (!member) return d.aoiError.fnError(d, "member", { inside: data.inside });

data.result = role[0];
const role = member.roles.cache.filter((role) => role.id !== guild.id).sort((a, b) => a.position - b.position).first();

return {
code: d.util.setCode(data)
}
}
data.result = !role
? guild?.roles.everyone.id
: role === undefined
? guild.id
: role?.[option.toLowerCase()];

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

0 comments on commit 2c7a408

Please sign in to comment.