Update 'node/chatbot.js'
This commit is contained in:
parent
6f4f47d8eb
commit
a756202f6a
160
node/chatbot.js
160
node/chatbot.js
|
@ -1,22 +1,162 @@
|
||||||
|
// GAME NGIN | MMOIRC
|
||||||
|
// ================================
|
||||||
|
// Inside Twitch Chat an adventure is growing!
|
||||||
|
// --------------------------------
|
||||||
|
require('dotenv').config();
|
||||||
const tmi = require('tmi.js');
|
const tmi = require('tmi.js');
|
||||||
|
var mysql = require('mysql'); // MySQL is optional
|
||||||
|
// MySQL Connection
|
||||||
|
// --------------------------------
|
||||||
|
var con = mysql.createConnection({
|
||||||
|
host: process.env.SQL_IP, // Add in DOTenv
|
||||||
|
user: process.env.SQL_USER, // Add in DOTenv
|
||||||
|
password: process.env.SQL_PASS // Add in DOTenv
|
||||||
|
});
|
||||||
|
// MySQL Error Check
|
||||||
|
// --------------------------------
|
||||||
|
con.connect(function(err) {
|
||||||
|
if (err) throw err;
|
||||||
|
console.log("MySQL | Connected!");
|
||||||
|
});
|
||||||
|
|
||||||
|
// TMI Config
|
||||||
|
// --------------------------------
|
||||||
|
console.log(process.env.API_HOST);
|
||||||
|
|
||||||
|
// TMI Init
|
||||||
|
// --------------------------------
|
||||||
const client = new tmi.Client({
|
const client = new tmi.Client({
|
||||||
options: { debug: true },
|
options: { debug: true },
|
||||||
identity: {
|
connection: {
|
||||||
username: 'my_bot_name',
|
secure: true,
|
||||||
password: 'oauth:my_bot_token'
|
reconnect: true
|
||||||
},
|
},
|
||||||
channels: [ 'my_name' ]
|
identity: {
|
||||||
|
username: process.env.TTV_BOT_USERNAME, // Add in DOTenv
|
||||||
|
password: process.env.TTV_BOT_OAUTH // Add in DOTenv
|
||||||
|
},
|
||||||
|
channels: [ process.env.TTV_CHANNELS ] // Add in DOTenv
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TTV IRC Connect
|
||||||
|
// --------------------------------
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
||||||
|
// Mod Setup
|
||||||
|
// ================================
|
||||||
|
// isMod = Broadcaster/Streamer & Mods
|
||||||
|
// --------------------------------
|
||||||
client.on('message', (channel, tags, message, self) => {
|
client.on('message', (channel, tags, message, self) => {
|
||||||
// Ignore echoed messages.
|
|
||||||
if(self) return;
|
if(self) return;
|
||||||
|
const badges = tags.badges || {};
|
||||||
if(message.toLowerCase() === '!hello') {
|
const isBroadcaster = badges.broadcaster;
|
||||||
// "@alca, heya!"
|
const isMod = badges.moderator;
|
||||||
client.say(channel, `@${tags.username}, heya!`);
|
const isModUp = isBroadcaster || isMod;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
// Channel Reactions
|
||||||
|
// ================================
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("anongiftpaidupgrade", (channel, username, userstate) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("ban", (channel, username, reason, userstate) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("cheer", (channel, userstate, message) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("clearchat", (channel) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("giftpaidupgrade", (channel, username, sender, userstate) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("hosting", (channel, target, viewers) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("join", (channel, username, self) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("part", (channel, username, self) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("raided", (channel, username, viewers) => {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => {
|
||||||
|
let senderCount = ~~userstate["msg-param-sender-count"];
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => {
|
||||||
|
let senderCount = ~~userstate["msg-param-sender-count"];
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("resub", function (channel, username, months, message, userstate, methods) {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
client.on("subscription", function (channel, username, method, message, userstate) {
|
||||||
|
client.say(channel, `/me Hello World!`);
|
||||||
|
});
|
||||||
|
// Anon Gifted Sub Upgraded to Paid
|
||||||
|
// --------------------------------
|
||||||
|
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;
|
||||||
|
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
|
Loading…
Reference in New Issue