off-loaded common functions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
+6
-1
@@ -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(
|
||||
@@ -156,3 +159,5 @@ async function updateChatMode(broadcaster_id, setTo) {
|
||||
async function getChannelInformation(broadcaster_id) {
|
||||
return await makeHelixRequest('GET', 'channels', { broadcaster_id });
|
||||
}
|
||||
|
||||
module.exports = { getChannelInformation, updateChatMode, getIDByName, makeHelixRequest, delay, refreshAccessToken }
|
||||
+3
-1
@@ -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();
|
||||
|
||||
@@ -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 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user