Skip to content

Commit 07eeb75

Browse files
committed
tons of new avatars incl. random mode! big refactor & cleanup, part 1
1 parent 9607ccb commit 07eeb75

37 files changed

+1668
-1438
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:18 as base
22
WORKDIR /app/drc
33
RUN apt update
4-
RUN apt -y install nmap
4+
RUN apt -y install nmap figlet
55
RUN useradd -u 1001 -U -p discordrc drc
66
COPY package*.json ./
77
RUN npm install

config/default.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const _config = {
6969
// options are: html, json, jsonl
7070
localQueryOutputFormat: 'html'
7171
},
72+
avatarGenerator: 'robohash',
7273
allowedSpeakers: [],
7374
allowedSpeakersRoleId: null,
7475
// options are
@@ -150,8 +151,8 @@ const _config = {
150151
},
151152

152153
figletBanners: {
153-
enabled: false,
154-
cacheDir: '.banners.cache',
154+
enabled: true,
155+
cacheDir: '/tmp/.discordrc.banners.cache',
155156
font: 'small'
156157
},
157158

@@ -174,13 +175,6 @@ const _config = {
174175
rootRedirectUrl: 'https://discordrc.com'
175176
},
176177

177-
capture: {
178-
enabled: true,
179-
autoCaptureWindowMins: 5,
180-
defaultCaptureWindowMins: 15,
181-
cleanupLoopFreqSeconds: 17
182-
},
183-
184178
ipinfo: {
185179
token: null
186180
},

discord.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,6 @@ setTimeout(alivenessCheck, 15 * 1000);
224224

225225
const ignoreSquelched = [];
226226

227-
const captureSpecs = {};
228-
229-
if (config.capture.enabled) {
230-
console.log(`Capture enabled: running cleanup loop on ${config.capture.cleanupLoopFreqSeconds} second frequency`);
231-
setInterval(() => {
232-
const nowNum = Number(new Date());
233-
Object.entries(captureSpecs).forEach(([network, netSpec]) => {
234-
Object.entries(netSpec).forEach(([channelId, chanSpec]) => {
235-
if (chanSpec && chanSpec.exp > (nowNum / 100) && nowNum > chanSpec.exp) {
236-
console.log(`Capture spec cleanup loop expiring ${network}:${channelId}`, chanSpec);
237-
sendToBotChan(`\`SYSTEM\` Expiring channel capture for <#${channelId}> on \`${network}\` having captured ${chanSpec.captured} messages.`);
238-
delete captureSpecs[network][channelId];
239-
}
240-
});
241-
});
242-
}, config.capture.cleanupLoopFreqSeconds * 1000);
243-
}
244-
245227
setDefaultFont(config.figletBanners.font);
246228

