diff --git a/node/boto.js b/node/boto.js index 4a3d061..62c6cd0 100644 --- a/node/boto.js +++ b/node/boto.js @@ -17,6 +17,51 @@ const client = new tmi.Client({ channels: [ process.env.TTV_CHANNELS ] }); +// RNG User + const rp = require('request-promise'); // For RNG + 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)]; + }); + } +} + client.connect(); // ALERTS START @@ -78,6 +123,8 @@ client.on("connected", (address, 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); }); @@ -133,6 +180,8 @@ client.on("join", (channel, username, self) => { 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; @@ -153,15 +202,23 @@ client.on("logon", () => { // 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); }); @@ -171,28 +228,42 @@ client.on("part", (channel, username, self) => { console.log('LOG:'.brightRed, username.yellow, 'left the chat...'.brightRed); // 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); + 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); }); @@ -202,6 +273,8 @@ 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); @@ -209,15 +282,21 @@ client.on("subgift", (channel, username, streakMonths, recipient, methods, users 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`); @@ -230,17 +309,25 @@ client.on("timeout", (channel, username, reason, duration, userstate) => { 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) => { - client.say(channel, `Oof, modship`); + 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); @@ -248,3 +335,33 @@ client.on("whisper", (from, userstate, message, self) => { }); // ALERTS STOP // ================================ + +client.on('message', (channel, tags, message, self) => { + if(self) 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 + 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)); + } + +}); \ No newline at end of file