Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const BeamClient = require('beam-client-node')
- const BeamSocket = require('beam-client-node/lib/ws')
- let userInfo;
- const client = new BeamClient();
- const creds = require('./creds.js');
- client.use('password', {
- username: creds.username,
- password: creds.password
- })
- .attempt()
- .then(response => {
- console.log(response.body)
- // Store the logged in user's details for later secret eating
- userInfo = response.body;
- // Returns a promise that resolves with our chat connection details.
- return client.chat.join(161609);
- })
- .then(response => {
- const body = response.body;
- // console.log(body)
- // connect 2 chat
- createChatSocket (userInfo.id, 161609, body.endpoints, body.authkey);
- // console.log (userInfo.channel.id);
- })
- .catch(error => {
- console.log(':127', error);
- });
- function createChatSocket (userId, ChannelId, endpoints, authkey) {
- const socket = new BeamSocket(endpoints).boot();
- socket.auth(ChannelId, userId, authkey)
- .then(() => {
- console.log('You are now authenticated!');
- return socket.call('msg', ['\\ :phoneW / _.-{ ViewBot OnLiNe ]-._ \\ :phoneW /']);
- })
- .catch(error => {
- console.log('not gucci fam');
- console.log(data);
- console.log(data.message);
- });
- socket.on('error', error => {
- console.error ('Socket error', error);
- });
- socket.on('ChatMessage', data => {
- // start dev here
- // socket.call('msg', [':pQuack'])
- let from = data.user_name;
- let txt = data.message.message[0].text;
- let args = txt.split(' ');
- if(txt[0] == '!'){
- // console.log('cmd:' + txt);
- let cmd = txt.substr(1);
- //cmds[cmd](socket, args);
- if(typeof cmds[cmd] === 'function'){
- cmds[cmd](socket,args);
- };
- }
- //if(data.message.message[1].text == ':phoneW'){
- //return socket.call('msg', [' \\ :pQuack /']);
- //}
- // end of dev
- console.log(data.message.message);
- });
- }
- let buttTouches = 0;
- let cmds = {
- quack: socket=>{ socket.call('msg', [':pQuack']);},
- so: (socket, data) => { socket.call('msg', ['Give ' + data.message.message[1].text + ' a follow!']);},
- time: socket=>{ socket.call('msg', ['time is : ' + new Date() ]);},
- butt: (socket,data)=>{
- buttTouches++;
- let response = ''; if (buttTouches%12==0 && buttTouches != 0) {
- response = buttTouches/12 + ' dozen butts'; }
- else { response = (buttTouches == 0 ? 'no' : buttTouches) + ' butt' + (buttTouches == 1 ? '' : 's'); }
- socket.call('msg', [ '@Myrathi has touched ' + response] );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement