This commit is contained in:
Skillz4Killz
2020-12-15 17:57:02 -05:00
parent 2f14cf75ac
commit aa39b1b62f
4 changed files with 56 additions and 20 deletions
+24 -12
View File
@@ -8,33 +8,42 @@ import { Member } from "./member.ts";
const baseRole: Partial<Role> = {
get guild() {
return cache.guilds.find(g => g.roles.has(this.id));
return cache.guilds.find((g) => g.roles.has(this.id));
},
get hexColor() {
return this.color!.toString(16);
},
get members() {
return cache.members.filter(m => m.guilds.some(g => g.roles.includes(this.id)));
return cache.members.filter((m) =>
m.guilds.some((g) => g.roles.includes(this.id))
);
},
get mention() {
return `<@&${this.id}>`;
},
// METHODS
delete: function (guildID?: string) {
// If not guild id was provided try and find one
if (!guildID) guildID = guildID || this.guild?.id;
// If a guild id is still not available error out
if (!guildID) throw new Error("role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)")
if (!guildID) {
throw new Error(
"role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)",
);
}
return deleteRole(guildID, this.id!).catch(console.error);
},
edit(options: CreateRoleOptions, guildID?: string) {
// If not guild id was provided try and find one
if (!guildID) guildID = guildID || this.guild?.id;
// If a guild id is still not available error out
if (!guildID) throw new Error("role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)")
if (!guildID) {
throw new Error(
"role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)",
);
}
return editRole(guildID, this.id!, options);
},
@@ -42,17 +51,20 @@ const baseRole: Partial<Role> = {
// If no position try and find one from cache
if (!position) position = this.guild?.roles.get(roleID)?.position;
// If still none error out.
if (!position) throw new Error("role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)")
if (!position) {
throw new Error(
"role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)",
);
}
// Rare edge case handling
if (this.position === position) {
return this.id! < roleID
return this.id! < roleID;
}
return this.position! > position;
},
}
};
export async function createRole(data: RoleData) {
const { tags, ...rest } = data;
@@ -68,7 +80,7 @@ export async function createRole(data: RoleData) {
botID: createNewProp(tags?.bot_id),
isNitroBoostRole: createNewProp("premium_subscriber" in (tags ?? {})),
integrationID: createNewProp(tags?.integration_id),
})
});
return role as Role;
}