Raw Dogged that custom shoutout event and made HelixRequest easier to handle universally
This commit is contained in:
+13
-36
@@ -3,41 +3,19 @@ module.exports = {
|
||||
name: 'Twitch/Message',
|
||||
once: false,
|
||||
async execute(channel, userstate, message, self, tClient) {
|
||||
const { dClient, mClient, makeTwitchRequest } = require('../../index')
|
||||
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 updateChatMode(userID, setTo) {
|
||||
let state
|
||||
if (setTo === 'on') {
|
||||
state = true
|
||||
} else if (setTo === 'off') {
|
||||
state = false
|
||||
} else {
|
||||
return
|
||||
}
|
||||
await Helix.chat.updateSettings(userID, process.env.MOD_ID, {
|
||||
follower_mode: state,
|
||||
follower_mode_duration: 0,
|
||||
subscriber_mode: state,
|
||||
emote_mode: state
|
||||
});
|
||||
|
||||
}
|
||||
async function getIDByName(user) {
|
||||
// Function to convert Names to ID
|
||||
const result = await Helix.users.get(user);
|
||||
return result.data[0].id
|
||||
}
|
||||
async function verifyUser(channel, username) {
|
||||
// Function checks if user is a target to shout out, default target: VIPs
|
||||
async function emitShoutoutInfo(channel, username) {
|
||||
// Function sends information to the Shoutout Handler if they haven't been shouted out before, default target: VIPs
|
||||
let db = mClient.db("shoutouts")
|
||||
let col = db.collection(channel)
|
||||
|
||||
let query = { user: username }
|
||||
let status = await col.findOne(query)
|
||||
let status = await col.findOne({ user: username })
|
||||
|
||||
if (!status) {
|
||||
dClient.emit('TwitchShoutout', "VIP", channel, username)
|
||||
dClient.emit('Twitch/Shoutout', "VIP", channel, username, tClient)
|
||||
await col.insertOne({
|
||||
user: username
|
||||
user: username,
|
||||
created_at: Date()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -61,6 +39,7 @@ module.exports = {
|
||||
return tClient.say(channel, positive_Messages[rdm])
|
||||
}
|
||||
async function sendDonationAd() {
|
||||
// Function to send static donate ad
|
||||
const links = ["https://bit.ly/heltwittergoals", "https://bit.ly/donatetohel", "http://bit.ly/donothon_goals"]
|
||||
tClient.say(channel, "Hel is currently celebrating her birthday with a donathon!")
|
||||
tClient.say(channel, `You can see goals and incentives here: ${links[0]}`)
|
||||
@@ -85,9 +64,6 @@ module.exports = {
|
||||
const args = message.substring(1).split(" ")
|
||||
const cmd = args[0]
|
||||
switch (cmd) {
|
||||
// case "test":
|
||||
// tClient.say(channel, "/me This is a test message")
|
||||
// break;
|
||||
case "mode":
|
||||
if (userstate.badges.moderator != 1 && userstate.badges.broadcaster != 1) { break } // return stops all further operations, so you should just break out of switch
|
||||
let regex = /^(on|off)$/
|
||||
@@ -98,7 +74,8 @@ module.exports = {
|
||||
sendDonationAd()
|
||||
break;
|
||||
case "test":
|
||||
console.log(await makeTwitchRequest('games/top'))
|
||||
await emitShoutoutInfo(channel, userstate.username)
|
||||
// console.log(await getIDByName(userstate))
|
||||
break;
|
||||
case "positivity":
|
||||
sendPositivity()
|
||||
@@ -109,8 +86,8 @@ module.exports = {
|
||||
}
|
||||
|
||||
// ---------------VIP Handler-------------------
|
||||
// if (!userstate.badges?.vip) { return }
|
||||
// verifyUser(channel, userstate.username)
|
||||
if (!userstate.badges?.vip) { return }
|
||||
emitShoutoutInfo(channel, userstate.username)
|
||||
// ---------------------------------------------
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
module.exports = {
|
||||
name: 'Twitch/Raided',
|
||||
once: false,
|
||||
execute(stream) {
|
||||
console.log(`Connected to ${stream.address}`)
|
||||
execute(channel, username, raiders, tClient) {
|
||||
const { dClient } = require('../../index')
|
||||
tClient.say(channel, `${username} entrusted us with ${raiders} people of their community, welcome xhelxBlankie`)
|
||||
dClient.emit('Twitch/Shoutout', "RAID", channel, username)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Event triggered by Custom Shoutout emitted in Messages.js
|
||||
const soBuffer = new Map();
|
||||
let isShoutoutInProgress = false; // Track shoutout status to avoid overlapping shoutouts
|
||||
|
||||
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) {
|
||||
try {
|
||||
// Use Nightbot command !so
|
||||
// tClient.say(channel, `!so ${user}`); // Send the shoutout command
|
||||
|
||||
// Use custom shoutout
|
||||
let channelID = await getIDByName(user)
|
||||
let res = await getChannelInformation(channelID)
|
||||
let channelInfo = res?.data[0]
|
||||
let shoutoutMessage = `Check out ${channelInfo.broadcaster_name} over at https://twitch.tv/${channelInfo.broadcaster_login}! They were last playing ${channelInfo.game_name}`
|
||||
tClient.say(channel, shoutoutMessage)
|
||||
|
||||
console.log(`Shouting out ${user} in channel ${channel} for reason: ${reason}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error during shoutout:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle buffered shoutout queue
|
||||
async function processShoutoutQueue() {
|
||||
if (soBuffer.size === 0 || isShoutoutInProgress) {
|
||||
return; // Exit if no users are in the buffer or a shoutout is in progress
|
||||
}
|
||||
|
||||
// Set shoutout in progress flag
|
||||
isShoutoutInProgress = true;
|
||||
|
||||
// Get the next user in the buffer
|
||||
const [user, channel] = soBuffer.entries().next().value;
|
||||
|
||||
try {
|
||||
await doShoutouts(channel, user); // Perform the shoutout
|
||||
soBuffer.delete(user); // Remove user after shoutout is done
|
||||
// console.log(`Shoutout for ${user} completed in channel ${channel}`);
|
||||
} catch (error) {
|
||||
console.error('Error while processing shoutout:', error);
|
||||
} finally {
|
||||
// Reset shoutout in progress flag and schedule next shoutout
|
||||
isShoutoutInProgress = false;
|
||||
setTimeout(processShoutoutQueue, 5000); // Schedule next shoutout after cooldown
|
||||
}
|
||||
}
|
||||
|
||||
// Add user to the buffer if not already present
|
||||
if (!soBuffer.has(username)) {
|
||||
soBuffer.set(username, channel);
|
||||
console.log(`Added ${username} to the shoutout buffer. Reason: ${reason}`);
|
||||
}
|
||||
|
||||
// Call the shoutout queue processing
|
||||
setTimeout(processShoutoutQueue, 5000); // Ensure 5-second cooldown between shoutouts
|
||||
}
|
||||
};
|
||||
@@ -2,7 +2,17 @@
|
||||
module.exports = {
|
||||
name: 'Twitch/Subscribers',
|
||||
once: false,
|
||||
execute(stream) {
|
||||
console.log(`Connected to ${stream.address}`)
|
||||
async execute(channel, enabled) {
|
||||
const { mClient } = require('../..')
|
||||
|
||||
let db = mClient.db('shoutouts')
|
||||
let col = db.collection(channel)
|
||||
|
||||
// Drop Shoutout Collection to reset
|
||||
try {
|
||||
await col.drop()
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user