feat: fix metadata in logging, lint prettier, typed Models (#747)

This commit is contained in:
Jef LeCompte
2020-11-10 10:38:14 -05:00
committed by GitHub
parent 0bf9ba2e18
commit 318e626e78
78 changed files with 2416 additions and 1021 deletions
+33 -10
View File
@@ -17,7 +17,10 @@ let tokenData = {
};
if (existsSync('./twitch.json')) {
tokenData = {...JSON.parse(readFileSync('./twitch.json', 'utf-8')), ...tokenData};
tokenData = {
...JSON.parse(readFileSync('./twitch.json', 'utf-8')),
...tokenData
};
}
const chatClient: ChatClient = new ChatClient(
@@ -25,13 +28,25 @@ const chatClient: ChatClient = new ChatClient(
new StaticAuthProvider(twitch.clientId, tokenData.accessToken),
{
clientSecret: twitch.clientSecret,
expiry: tokenData.expiryTimestamp === null ? null : new Date(tokenData.expiryTimestamp),
expiry:
tokenData.expiryTimestamp === null
? null
: new Date(tokenData.expiryTimestamp),
onRefresh: async ({accessToken, refreshToken, expiryDate}) => {
return promises.writeFile('./twitch.json', JSON.stringify({
accessToken,
expiryTimestamp: expiryDate === null ? null : expiryDate.getTime(),
refreshToken
}, null, 4), 'utf-8');
return promises.writeFile(
'./twitch.json',
JSON.stringify(
{
accessToken,
expiryTimestamp:
expiryDate === null ? null : expiryDate.getTime(),
refreshToken
},
null,
4
),
'utf-8'
);
},
refreshToken: tokenData.refreshToken
}
@@ -51,7 +66,7 @@ chatClient.onJoin((channel: string, user: string) => {
chatClient.say(channel, message);
logger.info('✔ twitch message sent');
} catch (error) {
logger.error('✖ couldn\'t send twitch message', error);
logger.error("✖ couldn't send twitch message", error);
}
}
}
@@ -65,10 +80,18 @@ chatClient.onDisconnect(() => {
});
export function sendTwitchMessage(link: Link, store: Store) {
if (tokenData.accessToken && twitch.channel && twitch.clientId && twitch.clientSecret && tokenData.refreshToken) {
if (
tokenData.accessToken &&
twitch.channel &&
twitch.clientId &&
twitch.clientSecret &&
tokenData.refreshToken
) {
logger.debug('↗ sending twitch message');
messages.push(`${Print.inStock(link, store)}\n${link.cartUrl ? link.cartUrl : link.url}`);
messages.push(
`${Print.inStock(link, store)}\n${link.cartUrl ? link.cartUrl : link.url}`
);
if (!alreadySaying) {
alreadySaying = true;