Retrying on connection failure.

This commit is contained in:
ThePendulum 2022-09-19 16:17:23 +02:00
parent 19fb233d8a
commit fb88ded822
3 changed files with 66 additions and 31 deletions

28
assets/mash-average.js Normal file
View File

@ -0,0 +1,28 @@
'use strict';
const fs = require('fs').promises;
async function init() {
const rawDictionary = await fs.readFile('./mash-words.json', 'utf8');
const dictionary = JSON.parse(rawDictionary);
const averages = Object.entries(dictionary)
.reduce((accAverages, [length, anagramsMap]) => {
const anagramsList = Object.values(anagramsMap);
const total = anagramsList.reduce((acc, words) => acc + words.length, 0);
const average = total / anagramsList.length;
return {
...accAverages,
[length]: average,
};
}, {});
console.log(averages);
// CSV
console.log(Object.keys(averages).join(','));
console.log(Object.values(averages).join(','));
}
init();

View File

@ -269,6 +269,7 @@ async function connect(bot, games) {
const socket = { ws: { readyState: 0 } };
socket.connect = async () => {
try {
const { user, httpSession, sessionCookie } = await auth();
const wsCreds = await getWsId(httpSession);
@ -309,6 +310,12 @@ async function connect(bot, games) {
});
logger.info(`Connected to ${config.socket}`);
} catch (error) {
logger.error(`Failed to connect, retrying in ${config.reconnectDelay} seconds: ${error.message}`);
await delay(config.reconnectDelay * 1000);
socket.connect();
}
};
socket.transmit = (domain, data) => {

View File

@ -49,8 +49,8 @@ function onCommand(args, context) {
const messages = [
`How could you miss *that*, @${context.user.username}...?!`,
`Better luck next time, @${context.user.username}.`,
`The duck got away, @${context.user.username}`,
`That's a miss! Better luck next time, @${context.user.username}.`,
`The duck outsmarted you, @${context.user.username}`,
`Channeling Gareth Southgate, @${context.user.username}? You missed!`,
];