Commit 02655b6bbbeadc4b790b1ded7f5719f9392e2642
1 parent
776e8a8525
Exists in
master
sendPM wrapper
Showing 1 changed file with 22 additions and 6 deletions Side-by-side Diff
index.js
... | ... | @@ -22,6 +22,23 @@ function isAdmin(user) { |
22 | 22 | return (admins.indexOf(user) >= 0); |
23 | 23 | } |
24 | 24 | |
25 | +function sendPM(destination, message) { | |
26 | + try { | |
27 | + logger.info("Sending to " + destination + ": " + message); | |
28 | + YahooMessenger.sendPM(destination, message); | |
29 | + } | |
30 | + catch (e) { | |
31 | + logger.info("Something wrong"); | |
32 | + logger.info(e); | |
33 | + logger.info("Try to reconnecting to yahoo messenger"); | |
34 | + YahooMessenger.login(config.yahoomessenger.username, config.yahoomessenger.password); | |
35 | + return false; | |
36 | + } | |
37 | + | |
38 | + return true; | |
39 | + | |
40 | +} | |
41 | + | |
25 | 42 | function broadcast(destinations, message, exclude) { |
26 | 43 | var destinations = destinations.split(','); |
27 | 44 | var destinationCount = destinations.length; |
... | ... | @@ -32,8 +49,7 @@ function broadcast(destinations, message, exclude) { |
32 | 49 | continue; |
33 | 50 | } |
34 | 51 | |
35 | - logger.info('Sending message to ' + destination); | |
36 | - YahooMessenger.sendPM(destination, message); | |
52 | + sendPM(destination, message); | |
37 | 53 | } |
38 | 54 | } |
39 | 55 | |
... | ... | @@ -44,8 +60,8 @@ var _keepAliveLoop = function() { |
44 | 60 | YahooMessenger.keepAlive(); |
45 | 61 | } |
46 | 62 | catch(e) { |
47 | - logger.error("Something wrong"); | |
48 | - logger.error(e); | |
63 | + logger.info("Something wrong"); | |
64 | + logger.info(e); | |
49 | 65 | logger.info("Try to reconnecting to yahoo messenger"); |
50 | 66 | YahooMessenger.login(config.yahoomessenger.username, config.yahoomessenger.password); |
51 | 67 | return; |
... | ... | @@ -154,7 +170,7 @@ function onYmPM(data) { |
154 | 170 | } |
155 | 171 | |
156 | 172 | logger.info('Forward to ' + target + ': ' + messageToForward); |
157 | - YahooMessenger.sendPM(target, '@' + partner + ': ' + messageToForward); | |
173 | + sendPM(target, '@' + partner + ': ' + messageToForward); | |
158 | 174 | |
159 | 175 | } else if (message.charAt(0) == '+') { |
160 | 176 | target = message.split(' ', 1).join(); |
... | ... | @@ -166,7 +182,7 @@ function onYmPM(data) { |
166 | 182 | } |
167 | 183 | |
168 | 184 | logger.info('Clean forward to ' + target + ': ' + messageToForward); |
169 | - YahooMessenger.sendPM(target, messageToForward); | |
185 | + sendPM(target, messageToForward); | |
170 | 186 | } |
171 | 187 | |
172 | 188 | } |