1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.org.iscream.client.alerters; |
2 |
> |
package uk.org.iscream.cms.server.client.alerters; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.org.iscream.client.*; |
6 |
< |
import uk.org.iscream.core.*; |
7 |
< |
import uk.org.iscream.util.*; |
8 |
< |
import uk.org.iscream.componentmanager.*; |
5 |
> |
import uk.org.iscream.cms.server.client.*; |
6 |
> |
import uk.org.iscream.cms.server.core.*; |
7 |
> |
import uk.org.iscream.cms.server.util.*; |
8 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
9 |
|
import java.io.*; |
10 |
|
import java.net.*; |
11 |
|
import java.util.*; |
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) { |
69 |
< |
// sort out the message |
70 |
< |
String alertType = Alert.alertLevels[alert.getLevel()]; |
71 |
< |
String message; |
72 |
< |
try { |
73 |
< |
message = _cp.getProperty(_name, "Alerter.IRC.message"); |
74 |
< |
} catch (PropertyNotFoundException e) { |
75 |
< |
message = NOT_CONFIGURED; |
76 |
< |
_logger.write(toString(), Logger.WARNING, "Alerter.IRC.message value unavailable using default of " + message); |
77 |
< |
} |
78 |
< |
message = processAlertMessage(message, alert); |
79 |
< |
|
78 |
> |
if(_active) { |
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(); |
85 |
< |
_alertCount ++; |
82 |
> |
// count sent alerts |
83 |
> |
_alertCount++; |
84 |
|
} else { |
85 |
< |
_ignoredCount ++; |
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.org.iscream.util.NameFormat class |
98 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
99 |
|
* to format the toString() |
100 |
|
* |
101 |
|
* @return the name of this class and its CVS revision |
120 |
|
|
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 |
|
/** |
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.org.iscream.util.NameFormat class |
420 |
> |
* This uses the uk.org.iscream.cms.server.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+",") || getMsg(line).startsWith(_nickname+":") || getMsg(line).startsWith(_nickname+" ")) { |
445 |
> |
else if(getMsg(line).toLowerCase().startsWith(_nickname.toLowerCase()+",") || |
446 |
> |
getMsg(line).toLowerCase().startsWith(_nickname.toLowerCase()+":") || |
447 |
> |
getMsg(line).toLowerCase().startsWith(_nickname.toLowerCase()+" ")) { |
448 |
|
// setup some String's |
449 |
|
String stopCommand, startCommand, timeSinceLastAlertCommand, lastAlertCommand, joinCommand; |
450 |
|
String nickChangeCommand, versionCommand, helpCommand, statCommand, uptimeCommand; |