2022-02-11 05:48:47 +00:00
|
|
|
// Heyo / TMI_js by Sarimoko.com
|
2022-02-11 05:35:55 +00:00
|
|
|
// ================================
|
2022-02-11 05:48:47 +00:00
|
|
|
// Hello World Chatbot for Twitch IRC using TMI.js!
|
|
|
|
// --------------------------------
|
|
|
|
// View README.md for .env setup!!!
|
2022-02-11 05:35:55 +00:00
|
|
|
// --------------------------------
|
|
|
|
require('dotenv').config();
|
2022-02-10 07:28:21 +00:00
|
|
|
const tmi = require('tmi.js');
|
2022-02-11 10:14:24 +00:00
|
|
|
|
2022-02-11 05:35:55 +00:00
|
|
|
console.log(process.env.API_HOST);
|
2022-02-11 10:14:24 +00:00
|
|
|
|
2022-02-10 07:28:21 +00:00
|
|
|
const client = new tmi.Client({
|
2022-02-11 05:35:55 +00:00
|
|
|
options: { debug: true },
|
|
|
|
connection: {
|
|
|
|
secure: true,
|
|
|
|
reconnect: true
|
|
|
|
},
|
|
|
|
identity: {
|
2022-02-11 10:14:24 +00:00
|
|
|
username: process.env.TTV_BOT_USERNAME,
|
|
|
|
password: process.env.TTV_BOT_OAUTH
|
2022-02-11 05:35:55 +00:00
|
|
|
},
|
2022-02-11 10:14:24 +00:00
|
|
|
channels: [ process.env.TTV_CHANNELS ]
|
2022-02-10 07:28:21 +00:00
|
|
|
});
|
2022-02-11 10:14:24 +00:00
|
|
|
|
2022-02-10 07:28:21 +00:00
|
|
|
client.connect();
|
2022-02-11 10:14:24 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
// ==================================
|
2022-02-11 05:35:55 +00:00
|
|
|
client.on("anongiftpaidupgrade", (channel, username, userstate) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Anon2PaidSub...'); // VERY specific... Anon Gift Sub => Paid Re-Sub
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("ban", (channel, username, reason, userstate) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: User Banned...'); // BYE FELICIA!
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("cheer", (channel, userstate, message) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Bits Cheered...'); // Get Bits via Cheer then React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("clearchat", (channel) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Chat Cleared...'); // Chat gets cleared by Mod/Streamer then this Reaction
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("giftpaidupgrade", (channel, username, sender, userstate) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Anon2PaidSub...'); // Huh? Tier 1 => Tier2?
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("hosting", (channel, target, viewers) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Incoming Host...'); // Get Hosted React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("join", (channel, username, self) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: User joined IRC...');// User joins IRC **WARNING: aggro/annoying
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("part", (channel, username, self) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: User left IRC...');// User leaves IRC **WARNING: aggro/annoying
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("raided", (channel, username, viewers) => {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Incoming Raid...');// Get Raided React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => {
|
|
|
|
let senderCount = ~~userstate["msg-param-sender-count"];
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Sub Gifted...');// Gift Sub React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => {
|
|
|
|
let senderCount = ~~userstate["msg-param-sender-count"];
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Sub Gifted Anonomously...');// Anon Sub React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("resub", function (channel, username, months, message, userstate, methods) {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: Sub Re-Subbed...');// Re-Sub React
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("subscription", function (channel, username, method, message, userstate) {
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: 1st Sub...'); // Either first or just General Sub
|
2022-02-11 05:35:55 +00:00
|
|
|
});
|
|
|
|
client.on("whisper", (from, userstate, message, self) => {
|
|
|
|
if (self) return;
|
2022-02-11 10:14:24 +00:00
|
|
|
console.log('TTV Alert: DM/Whisper recieved...'); // When your bot gets a DM
|
|
|
|
});
|