diff --git a/events/Twitch/Message.js b/events/Twitch/Message.js index c08a08c..b2bacea 100644 --- a/events/Twitch/Message.js +++ b/events/Twitch/Message.js @@ -1,9 +1,11 @@ +const { mClient, dClient } = require('../..') +const { updateChatMode, getIDByName } = require('../../functions') + require('dotenv').configDotenv module.exports = { name: 'Twitch/Message', once: false, async execute(channel, userstate, message, self, tClient) { - const { dClient, mClient, getIDByName, updateChatMode } = require('../../index') const knownBots = new Set(['streamlabs', 'nightbot', 'moobot', 'soundalerts', 'streamelements', 'remasuri_bot', 'commanderroot', 'x__hel_bot__x']) async function emitShoutoutInfo(channel, username) { // Function sends information to the Shoutout Handler if they haven't been shouted out before, default target: VIPs diff --git a/events/Twitch/Raided.js b/events/Twitch/Raided.js index eab2f9e..04416c8 100644 --- a/events/Twitch/Raided.js +++ b/events/Twitch/Raided.js @@ -1,9 +1,10 @@ +const { dClient, tClient } = require("../..") + // Event triggered by Raid module.exports = { name: 'Twitch/Raided', once: false, - execute(channel, username, raiders, tClient) { - const { dClient } = require('../../index') + execute(channel, username, raiders) { tClient.say(channel, `${username} entrusted us with ${raiders} people of their community, welcome xhelxBlankie`) dClient.emit('Twitch/Shoutout', "RAID", channel, username) } diff --git a/events/Twitch/Shoutout.js b/events/Twitch/Shoutout.js index 19eee50..a21fd1c 100644 --- a/events/Twitch/Shoutout.js +++ b/events/Twitch/Shoutout.js @@ -1,3 +1,5 @@ +const { getChannelInformation, getIDByName } = require("../../functions"); + // Event triggered by Custom Shoutout emitted in Messages.js const soBuffer = new Map(); let isShoutoutInProgress = false; // Track shoutout status to avoid overlapping shoutouts @@ -6,7 +8,6 @@ module.exports = { name: 'Twitch/Shoutout', once: false, async execute(reason, channel, username, tClient) { - const { getIDByName, getChannelInformation } = require('../../index'); // Function to perform shoutout (Nightbot or custom) async function doShoutouts(channel, user) { diff --git a/events/Twitch/Subscribers.js b/events/Twitch/Subscribers.js index ce37375..33f95bf 100644 --- a/events/Twitch/Subscribers.js +++ b/events/Twitch/Subscribers.js @@ -1,9 +1,10 @@ +const { mClient } = require("../..") + // Event triggered by SubscribersOnly mode module.exports = { name: 'Twitch/Subscribers', once: false, async execute(channel, enabled) { - const { mClient } = require('../..') let db = mClient.db('shoutouts') let col = db.collection(channel) diff --git a/functions.js b/functions.js index f9452f4..0206ca6 100644 --- a/functions.js +++ b/functions.js @@ -1,3 +1,6 @@ +const { default: axios } = require("axios"); +const { mClient } = require("."); + // Delay function for pauses function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -11,7 +14,7 @@ async function saveToken(access_token, refresh_token, expiresIn, scope) { refresh_token, scope, expiresIn, - obtainedAt: Date.now(), + obtainedAt: Date(), }; await credentialCollection.updateOne( @@ -155,4 +158,6 @@ async function updateChatMode(broadcaster_id, setTo) { // Get channel information async function getChannelInformation(broadcaster_id) { return await makeHelixRequest('GET', 'channels', { broadcaster_id }); -} \ No newline at end of file +} + +module.exports = { getChannelInformation, updateChatMode, getIDByName, makeHelixRequest, delay, refreshAccessToken } \ No newline at end of file diff --git a/handlers/events.js b/handlers/events.js index 77ebbec..6a8f2de 100644 --- a/handlers/events.js +++ b/handlers/events.js @@ -1,6 +1,8 @@ const fs = require('node:fs') const path = require('node:path'); const { dClient, mClient, tClient } = require('..'); +const { refreshAccessToken } = require('../functions'); +const tmi = require('tmi.js') const folderPath = path.join(__dirname, '../events') const eventFolders = fs.readdirSync(folderPath) @@ -66,7 +68,7 @@ tClient.on('disconnected', async (reason) => { username: tCreds.username, password: `oauth:${tCreds.token.access_token}`, }, - channels: channels, + channels: tClient.channels, }); await tClient.connect(); diff --git a/index.js b/index.js index 7be25a4..05cb13e 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,8 @@ // index.js -const { MongoClient } = require('mongodb'); -const dotenv = require('dotenv'); +require('dotenv').configDotenv const fs = require('fs'); -const axios = require('axios'); const initializeClients = require('./clients'); -dotenv.config(); // Validate required environment variables function validateEnvVariables() { @@ -22,7 +19,7 @@ function validateEnvVariables() { async function startApp() { const { mClient, dClient, tClient } = await initializeClients(); validateEnvVariables(); - + tClient.connect() // Export initialized clients module.exports = { mClient, dClient, tClient };