Moderation Bot integration WIP:

* Start and stop the bot WIP
* Prosody: removing the BOSH module from the global scope (must only be present on relevant virtualhosts)
* Some refactoring
This commit is contained in:
John Livingston
2023-09-18 18:53:07 +02:00
parent 65fd49a81c
commit f97e54d499
15 changed files with 348 additions and 26 deletions

View File

@ -1,4 +1,5 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { Config as XMPPBotConfig } from 'xmppjs-chat-bot'
import type { ProsodyLogLevel } from './config/content'
import * as fs from 'fs'
import * as path from 'path'
@ -9,6 +10,7 @@ import { getProsodyDomain } from './config/domain'
import { getAPIKey } from '../apikey'
import { parseExternalComponents } from './config/components'
import { getRemoteServerInfosDir } from '../federation/storage'
import { BotConfiguration } from '../configuration/bot'
async function getWorkingDir (options: RegisterServerOptions): Promise<string> {
const peertubeHelpers = options.peertubeHelpers
@ -125,6 +127,9 @@ interface ProsodyConfig {
logExpiration: ConfigLogExpiration
valuesToHideInDiagnostic: Map<string, string>
certificates: ProsodyConfigCertificates
bots: {
moderation?: XMPPBotConfig
}
}
async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<ProsodyConfig> {
const logger = options.peertubeHelpers.logger
@ -147,7 +152,8 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
'prosody-components-interfaces',
'prosody-components-list',
'chat-no-anonymous',
'federation-dont-publish-remotely'
'federation-dont-publish-remotely',
'disable-channel-configuration'
])
const valuesToHideInDiagnostic = new Map<string, string>()
@ -168,6 +174,7 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
// enableRemoteChatConnections: local users can communicate with external rooms
const enableRemoteChatConnections = !(settings['federation-dont-publish-remotely'] as boolean)
let certificates: ProsodyConfigCertificates = false
const bots: ProsodyConfig['bots'] = {}
const apikey = await getAPIKey(options)
valuesToHideInDiagnostic.set('APIKey', apikey)
@ -287,6 +294,12 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
config.usePeertubeVCards(basePeertubeUrl)
config.useAnonymousRandomVCards(paths.avatars)
if (!settings['disable-channel-configuration']) {
config.useBotsVirtualHost()
bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf()
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password)
}
config.useTestModule(apikey, testApiUrl)
let logLevel: ProsodyLogLevel | undefined
@ -315,7 +328,8 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
logByDefault,
logExpiration,
valuesToHideInDiagnostic,
certificates
certificates,
bots
}
}

View File

@ -140,6 +140,7 @@ class ProsodyConfigContent {
authenticated?: ProsodyConfigVirtualHost
anon?: ProsodyConfigVirtualHost
muc: ProsodyConfigComponent
bot?: ProsodyConfigVirtualHost
externalComponents: ProsodyConfigComponent[] = []
log: string
prosodyDomain: string
@ -170,7 +171,7 @@ class ProsodyConfigContent {
'version', // Replies to server version requests
'uptime', // Report how long server has been running
'ping', // Replies to XMPP pings with pongs
'bosh', // Enable BOSH clients, aka "Jabber over HTTP"
// 'bosh', // Enable BOSH clients, aka "Jabber over HTTP"
// 'websocket', // Enable Websocket clients
'posix', // POSIX functionality, sends server to background, enables syslog, etc.
// 'pep', // Enables users to publish their avatar, mood, activity, playing music and more
@ -192,6 +193,7 @@ class ProsodyConfigContent {
this.global.set('certificates', this.paths.certs)
}
this.muc.set('admins', [])
this.muc.set('muc_room_locking', false)
this.muc.set('muc_tombstones', false)
this.muc.set('muc_room_default_language', 'en')
@ -403,6 +405,16 @@ class ProsodyConfigContent {
}
}
/**
* Enable the bots virtualhost.
*/
useBotsVirtualHost (): void {
this.bot = new ProsodyConfigVirtualHost('bot.' + this.prosodyDomain)
this.bot.set('modules_enabled', ['ping'])
// TODO: bot vcards
}
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
let log = ''
log += 'log = {\n'
@ -431,6 +443,10 @@ class ProsodyConfigContent {
content += this.anon.write()
content += '\n\n'
}
if (this.bot) {
content += this.bot.write()
content += '\n\n'
}
content += this.muc.write()
content += '\n\n'
for (const externalComponent of this.externalComponents) {