MMOIRC/server/mmoirc.js

160 lines
5.4 KiB
JavaScript

require('dotenv').config();
var colors = require('colors');
var mysql = require('mysql');
// Twitch API
const tmi = require('tmi.js');
// Discord API
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login('token');
// TMI Config
// --------------------------------
console.log(process.env.API_HOST);
const client = new tmi.Client({
options: { debug: true },
connection: {
secure: true,
reconnect: true
},
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();
// 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("anongiftpaidupgrade", (channel, username, userstate) => {
client.say(channel, `/me Hello World!`);
});
// When a User is BANNED
// --------------------------------
client.on("ban", (channel, username, reason, userstate) => {
client.say(channel, `/me Hello World!`);
});
// When Bits are Cheered
// --------------------------------
client.on("cheer", (channel, userstate, message) => {
client.say(channel, `/me Hello World!`);
});
// After Chat is Cleared by a MOD
// --------------------------------
client.on("clearchat", (channel) => {
client.say(channel, `/me Hello World!`);
});
// 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!`);
});
// When @someone Hosts your channel
// --------------------------------
client.on("hosting", (channel, target, viewers) => {
client.say(channel, `/me Hello World!`);
});
// 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!`);
});
// 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!`);
});
// When @someone Raids your Channel
// --------------------------------
client.on("raided", (channel, username, viewers) => {
client.say(channel, `/me Hello World!`);
});
// 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!`);
});
// 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!`);
});
// When @someone Re-Subs
// --------------------------------
client.on("resub", function (channel, username, months, message, userstate, methods) {
client.say(channel, `/me Hello World!`);
});
// When @someone Subs for the first time!
// --------------------------------
client.on("subscription", function (channel, username, method, message, userstate) {
client.say(channel, `/me Hello World!`);
});
// 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