2022-02-09 06:55:26 +00:00
require ( 'dotenv' ) . config ( ) ;
2022-02-11 10:44:16 +00:00
const tmi = require ( 'tmi.js' ) ;
2022-02-13 14:27:53 +00:00
const colors = require ( 'colors' ) ;
2022-02-09 06:55:26 +00:00
2022-02-14 23:09:16 +00:00
console . log ( colors . green . underline ( process . env . API _HOST ) ) ;
2022-02-09 06:55:26 +00:00
2022-02-14 22:15:21 +00:00
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 ]
} ) ;
2022-02-09 06:55:26 +00:00
2022-02-14 23:52:11 +00:00
client . connect ( ) ;
2022-02-14 23:44:27 +00:00
2022-02-14 23:52:11 +00:00
// 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 ;
} )
2022-02-14 23:44:27 +00:00
}
2022-02-14 23:52:11 +00:00
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 . 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 ) ) ;
}
2022-02-09 06:55:26 +00:00
2022-02-14 23:52:11 +00:00
} ) ;
2022-02-14 22:21:03 +00:00
// ALERTS START
2022-02-14 22:46:18 +00:00
// ================================
// --------------------------------
2022-02-14 22:21:03 +00:00
// 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();
2022-02-14 22:46:18 +00:00
// SUB | Anon => Paid
// --------------------------------
2022-02-14 22:21:03 +00:00
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! ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// MOD | Ban
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "ban" , ( channel , username , reason , userstate ) => {
2022-02-14 22:46:18 +00:00
console . log ( 'MOD-LOG: @' . brightRed + username . yellow , 'was banned for:' . brightRed , reason . yellow ) ;
2022-02-14 22:21:03 +00:00
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');
// });
2022-02-14 22:46:18 +00:00
// HYPE | Bits / Cheer
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "cheer" , ( channel , userstate , message ) => {
2022-02-14 22:46:18 +00:00
console . log ( 'HYPE |' . green , userstate . yellow , 'with msg of' . green , message . yellow )
2022-02-14 22:21:03 +00:00
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 ` ) ;
}
} ) ;
2022-02-14 22:46:18 +00:00
// CHAT | Chat-Mode | Cleared
// --------------------------------
2022-02-14 22:21:03 +00:00
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! ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// DUPE | Connected & Connecting already logged in TMI
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "connected" , ( address , port ) => {
2022-02-14 22:46:18 +00:00
// console.log('LOG | Connected @'.green, address.yellow, 'on port'.green, port);
2022-02-14 22:21:03 +00:00
} ) ;
client . on ( "connecting" , ( address , port ) => {
2022-02-14 22:46:18 +00:00
// console.log('LOG | Connecting @'.green, address.yellow, 'on port'.green, port);
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 23:44:27 +00:00
// LOGS | Dis-Connections
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "disconnected" , ( reason ) => {
console . log ( 'LOG |' . brightRed , reason . yellow , 'caused a disconnection...' . brightRed ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// CHAT | Chat-Mode | Emote only
// --------------------------------
2022-02-14 22:21:03 +00:00
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);
// });
2022-02-14 22:46:18 +00:00
// CHAT | Chat-Mode | Followers
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "followersonly" , ( channel , enabled , length ) => {
console . log ( 'CHAT MOD: Followers only enabled!' ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// SUB | Gift => Paid
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "giftpaidupgrade" , ( channel , username , sender , userstate ) => {
console . log ( 'LOG: Gift-Sub UPGRADED to a real full blown sub! ' ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// HYPE | Hosted
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "hosted" , ( channel , username , viewers , autohost ) => {
2022-02-14 22:24:34 +00:00
console . log ( 'LOG: TYVM! For the host!' ) ;
2022-02-14 22:23:10 +00:00
client . say ( channel , ` /me TYVM @ ` + username , ` we may take your viewership of ` , viewers + ` , but we'll never take their FREEDOM!!! sarimoFREEDOM ` ) ;
2022-02-14 22:22:10 +00:00
client . say ( channel , ` !kappagen sarimoHYPE sarimoLURK ` ) ;
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 22:46:18 +00:00
// HYPE | Hosting
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "hosting" , ( channel , target , viewers ) => {
console . log ( 'HYPE | Logging into' . yellow , 'Twitch TV' . brightBlue ) ;
// HYPE | Hosting
2022-02-14 22:23:10 +00:00
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 ` ) ;
2022-02-14 22:21:03 +00:00
client . say ( channel , ` !kappagen sarimoNERD sarimoKO ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// CHAT | User Joined
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "join" , ( channel , username , self ) => {
console . log ( 'LOG |' . brightBlue , username . yellow , 'joined the chat!' . brightBlue ) ;
if ( username === 'cho0tem' ||
username === 'rusttv_com' ||
username === 'theframilyknight' ||
username === 'trip_228' ||
username === 'worgar396' ) {
client . say ( channel , ` /me Yo @ ` + username + ` , wb to chat! sarimoSOUP sarimoTRIP ` ) ;
}
} ) ;
2022-02-14 23:04:20 +00:00
// DUPE
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "logon" , ( ) => {
2022-02-14 23:04:20 +00:00
// console.log('LOG | Logging into'.yellow, 'Twitch TV'.brightBlue);
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 23:44:27 +00:00
// ???
// --------------------------------
2022-02-14 22:21:03 +00:00
// 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;
// }
// });
2022-02-14 23:44:27 +00:00
// MODS | Chat Message Deleted / Removed
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "messagedeleted" , ( channel , username , deletedMessage , userstate ) => {
console . log ( 'LOG | Deleted MSG' . brightRed ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// MOD | Added to MOD List
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "mod" , ( channel , username ) => {
console . log ( 'LOG |' . brightRed , username . yellow , 'was added as a MOD' . brightRed ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// CHAT | Mods List
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "mods" , ( channel , mods ) => {
console . log ( 'LOG: Mod?' . yellow , mods ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// ???
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "notice" , ( channel , msgid , message ) => {
console . log ( 'LOG: Notice? ' . yellow , msgid , message ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// CHAT | User left
// --------------------------------
2022-02-14 22:21:03 +00:00
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*`);
} ) ;
2022-02-14 23:44:27 +00:00
// ANNOYING
// --------------------------------
2022-02-14 22:21:03 +00:00
//client.on("ping", () => {});
//client.on("pong", (latency) => {});
// client.on("r9kbeta", (channel, enabled) => {
// console.log('r9kbeta? ');
// });
2022-02-14 23:44:27 +00:00
// HYPE | Incoming Raid
// --------------------------------
2022-02-14 22:21:03 +00:00
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 ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// ???
// --------------------------------
2022-02-14 22:21:03 +00:00
// client.on("raw_message", (messageCloned, message) => {
// console.log(message.raw);
// });
2022-02-14 23:44:27 +00:00
// LOG | Reconnecting
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "reconnect" , ( ) => {
2022-02-14 23:44:27 +00:00
console . log ( 'Re-Connecting...' . green ) ;
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 23:44:27 +00:00
// SUB | Re-Sub
// --------------------------------
2022-02-14 22:21:03 +00:00
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 ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// ???
// --------------------------------
2022-02-14 22:21:03 +00:00
// client.on("roomstate", (channel, state) => {
// console.log('LOG: Roomstate ');
// });
2022-02-14 23:44:27 +00:00
// ???
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "serverchange" , ( channel ) => {
console . log ( 'LOG | Server changed to:' . brightRed , channel ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// CHAT | Chat-Mode | Slow
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "slowmode" , ( channel , enabled , length ) => {
console . log ( 'CHAT MODE: Slow Mode enabled! ' ) ;
client . say ( channel , ` CHAT-MODE: Slow ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// SUB | Gift-Sub
// --------------------------------
2022-02-14 22:21:03 +00:00
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 ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// SUB | Anon Gift-Sub
// --------------------------------
2022-02-14 22:21:03 +00:00
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! ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// CHAT | Chat-Mode | Subs
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "subscribers" , ( channel , enabled ) => {
console . log ( 'LOG | CHAT MODE | Sub-Only is' . brightRed , eneabled . yellow ) ;
client . say ( channel , ` CHAT| Subscribers mode: ` , enabled ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// SUB | Subscriber
// --------------------------------
2022-02-14 22:21:03 +00:00
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 ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// MOD | Timeout
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "timeout" , ( channel , username , reason , duration , userstate ) => {
2022-02-14 23:04:20 +00:00
console . log ( ` MOD-LOG | Timeout @ ` + username , ` for ` , duration , ` seconds for the reason of: ` , reason ) ;
2022-02-14 23:00:23 +00:00
console . log ( ` MOD-LOG | @ ` + username , ` is a ` , userstate , ` status! ` ) ;
2022-02-14 22:55:03 +00:00
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 ` ) ;
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 23:44:27 +00:00
// HYPE | Un-Host
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "unhost" , ( channel , viewers ) => {
client . say ( channel , ` /me @Sarimoko has turned if hosting, please standby for further instruction! ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// MOD | Un-Modded
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "unmod" , ( channel , username ) => {
2022-02-14 23:44:27 +00:00
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 ` ) ;
2022-02-14 22:21:03 +00:00
} ) ;
2022-02-14 23:44:27 +00:00
// VIPs
// --------------------------------
2022-02-14 22:21:03 +00:00
client . on ( "vips" , ( channel , vips ) => {
2022-02-14 23:44:27 +00:00
console . log ( ` LOG VIPS ` + vips ) ;
2022-02-14 22:21:03 +00:00
client . say ( channel , ` @Sarimoko is fortunate to have many great viewers but these VIPs are a few specifically to thank! ` ) ;
} ) ;
2022-02-14 23:44:27 +00:00
// DM / Whispers
// --------------------------------
2022-02-14 22:21:03 +00:00
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 + ` ! ` ) ;
} ) ;
2022-02-14 22:46:18 +00:00
// ALERTS STOP
2022-02-14 23:52:11 +00:00
// ================================