Skip to content

Add restricted channels bypass (for devs or other role)#162

Closed
otiskujawa wants to merge 3 commits intoGeoxor:mainfrom
otiskujawa:add-general-bypass
Closed

Add restricted channels bypass (for devs or other role)#162
otiskujawa wants to merge 3 commits intoGeoxor:mainfrom
otiskujawa:add-general-bypass

Conversation

@otiskujawa
Copy link
Contributor

i forgot to add import in #161

@Its-treason
Copy link
Contributor

I think it would be better if we store all Role ID's inside a class constant, so the If doesn't get too long, and it makes it easier to add more roles later

  export default class RestrictedChannel extends AbstractPipelineElement {
    private readonly RESTRICTED_CHANNELS = [GEOXOR_GENERAL_CHANNEL_ID];
+   private readonly WHITELISTED_ROLES = [MOD_ROLE_ID, ADMIN_ROLE_ID, GEOXOR_DEV_ROLE_ID];

    execute(payload: MessageCreatePayload): Awaitable<boolean> {
      const message = payload.get("message");

      // Do not allow Commands in RestrictedChannels
      // Not Geoxor's guild or in a restricted channel -> Continue
      if (!message.member || !this.RESTRICTED_CHANNELS.includes(message.channel.id)) {
        return true;
      }

      // Check if user is a mod, admin or has admin perms if not, return
      if (
-       message.member.roles.cache.some((role) => role.id === MOD_ROLE_ID || role.id === ADMIN_ROLE_ID || role.id === RESTRICT_BYPASS_ROLE_ID) ||
+       message.member.roles.cache.some((role) => this.WHITELISTED_ROLES.includes(role.id)) ||
        message.member.permissions.has("Administrator")
      ) {
        return true;
      }
      return false;
    }
  }

@Geoxor
Copy link
Owner

Geoxor commented Dec 14, 2023

do i merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments