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

Commit

Permalink
Rejoin IRC channel if kicked.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed May 21, 2016
1 parent a9c9cb8 commit 94af5f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/cnaude/purpleirc/IRCListeners/KickListener.java
Expand Up @@ -49,8 +49,23 @@ public KickListener(PurpleIRC plugin, PurpleBot ircBot) {
@Override
public void onKick(KickEvent event) {
Channel channel = event.getChannel();
String channelName = channel.getName();
User recipient = event.getRecipient();
User user = event.getUser();

if (recipient.getNick().equalsIgnoreCase(ircBot.botNick)) {
plugin.logDebug("onKick: " + recipient.getNick());
if (ircBot.joinOnKick) {
plugin.logDebug("onKick: rejoining");
if (ircBot.channelPassword.get(channelName).isEmpty()) {
ircBot.asyncJoinChannel(channelName);
} else {
ircBot.asyncJoinChannel(channelName, ircBot.channelPassword.get(channelName));
}
} else {
plugin.logDebug("onKick: NOT rejoining");
}
}

if (ircBot.isValidChannel(channel.getName())) {
ircBot.broadcastIRCKick(recipient, user, event.getReason(), channel);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -201,6 +201,7 @@ public final class PurpleBot {
private String tailerRecipient;
private boolean tailerCtcp;
private CommandSender zncSender;
public boolean joinOnKick;
/**
* Map of player names to IRC nicks.
*/
Expand Down Expand Up @@ -650,6 +651,18 @@ public void run() {
}
});
}

public void asyncJoinChannel(final String channelName) {
if (!this.isConnected()) {
return;
}
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
bot.sendIRC().joinChannel(channelName);
}
});
}

public void asyncNotice(final String target, final String message) {
if (!this.isConnected()) {
Expand Down Expand Up @@ -853,6 +866,8 @@ private boolean loadConfig() {

// load tailer settings
tailerEnabled = config.getBoolean("file-tailer.enabled", false);

joinOnKick = config.getBoolean("join-on-kick", true);

String tailerFile = config.getString("file-tailer.file", "server.log");
if (!tailerFiles.contains(tailerFile)) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -121,6 +121,8 @@ bot-linking-enabled: false
# Map of remote linked bots and codes. Use /irc link and /irc linkaccept
bot-links:
# - remotebot: 249505593790847552435733176657146971496
# rejoin if kicked from a channel
join-on-kick: true
# channels - List the channels your bot will join here
channels:
# Channel name must be surrounded by sing quotes to be YAML compliant.
Expand Down

0 comments on commit 94af5f5

Please sign in to comment.