Advertisement
Guest User

soles sits

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. const Mixer = require('@mixer/client-node');
  2. const ws = require('ws');
  3. const config = require('./config.json')
  4.  
  5. const botUserName = process.argv[2]
  6. const channelName = process.argv[3]
  7.  
  8. let userInfo;
  9.  
  10. const client = new Mixer.Client(new Mixer.DefaultRequestRunner());
  11.  
  12. if (botUserName === 'me') {
  13. client.use(new Mixer.OAuthProvider(client, {
  14. tokens: {
  15. access: config.token.mackem_dan,
  16. expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
  17. },
  18. }));
  19.  
  20. } else if (botUserName === 'm2d2') {
  21.  
  22. client.use(new Mixer.OAuthProvider(client, {
  23. tokens: {
  24. access: config.token.m2d2,
  25. expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
  26. },
  27. }));
  28.  
  29. } else if (botUserName === 'sole') {
  30.  
  31. client.use(new Mixer.OAuthProvider(client, {
  32. tokens: {
  33. access: config.token.sole,
  34. expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
  35. },
  36. }));
  37.  
  38. } else {
  39. console.log('account not defined ending')
  40. process.exit()
  41. }
  42.  
  43. client.request('GET', `channels/${channelName}`)
  44. .then(res => {
  45. const user2ID = res.body.id;
  46. client.request('GET', 'users/current')
  47. .then(response => {
  48. userInfo = response.body;
  49. return new Mixer.ChatService(client).join(user2ID);
  50. })
  51. .then(response => {
  52. const body = response.body;
  53. return createChatSocket(userInfo.id, user2ID, body.endpoints, body.authkey);
  54. })
  55. .catch(error => {
  56. console.error('Something went wrong.');
  57. console.error(error);
  58. });
  59. })
  60. .catch(error => {
  61. console.log('Check User Name');
  62. console.log(error)
  63. });
  64.  
  65.  
  66. function createChatSocket(userId, channelId, endpoints, authkey) {
  67. // Chat connection
  68. const socket = new Mixer.Socket(ws, endpoints).boot();
  69.  
  70. // socket.on('ChatMessage', data => {
  71. // console.log(data.message);
  72. // })
  73.  
  74. socket.on('ChatMessage', data => {
  75. if (data.message.message[0].text.toLowerCase().startsWith('?party')) {
  76. socket.call('msg', ["o//"]);
  77. setTimeout(() => {
  78. socket.call('msg', ["\\\\o"]);
  79. setTimeout(() => {
  80. socket.call('msg', ["o//"]);
  81. setTimeout(() => {
  82. socket.call('msg', ['\\\\o']);
  83. setTimeout(() => {
  84. socket.call('msg', ["o//"]);
  85. setTimeout(() => {
  86. socket.call('msg', ["\\\\o"]);
  87. }, (1000))
  88. }, (1000))
  89. }, (1000))
  90. }, (1000))
  91. }, (1000))
  92. }
  93. });
  94.  
  95. socket.on('ChatMessage', data => {
  96. if (data.message.message[0].text.toLowerCase().startsWith('?m2d2')) {
  97. socket.call('msg', ["@M2D2 is a custom bot made my @Mackem_Dan this is a bot that is still in development"])
  98. console.log(`${data.user_name} is ${data.user_level} and ${data.user_roles} and ${data.id}`)
  99. }
  100. });
  101.  
  102. socket.on('ChatMessage', data => {
  103. if (data.message.message[0].text.toLowerCase().startsWith('?kill')) {
  104. if (data.user_roles = "Mod") {
  105. socket.call('msg', ['Bot is going offline bye bye'])
  106. console.log(`${data.user_name} has closed the bot`)
  107. setTimeout(() => {
  108. process.exit()
  109. }, 2000)
  110. } else if (data.user_roles === 'Owner') {
  111. socket.call('msg', ['Bot is going offline bye bye'])
  112. console.log(`${data.user_name} has closed the bot`)
  113. setTimeout(() => {
  114. process.exit()
  115. }, 2000)
  116. } else {
  117. socket.call('msg', [`@${data.user_name} You are not authorised to do that`])
  118. console.log(`${data.user_name} has tried to turn off the bot`)
  119. }
  120. }
  121. });
  122.  
  123. socket.on('ChatMessage', data => {
  124. if (data.message.message[0].text.toLowerCase().startsWith('?sobad')) {
  125. if (botUserName === 'me') {
  126. socket.call('msg', [':bad :shirobring :boi'])
  127. console.log(`${data.user_name} requested so bad,bringit `)
  128. } else {
  129. socket.call('msg', ['So bad bring it boi ;) '])
  130. console.log(`${data.user_name} requested so bad,bringit `)
  131. }
  132. }
  133. });
  134.  
  135. // Handle errors
  136. socket.on('error', error => {
  137. console.error('Socket error');
  138. console.error(error);
  139. });
  140.  
  141. return socket.auth(channelId, userId, authkey)
  142. .then(() => {
  143. console.log('Login successful');
  144. if (botUserName === 'me') {
  145. return socket.call('msg', [':howdy']);
  146. } else {
  147. return socket.call('msg', ['Hi']);
  148. }
  149. });
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement