Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const tmi = require('tmi.js');
  2. require('dotenv').config();
  3.  
  4. const options = {
  5. options: {
  6. debug: true
  7. },
  8. identity: {
  9. username: process.env.OAUTH_USERNAME,
  10. password: process.env.OAUTH_PASSWORD
  11. },
  12. connection: {
  13. reconnect: true
  14. },
  15. channels: [`instak`]
  16. };
  17.  
  18. const client = new tmi.client(options);
  19.  
  20. client.on(`chat`, (channel, userstate, message/*, self */) => {
  21. console.log(userstate.username); //This logs my userstate, I can see the username which is passed on correctly.
  22. switch (message) {
  23. case `!kluiten`:
  24. fetch(`http://localhost:8000/api/users/${userstate.username}`) // fetch from Express.js server
  25. .then(response => response.json())
  26. .then(result => {
  27. console.log(`USERSTATE IS`, userstate);
  28. client.action(channel, `${userstate[`display-name`]}, you've got ${result.instakluiten} instakluiten.`);
  29. });
  30. break;
  31. default:
  32. break;
  33. }
  34. });
  35.  
  36. // Connect the client to the server..
  37. client.connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement