Retrying on connection failure.
This commit is contained in:
parent
19fb233d8a
commit
fb88ded822
|
@ -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();
|
|
@ -269,6 +269,7 @@ async function connect(bot, games) {
|
||||||
const socket = { ws: { readyState: 0 } };
|
const socket = { ws: { readyState: 0 } };
|
||||||
|
|
||||||
socket.connect = async () => {
|
socket.connect = async () => {
|
||||||
|
try {
|
||||||
const { user, httpSession, sessionCookie } = await auth();
|
const { user, httpSession, sessionCookie } = await auth();
|
||||||
const wsCreds = await getWsId(httpSession);
|
const wsCreds = await getWsId(httpSession);
|
||||||
|
|
||||||
|
@ -309,6 +310,12 @@ async function connect(bot, games) {
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`Connected to ${config.socket}`);
|
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) => {
|
socket.transmit = (domain, data) => {
|
||||||
|
|
|
@ -49,8 +49,8 @@ function onCommand(args, context) {
|
||||||
|
|
||||||
const messages = [
|
const messages = [
|
||||||
`How could you miss *that*, @${context.user.username}...?!`,
|
`How could you miss *that*, @${context.user.username}...?!`,
|
||||||
`Better luck next time, @${context.user.username}.`,
|
`That's a miss! Better luck next time, @${context.user.username}.`,
|
||||||
`The duck got away, @${context.user.username}`,
|
`The duck outsmarted you, @${context.user.username}`,
|
||||||
`Channeling Gareth Southgate, @${context.user.username}? You missed!`,
|
`Channeling Gareth Southgate, @${context.user.username}? You missed!`,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue