Commit 00cf7da469a824c4d1823a3cdac4a337c297f61a
1 parent
c0f8694117
Exists in
master
quick bugfix
Showing 1 changed file with 0 additions and 8 deletions Inline Diff
adaptor-ym.js
1 | var YM = require('yahoomessenger'); | 1 | var YM = require('yahoomessenger'); |
2 | 2 | ||
3 | var username; | 3 | var username; |
4 | var password; | 4 | var password; |
5 | 5 | ||
6 | var callbacks; | 6 | var callbacks; |
7 | 7 | ||
8 | function onReady() { | 8 | function onReady() { |
9 | var _username = username; | ||
10 | var _password = password; | ||
11 | |||
12 | if (!_username || !_password) { | ||
13 | logger.warn('Undefined YM username and password') | ||
14 | process.exit(5); | ||
15 | } | ||
16 | |||
17 | logger.info('Going to login to YM as ' + username); | 9 | logger.info('Going to login to YM as ' + username); |
18 | YM.login(username, password); | 10 | YM.login(username, password); |
19 | } | 11 | } |
20 | 12 | ||
21 | function onLoginSuccessful(data) { | 13 | function onLoginSuccessful(data) { |
22 | logger.info('YM login successful', {data: data}); | 14 | logger.info('YM login successful', {data: data}); |
23 | if (callbacks.onLoginSuccessful) { | 15 | if (callbacks.onLoginSuccessful) { |
24 | callbacks.onLoginSuccessful(); | 16 | callbacks.onLoginSuccessful(); |
25 | } | 17 | } |
26 | } | 18 | } |
27 | 19 | ||
28 | function onLoginError(data) { | 20 | function onLoginError(data) { |
29 | logger.warn('YM login error', {data: data}); | 21 | logger.warn('YM login error', {data: data}); |
30 | } | 22 | } |
31 | 23 | ||
32 | function onFriendsList(data) { | 24 | function onFriendsList(data) { |
33 | logger.verbose('Got list of friendlist', {data: data}); | 25 | logger.verbose('Got list of friendlist', {data: data}); |
34 | } | 26 | } |
35 | 27 | ||
36 | function onPM(data) { | 28 | function onPM(data) { |
37 | logger.verbose('Got a message', {data: data}) | 29 | logger.verbose('Got a message', {data: data}) |
38 | if (callbacks.onPM) { | 30 | if (callbacks.onPM) { |
39 | callbacks.onPM(data.sender, data.message); | 31 | callbacks.onPM(data.sender, data.message); |
40 | } | 32 | } |
41 | } | 33 | } |
42 | 34 | ||
43 | function onPing(data) { | 35 | function onPing(data) { |
44 | logger.verbose('Got ping', {data: data}); | 36 | logger.verbose('Got ping', {data: data}); |
45 | } | 37 | } |
46 | 38 | ||
47 | function init(_username, _password, _logger, _callbacks) { | 39 | function init(_username, _password, _logger, _callbacks) { |
48 | username = _username; | 40 | username = _username; |
49 | password = _password; | 41 | password = _password; |
50 | logger = _logger; | 42 | logger = _logger; |
51 | callbacks = _callbacks; | 43 | callbacks = _callbacks; |
52 | 44 | ||
53 | YM.on('ready', onReady); | 45 | YM.on('ready', onReady); |
54 | YM.on('loginSuccessful', onLoginSuccessful); | 46 | YM.on('loginSuccessful', onLoginSuccessful); |
55 | YM.on('loginError', onLoginError); | 47 | YM.on('loginError', onLoginError); |
56 | YM.on('friendsList', onFriendsList); | 48 | YM.on('friendsList', onFriendsList); |
57 | YM.on('pm', onPM); | 49 | YM.on('pm', onPM); |
58 | YM.on('offlinePM', onPM); | 50 | YM.on('offlinePM', onPM); |
59 | 51 | ||
60 | /* | 52 | /* |
61 | setTimeout( | 53 | setTimeout( |
62 | YM.newInstance, | 54 | YM.newInstance, |
63 | 3000 | 55 | 3000 |
64 | ) | 56 | ) |
65 | */ | 57 | */ |
66 | YM.newInstance(); | 58 | YM.newInstance(); |
67 | } | 59 | } |
68 | 60 | ||
69 | function sendMessage(destination, msg) { | 61 | function sendMessage(destination, msg) { |
70 | logger.verbose('Sending message', {from: username, destination: destination, msg: msg}); | 62 | logger.verbose('Sending message', {from: username, destination: destination, msg: msg}); |
71 | YM.sendPM(destination, msg); | 63 | YM.sendPM(destination, msg); |
72 | } | 64 | } |
73 | 65 | ||
74 | exports.init = init; | 66 | exports.init = init; |
75 | exports.sendMessage = sendMessage; | 67 | exports.sendMessage = sendMessage; |
76 | 68 |