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
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
6 changed files with 52 additions and 9 deletions

View File

@ -32,3 +32,14 @@ for (let i = 1; i <= count; i++) {
sharp(inputFile).flatten({background}).resize(120, 120).jpeg({quality: 95, mozjpeg: true}).toFile(path.join(outputDir, out.toString() + '.jpg')) sharp(inputFile).flatten({background}).resize(120, 120).jpeg({quality: 95, mozjpeg: true}).toFile(path.join(outputDir, out.toString() + '.jpg'))
} }
} }
// Moderation bot avatar: for now taking image 2, and applying a grey background.
{
const i = 2
const inputFile = path.join(inputDir, i + '.svg')
const background = '#858da0'
const outputDir = './dist/server/bot_avatars/'
const out = 1
sharp(inputFile).flatten({background}).resize(120, 120).jpeg({quality: 95, mozjpeg: true}).toFile(path.join(outputDir, out.toString() + '.jpg'))
}

View File

@ -93,7 +93,7 @@
"build:converse": "bash conversejs/build-conversejs.sh", "build:converse": "bash conversejs/build-conversejs.sh",
"build:prosody": "bash build-prosody.sh", "build:prosody": "bash build-prosody.sh",
"build:images": "mkdir -p dist/client/images && npx svgo -f assets/images/ -o dist/client/images/", "build:images": "mkdir -p dist/client/images && npx svgo -f assets/images/ -o dist/client/images/",
"build:avatars": "mkdir -p dist/server/avatars && ./build-avatars.js", "build:avatars": "mkdir -p dist/server/avatars && mkdir -p dist/server/bot_avatars && ./build-avatars.js",
"check:client:tsc": "npx tsc --p client/ --noEmit --skipLibCheck && npx tsc --p conversejs/ --noemit --skipLibCheck", "check:client:tsc": "npx tsc --p client/ --noEmit --skipLibCheck && npx tsc --p conversejs/ --noemit --skipLibCheck",
"build:client": "node ./build-client.js --mode=production", "build:client": "node ./build-client.js --mode=production",
"build:server": "npx tsc --build server/tsconfig.json", "build:server": "npx tsc --build server/tsconfig.json",

View File

@ -6,6 +6,7 @@ local jid = require "util.jid";
module:add_feature("vcard-temp"); module:add_feature("vcard-temp");
local avatars_dir = assert(module:get_option_string("peertubelivechat_random_vcard_avatars_path", nil), "'peertubelivechat_random_vcard_avatars_path' is a required option"); local avatars_dir = assert(module:get_option_string("peertubelivechat_random_vcard_avatars_path", nil), "'peertubelivechat_random_vcard_avatars_path' is a required option");
local avatars_files = assert(module:get_option_array("peertubelivechat_random_vcard_avatars_files", nil), "'peertubelivechat_random_vcard_avatars_files' is a required option");
local avatars = {}; local avatars = {};
local function load_avatar(filename) local function load_avatar(filename)
local file = assert(io.open(path.join(avatars_dir, filename), "r")); local file = assert(io.open(path.join(avatars_dir, filename), "r"));
@ -16,10 +17,12 @@ local function load_avatar(filename)
file:close(); file:close();
return result; return result;
end end
local AVATARS_COUNT = 130; local AVATARS_COUNT = 0;
for i = 1, AVATARS_COUNT do for _, filename in pairs(avatars_files) do
avatars[i] = load_avatar(i .. '.jpg'); AVATARS_COUNT = AVATARS_COUNT + 1;
avatars[AVATARS_COUNT] = load_avatar(filename);
end end
module:log("info", "Loaded " .. AVATARS_COUNT .. ' avatars for host ' .. module:get_host() .. '.' );
module:hook("iq-get/bare/vcard-temp:vCard", function (event) module:hook("iq-get/bare/vcard-temp:vCard", function (event)
local origin, stanza = event.origin, event.stanza; local origin, stanza = event.origin, event.stanza;

View File

@ -94,6 +94,11 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
certsDir = path.resolve(dir, 'data') 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 { return {
dir: dir, dir: dir,
pid: path.resolve(dir, 'prosody.pid'), pid: path.resolve(dir, 'prosody.pid'),
@ -104,7 +109,10 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
certs: certsDir, certs: certsDir,
certsDirIsCustom, certsDirIsCustom,
modules: path.resolve(__dirname, '../../prosody-modules'), modules: path.resolve(__dirname, '../../prosody-modules'),
avatars: path.resolve(__dirname, '../../avatars'), avatars: avatarsDir,
avatarsFiles,
botAvatars: botAvatarsDir,
botAvatarsFiles,
exec, exec,
execArgs, execArgs,
execCtl, execCtl,
@ -300,10 +308,10 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
config.useListRoomsApi(apikey) config.useListRoomsApi(apikey)
config.usePeertubeVCards(basePeertubeUrl) config.usePeertubeVCards(basePeertubeUrl)
config.useAnonymousRandomVCards(paths.avatars) config.useAnonymousRandomVCards(paths.avatars, paths.avatarsFiles)
if (useBots) { if (useBots) {
config.useBotsVirtualHost() config.useBotsVirtualHost(paths.botAvatars, paths.botAvatarsFiles)
bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf() bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf()
if (bots.moderation?.connection?.password) { if (bots.moderation?.connection?.password) {
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password) valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password)
@ -419,6 +427,18 @@ function getProsodyConfigContentForDiagnostic (config: ProsodyConfig, content?:
return r 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 { export {
ProsodyConfig, ProsodyConfig,
getProsodyConfig, getProsodyConfig,

View File

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

View File

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