Skip to content

Commit

Permalink
adding some commands to the admin plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
mex committed Oct 11, 2010
1 parent 91df334 commit 1539241
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 21 additions & 8 deletions Admin/trunk/src/Admin/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.util.List;
import java.util.Set;

import com.PluggableBot.plugin.DefaultPlugin;

Expand All @@ -36,6 +37,8 @@ public class Admin extends DefaultPlugin {
public static final String ACTION_PART = ACTION_STRING + "part";
public static final String ACTION_JOIN = ACTION_STRING + "join";
public static final String ACTION_LIST = ACTION_STRING + "list";
public static final String ACTION_LIST_COMMANDS = ACTION_STRING
+ "listcommands";

@Override
public void load() {
Expand All @@ -45,8 +48,9 @@ public void load() {
bot.addAdminCommand(ACTION_RELOAD, this);
bot.addAdminCommand(ACTION_PART, this);
bot.addAdminCommand(ACTION_LIST, this);
bot.addAdminCommand(ACTION_LIST_COMMANDS, this);
}

@Override
public String getHelp() {
return "Like I would tell you!";
Expand All @@ -65,7 +69,6 @@ public String getAdminHelp() {
+ ACTION_STRING + ACTION_PART);
}


@Override
public void onPrivateAdminCommand(String command, String sender,
String login, String hostname, String message) {
Expand All @@ -87,20 +90,30 @@ public void onPrivateAdminCommand(String command, String sender,
} else if (command.equals(ACTION_JOIN)) {
bot.joinChannel(message);
bot.Message(sender, "joined " + message);
}else if (command.equals(ACTION_PART)) {
} else if (command.equals(ACTION_PART)) {
bot.partChannel(message);
bot.Message(sender, "left channel " + message);
}else if (command.equals(ACTION_LIST)) {
} else if (command.equals(ACTION_LIST)) {
File pluginsFolder = new File("./plugins");
List<String> loadedPlugins = bot.listPlugins();
String pluginsStr = "Plugins: ";
for (String f : pluginsFolder.list()) {
if (f.endsWith(".jar")) {

String jarName = f.substring(0, f.length() - 4);
bot.Message(sender, jarName + (loadedPlugins.contains(jarName)?"*":""));
pluginsStr += jarName
+ (loadedPlugins.contains(jarName) ? "* " : " ");
}
}
bot.sendMessage(sender, pluginsStr);
bot.sendMessage(sender, "Items marked with '*' are already loaded");
} else if (command.equals(ACTION_LIST_COMMANDS)) {
Set<String> commands = bot.listCommands();
String commandString = "";
for (String x : commands) {
commandString += x + " ";
}
bot.sendMessage(sender, "command = " + commandString);
}

}

}
}
8 changes: 7 additions & 1 deletion MainBot/trunk/src/com/PluggableBot/PluggableBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -402,6 +403,8 @@ public void passCommand(String channel, String sender, String login, String host
}
return;
}


}
}

Expand All @@ -418,7 +421,6 @@ public void cleanUpCommands(Plugin plugin) {
@Override
protected void onInvite(String targetNick, String sourceNick, String sourceLogin,
String sourceHostname, String channel) {
// TODO Auto-generated method stub
super.onInvite(targetNick, sourceNick, sourceLogin, sourceHostname, channel);
log.info("Joing " + channel + " because " + sourceNick + " invited me!");
joinChannel(channel);
Expand All @@ -428,4 +430,8 @@ public List<String> listPlugins() {
return Collections.list(loadedPlugins.keys());
}

public Set<String> listCommands() {
return commands.keySet();
}

}

0 comments on commit 1539241

Please sign in to comment.