Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Added alt-nicks option.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Nov 12, 2014
1 parent 06e512f commit afa27d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
Expand Up @@ -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());

}
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -94,6 +94,8 @@ public final class PurpleBot {
public String botServer;
public String bindAddress;
public String botNick;
public List<String> altNicks;
int nickIndex = 0;
public String botLogin;
public String botRealName;
public int ircMaxLineLength;
Expand Down Expand Up @@ -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<>();
Expand Down Expand Up @@ -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", "");
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -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
Expand Down

0 comments on commit afa27d3

Please sign in to comment.