Advertisement
Guest User

thingy

a guest
Jan 27th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. const user = "BOT_NAME";
  2.  
  3. const oauth = "OAUTH_HERE";
  4. const channels = ["#YOUR_CHANNEL"];
  5. const owner = "YOUR_NAME";
  6. const streamer = "YOUR_NAME";
  7.  
  8. const tmi = require('tmi.js'); //Make sure to install tmi.js through npm
  9.  
  10. var options = {
  11. options: {
  12. debug: true
  13. },
  14. connection: {
  15. reconnect: true
  16. },
  17. identity: {
  18. username: user,
  19. password: oauth
  20. },
  21. channels: channels
  22. };
  23.  
  24. var bot = new tmi.client(options);
  25. bot.connect();
  26.  
  27. bot.on('chat', function (channel,userstate,msg,self) {
  28. if (self) return;
  29.  
  30. runTos();
  31.  
  32. console.log(TOchannels);
  33.  
  34. var timedout = false;
  35. for (var i=0;i<TOchannels.length;i++) {
  36. if (TOchannels[i].channelTag == channel) {
  37. TOchannels[i].to(userstate.username);
  38. timedout = true;
  39. }
  40. }
  41. if (!timedout) {
  42. if (startsWith(msg.toLowerCase(),"!tomychat")) {
  43.  
  44. var args = [];
  45. args.push(userstate.username);
  46. args.push(channel);
  47. var splitMsg = msg.split(" ");
  48. for (j=1;j<splitMsg.length;j=j+1) {
  49. args.push(splitMsg[j]);
  50. }
  51.  
  52. toMyChat(args);
  53. }
  54. }
  55. });
  56.  
  57. function startsWith(msg,word,reqPre) {
  58. var splitMsg = msg.split(" ");
  59. if (reqPre == true) {
  60. if (splitMsg[0] == configuration.prefix+word) {
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. } else {
  66. if (splitMsg[0] == word) {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. }
  73.  
  74. TOchannels = [];
  75.  
  76. function runTos() {
  77. for (var i=0;i<TOchannels.length;i++) {
  78. TOchannels[i].tick();
  79. }
  80. }
  81.  
  82. function toMyChat(args) {
  83. var user = args[0];
  84. var channel = args[1];
  85. var target = args[2];
  86. if (!target.match(`[0-9]`)) {
  87. 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>");
  88. return;
  89. }
  90. bot.say(channel,"Make sure I'm modded in your channel!");
  91. TOchannels.push(new Channel(user,target,target));
  92. }
  93.  
  94. function Channel(username,minsToStay,TOmins) {
  95. bot.join("#"+username);
  96. console.log('Joined #'+username);
  97. this.stayTime = minsToStay*1000*60;
  98. this.toTime = TOmins*60;
  99. this.initTime = Date.now();
  100.  
  101. this.channelTag = "#"+username;
  102. this.channelName = username;
  103.  
  104. this.tick = function() {
  105. if (Date.now() >= this.initTime+this.stayTime) {
  106. bot.say(this.channelTag,"Seeya, hope I helped! If the problem persists, please have me re-join!");
  107. if (this.channelName != "kd8lvt") {
  108. bot.leave(this.channelTag);
  109. }
  110. for (var i=0;i<TOchannels.length;i++) {
  111. if (TOchannels[i].channelName == this.channelName) {
  112. TOchannels = TOchannels.splice(i,0);
  113. }
  114. }
  115. }
  116. }
  117.  
  118. this.to = function(username) {
  119. console.log(username);
  120. bot.timeout(this.channelTag,username,this.toTime);
  121. console.log('Timing out '+username);
  122. }
  123.  
  124. this.timeout = this.to;
  125. this.run = this.tick;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement