diff --git a/build-avatars.js b/build-avatars.js index c9159f52..7597f3ae 100755 --- a/build-avatars.js +++ b/build-avatars.js @@ -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')) } } + +// 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')) +} diff --git a/package.json b/package.json index c4d513fc..39f83b6f 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "build:converse": "bash conversejs/build-conversejs.sh", "build:prosody": "bash build-prosody.sh", "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", "build:client": "node ./build-client.js --mode=production", "build:server": "npx tsc --build server/tsconfig.json", diff --git a/prosody-modules/mod_random_vcard_peertubelivechat/mod_random_vcard_peertubelivechat.lua b/prosody-modules/mod_random_vcard_peertubelivechat/mod_random_vcard_peertubelivechat.lua index e1f08a8c..43aefbda 100644 --- a/prosody-modules/mod_random_vcard_peertubelivechat/mod_random_vcard_peertubelivechat.lua +++ b/prosody-modules/mod_random_vcard_peertubelivechat/mod_random_vcard_peertubelivechat.lua @@ -6,6 +6,7 @@ local jid = require "util.jid"; 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_files = assert(module:get_option_array("peertubelivechat_random_vcard_avatars_files", nil), "'peertubelivechat_random_vcard_avatars_files' is a required option"); local avatars = {}; local function load_avatar(filename) local file = assert(io.open(path.join(avatars_dir, filename), "r")); @@ -16,10 +17,12 @@ local function load_avatar(filename) file:close(); return result; end -local AVATARS_COUNT = 130; -for i = 1, AVATARS_COUNT do - avatars[i] = load_avatar(i .. '.jpg'); +local AVATARS_COUNT = 0; +for _, filename in pairs(avatars_files) do + AVATARS_COUNT = AVATARS_COUNT + 1; + avatars[AVATARS_COUNT] = load_avatar(filename); end +module:log("info", "Loaded " .. AVATARS_COUNT .. ' avatars for host ' .. module:get_host() .. '.' ); module:hook("iq-get/bare/vcard-temp:vCard", function (event) local origin, stanza = event.origin, event.stanza; diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 19cb2c42..6de084c9 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -94,6 +94,11 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise { + 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, diff --git a/server/lib/prosody/config/content.ts b/server/lib/prosody/config/content.ts index 5bddf818..b0660186 100644 --- a/server/lib/prosody/config/content.ts +++ b/server/lib/prosody/config/content.ts @@ -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()) diff --git a/server/lib/prosody/config/paths.ts b/server/lib/prosody/config/paths.ts index b1d34c4e..7dae365e 100644 --- a/server/lib/prosody/config/paths.ts +++ b/server/lib/prosody/config/paths.ts @@ -9,6 +9,9 @@ interface ProsodyFilePaths { certsDirIsCustom: boolean modules: string avatars: string + avatarsFiles: string[] + botAvatars: string + botAvatarsFiles: string[] exec?: string execArgs: string[] execCtl?: string