mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
feat: fix metadata in logging, lint prettier, typed Models (#747)
This commit is contained in:
+33
-10
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user