Update 'node/chatbot.js'

This commit is contained in:
Sarimoko 2022-02-11 05:48:47 +00:00
parent a756202f6a
commit 34054127b4
1 changed files with 29 additions and 31 deletions

View File

@ -1,12 +1,14 @@
// GAME NGIN | MMOIRC // Heyo / TMI_js by Sarimoko.com
// ================================ // ================================
// Inside Twitch Chat an adventure is growing! // Hello World Chatbot for Twitch IRC using TMI.js!
// --------------------------------
// View README.md for .env setup!!!
// -------------------------------- // --------------------------------
require('dotenv').config(); require('dotenv').config();
const tmi = require('tmi.js'); const tmi = require('tmi.js');
var mysql = require('mysql'); // MySQL is optional // MySQL Setup | Optional - View README.md for MySQL setup!
// MySQL Connection
// -------------------------------- // --------------------------------
var mysql = require('mysql');
var con = mysql.createConnection({ var con = mysql.createConnection({
host: process.env.SQL_IP, // Add in DOTenv host: process.env.SQL_IP, // Add in DOTenv
user: process.env.SQL_USER, // Add in DOTenv user: process.env.SQL_USER, // Add in DOTenv
@ -18,13 +20,9 @@ con.connect(function(err) {
if (err) throw err; if (err) throw err;
console.log("MySQL | Connected!"); console.log("MySQL | Connected!");
}); });
// TMI Config // TMI Config
// -------------------------------- // --------------------------------
console.log(process.env.API_HOST); console.log(process.env.API_HOST);
// TMI Init
// --------------------------------
const client = new tmi.Client({ const client = new tmi.Client({
options: { debug: true }, options: { debug: true },
connection: { connection: {
@ -37,11 +35,9 @@ const client = new tmi.Client({
}, },
channels: [ process.env.TTV_CHANNELS ] // Add in DOTenv channels: [ process.env.TTV_CHANNELS ] // Add in DOTenv
}); });
// TTV IRC Connect // TTV IRC Connect
// -------------------------------- // --------------------------------
client.connect(); client.connect();
// Mod Setup // Mod Setup
// ================================ // ================================
// isMod = Broadcaster/Streamer & Mods // isMod = Broadcaster/Streamer & Mods
@ -55,92 +51,95 @@ client.on('message', (channel, tags, message, self) => {
}); });
// Channel Reactions // Channel Reactions
// ================================ // ================================
// Anon Gifted Sub Upgraded to Paid // When an Anonymous Gift-Sub is Upgraded to Paid by the gifted user.
// -------------------------------- // --------------------------------
client.on("anongiftpaidupgrade", (channel, username, userstate) => { client.on("anongiftpaidupgrade", (channel, username, userstate) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When a User is BANNED
// -------------------------------- // --------------------------------
client.on("ban", (channel, username, reason, userstate) => { client.on("ban", (channel, username, reason, userstate) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When Bits are Cheered
// -------------------------------- // --------------------------------
client.on("cheer", (channel, userstate, message) => { client.on("cheer", (channel, userstate, message) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // After Chat is Cleared by a MOD
// -------------------------------- // --------------------------------
client.on("clearchat", (channel) => { client.on("clearchat", (channel) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When a Gift-Sub is Upgraded to Paid by the gifted user.
// -------------------------------- // --------------------------------
client.on("giftpaidupgrade", (channel, username, sender, userstate) => { client.on("giftpaidupgrade", (channel, username, sender, userstate) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Hosts your channel
// -------------------------------- // --------------------------------
client.on("hosting", (channel, target, viewers) => { client.on("hosting", (channel, target, viewers) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // 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.on("join", (channel, username, self) => {
client.say(channel, `/me Hello World!`); // client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // 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.on("part", (channel, username, self) => {
client.say(channel, `/me Hello World!`); // client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Raids your Channel
// -------------------------------- // --------------------------------
client.on("raided", (channel, username, viewers) => { client.on("raided", (channel, username, viewers) => {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Gifts a Sub
// -------------------------------- // --------------------------------
client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => { client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => {
let senderCount = ~~userstate["msg-param-sender-count"]; let senderCount = ~~userstate["msg-param-sender-count"];
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Randomly Gifts a Sub
// -------------------------------- // --------------------------------
client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => { client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => {
let senderCount = ~~userstate["msg-param-sender-count"]; let senderCount = ~~userstate["msg-param-sender-count"];
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Re-Subs
// -------------------------------- // --------------------------------
client.on("resub", function (channel, username, months, message, userstate, methods) { client.on("resub", function (channel, username, months, message, userstate, methods) {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When @someone Subs for the first time!
// -------------------------------- // --------------------------------
client.on("subscription", function (channel, username, method, message, userstate) { client.on("subscription", function (channel, username, method, message, userstate) {
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// Anon Gifted Sub Upgraded to Paid // When a DM/Whisper is recieved on the bot account
// -------------------------------- // --------------------------------
client.on("whisper", (from, userstate, message, self) => { client.on("whisper", (from, userstate, message, self) => {
// Don't listen to my own messages.. // Don't listen to my own messages..
if (self) return; if (self) return;
client.say(channel, `/me Hello World!`); client.say(channel, `/me Hello World!`);
}); });
// ! COMMAND => command // ! COMMAND => command
// ================================ // ================================
client.on('message', (channel, tags, message, self) => { client.on('message', (channel, tags, message, self) => {
if(self || !message.startsWith('!')) return; if(self || !message.startsWith('!')) return;
const args = message.slice(1).split(' '); const args = message.slice(1).split(' ');
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
const botUserState = client.userstate[channel]; const botUserState = client.userstate[channel];
const amMod = botUserState !== undefined && botUserState.mod === true; const amMod = botUserState !== undefined && botUserState.mod === true;
if(isModUp) { // ! MOD Commands
// ================================
if(isModUp) {
else if(command === 'abc' || command === 'alpha') { else if(command === 'abc' || command === 'alpha') {
client.say(channel, `Mod Command: A`); client.say(channel, `Mod Command: A`);
} }
@ -153,7 +152,6 @@ client.on('message', (channel, tags, message, self) => {
else if(command === 'heyo' || command === 'helloworld') { else if(command === 'heyo' || command === 'helloworld') {
client.say(channel, `${tags.username} says hi to @${args.join(' ')}!`); client.say(channel, `${tags.username} says hi to @${args.join(' ')}!`);
} }
// ERROR RESPONSE // ERROR RESPONSE
// -------------------------------- // --------------------------------
else { else {