diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index b2c51b37..c6a31403 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -42,6 +42,7 @@ import { ChatPoll, parseQuestionAndTime } from './poll'; import { isMuteActive, MutedTimer } from './mutedtimer'; import EmoteService from './emotes'; import UserFeatures from './features'; +import UserRoles from './roles'; import makeSafeForRegex, { regexslashcmd, regextime, @@ -2235,7 +2236,13 @@ class Chat { const displayName = parts[1]; let url = parts[0]; - if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) { + if ( + !this.user.hasAnyRoles( + UserRoles.ADMIN, + UserRoles.MODERATOR, + UserRoles.HOST, + ) + ) { MessageBuilder.error(errorstrings.get('nopermission')).into(this); return; } @@ -2277,7 +2284,13 @@ class Chat { } cmdUNHOST() { - if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) { + if ( + !this.user.hasAnyRoles( + UserRoles.ADMIN, + UserRoles.MODERATOR, + UserRoles.HOST, + ) + ) { MessageBuilder.error(errorstrings.get('nopermission')).into(this); return; } diff --git a/assets/chat/js/roles.js b/assets/chat/js/roles.js new file mode 100644 index 00000000..d3b1442d --- /dev/null +++ b/assets/chat/js/roles.js @@ -0,0 +1,7 @@ +export default { + USER: 'USER', + SUBSCRIBER: 'SUBSCRIBER', + ADMIN: 'ADMIN', + MODERATOR: 'MODERATOR', + HOST: 'HOST', +}; diff --git a/assets/chat/js/user.js b/assets/chat/js/user.js index 35039836..3f747f6d 100644 --- a/assets/chat/js/user.js +++ b/assets/chat/js/user.js @@ -6,6 +6,7 @@ import UserFeature from './features'; * @property {string} nick * @property {string} createdDate * @property {string[]} features + * @property {string[]} roles */ class ChatUser { @@ -39,6 +40,12 @@ class ChatUser { */ features = []; + /** + * User's roles. + * @type {[]string} + */ + roles = []; + /** * User's watching embed. * @type {?Object} @@ -58,24 +65,33 @@ class ChatUser { this.username = this.displayName.toLowerCase(); this.createdDate = user.createdDate || ''; this.features = user.features || []; + this.roles = user.roles || []; this.watching = user.watching || null; } } hasAnyFeatures(...features) { - let exists = false; - features.forEach((f) => { - if ( - this.features.indexOf(typeof f !== 'string' ? f.toString() : f) !== -1 - ) - exists = true; - }); - - return exists; + for (const feature of features) { + if (this.features.includes(feature)) return true; + } + + return false; + } + + hasAnyRoles(...roles) { + for (const role of roles) { + if (this.roles.includes(role)) return true; + } + + return false; } hasFeature(feature) { - return this.hasAnyFeatures(feature); + return this.features.includes(feature); + } + + hasRole(role) { + return this.roles.includes(role); } hasModPowers() {