Advertisement
phone_microwave

Untitled

Oct 23rd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. const BeamClient = require('beam-client-node')
  3. const BeamSocket = require('beam-client-node/lib/ws')
  4.  
  5. let userInfo;
  6.  
  7. const client = new BeamClient();
  8. const creds = require('./creds.js');
  9. client.use('password', {
  10.     username: creds.username,
  11.     password: creds.password
  12. })
  13. .attempt()
  14. .then(response => {
  15.     console.log(response.body)
  16.     // Store the logged in user's details for later secret eating
  17.     userInfo = response.body;
  18.     // Returns a promise that resolves with our chat connection details.
  19.     return client.chat.join(161609);
  20. })
  21. .then(response => {
  22.         const body = response.body;
  23.         // console.log(body)
  24.         // connect 2 chat
  25.         createChatSocket (userInfo.id, 161609, body.endpoints, body.authkey);
  26.  
  27.         // console.log (userInfo.channel.id);
  28. })
  29. .catch(error => {
  30.     console.log(':127', error);
  31. });
  32.  
  33. function createChatSocket (userId, ChannelId, endpoints, authkey) {
  34.     const socket = new BeamSocket(endpoints).boot();
  35.     socket.auth(ChannelId, userId, authkey)
  36.     .then(() => {
  37.         console.log('You are now authenticated!');
  38.         return socket.call('msg', ['\\ :phoneW / _.-{ ViewBot OnLiNe ]-._ \\ :phoneW /']);
  39.     })
  40.         .catch(error => {
  41.             console.log('not gucci fam');
  42.             console.log(data);
  43.             console.log(data.message);
  44.     });
  45.     socket.on('error', error => {
  46.             console.error ('Socket error', error);
  47.     });
  48. socket.on('ChatMessage', data => {
  49.     // start dev here
  50.     // socket.call('msg', [':pQuack'])
  51.     let from = data.user_name;
  52.     let txt = data.message.message[0].text;
  53.     let args = txt.split(' ');
  54.         if(txt[0] == '!'){
  55.         // console.log('cmd:' + txt);
  56.         let cmd = txt.substr(1);
  57.         //cmds[cmd](socket, args);
  58.         if(typeof cmds[cmd] === 'function'){
  59.             cmds[cmd](socket,args);
  60.           };
  61.         }
  62.     //if(data.message.message[1].text == ':phoneW'){
  63.         //return socket.call('msg', [' \\ :pQuack /']);
  64.     //}
  65.    
  66.     // end of dev
  67.     console.log(data.message.message);
  68. });
  69.  
  70.  
  71. }
  72. let buttTouches = 0;
  73. let cmds = {
  74.   quack: socket=>{ socket.call('msg', [':pQuack']);},
  75.   so: (socket, data) => { socket.call('msg', ['Give ' +  data.message.message[1].text     + ' a follow!']);},
  76.   time: socket=>{ socket.call('msg', ['time is : ' + new Date() ]);},
  77.   butt: (socket,data)=>{
  78. buttTouches++;
  79. let response = ''; if (buttTouches%12==0 && buttTouches != 0) {
  80.     response = buttTouches/12 + ' dozen butts'; }
  81.         else { response = (buttTouches == 0 ? 'no' : buttTouches) + ' butt' + (buttTouches == 1 ? '' : 's'); }
  82. socket.call('msg', [ '@Myrathi has touched ' + response] );
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement