Update 'node/chatbot.js'

This commit is contained in:
Sarimoko 2022-02-11 10:14:24 +00:00
parent d8c06ca14b
commit 565fd2793a
1 changed files with 52 additions and 97 deletions

View File

@ -6,9 +6,9 @@
// --------------------------------
require('dotenv').config();
const tmi = require('tmi.js');
// TMI Config
// --------------------------------
console.log(process.env.API_HOST);
const client = new tmi.Client({
options: { debug: true },
connection: {
@ -16,131 +16,86 @@ const client = new tmi.Client({
reconnect: true
},
identity: {
username: process.env.TTV_BOT_USERNAME, // Add in DOTenv
password: process.env.TTV_BOT_OAUTH // Add in DOTenv
username: process.env.TTV_BOT_USERNAME,
password: process.env.TTV_BOT_OAUTH
},
channels: [ process.env.TTV_CHANNELS ] // Add in DOTenv
channels: [ process.env.TTV_CHANNELS ]
});
// TTV IRC Connect
// --------------------------------
client.connect();
// Mod Setup
// ================================
// isMod = Broadcaster/Streamer & Mods
// --------------------------------
client.on('message', (channel, tags, message, self) => {
if(self) return;
const badges = tags.badges || {};
const isBroadcaster = badges.broadcaster;
const isMod = badges.moderator;
const isModUp = isBroadcaster || isMod;
});
// Channel Reactions
// ================================
// When an Anonymous Gift-Sub is Upgraded to Paid by the gifted user.
// --------------------------------
client.on('message', (channel, tags, message, self) => { // START | MSG
if(self) return; // Bot ignores itself
const badges = tags.badges || {}; // Scan Badges
const isBroadcaster = badges.broadcaster; // Define Streamer
const isMod = badges.moderator; // Define Mod
const isModUp = isBroadcaster || isMod; // Permission Merge = Mod+Streamer
const isSub = badges.subscriber || badges.founder; // Define Subs
const botUserState = client.userstate[channel]; // MOD Status Check
const amMod = botUserState !== undefined && botUserState.mod === true; // Define Mod Status
// !MODS
if(isModUp && message.toLowerCase().startsWith('!so')) {
console.log('MOD COMMAND | so | shoutout');
client.say(channel, `bloop`);
}
// !SUBS
if(isSub) {
console.log(tags.username, 'is a subscriber');
}
// General Commands
if(message.toLowerCase().startsWith('!2pac')) {
console.log('LOG: Non-Mod command used!');
}
}); // END | MSG
// TTV Re-Active
// ==================================
client.on("anongiftpaidupgrade", (channel, username, userstate) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Anon2PaidSub...'); // VERY specific... Anon Gift Sub => Paid Re-Sub
});
// When a User is BANNED
// --------------------------------
client.on("ban", (channel, username, reason, userstate) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: User Banned...'); // BYE FELICIA!
});
// When Bits are Cheered
// --------------------------------
client.on("cheer", (channel, userstate, message) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Bits Cheered...'); // Get Bits via Cheer then React
});
// After Chat is Cleared by a MOD
// --------------------------------
client.on("clearchat", (channel) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Chat Cleared...'); // Chat gets cleared by Mod/Streamer then this Reaction
});
// When a Gift-Sub is Upgraded to Paid by the gifted user.
// --------------------------------
client.on("giftpaidupgrade", (channel, username, sender, userstate) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Anon2PaidSub...'); // Huh? Tier 1 => Tier2?
});
// When @someone Hosts your channel
// --------------------------------
client.on("hosting", (channel, target, viewers) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Incoming Host...'); // Get Hosted React
});
// When @someone connects to your Twitch IRC
// --------------------------------
// DOES NOT COUNT AS VIEWER!
// *** WARNING: Annoying AF don't really use it! I've commented it out.
client.on("join", (channel, username, self) => {
// client.say(channel, `/me Hello World!`);
console.log('TTV Alert: User joined IRC...');// User joins IRC **WARNING: aggro/annoying
});
// When @someone dis-connects from your Twitch IRC
// --------------------------------
// BYE FELICIA!
// *** WARNING: Annoying AF don't really use it! I've commented it out.
client.on("part", (channel, username, self) => {
// client.say(channel, `/me Hello World!`);
console.log('TTV Alert: User left IRC...');// User leaves IRC **WARNING: aggro/annoying
});
// When @someone Raids your Channel
// --------------------------------
client.on("raided", (channel, username, viewers) => {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Incoming Raid...');// Get Raided React
});
// When @someone Gifts a Sub
// --------------------------------
client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => {
let senderCount = ~~userstate["msg-param-sender-count"];
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Sub Gifted...');// Gift Sub React
});
// When @someone Randomly Gifts a Sub
// --------------------------------
client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => {
let senderCount = ~~userstate["msg-param-sender-count"];
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Sub Gifted Anonomously...');// Anon Sub React
});
// When @someone Re-Subs
// --------------------------------
client.on("resub", function (channel, username, months, message, userstate, methods) {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: Sub Re-Subbed...');// Re-Sub React
});
// When @someone Subs for the first time!
// --------------------------------
client.on("subscription", function (channel, username, method, message, userstate) {
client.say(channel, `/me Hello World!`);
console.log('TTV Alert: 1st Sub...'); // Either first or just General Sub
});
// When a DM/Whisper is recieved on the bot account
// --------------------------------
client.on("whisper", (from, userstate, message, self) => {
// Don't listen to my own messages..
if (self) return;
client.say(channel, `/me Hello World!`);
});
// ! COMMAND => command
// ================================
client.on('message', (channel, tags, message, self) => {
if(self || !message.startsWith('!')) return;
const args = message.slice(1).split(' ');
const command = args.shift().toLowerCase();
const botUserState = client.userstate[channel];
const amMod = botUserState !== undefined && botUserState.mod === true;
// ! MOD Commands
// ================================
if(isModUp) {
else if(command === 'abc' || command === 'alpha') {
client.say(channel, `Mod Command: A`);
}
if(command === 'xyz' || command === 'beta') {
client.say(channel, `Mod Command: B`);
}
}
// !heyo | !helloworld
// ----------------------------------
else if(command === 'heyo' || command === 'helloworld') {
client.say(channel, `${tags.username} says hi to @${args.join(' ')}!`);
}
// ERROR RESPONSE
// --------------------------------
else {
client.say(channel, `/me Hey @${tags.username}, Command not found!`);
}
}); // ! COMMAND END
console.log('TTV Alert: DM/Whisper recieved...'); // When your bot gets a DM
});