Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const user = "BOT_NAME";
- const oauth = "OAUTH_HERE";
- const channels = ["#YOUR_CHANNEL"];
- const owner = "YOUR_NAME";
- const streamer = "YOUR_NAME";
- const tmi = require('tmi.js'); //Make sure to install tmi.js through npm
- var options = {
- options: {
- debug: true
- },
- connection: {
- reconnect: true
- },
- identity: {
- username: user,
- password: oauth
- },
- channels: channels
- };
- var bot = new tmi.client(options);
- bot.connect();
- bot.on('chat', function (channel,userstate,msg,self) {
- if (self) return;
- runTos();
- console.log(TOchannels);
- var timedout = false;
- for (var i=0;i<TOchannels.length;i++) {
- if (TOchannels[i].channelTag == channel) {
- TOchannels[i].to(userstate.username);
- timedout = true;
- }
- }
- if (!timedout) {
- if (startsWith(msg.toLowerCase(),"!tomychat")) {
- var args = [];
- args.push(userstate.username);
- args.push(channel);
- var splitMsg = msg.split(" ");
- for (j=1;j<splitMsg.length;j=j+1) {
- args.push(splitMsg[j]);
- }
- toMyChat(args);
- }
- }
- });
- function startsWith(msg,word,reqPre) {
- var splitMsg = msg.split(" ");
- if (reqPre == true) {
- if (splitMsg[0] == configuration.prefix+word) {
- return true;
- } else {
- return false;
- }
- } else {
- if (splitMsg[0] == word) {
- return true;
- } else {
- return false;
- }
- }
- }
- TOchannels = [];
- function runTos() {
- for (var i=0;i<TOchannels.length;i++) {
- TOchannels[i].tick();
- }
- }
- function toMyChat(args) {
- var user = args[0];
- var channel = args[1];
- var target = args[2];
- if (!target.match(`[0-9]`)) {
- bot.say(channel,"Please include a number of minutes for me to be in your chat, and time out people for (will be the same number) SYNTAX: !tomychat <minutes>");
- return;
- }
- bot.say(channel,"Make sure I'm modded in your channel!");
- TOchannels.push(new Channel(user,target,target));
- }
- function Channel(username,minsToStay,TOmins) {
- bot.join("#"+username);
- console.log('Joined #'+username);
- this.stayTime = minsToStay*1000*60;
- this.toTime = TOmins*60;
- this.initTime = Date.now();
- this.channelTag = "#"+username;
- this.channelName = username;
- this.tick = function() {
- if (Date.now() >= this.initTime+this.stayTime) {
- bot.say(this.channelTag,"Seeya, hope I helped! If the problem persists, please have me re-join!");
- if (this.channelName != "kd8lvt") {
- bot.leave(this.channelTag);
- }
- for (var i=0;i<TOchannels.length;i++) {
- if (TOchannels[i].channelName == this.channelName) {
- TOchannels = TOchannels.splice(i,0);
- }
- }
- }
- }
- this.to = function(username) {
- console.log(username);
- bot.timeout(this.channelTag,username,this.toTime);
- console.log('Timing out '+username);
- }
- this.timeout = this.to;
- this.run = this.tick;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement