MetaMarkTea

Untitled

Jan 6th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1.  
  2. const tmi = require('tmi.js');
  3.  
  4. const client = new tmi.Client({
  5. options: {debug: true},
  6. connection: {
  7. secure: true,
  8. reconnect: true
  9. },
  10. identity: {
  11. username: 'metamarktea',
  12. password: process.env.TWITCH_OAUTH_TOKEN
  13. },
  14. channels: ['eroaxee']
  15. });
  16.  
  17. // Register our event handlers (defined below)
  18. client.on('message', onMessageHandler);
  19. client.on('connected', onConnectedHandler);
  20.  
  21. // Connect to Twitch:
  22. client.connect();
  23.  
  24. // Called every time a message comes in
  25. function onMessageHandler(target, context, msg, self)
  26. {
  27. if (self) {return;} // Ignore messages from the bot
  28.  
  29. // Remove whitespace from chat message
  30. const commandName = msg.trim();
  31.  
  32. var parts = commandName.split(" ");
  33. var command = parts[0];
  34.  
  35.  
  36. if (command === '!char')
  37. {
  38. client.say(client.channels[0], 'Char\'s stream is at: https://www.twitch.tv/ch4rrq');
  39. }
  40.  
  41.  
  42. if (command === '!game')
  43. {
  44. client.say(client.channels[0], 'Our game is at: https://ldjam.com/events/ludum-dare/48/aye-aye-captain');
  45. }
  46.  
  47. if (command === '!bet' )
  48. {
  49. client.say(target, Date.now() + `${context["display-name"]} bet ${parts[1]}`);
  50. console.log(`* Executed ${commandName} command`);
  51. }
  52.  
  53. // If the command is known, let's execute it
  54. if (command === '!dice' || command === '!roll')
  55. {
  56. var sides = 64;
  57.  
  58. if (parts[1]){
  59. sides = parseInt(parts[1]);
  60. }
  61.  
  62. const num = rollDice(sides);
  63. client.say(target, Date.now() + `You rolled a ${num}`);
  64. console.log(`* Executed ${commandName} command`);
  65. } else
  66. {
  67. console.log(`* Unknown command ${commandName}`);
  68. }
  69.  
  70.  
  71. }
  72.  
  73. // Function called when the "dice" command is issued
  74. function rollDice(sides)
  75. {
  76. return Math.floor(Math.random() * sides) + 1;
  77. }
  78.  
  79. // Called every time the bot connects to Twitch chat
  80. function onConnectedHandler(addr, port)
  81. {
  82. console.log(`* Connected to ${addr}:${port}`);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment