require('dotenv').config(); const tmi = require('tmi.js'); const colors = require('colors'); const rp = require('request-promise'); // For RNG console.log(colors.green.underline(process.env.API_HOST)); const client = new tmi.Client({ options: { debug: true }, connection: { secure: true, reconnect: true }, identity: { username: process.env.TTV_BOT_USERNAME, password: process.env.TTV_BOT_OAUTH }, channels: [ process.env.TTV_CHANNELS ] }); client.connect(); // RNG User function getChatters(channelName, _attemptCount = 0) { return rp({ uri: `https://tmi.twitch.tv/group/user/sarimoko/chatters`, json: true }) .then(data => { return Object.entries(data.chatters) .reduce((p, [ type, list ]) => p.concat(list.map(name => { if(name === channelName) type = 'broadcaster'; return { name, type }; })), []); }) .catch(err => { if(_attemptCount < 3) { return getChatters(channelName, _attemptCount + 1); } throw err; }) } function getRandomChatter(channelName, opts = {}) { let { onlyViewers = false, noBroadcaster = false, skipList = [] } = opts; return getChatters(channelName) .then(data => { let chatters = data .filter(({ name, type }) => !( (onlyViewers && type !== 'viewers') || (noBroadcaster && type === 'broadcaster') || skipList.includes(name) ) ); return chatters.length === 0 ? null : chatters[Math.floor(Math.random() * chatters.length)]; }); } // ================================ // CHAT SCAN | START client.on('message', (channel, tags, message, self) => { if(self) return; if(tags.username === 'nightbot') return; if(tags.username === 'streamelements') return; if(tags.username === 'streamlabs') return; 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 if(self || !message.startsWith('!')) return; // Command Parser const args = message.slice(1).split(' '); const command = args.shift().toLowerCase(); // !COMMAND => command // ================================ // Chatbot Commands // ================================ if(command === 'rnguser') { // Get a random user but skip the user requesting a random user getRandomChatter(channel, { skipList: [ tags.username ] }) .then(user => { if(user === null) { client.say(channel, `Sorry ${tags.username}, this is embarrassing... There was no one to choose from! #smallstreamerproblems Bleep-Bloop!`); } else { let { name, type } = user; client.say(channel, `${tags.username} exluded, at random I choose "${name}" cuz they're such an amazing ${type}!`); } }) .catch(err => console.log('[ERR]', err)); } // CMD | Dice Roll if(command === 'dice' || command === 'roll') { const result = Math.floor(Math.random() * 6) + 1; client.say(channel, `/me RNGesus has rolled @${tags.username} a ${result}!`); } if(command === 'hibots') { client.say(channel, `!hichatbots `) } // CMD | Lurk if(command === 'lurk' || command === 'lurkin' || command === 'lurking') { client.say(channel, `/me Thanks @${tags.username} for your viewership! Lurk on! sarimoLURKbrb sarimoLURK`); } // ================================ // SUB Commands // ================================ if(isSub) { // CMD | Color if(command === 'color') { if (message === '!color'){ client.say(channel, `/me @{tags.username} you forgot to tell me what color to change to... You can enter hex (#000000) or choose fon the preset color names: Blue, BlueViolet, CadetBlue, Chocolate, Coral, DodgerBlue, Firebrick, GoldenRod, Green, HotPink, OrangeRed, Red, SeaGreen, SpringGreen, YellowGreen`) } // TO-DO: Build error checker if (message === `!color #******`){ client.say(channel, `/color ${args.join(' ')}`); client.say(channel, `/me @${tags.username} has changed my color to ${args.join(' ')}... Welp, alright!`); } if (message === `!color Blue` || message === `!color BlueViolet ` || message === `!color CadetBlue ` || message === `!color Chocolate ` || message === `!color Coral ` || message === `!color DodgerBlue ` || message === `!color Firebrick ` || message === `!color GoldenRod ` || message === `!color Green ` || message === `!color HotPink ` || message === `!color OrangeRed ` || message === `!color Red ` || message === `!color SeaGreen ` || message === `!color SpringGreen ` || message === `!color YellowGreen `){ client.say(channel, `/color ${args.join(' ')}`); client.say(channel, `/me @${tags.username} has changed my color to ${args.join(' ')}... Welp, alright!`); } else{ client.say(channel, `/me @Sorry ${tags.username}, but ${args.join(' ')} is not a valid color choice! Please try again!`); } } // FX | K A P P A G E N S if(command === 'bg' || command === 'notgg') { client.say(channel, `!kappagen sarimoDEAD sarimoGAME`); } if(command === 'clap' || command === 'claps') { client.say(channel, `!kappagen sarimoDEAD sarimoGAME`); } if(command === 'hair' || command === 'hairflip') { client.say(channel, `!kappagen sarimoHAIR sarimoBANG`); } if(command === 'hi' || command === 'hello') { client.say(channel, `!kappagen sarimoKO sarimoNERD`); } if(command === 'hype' || command === 'train') { client.say(channel, `!kappagen sarimoHYPE sarimoBITS`); } if(command === 'salt' || command === 'shoutout') { client.say(channel, `!kappagen sarimoSALT sarimoRAGE`); } if(command === 'soup' || command === 'sup') { client.say(channel, `!kappagen sarimoSOUP sarimoTRIP `); client.say(channel, `/me Yo @${tags.username}, how goes it? Whats soup! sarimoSOUP sarimoTRIP`); } } // SUB | END // ================================ // MOD Commands // ================================ if(isModUp) { // MOD Start // Shoutout if(command === 'so' || command === 'shoutout') { client.say(channel, `/me Roll the clip! Smash @${args.join(' ')}'s follow button at: https://twitch.tv/${args.join(' ')} Bleep-Bloop!`); } if(command === 'default' || command === 'sariboto') { client.say(channel, `/color #31737C`); client.say(channel, `/emoteonlyoff `); client.say(channel, `/followersoff `); client.say(channel, `/slowoff `); client.say(channel, `/subscribersoff `); client.say(channel, `/me Back to my original color & all chat-modes have been reset! Bleep-Bloop!`); } if(command === 'mute' || command === 'slap' || command === 'timeout' || command === 'warn') { client.say(channel, `/timeout ${args.join(' ')} 33`); } } // MOD | END }); // CHAT SCAN | END // ================================ // ================================ // ALERTS START // ================================ // client.on("action", (channel, userstate, message, self) => { // // Don't listen to my own messages.. // if (self) return; // console.log('LOG: Action '); // }); // import { ttv_alerts } from "./alerts.js"; // ttv_alerts(); // SUB | Anon => Paid // -------------------------------- client.on("anongiftpaidupgrade", (channel, username, userstate) => { console.log('HYPE | @'.green+ username.yellow, 'just upgraded their Anon-Gift-Sub => PAID! Userstate?', userstate.yellow); client.say(channel, `Legit, @`+ username, `just upgraded their Anon-Gift-Sub to a paid sub! Thanks for the support, I feel like a real boy!`); }); // MOD | Ban // -------------------------------- client.on("ban", (channel, username, reason, userstate) => { console.log('MOD-LOG: @'.brightRed+ username.yellow, 'was banned for:'.brightRed, reason.yellow); client.say(channel, `/me BYE FELICIA!!! Critical hit from the MODs Ban-Hammer attack!`); client.say(channel, `!kappagen BOP BOP BOP `); }); // client.on("chat", (channel, userstate, message, self) => { // // Don't listen to my own messages.. // if (self) return; // // Do your stuff. // console.log('LOG: Chat'); // }); // HYPE | Bits / Cheer // -------------------------------- client.on("cheer", (channel, userstate, message) => { console.log('HYPE |'.green, userstate.yellow, 'with msg of'.green, message.yellow) if (message !== null){ client.say(channel, `/me HYPE! Bits = Boto-fuel! Thanx for the support! I also found this message in a bottle "`+ message, `".`); client.say(channel, `!kappagen sarimoHYPE sarimoBITS`); } else { client.say(channel, `/me HYPE!!! Bits = Boto fuel! Thanx for the support!`); client.say(channel, `!kappagen sarimoHYPE sarimoBITS`); } }); // CHAT | Chat-Mode | Cleared // -------------------------------- client.on("clearchat", (channel) => { console.log('LOG | Chat was cleared!'.brightRed) client.say(channel, `Chat Rule Reminder`); client.say(channel, `/me 1. Do NOT feed the Trolls!`); client.say(channel, `/me 2. Do NOT be a Troll!`); client.say(channel, `/me 3. Do NOT be another brick in the wall!`); }); // DUPE | Connected & Connecting already logged in TMI // -------------------------------- client.on("connected", (address, port) => { // console.log('LOG | Connected @'.green, address.yellow, 'on port'.green, port); }); client.on("connecting", (address, port) => { // console.log('LOG | Connecting @'.green, address.yellow, 'on port'.green, port); }); // LOGS | Dis-Connections // -------------------------------- client.on("disconnected", (reason) => { console.log('LOG |'.brightRed, reason.yellow, 'caused a disconnection...'.brightRed); }); // CHAT | Chat-Mode | Emote only // -------------------------------- client.on("emoteonly", (channel, enabled) => { console.log('CHAT MODE: Emotes Only '); }); // client.on("emotesets", (sets, obj) => { // // Here are the emotes I can use: // console.log('Emote Sets: IDK WHAT TO DO WITH THESE '); // console.log(obj); // }); // CHAT | Chat-Mode | Followers // -------------------------------- client.on("followersonly", (channel, enabled, length) => { console.log('CHAT MOD: Followers only enabled!'); }); // SUB | Gift => Paid // -------------------------------- client.on("giftpaidupgrade", (channel, username, sender, userstate) => { console.log('LOG: Gift-Sub UPGRADED to a real full blown sub! '); }); // HYPE | Hosted // -------------------------------- client.on("hosted", (channel, username, viewers, autohost) => { console.log('LOG: TYVM! For the host!'); client.say(channel, `/me TYVM @`+ username, `we may take your viewership of`, viewers+ `, but we'll never take their FREEDOM!!! sarimoFREEDOM`); client.say(channel, `!kappagen sarimoHYPE sarimoLURK`); }); // HYPE | Hosting // -------------------------------- client.on("hosting", (channel, target, viewers) => { console.log('HYPE | Logging into'.yellow, 'Twitch TV'.brightBlue); // HYPE | Hosting client.say(channel, `/me Stick around as we host @`+ target, `they may take our viewership of`, viewers +`, but we'll never take their FREEDOM!!! sarimoFREEDOM`); client.say(channel, `!kappagen sarimoNERD sarimoKO`); }); // CHAT | User Joined // -------------------------------- client.on("join", (channel, username, self) => { console.log('LOG |'.black.bgBrightGreen, username.black.bgYellow, 'joined the chat!'.black.bgBrightGreen); client.say(channel, `!kappagen sarimoKO sarimoSOUP sarimoLURK New lurker, your secret is safe with me!`) //if(username === 'sarimoko') { // client.say(channel, `/me @`+ username +`, entered his own chat... Caught you lurking yourself! sarimoNERD sarimoDUDE`); //} //if(username === 'cho0tem') { // client.say(channel, `/me Yo @`+ username +`, wb to chat! sarimoSOUP sarimoTRIP`); //} }); // DUPE // -------------------------------- client.on("logon", () => { // console.log('LOG | Logging into'.yellow, 'Twitch TV'.brightBlue); }); // ??? // -------------------------------- // client.on("message", (channel, userstate, message, self) => { // // Don't listen to my own messages.. // if (self) return; // // // Handle different message types.. // switch(userstate["message-type"]) { // case "action": // // This is an action message.. // break; // case "chat": // // This is a chat message.. // break; // case "whisper": // // This is a whisper.. // break; // default: // // Something else ? // break; // } // }); // MODS | Chat Message Deleted / Removed // -------------------------------- client.on("messagedeleted", (channel, username, deletedMessage, userstate) => { console.log('LOG | Deleted MSG'.brightRed); }); // MOD | Added to MOD List // -------------------------------- client.on("mod", (channel, username) => { console.log('LOG |'.brightRed, username.yellow, 'was added as a MOD'.brightRed); }); // CHAT | Mods List // -------------------------------- client.on("mods", (channel, mods) => { console.log('LOG: Mod?'.yellow, mods); }); // ??? // -------------------------------- //client.on("notice", (channel, msgid, message) => { // console.log('LOG: Notice? '.yellow, msgid, message); //}); // CHAT | User left // -------------------------------- client.on("part", (channel, username, self) => { console.log('LOG:'.black.bgBrightRed, username.black.Yellow, 'left the chat...'.black.bgBrightRed); // client.say(channel, `/me -1 Chatter! Where's my bounty hunters? Essemble the *air-qoutes* search-party *air-qoutes*`); }); // ANNOYING // -------------------------------- //client.on("ping", () => {}); //client.on("pong", (latency) => {}); // client.on("r9kbeta", (channel, enabled) => { // console.log('r9kbeta? '); // }); // HYPE | Incoming Raid // -------------------------------- client.on("raided", (channel, username, viewers) => { client.say(channel, `/me TYVM @`+ username, `we may take your viewership of`, viewers+`, but we'll never take their FREEDOM!!! sarimoFREEDOM`); client.say(channel, `!kappagen sarimoRAID sarimoFREEDOM sarimoKO`); }); // ??? // -------------------------------- // client.on("raw_message", (messageCloned, message) => { // console.log(message.raw); // }); // LOG | Reconnecting // -------------------------------- client.on("reconnect", () => { console.log('Re-Connecting...'.green); }); // SUB | Re-Sub // -------------------------------- client.on("resub", function (channel, username, months, message, userstate, methods) { client.say(channel, `/me BLEEP! BLOOP! Legend re-sub! Thanks for your continued support!`); client.say(channel, `!kappagen sarimoHYPE sarimoKO`); }); // ??? // -------------------------------- // client.on("roomstate", (channel, state) => { // console.log('LOG: Roomstate '); // }); // ??? // -------------------------------- client.on("serverchange", (channel) => { console.log('LOG | Server changed to:'.brightRed, channel); }); // CHAT | Chat-Mode | Slow // -------------------------------- client.on("slowmode", (channel, enabled, length) => { console.log('CHAT MODE: Slow Mode enabled! '); client.say(channel, `CHAT-MODE: Slow`); }); // SUB | Gift-Sub // -------------------------------- client.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => { let senderCount = ~~userstate["msg-param-sender-count"]; // IDK console.log(username.yellow, `Gift-Subbed to`.brightBlue, recipient.yellow,`methods`.brightBlue, methods.yellow,`streak`.brightBlue, streakMonths.yellow); // HYPE | Gift Sub client.say(channel, `/me Wow @`+ username, `just gifted @`+ recipient, `a sub! SPAM those emotes!`); client.say(channel, `!kappagen sarimoKO sarimoNERD`); }); // SUB | Anon Gift-Sub // -------------------------------- client.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => { let senderCount = ~~userstate["msg-param-sender-count"]; // IDK console.log(username.yellow, `Username`.brightBlue, username.yellow,`methods`.brightBlue, methods.yellow,`userstate`.brightBlue, userstate.yellow); client.say(channel, `/me Shit, @Anon just gifted`, numbOfSubs, `am I getting hacked?! If I get erased... I love you all! Bleep-Bloop!`); }); // CHAT | Chat-Mode | Subs // -------------------------------- client.on("subscribers", (channel, enabled) => { console.log('LOG | CHAT MODE | Sub-Only is'.brightRed, eneabled.yellow); client.say(channel, `CHAT| Subscribers mode:`, enabled); }); // SUB | Subscriber // -------------------------------- client.on("subscription", function (channel, username, method, message, userstate) { client.say(channel, `/me BLEEP! BLOOP! New subscriber! Spam your new emotes!!! Let's see you're fav!`); client.say(channel, `!kappagen sarimoKO sarimoNERD`); }); // MOD | Timeout // -------------------------------- client.on("timeout", (channel, username, reason, duration, userstate) => { console.log(`MOD-LOG | Timeout @`+ username, `for`, duration, `seconds for the reason of:`, reason); console.log(`MOD-LOG | @`+ username, `is a `, userstate, `status!`); client.say(channel, `Mods have spoken! @`+ username +`, please take these `+ duration +` seconds to cooldown! Enjoy your lurk, talk to you soon!`); client.say(channel, `!kappagen sarimoSALT sarimoRAGE`); }); // HYPE | Un-Host // -------------------------------- client.on("unhost", (channel, viewers) => { client.say(channel, `/me @Sarimoko has turned if hosting, please standby for further instruction!`); }); // MOD | Un-Modded // -------------------------------- client.on("unmod", (channel, username) => { console.log(`@`+ username, `was UN-MODDED!`); client.say(channel, `Huge thanx to @`+ username +` for their time on the mods squad! We hope you enjoy your retirement as a viewer! sarimoKO sarimoDUDE`); }); // VIPs // -------------------------------- client.on("vips", (channel, vips) => { console.log(`LOG VIPS`+ vips); client.say(channel, `@Sarimoko is fortunate to have many great viewers but these VIPs are a few specifically to thank!`); }); // DM / Whispers // -------------------------------- client.on("whisper", (from, userstate, message, self) => { if (self) return; console.log('DM | From:'.green, from, userstate, 'MSG:'.green, message); client.say(channel, `/me [+1] Inbox | Received a new SEXT message from: @`+ from +`!`); }); // ALERTS STOP // ================================