Skip to content

Commit

Permalink
Update host permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev committed May 17, 2024
1 parent b03995c commit d660689
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2235,7 +2236,7 @@ class Chat {
const displayName = parts[1];
let url = parts[0];

if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
if (!this.user.hasRole(UserRoles.HOST)) {
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
return;
}
Expand Down Expand Up @@ -2277,7 +2278,7 @@ class Chat {
}

cmdUNHOST() {
if (!this.user.hasAnyFeatures(UserFeatures.ADMIN, UserFeatures.MODERATOR)) {
if (!this.user.hasRole(UserRoles.HOST)) {
MessageBuilder.error(errorstrings.get('nopermission')).into(this);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions assets/chat/js/roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
USER: 'USER',
SUBSCRIBER: 'SUBSCRIBER',
ADMIN: 'ADMIN',
MODERATOR: 'MODERATOR',
HOST: 'HOST',
};
22 changes: 22 additions & 0 deletions assets/chat/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UserFeature from './features';
* @property {string} nick
* @property {string} createdDate
* @property {string[]} features
* @property {string[]} roles
*/

class ChatUser {
Expand Down Expand Up @@ -39,6 +40,12 @@ class ChatUser {
*/
features = [];

/**
* User's roles.
* @type {[]string}
*/
roles = [];

/**
* User's watching embed.
* @type {?Object}
Expand All @@ -58,6 +65,7 @@ class ChatUser {
this.username = this.displayName.toLowerCase();
this.createdDate = user.createdDate || '';
this.features = user.features || [];
this.roles = user.roles || [];
this.watching = user.watching || null;
}
}
Expand All @@ -74,10 +82,24 @@ class ChatUser {
return exists;
}

hasAnyRoles(...roles) {
let exists = false;
roles.forEach((f) => {
if (this.roles.indexOf(typeof f !== 'string' ? f.toString() : f) !== -1)
exists = true;
});

return exists;
}

hasFeature(feature) {
return this.hasAnyFeatures(feature);
}

hasRole(role) {
return this.hasAnyRoles(role);
}

hasModPowers() {
return this.hasAnyFeatures(UserFeature.ADMIN, UserFeature.MODERATOR);
}
Expand Down

0 comments on commit d660689

Please sign in to comment.