Skip to content

Commit

Permalink
fix(/checkroles): check for autorole and requiredRole
Browse files Browse the repository at this point in the history
  • Loading branch information
tippfehlr committed May 1, 2024
1 parent 1ddfc4c commit 8007214
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/modules/bot.presenceUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,18 @@ export async function processRoles({
member: GuildMember;
activeTemporaryRoles: Selectable<ActiveTemporaryRoles>[];
}): Promise<{ added: number; removed: number }> {
if (member.user.bot) return { added: 0, removed: 0 };
const status = { added: 0, removed: 0 };
if (member.user.bot) return status;

const userConfig = await getUserConfig(member.id);
if (!userConfig.autorole) return status;

const guildConfig = await getGuildConfig(guild.id);
if (guildConfig.requiredRoleID !== null && !member.roles.cache.has(guildConfig.requiredRoleID)) {
return status;
}
const permanentRoleIDsToBeAdded: Set<string> = new Set();
const tempRoleIDsToBeAdded: Set<string> = new Set();
const status = { added: 0, removed: 0 };

const addRoleHelper = async (roleID: string, change: 'add' | 'remove', permanent: boolean) => {
switch (
Expand Down Expand Up @@ -222,10 +229,6 @@ export function initPresenceUpdate() {
);
return;
}
if (!newMember.user || !newMember.guild || newMember.member?.user.bot) return;

const userConfig = await getUserConfig(newMember.userId);
if (!userConfig.autorole) return;

const userIDHash = hashUserID(newMember.userId);
const guildConfig = await getGuildConfig(guildID);
Expand Down
13 changes: 13 additions & 0 deletions src/modules/commands/checkRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ export async function checkRoles({
interaction?: CommandInteraction;
locale?: string;
}) {
if (!guild.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) {
if (interaction && locale) {
//TODO: add message to allow permission
return;
} else {
log.warn(
`MISSING ACCESS: LEFT guild: ${guild.name} (ID: ${guild.id}, OwnerID: ${guild.ownerId}), Permission: MANAGE_ROLES`,
);
await guild.leave();
return;
}
}

if (checkrolesCurrentGuilds.has(guild.id)) {
log.debug(`checkroles already running on ${guild.name} (${guild.id})`);
if (interaction && locale) {
Expand Down

0 comments on commit 8007214

Please sign in to comment.