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
|
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
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
+7
-2
@@ -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(
|
||||||
@@ -155,4 +158,6 @@ async function updateChatMode(broadcaster_id, setTo) {
|
|||||||
// Get channel information
|
// Get channel information
|
||||||
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
@@ -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();
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user