-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06b3598
Showing
3 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.GUIpsp.GuiBot; | ||
|
||
public abstract class BasePlugin { | ||
|
||
public abstract void main() throws Throwable; | ||
|
||
public abstract String version(); | ||
|
||
public abstract String pluginName(); | ||
|
||
public abstract String author(); | ||
|
||
public boolean hidden() { | ||
return false; | ||
}; | ||
|
||
public final void registerCmd(String cmd, Object toCall, Object that) { | ||
Main.cmdmap.put(cmd, toCall); | ||
Main.classmap.put(cmd, that); | ||
|
||
System.out | ||
.println("Hooked command \"" | ||
+ cmd | ||
+ "\" to " | ||
+ toCall.toString().split(" ")[toCall.toString().split( | ||
" ").length - 1]); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.GUIpsp.GuiBot; | ||
|
||
import java.lang.reflect.*; | ||
import java.util.regex.*; | ||
|
||
import org.jibble.pircbot.*; | ||
|
||
public class GuiBot extends PircBot { | ||
public static String pref = "$"; | ||
|
||
public GuiBot() { | ||
this.setName("GuiBot"); | ||
} | ||
|
||
public void onMessage(String channel, String sender, String login, | ||
String hostname, String message) { | ||
if (message.trim().startsWith(pref)) { | ||
message = message.replaceFirst(Matcher.quoteReplacement(pref), ""); | ||
String[] parts = message.split(" "); | ||
String first = parts[0]; | ||
if ((first.equalsIgnoreCase(("exit")) | ||
|| message.equalsIgnoreCase("quit"))&& sender.equalsIgnoreCase("guipsp")) { | ||
System.exit(0); | ||
} else if (first.equalsIgnoreCase("reload")) { | ||
try { | ||
System.out.println("Reloading..."); | ||
Main.reLoad(); | ||
System.out.println("Reloaded"); | ||
Main.bot.sendMessage(channel, "Plugins reloaded."); | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} else if (Main.cmdmap.containsKey(first)) { | ||
try { | ||
Method met = (Method) Main.cmdmap.get(first); | ||
String result = ""; | ||
for (int i = 1; i < parts.length; i++) { | ||
if (result.length() != 0) | ||
result += " "; | ||
result += parts[i]; | ||
} | ||
met.invoke((BasePlugin) Main.classmap.get(first), channel, | ||
sender, login, hostname, result); | ||
|
||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.GUIpsp.GuiBot; | ||
|
||
import java.io.*; | ||
|
||
import java.net.*; | ||
import java.util.*; | ||
import org.jibble.pircbot.*; | ||
|
||
public class Main { | ||
public static Map classmap = new HashMap(); | ||
public static Map cmdmap = new HashMap(); | ||
static String plugdir = "/home/guipsp/Desktop/GuiBot/plugins/"; | ||
static File directory = new File(plugdir); | ||
public static GuiBot bot = new GuiBot(); | ||
|
||
public static void main(String[] args) throws Throwable { | ||
reLoad(); | ||
bot.setVerbose(true); | ||
try { | ||
bot.connect("irc.esper.net"); | ||
} catch (NickAlreadyInUseException e) { | ||
System.out.println("Nickname is in use."); | ||
} | ||
//bot.identify(""); | ||
bot.joinChannel("##crow"); | ||
} | ||
|
||
public static void reLoad() throws Throwable { | ||
classmap.clear(); | ||
cmdmap.clear(); | ||
URL classUrl; | ||
classUrl = new URL("file://" + plugdir); | ||
URL[] classUrls = { classUrl }; | ||
URLClassLoader ucl = new URLClassLoader(classUrls); | ||
File files[] = directory.listFiles(); | ||
int count=0; | ||
for (File f : files) { | ||
if (f.getName().endsWith(".class")) { | ||
String safename = f.getName().replaceAll(".class", ""); | ||
// bot.sendMessage("##crow", safename); | ||
Class<?> cls = ucl.loadClass(safename); | ||
BasePlugin inst = (BasePlugin) ((Class<?>) cls).newInstance(); | ||
inst.getClass().getMethod("main").invoke(inst); | ||
System.out.println("Loaded " + inst.pluginName() + " " | ||
+ inst.version() + " by " + inst.author()); | ||
count++; | ||
} | ||
} | ||
System.out.println(count+" plugins"); | ||
} | ||
} |