1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-12-01 13:22:20 -05:00

PircBot Patch: Recognize "%" as a nickname prefix

This commit is contained in:
Sebastian Kaspari 2011-02-05 15:23:41 +01:00
parent cf5ea6049c
commit c35e1fc1ab

View File

@ -11,7 +11,7 @@ found at http://www.jibble.org/licenses/
Modified by: Sebastian Kaspari <sebastian@yaaic.org> Modified by: Sebastian Kaspari <sebastian@yaaic.org>
*/ */
package org.jibble.pircbot; package org.jibble.pircbot;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -225,8 +225,8 @@ public abstract class PircBot implements ReplyConstants {
tries++; tries++;
nick = ((tries - 1) <= aliases.size()) ? nick = ((tries - 1) <= aliases.size()) ?
aliases.get(tries - 2) : aliases.get(tries - 2) :
getName() + (tries - aliases.size()); getName() + (tries - aliases.size());
OutputThread.sendRawLine(this, bwriter, "NICK " + nick); OutputThread.sendRawLine(this, bwriter, "NICK " + nick);
} }
else { else {
socket.close(); socket.close();
@ -757,6 +757,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @deprecated As of PircBot 1.2.0, use {@link #onIncomingFileTransfer(DccFileTransfer)} * @deprecated As of PircBot 1.2.0, use {@link #onIncomingFileTransfer(DccFileTransfer)}
*/ */
@Deprecated
protected final void dccReceiveFile(File file, long address, int port, int size) { protected final void dccReceiveFile(File file, long address, int port, int size) {
throw new RuntimeException("dccReceiveFile is deprecated, please use sendFile"); throw new RuntimeException("dccReceiveFile is deprecated, please use sendFile");
} }
@ -846,6 +847,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @deprecated As of PircBot 1.2.0, use {@link #onIncomingChatRequest(DccChat)} * @deprecated As of PircBot 1.2.0, use {@link #onIncomingChatRequest(DccChat)}
*/ */
@Deprecated
protected final DccChat dccAcceptChatRequest(String sourceNick, long address, int port) { protected final DccChat dccAcceptChatRequest(String sourceNick, long address, int port) {
throw new RuntimeException("dccAcceptChatRequest is deprecated, please use onIncomingChatRequest"); throw new RuntimeException("dccAcceptChatRequest is deprecated, please use onIncomingChatRequest");
} }
@ -1149,7 +1151,7 @@ public abstract class PircBot implements ReplyConstants {
// Stick with the default value of zero. // Stick with the default value of zero.
} }
String topic = (String) _topics.get(channel); String topic = _topics.get(channel);
_topics.remove(channel); _topics.remove(channel);
this.onTopic(channel, topic, setBy, date, false); this.onTopic(channel, topic, setBy, date, false);
@ -1175,6 +1177,10 @@ public abstract class PircBot implements ReplyConstants {
// Some wibbly status I've never seen before... // Some wibbly status I've never seen before...
prefix = "."; prefix = ".";
} }
// XXX: PircBot Patch - Recognize % as prefix - Often used as "half-operator" prefix
else if (nick.startsWith("%")) {
prefix = "%";
}
nick = nick.substring(prefix.length()); nick = nick.substring(prefix.length());
this.addUser(channel, new User(prefix, nick)); this.addUser(channel, new User(prefix, nick));
} }
@ -1401,6 +1407,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @deprecated As of 1.2.0, replaced by {@link #onTopic(String,String,String,long,boolean)} * @deprecated As of 1.2.0, replaced by {@link #onTopic(String,String,String,long,boolean)}
*/ */
@Deprecated
protected void onTopic(String channel, String topic) {} protected void onTopic(String channel, String topic) {}
@ -1483,26 +1490,26 @@ public abstract class PircBot implements ReplyConstants {
pn = atPos; pn = atPos;
} }
else if (atPos == 'o') { else if (atPos == 'o') {
if (pn == '+') { if (pn == '+') {
this.updateUser(channel, OP_ADD, params[p]); this.updateUser(channel, OP_ADD, params[p]);
onOp(channel, sourceNick, sourceLogin, sourceHostname, params[p]); onOp(channel, sourceNick, sourceLogin, sourceHostname, params[p]);
} }
else { else {
this.updateUser(channel, OP_REMOVE, params[p]); this.updateUser(channel, OP_REMOVE, params[p]);
onDeop(channel, sourceNick, sourceLogin, sourceHostname, params[p]); onDeop(channel, sourceNick, sourceLogin, sourceHostname, params[p]);
} }
p++; p++;
} }
else if (atPos == 'v') { else if (atPos == 'v') {
if (pn == '+') { if (pn == '+') {
this.updateUser(channel, VOICE_ADD, params[p]); this.updateUser(channel, VOICE_ADD, params[p]);
onVoice(channel, sourceNick, sourceLogin, sourceHostname, params[p]); onVoice(channel, sourceNick, sourceLogin, sourceHostname, params[p]);
} }
else { else {
this.updateUser(channel, VOICE_REMOVE, params[p]); this.updateUser(channel, VOICE_REMOVE, params[p]);
onDeVoice(channel, sourceNick, sourceLogin, sourceHostname, params[p]); onDeVoice(channel, sourceNick, sourceLogin, sourceHostname, params[p]);
} }
p++; p++;
} }
else if (atPos == 'k') { else if (atPos == 'k') {
if (pn == '+') { if (pn == '+') {
@ -2096,6 +2103,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @deprecated As of PircBot 1.2.0, use {@link #onIncomingFileTransfer(DccFileTransfer)} * @deprecated As of PircBot 1.2.0, use {@link #onIncomingFileTransfer(DccFileTransfer)}
*/ */
@Deprecated
protected void onDccSendRequest(String sourceNick, String sourceLogin, String sourceHostname, String filename, long address, int port, int size) {} protected void onDccSendRequest(String sourceNick, String sourceLogin, String sourceHostname, String filename, long address, int port, int size) {}
@ -2106,6 +2114,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @deprecated As of PircBot 1.2.0, use {@link #onIncomingChatRequest(DccChat)} * @deprecated As of PircBot 1.2.0, use {@link #onIncomingChatRequest(DccChat)}
*/ */
@Deprecated
protected void onDccChatRequest(String sourceNick, String sourceLogin, String sourceHostname, long address, int port) {} protected void onDccChatRequest(String sourceNick, String sourceLogin, String sourceHostname, long address, int port) {}
@ -2709,7 +2718,7 @@ public abstract class PircBot implements ReplyConstants {
return null; return null;
} }
// Clone the array to prevent external modification. // Clone the array to prevent external modification.
return (int[]) _dccPorts.clone(); return _dccPorts.clone();
} }
@ -2733,7 +2742,7 @@ public abstract class PircBot implements ReplyConstants {
} }
else { else {
// Clone the array to prevent external modification. // Clone the array to prevent external modification.
_dccPorts = (int[]) ports.clone(); _dccPorts = ports.clone();
} }
} }
@ -2747,6 +2756,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @return true if and only if Object o is a PircBot and equal to this. * @return true if and only if Object o is a PircBot and equal to this.
*/ */
@Override
public boolean equals(Object o) { public boolean equals(Object o) {
// This probably has the same effect as Object.equals, but that may change... // This probably has the same effect as Object.equals, but that may change...
if (o instanceof PircBot) { if (o instanceof PircBot) {
@ -2766,6 +2776,7 @@ public abstract class PircBot implements ReplyConstants {
* *
* @return the hash code for this instance of PircBot. * @return the hash code for this instance of PircBot.
*/ */
@Override
public int hashCode() { public int hashCode() {
return super.hashCode(); return super.hashCode();
} }
@ -2790,12 +2801,13 @@ public abstract class PircBot implements ReplyConstants {
* *
* @return a String representation of this object. * @return a String representation of this object.
*/ */
@Override
public String toString() { public String toString() {
return "Version{" + _version + "}" + return "Version{" + _version + "}" +
" Connected{" + isConnected() + "}" + " Connected{" + isConnected() + "}" +
" Server{" + _server + "}" + " Server{" + _server + "}" +
" Port{" + _port + "}" + " Port{" + _port + "}" +
" Password{" + _password + "}"; " Password{" + _password + "}";
} }
@ -2838,7 +2850,7 @@ public abstract class PircBot implements ReplyConstants {
userArray = new User[users.size()]; userArray = new User[users.size()];
Enumeration<User> enumeration = users.elements(); Enumeration<User> enumeration = users.elements();
for (int i = 0; i < userArray.length; i++) { for (int i = 0; i < userArray.length; i++) {
User user = (User) enumeration.nextElement(); User user = enumeration.nextElement();
userArray[i] = user; userArray[i] = user;
} }
} }
@ -2865,7 +2877,7 @@ public abstract class PircBot implements ReplyConstants {
channels = new String[_channels.size()]; channels = new String[_channels.size()];
Enumeration<String> enumeration = _channels.keys(); Enumeration<String> enumeration = _channels.keys();
for (int i = 0; i < channels.length; i++) { for (int i = 0; i < channels.length; i++) {
channels[i] = (String) enumeration.nextElement(); channels[i] = enumeration.nextElement();
} }
} }
return channels; return channels;
@ -2924,7 +2936,7 @@ public abstract class PircBot implements ReplyConstants {
synchronized (_channels) { synchronized (_channels) {
Hashtable<User, User> users = _channels.get(channel); Hashtable<User, User> users = _channels.get(channel);
if (users != null) { if (users != null) {
return (User) users.remove(user); return users.remove(user);
} }
} }
return null; return null;
@ -2938,7 +2950,7 @@ public abstract class PircBot implements ReplyConstants {
synchronized (_channels) { synchronized (_channels) {
Enumeration<String> enumeration = _channels.keys(); Enumeration<String> enumeration = _channels.keys();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
String channel = (String) enumeration.nextElement(); String channel = enumeration.nextElement();
this.removeUser(channel, nick); this.removeUser(channel, nick);
} }
} }
@ -2952,7 +2964,7 @@ public abstract class PircBot implements ReplyConstants {
synchronized (_channels) { synchronized (_channels) {
Enumeration<String> enumeration = _channels.keys(); Enumeration<String> enumeration = _channels.keys();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
String channel = (String) enumeration.nextElement(); String channel = enumeration.nextElement();
User user = this.removeUser(channel, oldNick); User user = this.removeUser(channel, oldNick);
if (user != null) { if (user != null) {
user = new User(user.getPrefix(), newNick); user = new User(user.getPrefix(), newNick);
@ -2992,7 +3004,7 @@ public abstract class PircBot implements ReplyConstants {
if (users != null) { if (users != null) {
Enumeration<User> enumeration = users.elements(); Enumeration<User> enumeration = users.elements();
while(enumeration.hasMoreElements()) { while(enumeration.hasMoreElements()) {
User userObj = (User) enumeration.nextElement(); User userObj = enumeration.nextElement();
if (userObj.getNick().equalsIgnoreCase(nick)) { if (userObj.getNick().equalsIgnoreCase(nick)) {
if (userMode == OP_ADD) { if (userMode == OP_ADD) {
if (userObj.hasVoice()) { if (userObj.hasVoice()) {
@ -3053,7 +3065,7 @@ public abstract class PircBot implements ReplyConstants {
private String _password = null; private String _password = null;
// Outgoing message stuff. // Outgoing message stuff.
private Queue _outQueue = new Queue(); private final Queue _outQueue = new Queue();
private long _messageDelay = 1000; private long _messageDelay = 1000;
// A Hashtable of channels that points to a selfreferential Hashtable of // A Hashtable of channels that points to a selfreferential Hashtable of
@ -3062,10 +3074,10 @@ public abstract class PircBot implements ReplyConstants {
// A Hashtable to temporarily store channel topics when we join them // A Hashtable to temporarily store channel topics when we join them
// until we find out who set that topic. // until we find out who set that topic.
private Hashtable<String, String> _topics = new Hashtable<String, String>(); private final Hashtable<String, String> _topics = new Hashtable<String, String>();
// DccManager to process and handle all DCC events. // DccManager to process and handle all DCC events.
private DccManager _dccManager = new DccManager(this); private final DccManager _dccManager = new DccManager(this);
private int[] _dccPorts = null; private int[] _dccPorts = null;
private InetAddress _dccInetAddress = null; private InetAddress _dccInetAddress = null;
@ -3074,11 +3086,11 @@ public abstract class PircBot implements ReplyConstants {
private boolean _useSSL = false; private boolean _useSSL = false;
private String _name = "PircBot"; private String _name = "PircBot";
private List<String> _aliases = new ArrayList<String>(); private final List<String> _aliases = new ArrayList<String>();
private String _nick = _name; private String _nick = _name;
private String _login = "PircBot"; private String _login = "PircBot";
private String _version = "PircBot " + VERSION + " Java IRC Bot - www.jibble.org"; private String _version = "PircBot " + VERSION + " Java IRC Bot - www.jibble.org";
private String _finger = "You ought to be arrested for fingering a bot!"; private String _finger = "You ought to be arrested for fingering a bot!";
private String _channelPrefixes = "#&+!"; private final String _channelPrefixes = "#&+!";
} }