Bot avatar:

* For now, only one avatar possible,
* uses mod_random_vcard_peertubelivechat,
* mod_random_vcard_peertubelivechat has a new option with the avatar
  list (instead of a hardcoded avatar number)
* Peertube lists available avatars files, and pass it to mod_random_vcard_peertubelivechat
This commit is contained in:
John Livingston
2023-09-25 11:20:46 +02:00
parent 15ec31426e
commit e2c85af001
6 changed files with 52 additions and 9 deletions

View File

@ -94,6 +94,11 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
certsDir = path.resolve(dir, 'data')
}
const avatarsDir = path.resolve(__dirname, '../../avatars')
const avatarsFiles = await _listAvatars(avatarsDir)
const botAvatarsDir = path.resolve(__dirname, '../../bot_avatars')
const botAvatarsFiles = await _listAvatars(botAvatarsDir)
return {
dir: dir,
pid: path.resolve(dir, 'prosody.pid'),
@ -104,7 +109,10 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
certs: certsDir,
certsDirIsCustom,
modules: path.resolve(__dirname, '../../prosody-modules'),
avatars: path.resolve(__dirname, '../../avatars'),
avatars: avatarsDir,
avatarsFiles,
botAvatars: botAvatarsDir,
botAvatarsFiles,
exec,
execArgs,
execCtl,
@ -300,10 +308,10 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
config.useListRoomsApi(apikey)
config.usePeertubeVCards(basePeertubeUrl)
config.useAnonymousRandomVCards(paths.avatars)
config.useAnonymousRandomVCards(paths.avatars, paths.avatarsFiles)
if (useBots) {
config.useBotsVirtualHost()
config.useBotsVirtualHost(paths.botAvatars, paths.botAvatarsFiles)
bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf()
if (bots.moderation?.connection?.password) {
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password)
@ -419,6 +427,18 @@ function getProsodyConfigContentForDiagnostic (config: ProsodyConfig, content?:
return r
}
async function _listAvatars (dir: string): Promise<string[]> {
const files = await fs.promises.readdir(dir)
const r = []
for (const file of files) {
if (!file.endsWith('.jpg') && !file.endsWith('.png')) {
continue
}
r.push(file)
}
return r.sort()
}
export {
ProsodyConfig,
getProsodyConfig,

View File

@ -427,21 +427,27 @@ class ProsodyConfigContent {
}
}
useAnonymousRandomVCards (avatarPath: string): void {
useAnonymousRandomVCards (avatarPath: string, avatarFiles: string[]): void {
if (this.anon) {
this.anon.add('modules_enabled', 'random_vcard_peertubelivechat')
this.anon.set('peertubelivechat_random_vcard_avatars_path', avatarPath)
this.anon.set('peertubelivechat_random_vcard_avatars_files', avatarFiles)
}
}
/**
* Enable the bots virtualhost.
*/
useBotsVirtualHost (): void {
useBotsVirtualHost (botAvatarPath: string, botAvatarFiles: string[]): void {
this.bot = new ProsodyConfigVirtualHost('bot.' + this.prosodyDomain)
this.bot.set('modules_enabled', ['ping'])
this.bot.set('authentication', 'peertubelivechat_bot')
// For now, just using random_vcard_peertubelivechat to set bot avatar
this.bot.add('modules_enabled', 'random_vcard_peertubelivechat')
this.bot.set('peertubelivechat_random_vcard_avatars_path', botAvatarPath)
this.bot.set('peertubelivechat_random_vcard_avatars_files', botAvatarFiles)
// Adding the moderation bot as admin to the muc component.
this.muc.add('admins', BotConfiguration.singleton().moderationBotJID())

View File

@ -9,6 +9,9 @@ interface ProsodyFilePaths {
certsDirIsCustom: boolean
modules: string
avatars: string
avatarsFiles: string[]
botAvatars: string
botAvatarsFiles: string[]
exec?: string
execArgs: string[]
execCtl?: string