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

Abstract out isAdmin check to new utility in /utils #566

Closed
2 of 4 tasks
Asartea opened this issue Jul 13, 2024 · 1 comment · Fixed by #567
Closed
2 of 4 tasks

Abstract out isAdmin check to new utility in /utils #566

Asartea opened this issue Jul 13, 2024 · 1 comment · Fixed by #567
Assignees
Labels
Status: In Progress This issue/PR has ongoing work being done

Comments

@Asartea
Copy link
Contributor

Asartea commented Jul 13, 2024

Complete the following REQUIRED checkboxes:

- [ ] The title of this issue follows the command name: brief description of request format, e.g. /help: add optional @user parameter

The following checkbox is OPTIONAL:

  • I would like to be assigned this issue to work on it

1. Description of the Feature Request:
We currently duplicate the code for checking if an user is an "admin" in a number of places using roughly this snippet[1]

      authorMember.roles.cache.forEach((value) => {
        if (config.roles.adminRolesName.includes(value.name)) {
          isAdmin = true;
        }
      });

this duplicates code, and also can be simplified to

const isAdmin = member.roles.cache.some((role) => roles.adminRolesName.includes(role.name))

It would be beneficial to abstract this functionality out to a new is-admin.js file in /utils

[1] Taken from points.js

2. Acceptance Criteria:

  • There is an utility function which checks if an member is an admin
  • All code that needs to check this uses the utility function
@Asartea Asartea added the Status: Needs Review This issue/PR needs an initial or additional review label Jul 13, 2024
@MaoShizhong
Copy link
Contributor

MaoShizhong commented Jul 14, 2024

We can certainly extract out the logic for isAdmin to a util function. Can just pass in the member so we have like const isAdminMessage = isAdmin(message.member) and const isAdminUser = isAdmin(authorMember) or equivalent.

@MaoShizhong MaoShizhong added Status: In Progress This issue/PR has ongoing work being done and removed Status: Needs Review This issue/PR needs an initial or additional review labels Jul 14, 2024
@Asartea Asartea mentioned this issue Jul 14, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress This issue/PR has ongoing work being done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants