TheOdinProject / odin-bot-v2

The bot that breathes life into our Discord community
ISC License
48 stars 77 forks source link

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

Closed Asartea closed 3 months ago

Asartea commented 4 months ago

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:


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:

MaoShizhong commented 4 months ago

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.