Commit 4f3e91223c75ee70705de468ae640c0e12b6a349
1 parent
4aebdeed4a
Exists in
master
relay message from admin
Showing 1 changed file with 26 additions and 7 deletions Side-by-side Diff
index.js
... | ... | @@ -22,12 +22,16 @@ function isAdmin(user) { |
22 | 22 | return (admins.indexOf(user) >= 0); |
23 | 23 | } |
24 | 24 | |
25 | -function broadcast(destinations, message) { | |
25 | +function broadcast(destinations, message, exclude) { | |
26 | 26 | var destinations = destinations.split(','); |
27 | 27 | var destinationCount = destinations.length; |
28 | 28 | |
29 | 29 | for (var i=0; i < destinationCount; i++) { |
30 | - destination = destinations[i] | |
30 | + destination = destinations[i]; | |
31 | + if (destination == exclude) { | |
32 | + continue; | |
33 | + } | |
34 | + | |
31 | 35 | logger.info('Sending message to ' + destination); |
32 | 36 | YahooMessenger.sendPM(destination, message); |
33 | 37 | } |
... | ... | @@ -85,6 +89,7 @@ function onYmLoginSuccesful(data){ |
85 | 89 | } |
86 | 90 | |
87 | 91 | function onYmPM(data) { |
92 | + var direction = 'IN'; | |
88 | 93 | |
89 | 94 | if (config.globals.debug == 1) { |
90 | 95 | console.log(data); |
... | ... | @@ -100,15 +105,13 @@ function onYmPM(data) { |
100 | 105 | loggedPM = loggedPM.slice(0, 10); |
101 | 106 | } |
102 | 107 | |
103 | - direction = 'IN'; | |
104 | - | |
105 | 108 | partner = data.sender; |
106 | - if (partner = data.sender) { | |
109 | + if (partner == data.user_id) { | |
107 | 110 | partner = data.target_user; |
108 | 111 | direction = 'OUT'; |
109 | 112 | } |
110 | 113 | |
111 | - var message = striptags(data.message) | |
114 | + var message = striptags(data.message).trim(); | |
112 | 115 | |
113 | 116 | logger.info('New ' + direction + ' message from ' + data.sender + ' to ' + data.target_user + ': ' + message); |
114 | 117 | |
... | ... | @@ -129,7 +132,23 @@ function onYmPM(data) { |
129 | 132 | sentdate |
130 | 133 | ); |
131 | 134 | |
132 | - broadcast(config.yahoomessenger.report_to, '@' + data.sender + ': ' + message); | |
135 | + broadcast(config.yahoomessenger.report_to, '@' + data.sender + ': ' + message, partner); | |
136 | + | |
137 | + if ((direction == 'IN') && (isAdmin(partner))) { | |
138 | + if (message.charAt(0) == '@') { | |
139 | + target = message.split(' ', 1).join(); | |
140 | + target = target.slice(1); | |
141 | + | |
142 | + var messageToForward = message.replace('@' + target, '').trim(); | |
143 | + if (messageToForward == '') { | |
144 | + return; | |
145 | + } | |
146 | + | |
147 | + logger.info('Forward to ' + target + ': ' + messageToForward); | |
148 | + YahooMessenger.sendPM(target, '@' + partner + ': ' + messageToForward); | |
149 | + } | |
150 | + | |
151 | + } | |
133 | 152 | } |
134 | 153 | |
135 | 154 | function onYmBuddyAddRequest(data) { |