1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.client.alerters; |
2 |
> |
package uk.org.iscream.client.alerters; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.client.*; |
6 |
< |
import uk.ac.ukc.iscream.core.*; |
7 |
< |
import uk.ac.ukc.iscream.util.*; |
8 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
9 |
< |
|
5 |
> |
import uk.org.iscream.client.*; |
6 |
> |
import uk.org.iscream.core.*; |
7 |
> |
import uk.org.iscream.util.*; |
8 |
> |
import uk.org.iscream.componentmanager.*; |
9 |
|
import java.io.*; |
10 |
|
import java.net.*; |
11 |
|
import java.util.*; |
12 |
< |
import java.text.*; |
12 |
> |
import java.text.DateFormat; |
13 |
|
|
14 |
|
/** |
15 |
|
* This Alert sends an IRC message. |
20 |
|
* @author $Author$ |
21 |
|
* @version $Id$ |
22 |
|
*/ |
23 |
< |
public class IRC__Alerter implements PluginAlerter { |
23 |
> |
public class IRC__Alerter extends AlerterSkeleton { |
24 |
|
|
25 |
|
//---FINAL ATTRIBUTES--- |
26 |
|
|
44 |
|
//---CONSTRUCTORS--- |
45 |
|
|
46 |
|
public IRC__Alerter() { |
47 |
< |
|
47 |
> |
super(); |
48 |
|
// connect to the IRC server |
49 |
|
_ircbot = new IRCBot(); |
50 |
+ |
// set it's name and start it |
51 |
+ |
_ircbot.setName("client.IRC__Alerter$IRCBot"); |
52 |
|
_ircbot.start(); |
53 |
|
_startTime = System.currentTimeMillis(); |
53 |
– |
|
54 |
|
_logger.write(toString(), Logger.SYSINIT, "IRC Alerter started"); |
55 |
|
} |
56 |
|
|
57 |
|
//---PUBLIC METHODS--- |
58 |
|
|
59 |
+ |
/** |
60 |
+ |
* Implements the abstract method from the skeleton class. |
61 |
+ |
* This method will attempt to send an alert |
62 |
+ |
* message over the IRC channel. |
63 |
+ |
* |
64 |
+ |
* @param alert the alert to send |
65 |
+ |
*/ |
66 |
|
public void sendAlert(Alert alert) { |
67 |
+ |
// sort out the message |
68 |
+ |
String alertType = Alert.alertLevels[alert.getLevel()]; |
69 |
+ |
String message; |
70 |
+ |
try { |
71 |
+ |
message = _cp.getProperty(_name, "Alerter.IRC.message"); |
72 |
+ |
} catch (PropertyNotFoundException e) { |
73 |
+ |
message = NOT_CONFIGURED; |
74 |
+ |
_logger.write(toString(), Logger.WARNING, "Alerter.IRC.message value unavailable using default of " + message); |
75 |
+ |
} |
76 |
+ |
message = processAlertMessage(message, alert); |
77 |
|
// only send alerts if we're active |
78 |
< |
if(_active) { |
79 |
< |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
80 |
< |
String levelName = cp.getProperty(_name, "Alerter.IRC.level"); |
81 |
< |
int level = StringUtils.getStringPos(levelName, Alert.alertLevels); |
82 |
< |
// only send if it's equal (or above) our level |
83 |
< |
if(((alert.getLevel() == 0) && (alert.getLastLevel() >= level)) || (alert.getLevel() >= level)) { |
84 |
< |
String alertType = Alert.alertLevels[alert.getLevel()]; |
85 |
< |
String thresholdType = Alert.thresholdLevels[alert.getThreshold()]; |
86 |
< |
// sort out the message |
70 |
< |
String message = cp.getProperty(_name, "Alerter.IRC.message"); |
71 |
< |
message = StringUtils.replaceText(message, "%level%", alertType); |
72 |
< |
message = StringUtils.replaceText(message, "%threshold%", thresholdType); |
73 |
< |
message = StringUtils.replaceText(message, "%source%", alert.getSource()); |
74 |
< |
message = StringUtils.replaceText(message, "%value%", alert.getValue()); |
75 |
< |
message = StringUtils.replaceText(message, "%thresholdValue%", alert.getThresholdValue()); |
76 |
< |
message = StringUtils.replaceText(message, "%attributeName%", alert.getAttributeName()); |
77 |
< |
message = StringUtils.replaceText(message, "%timeTillNextAlert%", getTimeString(Long.parseLong(alert.getTimeTillNextAlert()))); |
78 |
< |
|
79 |
< |
// send the message |
80 |
< |
_logger.write(toString(), Logger.DEBUG, "Sending " + _name + " at "+ alertType + " level"); |
81 |
< |
_ircbot.sendMsg(message); |
82 |
< |
_lastAlert = message; |
83 |
< |
_lastAlertTime = System.currentTimeMillis(); |
84 |
< |
_alertCount ++; |
85 |
< |
} |
78 |
> |
if(_active) { |
79 |
> |
// send the message |
80 |
> |
_logger.write(toString(), Logger.DEBUG, "Sending " + _name + " at "+ alertType + " level"); |
81 |
> |
_ircbot.sendMsg(message); |
82 |
> |
// count sent alerts |
83 |
> |
_alertCount++; |
84 |
> |
} else { |
85 |
> |
// don't send, but keep a count that we ignored it |
86 |
> |
_ignoredCount++; |
87 |
|
} |
88 |
+ |
// we'll always store the "last alert", regardless |
89 |
+ |
// of whether we actually display it or not |
90 |
+ |
_lastAlert = message; |
91 |
+ |
_lastAlertTime = System.currentTimeMillis(); |
92 |
|
} |
93 |
|
|
94 |
|
/** |
95 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
96 |
|
* method to provide clean logging (every class should have this). |
97 |
|
* |
98 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
98 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
99 |
|
* to format the toString() |
100 |
|
* |
101 |
|
* @return the name of this class and its CVS revision |
107 |
|
REVISION); |
108 |
|
} |
109 |
|
|
110 |
< |
/** |
111 |
< |
* return the String representation of what the filter does |
110 |
> |
/** |
111 |
> |
* Return the String representation of what the alerter does |
112 |
> |
* |
113 |
> |
* @return the description |
114 |
|
*/ |
115 |
|
public String getDescription(){ |
116 |
|
return DESC; |
118 |
|
|
119 |
|
//---PRIVATE METHODS--- |
120 |
|
|
114 |
– |
private String getTimeString(long time) { |
115 |
– |
String timeString = null; |
116 |
– |
if (time >= 60) { |
117 |
– |
timeString = (time / 60) + " minute(s)"; |
118 |
– |
} else if (time >= 3600) { |
119 |
– |
timeString = ((time/60) / 60) + " hour(s)"; |
120 |
– |
} else { |
121 |
– |
timeString = time + " second(s)"; |
122 |
– |
} |
123 |
– |
return timeString; |
124 |
– |
} |
125 |
– |
|
121 |
|
//---ACCESSOR/MUTATOR METHODS--- |
122 |
|
|
123 |
+ |
/** |
124 |
+ |
* Returns the "friendly" name of this class. This |
125 |
+ |
* is simply an accessor for _name, required due to |
126 |
+ |
* inheritance issues with extending AlerterSkeleton. |
127 |
+ |
* |
128 |
+ |
* @return the friendly name |
129 |
+ |
*/ |
130 |
+ |
protected String getFName() { |
131 |
+ |
return _name; |
132 |
+ |
} |
133 |
+ |
|
134 |
|
//---ATTRIBUTES--- |
135 |
|
|
136 |
|
/** |
156 |
|
/** |
157 |
|
* Number of alerts sent |
158 |
|
*/ |
159 |
< |
private long _alertCount = 0; |
159 |
> |
private int _alertCount = 0; |
160 |
|
|
161 |
|
/** |
162 |
+ |
* Number of alerts ignored when in "stopped" mode |
163 |
+ |
*/ |
164 |
+ |
private int _ignoredCount = 0; |
165 |
+ |
|
166 |
+ |
/** |
167 |
|
* Time of IRCBot startup |
168 |
|
*/ |
169 |
|
private long _startTime; |
177 |
|
* can be placed here. This name could also |
178 |
|
* be changed to null for utility classes. |
179 |
|
*/ |
180 |
< |
private String _name = "IRC Alert"; |
180 |
> |
private String _name = "IRC"; |
181 |
|
|
171 |
– |
/** |
172 |
– |
* This holds a reference to the |
173 |
– |
* system logger that is being used. |
174 |
– |
*/ |
175 |
– |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
176 |
– |
|
182 |
|
//---STATIC ATTRIBUTES--- |
183 |
|
|
184 |
|
//---INNER CLASSES--- |
191 |
|
*/ |
192 |
|
class IRCBot extends Thread { |
193 |
|
|
194 |
+ |
public static final String DEFAULT_STARTUP_NOTICE = "i-scream ircbot starting..."; |
195 |
+ |
|
196 |
|
/** |
197 |
|
* Main thread loop, this part of the class listens for |
198 |
|
* messages from the server, and acts accordingly. At the |
204 |
|
while(run) { |
205 |
|
// flag so we can stop the loop |
206 |
|
boolean doRead = true; |
207 |
+ |
// get the startup notice |
208 |
+ |
String startupNotice; |
209 |
+ |
try { |
210 |
+ |
startupNotice = ConfigurationProxy.getInstance().getProperty(_name, "Alerter.IRC.startupNotice"); |
211 |
+ |
} catch (PropertyNotFoundException e) { |
212 |
+ |
startupNotice = DEFAULT_STARTUP_NOTICE; |
213 |
+ |
_logger.write(this.toString(), Logger.WARNING, "Configuration error: "+e); |
214 |
+ |
} |
215 |
|
// connect to the IRC server |
216 |
|
try { |
217 |
|
connect(); |
218 |
< |
sendNotice(ConfigurationProxy.getInstance().getProperty(_name, "Alerter.IRC.startupNotice")); |
218 |
> |
sendNotice(startupNotice); |
219 |
|
} catch(IOException e) { |
220 |
|
doRead=false; |
221 |
|
_logger.write(this.toString(), Logger.ERROR, "Error connecting: "+e); |
251 |
|
} catch (NumberFormatException e) { |
252 |
|
delayTime = DEFAULT_RECONNECT_DELAY; |
253 |
|
_logger.write(this.toString(), Logger.WARNING, "Erronous Alerter.IRC.reconnectDelay value in configuration using default of " + delayTime + " seconds"); |
254 |
< |
} catch (org.omg.CORBA.MARSHAL e2) { |
254 |
> |
} catch (PropertyNotFoundException e) { |
255 |
|
delayTime = DEFAULT_RECONNECT_DELAY; |
256 |
|
_logger.write(this.toString(), Logger.WARNING, "Alerter.IRC.reconnectDelay value unavailable using default of " + delayTime + " seconds"); |
257 |
|
} |
321 |
|
public void connect() throws IOException { |
322 |
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
323 |
|
// setup the socket, reader and writer |
324 |
< |
String server = cp.getProperty(_name, "Alerter.IRC.IRCServer"); |
325 |
< |
int port = Integer.parseInt(cp.getProperty(_name, "Alerter.IRC.IRCPort")); |
324 |
> |
String server; |
325 |
> |
int port; |
326 |
> |
try { |
327 |
> |
server = cp.getProperty(_name, "Alerter.IRC.IRCServer"); |
328 |
> |
port = Integer.parseInt(cp.getProperty(_name, "Alerter.IRC.IRCPort")); |
329 |
> |
} catch (PropertyNotFoundException e) { |
330 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
331 |
> |
throw new IOException("Can't get irc server details due to configuration error"); |
332 |
> |
} catch (NumberFormatException e) { |
333 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
334 |
> |
throw new IOException("Can't get irc server details due to malformed configuration"); |
335 |
> |
} |
336 |
|
_socket = new Socket(server, port); |
337 |
|
_socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); |
338 |
|
_socketOut = new PrintWriter(_socket.getOutputStream(), true); |
339 |
|
//_socketOut.println("PASS"); |
340 |
|
// send USER details |
341 |
< |
String user = cp.getProperty(_name, "Alerter.IRC.user"); |
342 |
< |
String comment = cp.getProperty(_name, "Alerter.IRC.comment"); |
341 |
> |
String user, comment; |
342 |
> |
try { |
343 |
> |
user = cp.getProperty(_name, "Alerter.IRC.user"); |
344 |
> |
comment = cp.getProperty(_name, "Alerter.IRC.comment"); |
345 |
> |
} catch (PropertyNotFoundException e) { |
346 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
347 |
> |
throw new IOException("Can't get user details due to configuration error"); |
348 |
> |
} |
349 |
|
_socketOut.println("USER "+user+" 8 * :"+comment); |
350 |
|
// attempt to get a nick |
351 |
< |
String nickList = cp.getProperty(_name, "Alerter.IRC.nickList"); |
351 |
> |
String nickList; |
352 |
> |
try { |
353 |
> |
nickList = cp.getProperty(_name, "Alerter.IRC.nickList"); |
354 |
> |
} catch (PropertyNotFoundException e) { |
355 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
356 |
> |
throw new IOException("Can't get nickname due to configuration error"); |
357 |
> |
} |
358 |
|
StringTokenizer st = new StringTokenizer(nickList, ";"); |
359 |
|
boolean ok = false; |
360 |
|
// try until we exhaust our list |
386 |
|
throw new IOException("All nicknames in use"); |
387 |
|
} |
388 |
|
// join the channel |
389 |
< |
_channel = cp.getProperty(_name, "Alerter.IRC.channel"); |
389 |
> |
try { |
390 |
> |
_channel = cp.getProperty(_name, "Alerter.IRC.channel"); |
391 |
> |
} catch (PropertyNotFoundException e) { |
392 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
393 |
> |
throw new IOException("Can't get channel name due to configuration error"); |
394 |
> |
} |
395 |
|
_socketOut.println("JOIN "+_channel); |
396 |
|
// allow alerts |
397 |
|
_active = true; |
417 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
418 |
|
* method to provide clean logging (every class should have this). |
419 |
|
* |
420 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
420 |
> |
* This uses the uk.org.iscream.util.NameFormat class |
421 |
|
* to format the toString() |
422 |
|
* |
423 |
|
* @return the name of this class and its CVS revision |
442 |
|
_socketOut.println("PONG" + line.substring(4)); |
443 |
|
} |
444 |
|
// see if it's for us |
445 |
< |
else if(getMsg(line).startsWith(_nickname+",") |
446 |
< |
|| getMsg(line).startsWith(_nickname+":") |
447 |
< |
|| getMsg(line).startsWith(_nickname+" ")) { |
445 |
> |
else if(getMsg(line).startsWith(_nickname+",") || getMsg(line).startsWith(_nickname+":") || getMsg(line).startsWith(_nickname+" ")) { |
446 |
> |
// setup some String's |
447 |
> |
String stopCommand, startCommand, timeSinceLastAlertCommand, lastAlertCommand, joinCommand; |
448 |
> |
String nickChangeCommand, versionCommand, helpCommand, statCommand, uptimeCommand; |
449 |
> |
// get the command set |
450 |
> |
try { |
451 |
> |
stopCommand = cp.getProperty(_name, "Alerter.IRC.stopCommand"); |
452 |
> |
startCommand = cp.getProperty(_name, "Alerter.IRC.startCommand"); |
453 |
> |
timeSinceLastAlertCommand = cp.getProperty(_name, "Alerter.IRC.timeSinceLastAlertCommand"); |
454 |
> |
lastAlertCommand = cp.getProperty(_name, "Alerter.IRC.lastAlertCommand"); |
455 |
> |
joinCommand = cp.getProperty(_name, "Alerter.IRC.joinCommand"); |
456 |
> |
nickChangeCommand = cp.getProperty(_name, "Alerter.IRC.nickChangeCommand"); |
457 |
> |
versionCommand = cp.getProperty(_name, "Alerter.IRC.versionCommand"); |
458 |
> |
helpCommand = cp.getProperty(_name, "Alerter.IRC.helpCommand"); |
459 |
> |
statCommand = cp.getProperty(_name, "Alerter.IRC.statCommand"); |
460 |
> |
uptimeCommand = cp.getProperty(_name, "Alerter.IRC.uptimeCommand"); |
461 |
> |
} catch (PropertyNotFoundException e) { |
462 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
463 |
> |
// lets bail from handling this line... |
464 |
> |
// ...it's gonna be hard without a command set! |
465 |
> |
return; |
466 |
> |
} |
467 |
> |
|
468 |
|
// we have a message for us |
469 |
|
String message = getMsg(line).substring(_nickname.length()); |
470 |
< |
if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.stopCommand"))!=-1) { |
470 |
> |
if(message.indexOf(stopCommand)!=-1) { |
471 |
|
_active = false; |
472 |
|
sendMsg(getMsgSender(line)+", alerts have been stopped"); |
473 |
|
} |
474 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.startCommand"))!=-1) { |
474 |
> |
else if(message.indexOf(startCommand)!=-1) { |
475 |
|
_active = true; |
476 |
|
sendMsg(getMsgSender(line)+", alerts have been activated"); |
477 |
|
} |
478 |
|
// this needs to go here if it contains the same words as the lastAlertCommand |
479 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.timeSinceLastAlertCommand"))!=-1) { |
479 |
> |
else if(message.indexOf(timeSinceLastAlertCommand)!=-1) { |
480 |
|
if(_lastAlertTime != -1) { |
481 |
|
long uptime = (System.currentTimeMillis() - _lastAlertTime) / 1000; |
482 |
|
String uptimeText = DateUtils.formatTime(uptime, "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs"); |
486 |
|
sendMsg(getMsgSender(line)+", I've never sent an alert!"); |
487 |
|
} |
488 |
|
} |
489 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.lastAlertCommand"))!=-1) { |
489 |
> |
else if(message.indexOf(lastAlertCommand)!=-1) { |
490 |
|
if(_lastAlertTime != -1) { |
491 |
|
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.UK).format(new Date(_lastAlertTime)); |
492 |
|
sendMsg(getMsgSender(line)+", last alert was at "+date+"; "+_lastAlert); |
496 |
|
} |
497 |
|
|
498 |
|
} |
499 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.joinCommand"))!=-1) { |
500 |
< |
String joinCmd = cp.getProperty(_name, "Alerter.IRC.joinCommand"); |
499 |
> |
else if(message.indexOf(joinCommand)!=-1) { |
500 |
> |
String joinCmd = joinCommand; |
501 |
|
String newChan = message.substring(message.indexOf(joinCmd) + joinCmd.length() + 1); |
502 |
|
int endOfChan = newChan.indexOf(" "); |
503 |
|
if(endOfChan == -1) { |
504 |
|
endOfChan = newChan.length(); |
505 |
|
} |
506 |
|
newChan = newChan.substring(0, endOfChan); |
507 |
< |
sendMsg(getMsgSender(line)+", okay, I'm off to "+newChan); |
508 |
< |
_socketOut.println("PART "+_channel); |
509 |
< |
_socketOut.println("JOIN "+newChan); |
510 |
< |
_channel = newChan; |
507 |
> |
if(newChan.equals(_channel)) { |
508 |
> |
sendMsg(getMsgSender(line)+", I'm already on "+newChan+"!"); |
509 |
> |
} else { |
510 |
> |
sendMsg(getMsgSender(line)+", okay, I'm off to "+newChan); |
511 |
> |
_socketOut.println("PART "+_channel); |
512 |
> |
_socketOut.println("JOIN "+newChan); |
513 |
> |
_channel = newChan; |
514 |
> |
} |
515 |
|
} |
516 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.nickChangeCommand"))!=-1) { |
517 |
< |
String nickChangeCmd = cp.getProperty(_name, "Alerter.IRC.nickChangeCommand"); |
516 |
> |
else if(message.indexOf(nickChangeCommand)!=-1) { |
517 |
> |
String nickChangeCmd = nickChangeCommand; |
518 |
|
String newNick = message.substring(message.indexOf(nickChangeCmd) + nickChangeCmd.length() + 1); |
519 |
|
int endOfNick = newNick.indexOf(" "); |
520 |
|
if(endOfNick == -1) { |
525 |
|
_socketOut.println("NICK "+newNick); |
526 |
|
_nickname = newNick; |
527 |
|
} |
528 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.versionCommand"))!=-1) { |
528 |
> |
else if(message.indexOf(versionCommand)!=-1) { |
529 |
|
sendMsg(getMsgSender(line)+", I am version "+REVISION.substring(11, REVISION.length() -2)+" of the i-scream alerting bot"); |
530 |
|
} |
531 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.helpCommand"))!=-1) { |
531 |
> |
else if(message.indexOf(helpCommand)!=-1) { |
532 |
|
sendPrivMsg(getMsgSender(line), "Hello, I am the i-scream alerting bot version "+REVISION.substring(11, REVISION.length() -2)); |
533 |
|
sendPrivMsg(getMsgSender(line), "I understand the following commands;"); |
534 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.stopCommand")); |
535 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.startCommand")); |
536 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.lastAlertCommand")); |
537 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.joinCommand")); |
538 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.nickChangeCommand")); |
539 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.statCommand")); |
540 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.uptimeCommand")); |
541 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.timeSinceLastAlertCommand")); |
542 |
< |
sendPrivMsg(getMsgSender(line), cp.getProperty(_name, "Alerter.IRC.helpCommand")); |
534 |
> |
sendPrivMsg(getMsgSender(line), stopCommand); |
535 |
> |
sendPrivMsg(getMsgSender(line), startCommand); |
536 |
> |
sendPrivMsg(getMsgSender(line), lastAlertCommand); |
537 |
> |
sendPrivMsg(getMsgSender(line), joinCommand); |
538 |
> |
sendPrivMsg(getMsgSender(line), nickChangeCommand); |
539 |
> |
sendPrivMsg(getMsgSender(line), statCommand); |
540 |
> |
sendPrivMsg(getMsgSender(line), uptimeCommand); |
541 |
> |
sendPrivMsg(getMsgSender(line), timeSinceLastAlertCommand); |
542 |
> |
sendPrivMsg(getMsgSender(line), helpCommand); |
543 |
|
} |
544 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.statCommand"))!=-1) { |
545 |
< |
sendMsg(getMsgSender(line)+", I have sent a total of "+_alertCount+" alerts!"); |
544 |
> |
else if(message.indexOf(statCommand)!=-1) { |
545 |
> |
sendMsg(getMsgSender(line)+", I have sent a total of "+_alertCount+" alerts, and ignored a total of "+_ignoredCount+"!"); |
546 |
|
} |
547 |
< |
else if(message.indexOf(cp.getProperty(_name, "Alerter.IRC.uptimeCommand"))!=-1) { |
547 |
> |
else if(message.indexOf(uptimeCommand)!=-1) { |
548 |
|
long uptime = (System.currentTimeMillis() - _startTime) / 1000; |
549 |
|
String uptimeText = DateUtils.formatTime(uptime, "%DAYS% days, %HOURS% hours, %MINS% mins, and %SECS% secs"); |
550 |
|
sendMsg(getMsgSender(line)+", I have been running for "+uptimeText); |
551 |
|
} |
552 |
+ |
else if(message.indexOf("ping")!=-1) { |
553 |
+ |
sendMsg("pong"); |
554 |
+ |
} |
555 |
|
else if(message.indexOf("do a jibble dance")!=-1) { |
556 |
|
// little joke :) |
557 |
|
sendAction("jives to the funky beat shouting \"ii--screeeaaammm\""); |
558 |
|
} |
559 |
|
else { |
560 |
< |
sendMsg(getMsgSender(line)+", "+cp.getProperty(_name, "Alerter.IRC.rejectMessage")); |
560 |
> |
String rejectMessage = NOT_CONFIGURED; |
561 |
> |
try { |
562 |
> |
rejectMessage = cp.getProperty(_name, "Alerter.IRC.rejectMessage"); |
563 |
> |
} catch(PropertyNotFoundException e) { |
564 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
565 |
> |
} |
566 |
> |
sendMsg(getMsgSender(line)+", "+rejectMessage); |
567 |
|
} |
568 |
|
} |
569 |
|
else if(line.indexOf(_nickname)!=-1 && line.indexOf(_channel)!=-1 && line.indexOf("KICK")!=-1) { |
570 |
|
sendPrivMsg(getMsgSender(line), "That wasn't a nice thing to do..."); |
571 |
< |
_channel = cp.getProperty(_name, "Alerter.IRC.channel"); |
571 |
> |
try { |
572 |
> |
_channel = cp.getProperty(_name, "Alerter.IRC.channel"); |
573 |
> |
} catch(PropertyNotFoundException e) { |
574 |
> |
_logger.write(this.toString(), Logger.ERROR, "Configuration error: "+e); |
575 |
> |
} |
576 |
|
_socketOut.println("JOIN "+_channel); |
577 |
|
} |
578 |
|
} |
638 |
|
* A reminder of our current nickname... |
639 |
|
*/ |
640 |
|
private String _nickname; |
641 |
+ |
|
642 |
+ |
/** |
643 |
+ |
* This holds a reference to the |
644 |
+ |
* system logger that is being used. |
645 |
+ |
*/ |
646 |
+ |
protected Logger _logger = ReferenceManager.getInstance().getLogger(); |
647 |
|
|
648 |
|
} |
649 |
|
|