diff --git a/README.md b/README.md index 7c1c5da..7fb8a51 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ PurpleIRC is a Minecraft Bukkit plugin that connects to IRC as a bot. It will re It uses the PircBotX API. https://code.google.com/p/pircbotx/ Latest dev build: -* http://cn.revisited.us:8081/job/PurpleIRC/lastBuild +* http://cnaude.org/jenkins/job/PurpleIRC/lastSuccessfulBuild/ Live demo and chat: * irc.esper.net - #PurpleIRC diff --git a/src/main/java/com/cnaude/purpleirc/IRCListeners/ServerResponseListener.java b/src/main/java/com/cnaude/purpleirc/IRCListeners/ServerResponseListener.java index 72cea61..bb54a93 100644 --- a/src/main/java/com/cnaude/purpleirc/IRCListeners/ServerResponseListener.java +++ b/src/main/java/com/cnaude/purpleirc/IRCListeners/ServerResponseListener.java @@ -57,6 +57,11 @@ public void onServerResponse(ServerResponseEvent event) { plugin.logInfo("Banned from the channel."); } + if (serverReply == ReplyConstants.ERR_NICKNAMEINUSE) { + plugin.logInfo("Nickname already in use."); + ircBot.altNickChange(); + } + //plugin.logDebug("Server response: " + event.getRawLine()); } diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index fa5729b..cc5b2df 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -94,6 +94,8 @@ public final class PurpleBot { public String botServer; public String bindAddress; public String botNick; + public List altNicks; + int nickIndex = 0; public String botLogin; public String botRealName; public int ircMaxLineLength; @@ -157,6 +159,7 @@ public final class PurpleBot { */ public PurpleBot(File file, PurpleIRC plugin) { fileName = file.getName(); + this.altNicks = new ArrayList<>(); this.connected = false; this.botChannels = new ArrayList<>(); this.ircListeners = new ArrayList<>(); @@ -585,6 +588,7 @@ private void loadConfig() { partInvalidChannels = config.getBoolean("part-invalid-channels", false); partInvalidChannelsMsg = config.getString("part-invalid-channels-message", ""); botNick = config.getString("nick", ""); + altNicks = config.getStringList("alt-nicks"); plugin.loadTemplates(config, botNick); botLogin = config.getString("login", "PircBot"); botRealName = config.getString("realname", ""); @@ -2385,7 +2389,7 @@ public void broadcastAction(User user, org.pircbotx.Channel channel, String mess ) ); } - + if (plugin.dynmapHook != null) { plugin.logDebug("xChecking if " + TemplateName.IRC_ACTION_DYNMAP_WEB_CHAT + " is enabled ..."); if (enabledMessages.get(myChannel).contains(TemplateName.IRC_ACTION_DYNMAP_WEB_CHAT)) { @@ -2894,4 +2898,18 @@ public void joinNotice(Channel channel, User user) { } } } + + public void altNickChange() { + if (altNicks.isEmpty()) { + return; + } + if (nickIndex >= 0 && nickIndex < altNicks.size()) { + botNick = altNicks.get(nickIndex); + nickIndex++; + } else { + nickIndex = 0; + } + plugin.logInfo("Trying alternate nick " + botNick); + bot.sendIRC().changeNick(botNick); + } } diff --git a/src/main/resources/SampleBot.yml b/src/main/resources/SampleBot.yml index e234470..3653757 100644 --- a/src/main/resources/SampleBot.yml +++ b/src/main/resources/SampleBot.yml @@ -5,6 +5,10 @@ # # nick - Your bot's unique nickname nick: AwesomeBot +# if your bot's nick is in use try these alternates +alt-nicks: + - AwesomeBot_ + - AwesomeBotA # login - Your bot's login name login: AwesomeName # realname