Bots settings (WIP).
This commit is contained in:
19
server/lib/prosody/config/bots.ts
Normal file
19
server/lib/prosody/config/bots.ts
Normal file
@ -0,0 +1,19 @@
|
||||
function parseConfigDemoBotUUIDs (s: string): string[] {
|
||||
if (!s) {
|
||||
return []
|
||||
}
|
||||
let a = s.split('\n')
|
||||
// find lines that are like:
|
||||
// 6432f147-83c7-4fa3-b3b5-e49c2590e825 #!demobot
|
||||
a = a.filter(line => /#!demobot\b/.test(line))
|
||||
a = a.map(line => {
|
||||
return line.replace(/#.*$/, '')
|
||||
.replace(/^\s+/, '')
|
||||
.replace(/\s+$/, '')
|
||||
})
|
||||
return a.filter(line => line !== '')
|
||||
}
|
||||
|
||||
export {
|
||||
parseConfigDemoBotUUIDs
|
||||
}
|
@ -102,16 +102,19 @@ class ProsodyConfigVirtualHost extends ProsodyConfigBlock {
|
||||
|
||||
class ProsodyConfigComponent extends ProsodyConfigBlock {
|
||||
name: string
|
||||
type: string
|
||||
type?: string
|
||||
|
||||
constructor (type: string, name: string) {
|
||||
constructor (name: string, type?: string) {
|
||||
super(' ')
|
||||
this.type = type
|
||||
this.name = name
|
||||
}
|
||||
|
||||
write (): string {
|
||||
return `Component "${this.name}" "${this.type}"\n` + super.write()
|
||||
if (this.type !== undefined) {
|
||||
return `Component "${this.name}" "${this.type}"\n` + super.write()
|
||||
}
|
||||
return `Component "${this.name}"\n` + super.write()
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,6 +126,7 @@ class ProsodyConfigContent {
|
||||
authenticated?: ProsodyConfigVirtualHost
|
||||
anon: ProsodyConfigVirtualHost
|
||||
muc: ProsodyConfigComponent
|
||||
externalComponents: ProsodyConfigComponent[] = []
|
||||
log: string
|
||||
prosodyDomain: string
|
||||
|
||||
@ -132,7 +136,7 @@ class ProsodyConfigContent {
|
||||
this.log = ''
|
||||
this.prosodyDomain = prosodyDomain
|
||||
this.anon = new ProsodyConfigVirtualHost('anon.' + prosodyDomain)
|
||||
this.muc = new ProsodyConfigComponent('muc', 'room.' + prosodyDomain)
|
||||
this.muc = new ProsodyConfigComponent('room.' + prosodyDomain, 'muc')
|
||||
|
||||
this.global.set('daemonize', false)
|
||||
this.global.set('allow_registration', false)
|
||||
@ -281,6 +285,21 @@ class ProsodyConfigContent {
|
||||
this.muc.set('peertubelivechat_test_peertube_api_url', apiurl)
|
||||
}
|
||||
|
||||
useExternalComponents (componentsPort: string): void {
|
||||
this.global.set('component_ports', [componentsPort])
|
||||
this.global.set('component_interfaces', ['127.0.0.1', '::1'])
|
||||
}
|
||||
|
||||
useDemoBot (componentSecret: string): void {
|
||||
const demoBot = new ProsodyConfigComponent('demobot.' + this.prosodyDomain)
|
||||
demoBot.set('component_secret', componentSecret)
|
||||
|
||||
// If we want the bot to be moderator, should do the trick:
|
||||
// this.global.add('admins', 'demobot.' + this.prosodyDomain)
|
||||
|
||||
this.externalComponents.push(demoBot)
|
||||
}
|
||||
|
||||
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
||||
let log = ''
|
||||
log += 'log = {\n'
|
||||
@ -309,6 +328,11 @@ class ProsodyConfigContent {
|
||||
content += '\n\n'
|
||||
content += this.muc.write()
|
||||
content += '\n\n'
|
||||
this.externalComponents.forEach((externalComponent) => {
|
||||
content += '\n\n'
|
||||
content += externalComponent.write()
|
||||
content += '\n\n'
|
||||
})
|
||||
return content
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user