Moderation.
This commit is contained in:
parent
4fe972dc10
commit
852221d232
16
package-lock.json
generated
16
package-lock.json
generated
@ -15,7 +15,7 @@
|
|||||||
"http-proxy": "^1.18.1",
|
"http-proxy": "^1.18.1",
|
||||||
"log-rotate": "^0.2.8",
|
"log-rotate": "^0.2.8",
|
||||||
"validate-color": "^2.2.1",
|
"validate-color": "^2.2.1",
|
||||||
"xmppjs-chat-bot": "^0.2.4"
|
"xmppjs-chat-bot": "^0.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@peertube/feed": "^5.1.0",
|
"@peertube/feed": "^5.1.0",
|
||||||
@ -12026,9 +12026,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/xmppjs-chat-bot": {
|
"node_modules/xmppjs-chat-bot": {
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/xmppjs-chat-bot/-/xmppjs-chat-bot-0.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/xmppjs-chat-bot/-/xmppjs-chat-bot-0.2.5.tgz",
|
||||||
"integrity": "sha512-gS6oS9tpRENjrx5nr++PmlYZF6LlvsmLQqS56Di8npASIY9nXS7Ka+OvK13Kb6mzVTiR7HyG9qYQQLKVYpoUhg==",
|
"integrity": "sha512-74gTrXmvz8a2xTm5oFdKxyeMWPz3MQZFF+TI6aB75IUhJlT03+SuGixB6u2rDyWGe6DHy1A9lsZFwCtdeQfE3g==",
|
||||||
"funding": [
|
"funding": [
|
||||||
"https://paypal.me/JohnXLivingston",
|
"https://paypal.me/JohnXLivingston",
|
||||||
"https://liberapay.com/JohnLivingston/"
|
"https://liberapay.com/JohnLivingston/"
|
||||||
@ -12037,6 +12037,7 @@
|
|||||||
"@xmpp/client": "^0.13.1",
|
"@xmpp/client": "^0.13.1",
|
||||||
"@xmpp/component": "^0.13.1",
|
"@xmpp/component": "^0.13.1",
|
||||||
"@xmpp/debug": "^0.13.0",
|
"@xmpp/debug": "^0.13.0",
|
||||||
|
"@xmpp/id": "^0.13.1",
|
||||||
"@xmpp/jid": "^0.13.1",
|
"@xmpp/jid": "^0.13.1",
|
||||||
"@xmpp/xml": "^0.13.1",
|
"@xmpp/xml": "^0.13.1",
|
||||||
"commander": "^11.0.0"
|
"commander": "^11.0.0"
|
||||||
@ -21248,13 +21249,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"xmppjs-chat-bot": {
|
"xmppjs-chat-bot": {
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/xmppjs-chat-bot/-/xmppjs-chat-bot-0.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/xmppjs-chat-bot/-/xmppjs-chat-bot-0.2.5.tgz",
|
||||||
"integrity": "sha512-gS6oS9tpRENjrx5nr++PmlYZF6LlvsmLQqS56Di8npASIY9nXS7Ka+OvK13Kb6mzVTiR7HyG9qYQQLKVYpoUhg==",
|
"integrity": "sha512-74gTrXmvz8a2xTm5oFdKxyeMWPz3MQZFF+TI6aB75IUhJlT03+SuGixB6u2rDyWGe6DHy1A9lsZFwCtdeQfE3g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@xmpp/client": "^0.13.1",
|
"@xmpp/client": "^0.13.1",
|
||||||
"@xmpp/component": "^0.13.1",
|
"@xmpp/component": "^0.13.1",
|
||||||
"@xmpp/debug": "^0.13.0",
|
"@xmpp/debug": "^0.13.0",
|
||||||
|
"@xmpp/id": "^0.13.1",
|
||||||
"@xmpp/jid": "^0.13.1",
|
"@xmpp/jid": "^0.13.1",
|
||||||
"@xmpp/xml": "^0.13.1",
|
"@xmpp/xml": "^0.13.1",
|
||||||
"commander": "^11.0.0"
|
"commander": "^11.0.0"
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
"http-proxy": "^1.18.1",
|
"http-proxy": "^1.18.1",
|
||||||
"log-rotate": "^0.2.8",
|
"log-rotate": "^0.2.8",
|
||||||
"validate-color": "^2.2.1",
|
"validate-color": "^2.2.1",
|
||||||
"xmppjs-chat-bot": "^0.2.4"
|
"xmppjs-chat-bot": "^0.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@peertube/feed": "^5.1.0",
|
"@peertube/feed": "^5.1.0",
|
||||||
|
@ -6,6 +6,10 @@ import { sanitizeChannelConfigurationOptions } from '../../configuration/channel
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
|
// FIXME: should be exported by xmppjs-chat-bot
|
||||||
|
type ConfigHandlers = ChannelCommonRoomConf['handlers']
|
||||||
|
type ConfigHandler = ConfigHandlers[0]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get saved configuration options for the given channel.
|
* Get saved configuration options for the given channel.
|
||||||
* Can throw an exception.
|
* Can throw an exception.
|
||||||
@ -78,9 +82,18 @@ function channelConfigurationOptionsToBotRoomConf (
|
|||||||
options: RegisterServerOptions,
|
options: RegisterServerOptions,
|
||||||
channelConfigurationOptions: ChannelConfigurationOptions
|
channelConfigurationOptions: ChannelConfigurationOptions
|
||||||
): ChannelCommonRoomConf {
|
): ChannelCommonRoomConf {
|
||||||
|
// Note concerning handlers:
|
||||||
|
// If we want the bot to correctly enable/disable the handlers,
|
||||||
|
// we must always define all handlers, even if not used.
|
||||||
|
const handlers: ConfigHandlers = []
|
||||||
|
handlers.push(_getForbiddenWordsHandler(
|
||||||
|
'forbidden_words_0',
|
||||||
|
channelConfigurationOptions.forbiddenWords
|
||||||
|
))
|
||||||
|
|
||||||
const roomConf: ChannelCommonRoomConf = {
|
const roomConf: ChannelCommonRoomConf = {
|
||||||
enabled: channelConfigurationOptions.bot,
|
enabled: channelConfigurationOptions.bot,
|
||||||
handlers: []
|
handlers
|
||||||
}
|
}
|
||||||
if (channelConfigurationOptions.botNickname && channelConfigurationOptions.botNickname !== '') {
|
if (channelConfigurationOptions.botNickname && channelConfigurationOptions.botNickname !== '') {
|
||||||
roomConf.nick = channelConfigurationOptions.botNickname
|
roomConf.nick = channelConfigurationOptions.botNickname
|
||||||
@ -88,6 +101,39 @@ function channelConfigurationOptionsToBotRoomConf (
|
|||||||
return roomConf
|
return roomConf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _getForbiddenWordsHandler (
|
||||||
|
id: string,
|
||||||
|
forbiddenWords: string[],
|
||||||
|
reason?: string
|
||||||
|
): ConfigHandler {
|
||||||
|
const handler: ConfigHandler = {
|
||||||
|
type: 'moderate',
|
||||||
|
id,
|
||||||
|
enabled: false,
|
||||||
|
options: {
|
||||||
|
rules: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (forbiddenWords.length === 0) {
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.enabled = true
|
||||||
|
// Note: on the Peertube frontend, channelConfigurationOptions.forbiddenWords
|
||||||
|
// is an array of RegExp definition (strings).
|
||||||
|
// They are validated one by bone.
|
||||||
|
// To increase the bot performance, we will join them all (hopping the bot will optimize them).
|
||||||
|
const rule: any = {
|
||||||
|
name: id,
|
||||||
|
regexp: '(?:' + forbiddenWords.join(')|(?:') + ')'
|
||||||
|
}
|
||||||
|
if (reason) {
|
||||||
|
rule.reason = reason
|
||||||
|
}
|
||||||
|
handler.options.rules.push(rule)
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
function _getFilePath (
|
function _getFilePath (
|
||||||
options: RegisterServerOptions,
|
options: RegisterServerOptions,
|
||||||
channelId: number | string
|
channelId: number | string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user