Skip to content

Commit

Permalink
Added improvements to nickCompelte(...), ban list tracking, and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
R2D2Warrior committed Mar 7, 2014
1 parent 26498b3 commit 8130f80
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/com/r2d2warrior/c3p0j/commands/Cycle.java
Expand Up @@ -20,8 +20,7 @@ public void execute()
if (event.getBot().getUserChannelDao().channelExists(chan))
{
event.respondToUser("Trying to cycle channel: " + chan);
userChannelDao.getChannel(chan).send().part("Rejoining...");
bot.sendIRC().joinChannel(chan);
userChannelDao.getChannel(chan).send().cycle();
}
else
event.respondToUser("Not in channel: " + chan);
Expand Down
1 change: 1 addition & 0 deletions src/com/r2d2warrior/c3p0j/commands/Ping.java
Expand Up @@ -4,6 +4,7 @@

import com.r2d2warrior.c3p0j.handling.CommandEvent;

//Testing command for CommandEvent.completeNick(...)
@Command(name="ping", desc="Sends a PONG")
public class Ping extends GenericCommand
{
Expand Down
10 changes: 7 additions & 3 deletions src/com/r2d2warrior/c3p0j/handling/CommandEvent.java
Expand Up @@ -90,17 +90,21 @@ public String completeNick(String oldNick)
if (matchUsers.size() > 1 && matchUsers.size() <= 5)
{
respondToUser("Did you mean " + Utils.commaWithOr(matchUsers));
return oldNick;
throw new IllegalArgumentException("Nick completion failed.");
}
else if (matchUsers.size() > 5)
{
respondToUser("More than 5 matches for \"" + oldNick + ",\" be more specific.");
return oldNick;
throw new IllegalArgumentException("Nick completion failed.");
}
else// if (matchUsers.size() == 1)
else if (matchUsers.size() == 1)
{
return matchUsers.get(0);
}
else
{
throw new IllegalArgumentException("Nick completion failed.");
}
}

public String completeNick(int argIndex)
Expand Down
49 changes: 49 additions & 0 deletions src/com/r2d2warrior/c3p0j/listeners/BanListListener.java
@@ -0,0 +1,49 @@
package com.r2d2warrior.c3p0j.listeners;

import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.ReplyConstants;
import org.pircbotx.User;
import org.pircbotx.UserChannelDao;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.JoinEvent;
import org.pircbotx.hooks.events.RemoveChannelBanEvent;
import org.pircbotx.hooks.events.ServerResponseEvent;
import org.pircbotx.hooks.events.SetChannelBanEvent;

@AddListener
public class BanListListener extends ListenerAdapter<PircBotX>
{
public void onJoin(JoinEvent<PircBotX> event)
{
if (event.getUser().equals(event.getBot().getUserBot()))
// Get the banlist for the channel
event.getBot().sendRaw().rawLine("MODE " + event.getChannel().getName() + " b");
}

public void onServerResponse(ServerResponseEvent<PircBotX> event)
{
UserChannelDao<User, Channel> dao = event.getBot().getUserChannelDao();

// This is triggered for each ban list entry
if (event.getCode() == ReplyConstants.RPL_BANLIST)
{
// event.getParsedResponse() = [botNick, #chan, banMask, setterHostmask, timestamp]
if (!dao.channelExists(event.getParsedResponse().get(1)))
return;

Channel channel = dao.getChannel(event.getParsedResponse().get(1));
channel.getBanList().add(event.getParsedResponse().get(2));
}
}

public void onSetChannelBan(SetChannelBanEvent<PircBotX> event)
{
event.getChannel().getBanList().add(event.getHostmask());
}

public void onRemoveChannelBan(RemoveChannelBanEvent<PircBotX> event)
{
event.getChannel().getBanList().remove(event.getHostmask());
}
}
9 changes: 9 additions & 0 deletions src/org/pircbotx/Channel.java
Expand Up @@ -21,14 +21,19 @@
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.concurrent.AtomicSafeInitializer;
import org.apache.commons.lang3.concurrent.ConcurrentException;
Expand Down Expand Up @@ -115,6 +120,10 @@ protected OutputChannel initialize() {
* Channel key (+k)
*/
protected String channelKey = null;
/**
* List of banned hostmasks (nick!user@host)
*/
protected List<String> banList = new ArrayList<>(); // Added by R2D2Warrior
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
protected boolean modeStale = false;
Expand Down

0 comments on commit 8130f80

Please sign in to comment.