Skip to content

Commit

Permalink
Moderate handler: option to also apply to moderators.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnXLivingston committed Sep 21, 2023
1 parent 1e0549e commit 29c1f1f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.6

* Moderate handler: option to also apply to moderators.

## 0.2.5

* Fix message moderation, when not used as a component.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Type name (to use in configuration files): `moderate`.
Options:

* `rules`: one ore more moderation rules
* `applyToModerators`: by default, moderator's messages will not be moderated, unless you set this option to true

A moderation rule can be:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmppjs-chat-bot",
"version": "0.2.5",
"version": "0.2.6",
"description": "Server-side XMPP chat bot",
"engines": {
"node": ">= 14.4.0"
Expand Down
7 changes: 6 additions & 1 deletion src/handlers/moderate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Rule {
class HandlerModerate extends Handler {
private readonly roomMessage
protected rules: Rule[]
protected applyToModerators: boolean = false

/**
* @param room
Expand All @@ -37,7 +38,7 @@ class HandlerModerate extends Handler {
for (const regexp of regexps) {
if (regexp.test(body)) {
this.logger.debug('Message match following rule: ' + rule.name)
if (fromUser.isModerator()) {
if (!this.applyToModerators && fromUser.isModerator()) {
this.logger.debug('Ignoring the moderation rule ' + rule.name + ', because the user is moderator.')
continue
}
Expand All @@ -52,6 +53,10 @@ class HandlerModerate extends Handler {
public loadOptions (options: any): void {
if (typeof options !== 'object') { return }

if (('applyToModerators' in options) && (typeof options.applyToModerators === 'boolean')) {
this.applyToModerators = options.applyToModerators
}

if (!('rules' in options)) { return }
let rules = options.rules

Expand Down

0 comments on commit 29c1f1f

Please sign in to comment.