Boto/node/boto.js

602 lines
24 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
// TODO
// Filter | Buy followers, primes and viewers on
// 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 === 'Botisimo') return;
if(tags.username === 'Fossabot') return;
if(tags.username === 'moobot') return;
if(tags.username === 'nightbot') return;
if(tags.username === 'OWN3D') return;
if(tags.username === 'streamelements') return;
if(tags.username === 'streamlabs') return;
if(tags.username === 'Wizebot') 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 isVIP = badges.vip; // Define Mod
const botUserState = client.userstate[channel]; // MOD Status Check
const amMod = botUserState !== undefined && botUserState.mod === true; // Define Mod Status
const percent = Math.floor(Math.random() * 100) + 1; //RNG Percentages%
if(self || !message.startsWith('!')) return; // Command Parser
const args = message.slice(1).split(' ');
const command = args.shift().toLowerCase(); // !COMMAND => command
// ================================
// Chatbot Commands
// ================================
// RNG User
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));
}
// Simp
if (command === 'simp') {
// 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}, no one in chat to simp on! #smallstreamerproblems`);
}
else {
let { name, type } = user;
client.say(channel, `/me @${tags.username}'s simp meter for @${name} is now ${percent}%!`);
}
})
.catch(err => console.log('[ERR]', err));
}
// RNGesus
if (command === 'cult' ||
command === 'rngesus') {
// 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}, no one in chat to simp on! #smallstreamerproblems`);
}
else {
let { name, type } = user;
// const percent = Math.floor(Math.random() * 100) + 1;
client.say(channel, `/me Sorry @${tags.username} but RNGesus favors @${name} offering ${percent}% more!`);
}
})
.catch(err => console.log('[ERR]', err));
}
// CMD | Dice Roll 4/6/8/9/12/20
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 `)
}
// 420 California
if (command === 'cali' ||
command === 'california' ||
command === 'californication' ||
command === '420' ||
command === '710' ||
command === '1130' ||
command === 'dab' ||
command === 'dab30' ||
command === 'roach' ||
command === 'roach30' ||
command === 'bowl' ||
command === 'bowl30' ||
command === 'weed' ||
command === 'dabs' ||
command === 'crumble' ||
command === 'shatter' ||
command === 'oil' ||
command === 'marijuana' ||
command === 'canabis' ||
command === 'reefer' ||
command === 'cronic' ||
command === 'wackytobacy' ||
command === 'edibles' ||
command === 'tincture' ||
command === 'tinctures' ||
command === 'hash' ||
command === 'cheech' ||
command === 'chong') {
client.say(channel, `/me "I hate to advocate drugs, alcohol, violence, or insanity to anyone, but they've always worked for me." - Hunter S. Thompson`);
client.say(channel, `/me The Sarimoko Show is an adults only channel based in California where we've passed Prop 64: Adult Use of Marijuana Act.`);
client.say(channel, `/me Marijuana and Cannabis is not for everyone, please seek a professional for further guidance on THC and CBD use.`);
}
// CMD | Lurk
if(command === 'lurk' ||
command === 'lurkin' ||
command === 'lurking') {
client.say(channel, `/me Thanks @${tags.username} for your viewership! Lurk on! sarimoLURKbrb sarimoLURK`);
}
// CMD | Raid
if(command === 'raid' ||
command === 'riad' ||
command === 'raidcall') {
client.say(channel, `/me Copy'n'Paste the following:`);
client.say(channel, `sarimoRAID sarimoFREEDOM You may take us viewers, but you'll NEVER take our FREEDOM!`);
}
// ================================
// 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`)
}
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` ||
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, `/color ${args.join(' ')}`);
client.say(channel, `/me @${tags.username} has changed my color to ${args.join(' ')}... Welp, alright!`);
}
}
// FX | K A P P A G E N S
if(command === 'bg' ||
command === 'notgg' ||
command === 'rip') {
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
// ================================
// ================================
// CHANNEL POINT REWARDS START
// ================================
//var jokes = [
// "Two bytes meet. The first byte asks, “Are you ill?” +
// "The second byte replies, “No, just feeling a bit off.”",
// "How many programmers does it take to change a light bulb?" +
// "None Its a hardware problem",
// "Debugging: Removing the needles from the haystack."
//];
//client.on('message', (channel, context, message, self) => {
// if (context["custom-reward-id"] === "YOUR-REWARD-ID") {
// client.say(channel, jokes[Math.floor(Math.random() * jokes.length)]);
// }
//}
// ================================
// 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!!! MODs used Ban-Hammer attack on `+ username +` and CRITICAL HIT!`);
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.say(channel, `/me CHAT| Emote Only Mode:`, enabled);
});
// 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!');
client.say(channel, `/me CHAT| Followers Only Mode:`, 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);
//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);
client.say(channel, `/me 404 | Error | @`+ username +`'s message NOT found!`);
client.say(channel, `I eat trolls like your for breakfast... Feed me Seymour!`);
});
// MOD | Added to MOD List
// --------------------------------
client.on("mod", (channel, username) => {
console.log('LOG |'.brightRed, username.yellow, 'was added as a MOD'.brightRed);
client.say(channel, `/me @` + username + ` was added to The Mods!`);
client.say(channel, `You're not after my job are you?! I have tenor...`);
});
// CHAT | Mods List
// --------------------------------
client.on("mods", (channel, mods) => {
console.log('LOG: Mod?'.yellow, mods);
client.say(channel, `/me The Mods: `+ 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) => {
if (viewers === 0 || viewers === 1) {
client.say(channel, `!kappagen sarimoRAID sarimoFREEDOM sarimoKO`);
} else {
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 HYPE! TYVM @`+ username +` for re-subbing for `+ months +` months now!`);
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, `/me CHAT| Slow Mode:`, enabled);
});
// 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, `/me CHAT| Subscribers Only 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
// ================================