From 86169698b877a91c85a44a4c2b1ad9d04c52cacf Mon Sep 17 00:00:00 2001 From: "Zrimsek, Mike" Date: Mon, 14 Jun 2021 13:20:17 -0400 Subject: [PATCH] add prettier --- .prettierignore | 1 + .prettierrc | 9 ++++ README.md | 46 +++++++++---------- docker-compose.yml | 2 +- package-lock.json | 6 +++ package.json | 4 +- src/clients/discord.ts | 2 +- src/clients/firebase.ts | 5 +-- src/clients/index.ts | 2 +- src/clients/mqtt.ts | 2 +- src/clients/obs.ts | 2 +- src/clients/twitch.ts | 2 +- src/commands/shared.ts | 6 ++- src/commands/twitch.ts | 95 ++++++++++++++++++++++++++++----------- src/config/discord.ts | 2 +- src/config/firebase.ts | 10 ++--- src/config/index.ts | 2 +- src/config/logger.ts | 12 ++--- src/config/mqtt.ts | 2 +- src/config/obs.ts | 2 +- src/config/twitch.ts | 2 +- src/constants/commands.ts | 4 +- src/constants/firebase.ts | 2 +- src/constants/index.ts | 2 +- src/constants/mqtt.ts | 2 +- src/constants/obs.ts | 2 +- src/index.ts | 40 +++++++++++++---- src/utils/index.ts | 2 +- 28 files changed, 174 insertions(+), 96 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1521c8b --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +dist diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..5ebed5d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "printWidth": 100, + "trailingComma": "none", + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "arrowParens": "avoid", + "bracketSpacing": true +} \ No newline at end of file diff --git a/README.md b/README.md index 93c5fb0..718d254 100644 --- a/README.md +++ b/README.md @@ -6,40 +6,40 @@ A bot to interact with Twitch, Discord, and anything else your mind (and my free ### Admin (only work when triggered from Twitch chat) -* !active - toggles whether commands work or not -* !add - adds a command (or edits the existing command) with the specified message -* !rm - removes the specified command +- !active - toggles whether commands work or not +- !add - adds a command (or edits the existing command) with the specified message +- !rm - removes the specified command ### Mod (only work when triggered from Twitch chat) -* !addw - adds a word/phrase to be tracked -* !rmw - removes a word/phrase from being tracked -* !incw - increments the word/phrase count. Optional number parameter sets the amount to increment by -* !clrw - resets the word/phrase count back to 0 +- !addw - adds a word/phrase to be tracked +- !rmw - removes a word/phrase from being tracked +- !incw - increments the word/phrase count. Optional number parameter sets the amount to increment by +- !clrw - resets the word/phrase count back to 0 ### General (work when triggered from both Twitch chat and Discord) -* !help - displays help command (this shows different commands based on where it is triggered from) +- !help - displays help command (this shows different commands based on where it is triggered from) ### General Twitch Only -* !wordcount - gets the tracked count of a word/phrase -* !lightsoff - turns off the lights in stream room -* !lightson - turns on the lights in stream room -* !lightscol - sets color of lights in stream room - * color_name must be a [valid CSS3 color name](https://www.w3.org/wiki/CSS/Properties/color/keywords) - * ex: !lightscol red - * RGB value must be 3 numbers between 0 and 255 - * ex: !lightscol 255 0 0 -* !lightsrand - sets color of lights in stream room to random color +- !wordcount - gets the tracked count of a word/phrase +- !lightsoff - turns off the lights in stream room +- !lightson - turns on the lights in stream room +- !lightscol - sets color of lights in stream room + - color_name must be a [valid CSS3 color name](https://www.w3.org/wiki/CSS/Properties/color/keywords) + - ex: !lightscol red + - RGB value must be 3 numbers between 0 and 255 + - ex: !lightscol 255 0 0 +- !lightsrand - sets color of lights in stream room to random color ### OBS (only work when triggered from Twitch chat) -* !cam - toggles face cam visibility -* !mic - toggles desktop mic active -* !color - changes face cam color overlay color. Optional number parameter causes color to change that many times in 1 second (max 1000) -* !reset - reset face cam and mic changes back to default -* !aqua - toggle Aqua visibility on scenes with her in them +- !cam - toggles face cam visibility +- !mic - toggles desktop mic active +- !color - changes face cam color overlay color. Optional number parameter causes color to change that many times in 1 second (max 1000) +- !reset - reset face cam and mic changes back to default +- !aqua - toggle Aqua visibility on scenes with her in them ## Invite to Server @@ -47,4 +47,4 @@ https://discord.com/api/oauth2/authorize?client_id=772707347520946197&permission ## Development Notes -* Command functions return true when it handles the command, false if not +- Command functions return true when it handles the command, false if not diff --git a/docker-compose.yml b/docker-compose.yml index 10b17f2..86ee24f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,4 +19,4 @@ services: - DISCORD_TOKEN=${DISCORD_TOKEN} - DISCORD_BOT_USER_ID=${DISCORD_BOT_USER_ID} - MQTT_BROKER_ADDRESS=${MQTT_BROKER_ADDRESS} - restart: unless-stopped \ No newline at end of file + restart: unless-stopped diff --git a/package-lock.json b/package-lock.json index 5706158..56a427c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2033,6 +2033,12 @@ "pinkie": "^2.0.0" } }, + "prettier": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.1.tgz", + "integrity": "sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==", + "dev": true + }, "prism-media": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.3.1.tgz", diff --git a/package.json b/package.json index e6e17d9..051c685 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "tsc": "tsc", "dev": "ts-node-dev src/index.ts", - "start": "tsc && node ./dist/index.js" + "start": "tsc && node ./dist/index.js", + "format": "prettier --write ./src/**" }, "author": "Mike Zrimsek", "license": "MIT", @@ -21,6 +22,7 @@ }, "devDependencies": { "@types/tmi.js": "^1.7.1", + "prettier": "2.3.1", "ts-node-dev": "^1.1.6", "typescript": "^4.3.2" } diff --git a/src/clients/discord.ts b/src/clients/discord.ts index efa1982..c6cc796 100644 --- a/src/clients/discord.ts +++ b/src/clients/discord.ts @@ -7,4 +7,4 @@ discordClient.login(discordConfig.token); discordClient.on('ready', () => { logger.info('Connected to Discord'); logger.info(`Logged in as: ${discordClient.user.tag} - (${discordClient.user.id})`); -}); \ No newline at end of file +}); diff --git a/src/clients/firebase.ts b/src/clients/firebase.ts index 69c2e5c..7c444d3 100644 --- a/src/clients/firebase.ts +++ b/src/clients/firebase.ts @@ -23,7 +23,4 @@ try { const commandsCollection = firestore.collection(COMMANDS_COLLECTION); const trackingWordsCollection = firestore.collection(WORD_TRACKING_COLLECTION); -export const collections = [ - commandsCollection, - trackingWordsCollection -]; \ No newline at end of file +export const collections = [commandsCollection, trackingWordsCollection]; diff --git a/src/clients/index.ts b/src/clients/index.ts index 5eb444b..7a844f5 100644 --- a/src/clients/index.ts +++ b/src/clients/index.ts @@ -2,4 +2,4 @@ export * from './twitch'; export * from './obs'; export * from './firebase'; export * from './discord'; -export * from './mqtt'; \ No newline at end of file +export * from './mqtt'; diff --git a/src/clients/mqtt.ts b/src/clients/mqtt.ts index 4754d7c..1294f5c 100644 --- a/src/clients/mqtt.ts +++ b/src/clients/mqtt.ts @@ -4,4 +4,4 @@ import { mqttConfig, logger } from '../config'; export const mqttClient = mqtt.connect(`tcp://${mqttConfig.address}`); mqttClient.on('connect', () => { logger.info('Connected to MQTT Broker'); -}); \ No newline at end of file +}); diff --git a/src/clients/obs.ts b/src/clients/obs.ts index 2eca6cd..0bc50c6 100644 --- a/src/clients/obs.ts +++ b/src/clients/obs.ts @@ -10,4 +10,4 @@ obsClient.on('ConnectionOpened', () => { obsClient.on('ConnectionClosed', () => { obsConnected = false; logger.info('Disconnected from OBSWebSocket'); -}); \ No newline at end of file +}); diff --git a/src/clients/twitch.ts b/src/clients/twitch.ts index 3224e64..5f621b0 100644 --- a/src/clients/twitch.ts +++ b/src/clients/twitch.ts @@ -2,4 +2,4 @@ import * as tmi from 'tmi.js'; import { twitchConfig } from '../config'; export const twitchClient = new tmi.client(twitchConfig); -twitchClient.connect(); \ No newline at end of file +twitchClient.connect(); diff --git a/src/commands/shared.ts b/src/commands/shared.ts index 6d72ad1..a077ae7 100644 --- a/src/commands/shared.ts +++ b/src/commands/shared.ts @@ -36,7 +36,9 @@ async function handleHelpCommand(messageParts, printFunc, clients, ...extraComma const userCommandList = userCommands.map(userCommand => userCommand.command); const allCommandList = [...userCommandList, ...extraCommandsList, HELP_COMMAND]; - const helpMessageList = allCommandList.map(command => `${COMMAND_PREFACE}${command}`).join(', '); + const helpMessageList = allCommandList + .map(command => `${COMMAND_PREFACE}${command}`) + .join(', '); printFunc(`Here are the available commands: \n${helpMessageList}`); return true; @@ -48,4 +50,4 @@ async function handleHelpCommand(messageParts, printFunc, clients, ...extraComma module.exports = { handleUserCommand, handleHelpCommand -}; \ No newline at end of file +}; diff --git a/src/commands/twitch.ts b/src/commands/twitch.ts index 837402c..bf291b1 100644 --- a/src/commands/twitch.ts +++ b/src/commands/twitch.ts @@ -1,5 +1,13 @@ import { obsConfig, logger } from '../config'; -import { COMMAND_PREFACE, ADMIN_COMMANDS, OBS_COMMANDS, WORD_TRACKING_COMMANDS, LIGHT_COMMANDS, LIGHT_TOPICS, SOURCES } from '../constants'; +import { + COMMAND_PREFACE, + ADMIN_COMMANDS, + OBS_COMMANDS, + WORD_TRACKING_COMMANDS, + LIGHT_COMMANDS, + LIGHT_TOPICS, + SOURCES +} from '../constants'; const { getRandomColor, loadTrackingPhrases, getRandomInt } = require('../utils'); async function handleOBSCommand(messageParts, clients, obsConnected) { @@ -11,7 +19,7 @@ async function handleOBSCommand(messageParts, clients, obsConnected) { await obsClient.connect(obsConfig); return true; } catch { - logger.info('Unable to connect to OBSWebsocket') + logger.info('Unable to connect to OBSWebsocket'); return false; } } @@ -28,16 +36,24 @@ async function handleOBSCommand(messageParts, clients, obsConnected) { filterName: 'Color Correction', filterEnabled: false }); - obsClient.send('SetSceneItemRender', { source: SOURCES.WEBCAM, render: true }); + obsClient.send('SetSceneItemRender', { + source: SOURCES.WEBCAM, + render: true + }); obsClient.send('SetMute', { source: SOURCES.MIC, mute: false }); } return true; } case `${COMMAND_PREFACE}${OBS_COMMANDS.TOGGLE_CAM}`: { if (await isOBSClientConnected()) { - const properties = await obsClient.send('GetSceneItemProperties', { item: { name: SOURCES.WEBCAM } }); + const properties = await obsClient.send('GetSceneItemProperties', { + item: { name: SOURCES.WEBCAM } + }); const { visible } = properties; - obsClient.send('SetSceneItemRender', { source: SOURCES.WEBCAM, render: !visible }); + obsClient.send('SetSceneItemRender', { + source: SOURCES.WEBCAM, + render: !visible + }); } return true; } @@ -74,7 +90,7 @@ async function handleOBSCommand(messageParts, clients, obsConnected) { color: randomColor } }); - }; + } const rate = 1000 / numTimes; for (let i = 0; i < numTimes; i++) { @@ -85,9 +101,14 @@ async function handleOBSCommand(messageParts, clients, obsConnected) { } case `${COMMAND_PREFACE}${OBS_COMMANDS.TOGGLE_AQUA}`: { if (await isOBSClientConnected()) { - const properties = await obsClient.send('GetSceneItemProperties', { item: { name: SOURCES.AQUA } }); + const properties = await obsClient.send('GetSceneItemProperties', { + item: { name: SOURCES.AQUA } + }); const { visible } = properties; - obsClient.send('SetSceneItemRender', { source: SOURCES.AQUA, render: !visible }); + obsClient.send('SetSceneItemRender', { + source: SOURCES.AQUA, + render: !visible + }); } return true; } @@ -97,7 +118,13 @@ async function handleOBSCommand(messageParts, clients, obsConnected) { } } -function handleAdminCommand(messageParts, printFunc, commandsActive, commandsActiveUpdateFunc, clients) { +function handleAdminCommand( + messageParts, + printFunc, + commandsActive, + commandsActiveUpdateFunc, + clients +) { const { firebase } = clients; const { collections } = firebase; const { commandsCollection } = collections; @@ -110,8 +137,7 @@ function handleAdminCommand(messageParts, printFunc, commandsActive, commandsAct printFunc('Bot commands are disabled!'); logger.info('Twitch commands are disabled'); commandsActiveUpdateFunc(false); - } - else { + } else { printFunc('Bot commands are enabled!'); logger.info('Twitch commands are enabled'); commandsActiveUpdateFunc(true); @@ -121,22 +147,28 @@ function handleAdminCommand(messageParts, printFunc, commandsActive, commandsAct case `${COMMAND_PREFACE}${ADMIN_COMMANDS.ADD_COMMAND}`: { const newCommand = messageParts[1]; const newMessage = messageParts.slice(2).join(' '); - commandsCollection.doc(newCommand).set({ - command: newCommand, - message: newMessage - }).then(() => logger.info(`Command added: ${newCommand}`)); + commandsCollection + .doc(newCommand) + .set({ + command: newCommand, + message: newMessage + }) + .then(() => logger.info(`Command added: ${newCommand}`)); return true; } case `${COMMAND_PREFACE}${ADMIN_COMMANDS.REMOVE_COMMAND}`: { const commandToRemove = messageParts[1]; - commandsCollection.doc(commandToRemove).delete().then(() => logger.info(`Command removed: ${commandToRemove}`)); + commandsCollection + .doc(commandToRemove) + .delete() + .then(() => logger.info(`Command removed: ${commandToRemove}`)); return true; } default: { return false; } } -}; +} async function handleTwitchUserCommand(messageParts, username, printFunc, clients) { const { firebase, mqttClient } = clients; @@ -227,9 +259,12 @@ async function handleModCommand(messageParts, printFunc, clients) { const newPhrase = messageParts.slice(1).join('_'); if (newPhrase && !trackingPhrases.includes(newPhrase)) { - trackingWordsCollection.doc(newPhrase).set({ - count: 0 - }).then(() => logger.info(`Tracking word added: ${newPhrase}`)); + trackingWordsCollection + .doc(newPhrase) + .set({ + count: 0 + }) + .then(() => logger.info(`Tracking word added: ${newPhrase}`)); } return true; } @@ -238,7 +273,10 @@ async function handleModCommand(messageParts, printFunc, clients) { const phraseToRemove = messageParts.slice(1).join('_'); if (phraseToRemove && trackingPhrases.includes(phraseToRemove)) { - trackingWordsCollection.doc(phraseToRemove).delete().then(() => logger.info(`Tracking word removed: ${phraseToRemove}`)); + trackingWordsCollection + .doc(phraseToRemove) + .delete() + .then(() => logger.info(`Tracking word removed: ${phraseToRemove}`)); } return true; } @@ -247,7 +285,10 @@ async function handleModCommand(messageParts, printFunc, clients) { const phraseToClear = messageParts.slice(1).join('_'); if (phraseToClear && trackingPhrases.includes(phraseToClear)) { - trackingWordsCollection.doc(phraseToClear).update('count', 0).then(() => logger.info(`Tracking word cleared: ${phraseToClear}`)); + trackingWordsCollection + .doc(phraseToClear) + .update('count', 0) + .then(() => logger.info(`Tracking word cleared: ${phraseToClear}`)); } return true; } @@ -260,14 +301,18 @@ async function handleModCommand(messageParts, printFunc, clients) { const hasCount = Number.isInteger(lastTokenAsNum); const count = hasCount ? Number.parseInt(lastToken) : 1; - const phraseParts = hasCount ? messageParts.slice(1, messageParts.length - 1) : messageParts.slice(1); + const phraseParts = hasCount + ? messageParts.slice(1, messageParts.length - 1) + : messageParts.slice(1); const phraseToIncrement = phraseParts.join('_'); if (phraseToIncrement && trackingPhrases.includes(phraseToIncrement)) { const documentRef = trackingWordsCollection.doc(phraseToIncrement); const document = await documentRef.get(); const currentCount = document.get('count'); - documentRef.update('count', currentCount + count).then(() => logger.info(`Tracking word incremented: ${phraseToIncrement}`)); + documentRef + .update('count', currentCount + count) + .then(() => logger.info(`Tracking word incremented: ${phraseToIncrement}`)); } return true; } @@ -282,4 +327,4 @@ module.exports = { handleAdminCommand, handleModCommand, handleTwitchUserCommand -}; \ No newline at end of file +}; diff --git a/src/config/discord.ts b/src/config/discord.ts index 6c2fe48..998b26d 100644 --- a/src/config/discord.ts +++ b/src/config/discord.ts @@ -1,4 +1,4 @@ export default { token: process.env.DISCORD_TOKEN, bot_user_id: process.env.DISCORD_BOT_USER_ID -}; \ No newline at end of file +}; diff --git a/src/config/firebase.ts b/src/config/firebase.ts index 050f983..aeaf244 100644 --- a/src/config/firebase.ts +++ b/src/config/firebase.ts @@ -1,16 +1,16 @@ export default { service_account: { - type: "service_account", + type: 'service_account', project_id: process.env.FIREBASE_PROJECT_ID, private_key_id: process.env.FIREBASE_PRIVATE_KEY_ID, // https://stackoverflow.com/questions/50299329/node-js-firebase-service-account-private-key-wont-parse private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'), client_email: process.env.FIREBASE_CLIENT_EMAIL, client_id: process.env.FIREBASE_CLIENT_ID, - auth_uri: "https://accounts.google.com/o/oauth2/auth", - token_uri: "https://oauth2.googleapis.com/token", - auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs", + auth_uri: 'https://accounts.google.com/o/oauth2/auth', + token_uri: 'https://oauth2.googleapis.com/token', + auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', client_x509_cert_url: process.env.FIREBASE_CLIENT_CERT_URL }, database_url: process.env.FIREBASE_DATABASE_URL -}; \ No newline at end of file +}; diff --git a/src/config/index.ts b/src/config/index.ts index 30ba461..34b944c 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -4,4 +4,4 @@ export { default as firebaseConfig } from './firebase'; export { default as discordConfig } from './discord'; export { default as mqttConfig } from './mqtt'; -export { default as logger } from './logger'; \ No newline at end of file +export { default as logger } from './logger'; diff --git a/src/config/logger.ts b/src/config/logger.ts index 450dd75..0ec92a0 100644 --- a/src/config/logger.ts +++ b/src/config/logger.ts @@ -3,14 +3,8 @@ const { combine, timestamp, prettyPrint, colorize } = format; const logger = createLogger({ level: 'debug', - format: combine( - timestamp(), - prettyPrint(), - colorize() - ), - transports: [ - new transports.Console() - ] + format: combine(timestamp(), prettyPrint(), colorize()), + transports: [new transports.Console()] }); -export default logger; \ No newline at end of file +export default logger; diff --git a/src/config/mqtt.ts b/src/config/mqtt.ts index 06fa777..4ea3ae1 100644 --- a/src/config/mqtt.ts +++ b/src/config/mqtt.ts @@ -1,3 +1,3 @@ export default { address: process.env.MQTT_BROKER_ADDRESS -}; \ No newline at end of file +}; diff --git a/src/config/obs.ts b/src/config/obs.ts index 973e2b5..3938038 100644 --- a/src/config/obs.ts +++ b/src/config/obs.ts @@ -1,4 +1,4 @@ export default { address: process.env.OBS_URL, password: process.env.OBS_PASSWORD -}; \ No newline at end of file +}; diff --git a/src/config/twitch.ts b/src/config/twitch.ts index e41fe44..7b6499c 100644 --- a/src/config/twitch.ts +++ b/src/config/twitch.ts @@ -10,4 +10,4 @@ export default { password: `oauth:${process.env.TMI_TOKEN}` }, channels -}; \ No newline at end of file +}; diff --git a/src/constants/commands.ts b/src/constants/commands.ts index b9e0ae7..465b9a8 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -7,7 +7,7 @@ export const ADMIN_USER = 'bastulos'; export const ADMIN_COMMANDS = { TOGGLE_COMMANDS_ACTIVE: 'active', ADD_COMMAND: 'add', - REMOVE_COMMAND: 'rm', + REMOVE_COMMAND: 'rm' }; export const OBS_COMMANDS = { @@ -33,4 +33,4 @@ export const LIGHT_COMMANDS = { RANDOM_COLOR: 'lightsrand' }; -export const HELP_COMMAND = 'help'; \ No newline at end of file +export const HELP_COMMAND = 'help'; diff --git a/src/constants/firebase.ts b/src/constants/firebase.ts index a8d1a6b..de957df 100644 --- a/src/constants/firebase.ts +++ b/src/constants/firebase.ts @@ -1,2 +1,2 @@ export const COMMANDS_COLLECTION = 'commands'; -export const WORD_TRACKING_COLLECTION = 'wordTracking'; \ No newline at end of file +export const WORD_TRACKING_COLLECTION = 'wordTracking'; diff --git a/src/constants/index.ts b/src/constants/index.ts index d7095a4..b02b365 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,4 +1,4 @@ export * from './obs'; export * from './firebase'; export * from './commands'; -export * from './mqtt'; \ No newline at end of file +export * from './mqtt'; diff --git a/src/constants/mqtt.ts b/src/constants/mqtt.ts index 45b8743..d5eaeda 100644 --- a/src/constants/mqtt.ts +++ b/src/constants/mqtt.ts @@ -4,4 +4,4 @@ export const LIGHT_TOPICS = { named_color: 'lights/office/color/name', rgb_color: 'lights/office/color/rgb' } -}; \ No newline at end of file +}; diff --git a/src/constants/obs.ts b/src/constants/obs.ts index 2872dbc..8cc328d 100644 --- a/src/constants/obs.ts +++ b/src/constants/obs.ts @@ -2,4 +2,4 @@ export const SOURCES = { WEBCAM: 'Webcam', MIC: 'Desktop Mic', AQUA: 'Aqua' -}; \ No newline at end of file +}; diff --git a/src/index.ts b/src/index.ts index 275ffec..bdf6371 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,23 @@ require('dotenv').config(); -import { twitchClient, obsClient, obsConnected, firestore, collections, discordClient, mqttClient } from './clients'; +import { + twitchClient, + obsClient, + obsConnected, + firestore, + collections, + discordClient, + mqttClient +} from './clients'; import { discordConfig, logger } from './config'; import { COMMAND_PREFACE, ADMIN_USER, OBS_COMMANDS, LIGHT_COMMANDS } from './constants'; -const { handleAdminCommand, handleOBSCommand, handleModCommand, handleTwitchUserCommand } = require('./commands/twitch'); +const { + handleAdminCommand, + handleOBSCommand, + handleModCommand, + handleTwitchUserCommand +} = require('./commands/twitch'); const { handleUserCommand, handleHelpCommand } = require('./commands/shared'); - const { randomlyPadContent } = require('./utils'); const clients = { @@ -22,18 +34,27 @@ const clients = { let commandsActive = true; twitchClient.on('chat', async (channel, userInfo, message, self) => { - if (self) return; // ignore messages from the bot + if (self) return; // ignore messages from the bot if (message[0] !== COMMAND_PREFACE) return; // ignore non command messages const messageParts = message.split(' '); const username = `@${userInfo.username}`; const printFunc = content => twitchClient.say(channel, randomlyPadContent(content)); - const commandsActiveUpdateFunc = newState => commandsActive = newState; + const commandsActiveUpdateFunc = (newState: boolean) => (commandsActive = newState); try { if (userInfo.username === ADMIN_USER) { - if (handleAdminCommand(messageParts, printFunc, commandsActive, commandsActiveUpdateFunc, clients)) return; + if ( + handleAdminCommand( + messageParts, + printFunc, + commandsActive, + commandsActiveUpdateFunc, + clients + ) + ) + return; } if (userInfo.username === ADMIN_USER || userInfo.mod) { @@ -44,7 +65,8 @@ twitchClient.on('chat', async (channel, userInfo, message, self) => { if (await handleTwitchUserCommand(messageParts, username, printFunc, clients)) return; if (await handleOBSCommand(messageParts, clients, obsConnected)) return; - if (await handleHelpCommand(messageParts, printFunc, clients, OBS_COMMANDS, LIGHT_COMMANDS)) return; + if (await handleHelpCommand(messageParts, printFunc, clients, OBS_COMMANDS, LIGHT_COMMANDS)) + return; if (await handleUserCommand(messageParts, username, printFunc, clients)) return; } catch (error) { logger.error(error); @@ -52,7 +74,7 @@ twitchClient.on('chat', async (channel, userInfo, message, self) => { }); discordClient.on('message', async message => { - const member = await message.guild.fetchMember(message.author); + const member = await message.guild.members.fetch(message.author); const isBastulosBot = member.id === discordConfig.bot_user_id; const { content } = message; @@ -70,4 +92,4 @@ discordClient.on('message', async message => { } catch (error) { logger.error(error); } -}); \ No newline at end of file +}); diff --git a/src/utils/index.ts b/src/utils/index.ts index afc994e..8c2c515 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -44,4 +44,4 @@ module.exports = { loadUserCommands, loadTrackingPhrases, randomlyPadContent -}; \ No newline at end of file +};