247229
console.log(`${PREFIX} Discord controller starting...`);
@@ -259,7 +241,11 @@ client.once('ready', async () => {
259241
client.user.setActivity('the IRC daemon...', { type: 'LISTENING' });
260242

261243
const onExit = async (s) => {
262-
sendToBotChan('\n```\n' + (await banner(s)) + '\n```\n');
244+
sendToBotChan({
245+
embeds: [
246+
new MessageEmbed().setDescription('\n```\n' + (await banner(s)) + '\n```\n')
247+
]
248+
}, true);
263249
client.user.setStatus('invisible');
264250
client.user.setActivity('nothing! (I\'m offline!)', { type: 'LISTENING' });
265251
};
@@ -376,7 +362,11 @@ client.once('ready', async () => {
376362
stbcServicer();
377363
}
378364

379-
sendToBotChan('\n```\n' + (await banner('Hello!')) + '\n```\n\n');
365+
sendToBotChan({
366+
embeds: [
367+
new MessageEmbed().setDescription('\n```\n' + (await banner('Hello!')) + '\n```\n\n')
368+
]
369+
}, true);
380370

381371
siteCheck();
382372

@@ -477,7 +467,6 @@ client.once('ready', async () => {
477467
registerButtonHandler,
478468
discordAuthor: data.author,
479469
ignoreSquelched,
480-
captureSpecs,
481470
channelsById,
482471
categoriesByName,
483472
toChanId,
@@ -970,7 +959,6 @@ client.once('ready', async () => {
970959
ircReadyHandler,
971960
client,
972961
channelsById,
973-
captureSpecs,
974962
allowedSpeakersMentionString,
975963
subscribedChans,
976964
listenedToMutate,

discord/avatarGenerators.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';
2+
3+
const {
4+
scopedRedisClient
5+
} = require('../util');
6+
7+
async function DiceBearGenerator (style, fName) {
8+
return `https://api.dicebear.com/5.x/${style}/png?seed=${fName}`;
9+
}
10+
11+
const AvatarGenerators = {
12+
robohash: async (fName) => `https://robohash.org/${fName}.png`,
13+
dicebear_shapes: DiceBearGenerator.bind(null, 'shapes'),
14+
dicebear_pixelart: DiceBearGenerator.bind(null, 'pixel-art'),
15+
dicebear_identicon: DiceBearGenerator.bind(null, 'identicon'),
16+
dicebear_personas: DiceBearGenerator.bind(null, 'personas'),
17+
dicebear_micah: DiceBearGenerator.bind(null, 'micah'),
18+
dicebear_miniavs: DiceBearGenerator.bind(null, 'miniavs'),
19+
dicebear_bottts: DiceBearGenerator.bind(null, 'bottts'),
20+
dicebear_botttsneutral: DiceBearGenerator.bind(null, 'bottts-neutral'),
21+
dicebear_bigsmile: DiceBearGenerator.bind(null, 'big-smile'),
22+
multiavatar: async (fName) => `https://api.multiavatar.com/${fName}.png`,
23+
uiavatars: async (fName) => `https://ui-avatars.com/api/${fName}.png?name=${fName}&background=random&format=png`,
24+
uiavatars_red: async (fName) => `https://ui-avatars.com/api/${fName}.png?name=${fName}&background=ff0000&format=png`,
25+
random_style: RandomGenerator
26+
};
27+
28+
const rKey = (p) => [p, 'randomAvatarStyles'].join(':');
29+
30+
async function randomStyle () {
31+
const excluded = JSON.parse(await scopedRedisClient((c, p) => c.get(rKey(p) + ':excludeRandomStyles'))) ?? [];
32+
const styles = Object.keys(AvatarGenerators).filter((style) => !excluded.includes(style));
33+
let setStyle;
34+
// don't ever chose "random_style"!
35+
while (!setStyle || setStyle === 'random_style') {
36+
setStyle = styles[Math.floor(Math.random() * styles.length)];
37+
}
38+
return setStyle;
39+
}
40+
41+
async function RandomGenerator (fName) {
42+
let setStyle = await scopedRedisClient((c, p) => c.hget(rKey(p), fName));
43+
44+
if (!setStyle) {
45+
setStyle = await randomStyle();
46+
console.info(`User ${fName} did not have an avatar style: chose ${setStyle}`);
47+
await scopedRedisClient((c, p) => c.hset(rKey(p), fName, setStyle));
48+
}
49+
50+
return AvatarGenerators[setStyle](fName);
51+
}
52+
53+
module.exports = {
54+
AvatarGenerators,
55+
56+
createAvatarName (nick, network) {
57+
return [nick, network].map((s) => s.replaceAll(/[^\d\w._-]+/g, '')).join('_');
58+
},
59+
60+
randomStyle,
61+
62+
async excludeRandomStyles (...styles) {
63+
return scopedRedisClient((c, p) => c.set(rKey(p) + ':excludeRandomStyles', JSON.stringify(styles)));
64+
}
65+
};

0 commit comments

Comments
 (0)