Skip to content

Commit

Permalink
update client exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mzrimsek committed Jun 14, 2021
1 parent 33e84df commit 4ddc879
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 66 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"winston": "~3.3.3"
},
"devDependencies": {
"@types/tmi.js": "^1.7.1",
"ts-node-dev": "^1.1.6",
"typescript": "^4.3.2"
}
}
}
13 changes: 4 additions & 9 deletions src/clients/discord.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const discord = require('discord.js');
import * as discord from 'discord.js';
import { discordConfig, logger } from '../config';

const discordConfig = require('../config/discord');

const discordClient = new discord.Client();
export const discordClient = new discord.Client();
discordClient.login(discordConfig.token);

discordClient.on('ready', () => {
logger.info('Connected to Discord');
logger.info(`Logged in as: ${discordClient.user.tag} - (${discordClient.user.id})`);
});

module.exports = {
discordClient
};
});
20 changes: 8 additions & 12 deletions src/clients/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const admin = require('firebase-admin');

const firebaseConfig = require('../config/firebase');
const { COMMANDS_COLLECTION, WORD_TRACKING_COLLECTION } = require('../constants/firebase');
import * as admin from 'firebase-admin';
import { firebaseConfig, logger } from '../config';
import { COMMANDS_COLLECTION, WORD_TRACKING_COLLECTION } from '../constants';

const firestoreSettings = {
timestampsInSnapshots: true
Expand All @@ -12,7 +11,7 @@ admin.initializeApp({
databaseURL: firebaseConfig.database_url
});

let firestore = null;
export let firestore = null;
try {
firestore = admin.firestore();
firestore.settings(firestoreSettings);
Expand All @@ -24,10 +23,7 @@ try {
const commandsCollection = firestore.collection(COMMANDS_COLLECTION);
const trackingWordsCollection = firestore.collection(WORD_TRACKING_COLLECTION);

module.exports = {
firestore,
collections: {
commandsCollection,
trackingWordsCollection
}
};
export const collections = [
commandsCollection,
trackingWordsCollection
];
13 changes: 4 additions & 9 deletions src/clients/mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const mqtt = require('mqtt');
import * as mqtt from 'mqtt';
import { mqttConfig, logger } from '../config';

const mqttConfig = require('../config/mqtt');

const mqttClient = mqtt.connect(`tcp://${mqttConfig.address}`);
export const mqttClient = mqtt.connect(`tcp://${mqttConfig.address}`);
mqttClient.on('connect', () => {
logger.info('Connected to MQTT Broker');
});

module.exports = {
mqttClient
};
});
14 changes: 5 additions & 9 deletions src/clients/obs.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const OBSWebSocket = require('obs-websocket-js');
import * as OBSWebSocket from 'obs-websocket-js';
import { logger } from '../config';

let obsConnected = false;
const obsClient = new OBSWebSocket();
export let obsConnected = false;
export const obsClient = new OBSWebSocket();
obsClient.on('ConnectionOpened', () => {
obsConnected = true;
logger.info('Connected to OBSWebSocket');
});
obsClient.on('ConnectionClosed', () => {
obsConnected = false;
logger.info('Disconnected from OBSWebSocket');
});

module.exports = {
obsClient,
obsConnected
};
});
13 changes: 4 additions & 9 deletions src/clients/twitch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const tmi = require('tmi.js');
import * as tmi from 'tmi.js';
import { twitchConfig } from '../config';

const tmiConfig = require('../config/twitch');

const twitchClient = new tmi.client(tmiConfig);
twitchClient.connect();

module.exports = {
twitchClient
};
export const twitchClient = new tmi.client(twitchConfig);
twitchClient.connect();
19 changes: 3 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
require('dotenv').config();

const logger = require('winston');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, { colorize: true });
logger.level = 'debug';
global['logger'] = logger;

const { twitchClient } = require('./clients/twitch');
const { obsClient, obsConnected } = require('./clients/obs');
const { firestore, collections } = require('./clients/firebase');
const { discordClient } = require('./clients/discord');
const { mqttClient } = require('./clients/mqtt');

const discordConfig = require('./config/discord');

const { COMMAND_PREFACE, ADMIN_USER, OBS_COMMANDS, LIGHT_COMMANDS } = require('./constants/commands');
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 { handleUserCommand, handleHelpCommand } = require('./commands/shared');
Expand Down
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { COMMAND_SPACER } from '../constants/commands';
import { logger } from '../config';
import { COMMAND_SPACER } from '../constants';

function getRandomColor() {
return (Math.random() * 4294967296) >>> 0;
Expand Down

0 comments on commit 4ddc879

Please sign in to comment.