off-loaded common functions

This commit is contained in:
DeSqBlocki
2025-02-08 17:07:13 +01:00
parent 5397e076ca
commit f978dbdf2e
7 changed files with 22 additions and 13 deletions
+3 -1
View File
@@ -1,9 +1,11 @@
const { mClient, dClient } = require('../..')
const { updateChatMode, getIDByName } = require('../../functions')
require('dotenv').configDotenv require('dotenv').configDotenv
module.exports = { module.exports = {
name: 'Twitch/Message', name: 'Twitch/Message',
once: false, once: false,
async execute(channel, userstate, message, self, tClient) { 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']) const knownBots = new Set(['streamlabs', 'nightbot', 'moobot', 'soundalerts', 'streamelements', 'remasuri_bot', 'commanderroot', 'x__hel_bot__x'])
async function emitShoutoutInfo(channel, username) { async function emitShoutoutInfo(channel, username) {
// Function sends information to the Shoutout Handler if they haven't been shouted out before, default target: VIPs // Function sends information to the Shoutout Handler if they haven't been shouted out before, default target: VIPs
+3 -2
View File
@@ -1,9 +1,10 @@
const { dClient, tClient } = require("../..")
// Event triggered by Raid // Event triggered by Raid
module.exports = { module.exports = {
name: 'Twitch/Raided', name: 'Twitch/Raided',
once: false, once: false,
execute(channel, username, raiders, tClient) { execute(channel, username, raiders) {
const { dClient } = require('../../index')
tClient.say(channel, `${username} entrusted us with ${raiders} people of their community, welcome xhelxBlankie`) tClient.say(channel, `${username} entrusted us with ${raiders} people of their community, welcome xhelxBlankie`)
dClient.emit('Twitch/Shoutout', "RAID", channel, username) dClient.emit('Twitch/Shoutout', "RAID", channel, username)
} }
+2 -1
View File
@@ -1,3 +1,5 @@
const { getChannelInformation, getIDByName } = require("../../functions");
// Event triggered by Custom Shoutout emitted in Messages.js // Event triggered by Custom Shoutout emitted in Messages.js
const soBuffer = new Map(); const soBuffer = new Map();
let isShoutoutInProgress = false; // Track shoutout status to avoid overlapping shoutouts let isShoutoutInProgress = false; // Track shoutout status to avoid overlapping shoutouts
@@ -6,7 +8,6 @@ module.exports = {
name: 'Twitch/Shoutout', name: 'Twitch/Shoutout',
once: false, once: false,
async execute(reason, channel, username, tClient) { async execute(reason, channel, username, tClient) {
const { getIDByName, getChannelInformation } = require('../../index');
// Function to perform shoutout (Nightbot or custom) // Function to perform shoutout (Nightbot or custom)
async function doShoutouts(channel, user) { async function doShoutouts(channel, user) {
+2 -1
View File
@@ -1,9 +1,10 @@
const { mClient } = require("../..")
// Event triggered by SubscribersOnly mode // Event triggered by SubscribersOnly mode
module.exports = { module.exports = {
name: 'Twitch/Subscribers', name: 'Twitch/Subscribers',
once: false, once: false,
async execute(channel, enabled) { async execute(channel, enabled) {
const { mClient } = require('../..')
let db = mClient.db('shoutouts') let db = mClient.db('shoutouts')
let col = db.collection(channel) let col = db.collection(channel)
+6 -1
View File
@@ -1,3 +1,6 @@
const { default: axios } = require("axios");
const { mClient } = require(".");
// Delay function for pauses // Delay function for pauses
function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } 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, refresh_token,
scope, scope,
expiresIn, expiresIn,
obtainedAt: Date.now(), obtainedAt: Date(),
}; };
await credentialCollection.updateOne( await credentialCollection.updateOne(
@@ -156,3 +159,5 @@ async function updateChatMode(broadcaster_id, setTo) {
async function getChannelInformation(broadcaster_id) { async function getChannelInformation(broadcaster_id) {
return await makeHelixRequest('GET', 'channels', { broadcaster_id }); return await makeHelixRequest('GET', 'channels', { broadcaster_id });
} }
module.exports = { getChannelInformation, updateChatMode, getIDByName, makeHelixRequest, delay, refreshAccessToken }
+3 -1
View File
@@ -1,6 +1,8 @@
const fs = require('node:fs') const fs = require('node:fs')
const path = require('node:path'); const path = require('node:path');
const { dClient, mClient, tClient } = require('..'); const { dClient, mClient, tClient } = require('..');
const { refreshAccessToken } = require('../functions');
const tmi = require('tmi.js')
const folderPath = path.join(__dirname, '../events') const folderPath = path.join(__dirname, '../events')
const eventFolders = fs.readdirSync(folderPath) const eventFolders = fs.readdirSync(folderPath)
@@ -66,7 +68,7 @@ tClient.on('disconnected', async (reason) => {
username: tCreds.username, username: tCreds.username,
password: `oauth:${tCreds.token.access_token}`, password: `oauth:${tCreds.token.access_token}`,
}, },
channels: channels, channels: tClient.channels,
}); });
await tClient.connect(); await tClient.connect();
+2 -5
View File
@@ -1,11 +1,8 @@
// index.js // index.js
const { MongoClient } = require('mongodb'); require('dotenv').configDotenv
const dotenv = require('dotenv');
const fs = require('fs'); const fs = require('fs');
const axios = require('axios');
const initializeClients = require('./clients'); const initializeClients = require('./clients');
dotenv.config();
// Validate required environment variables // Validate required environment variables
function validateEnvVariables() { function validateEnvVariables() {
@@ -22,7 +19,7 @@ function validateEnvVariables() {
async function startApp() { async function startApp() {
const { mClient, dClient, tClient } = await initializeClients(); const { mClient, dClient, tClient } = await initializeClients();
validateEnvVariables(); validateEnvVariables();
tClient.connect()
// Export initialized clients // Export initialized clients
module.exports = { mClient, dClient, tClient }; module.exports = { mClient, dClient, tClient };