Initial commit

This commit is contained in:
Kegan Myers 2013-06-25 10:15:25 -05:00
commit f255626098
17 changed files with 1337 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,13 @@
package be.xrg.evilbotx;
import org.pircbotx.PircBotX;
public class BotPair {
public Network a;
public PircBotX b;
public BotPair(Network a, PircBotX b) {
this.a = a;
this.b = b;
}
}

View file

@ -0,0 +1,49 @@
package be.xrg.evilbotx;
import java.util.ArrayList;
import org.pircbotx.PircBotX;
public class EvilBotX {
public static String VERSION = "EvilBotX v0.1.0";
private ArrayList<BotPair> b = new ArrayList<BotPair>();
public EvilBotX(ArrayList<Network> nets, XListener shared) {
for (Network a : nets) {
PircBotX bot = new PircBotX();
bot.setLogin(a.getLogin());
bot.setName(a.getNick());
bot.setVerbose(a.useVerbose());
bot.setAutoNickChange(a.useAutoNick());
bot.getListenerManager().addListener(shared);
if (a.useCustomListener()) {
bot.getListenerManager().addListener(a.getListener());
}
this.b.add(new BotPair(a, bot));
}
}
public void go() {
for (BotPair c : this.b) {
try {
if (c.a.useSSL()) {
c.b.connect(c.a.getAddress(), c.a.getPort(), c.a.getPass(),
new org.pircbotx.UtilSSLSocketFactory()
.trustAllCertificates());
} else {
c.b.connect(c.a.getAddress(), c.a.getPort(), c.a.getPass());
}
for (String a : c.a.getChannels()) {
c.b.joinChannel(a);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
System.out.println("You need to create your own runner class to use EvilBotX. Please check the documentation for details.");
}
}

View file

@ -0,0 +1,86 @@
package be.xrg.evilbotx;
import java.util.ArrayList;
public class Network {
private XListener privateListener;
private String name;
private String nick;
private String address;
private String pass;
private ArrayList<String> channels;
private int port;
private boolean autoNickChange = true;
private boolean customListener = false;
private boolean verbose = false;
private boolean ssl = true;
public Network(String login, String nick, String address, String pass, int port) {
this.address = address;
this.channels = new ArrayList<String>();
this.name = login;
this.nick = nick;
this.pass = pass;
this.port = port;
}
public void addChannel(String channel) {
this.channels.add(channel);
}
public void setSSL(boolean ssl) {
this.ssl = ssl;
}
public void setCustomListener(XListener listen) {
this.privateListener = listen;
this.customListener = true;
}
public String getAddress() {
return this.address;
}
public XListener getListener() {
return this.privateListener;
}
public String getLogin() {
return this.name;
}
public String getNick() {
return this.nick;
}
public String getPass() {
return this.pass;
}
public int getPort() {
return this.port;
}
public boolean useAutoNick() {
return this.autoNickChange;
}
public boolean useCustomListener() {
return this.customListener;
}
public boolean useSSL() {
return this.ssl;
}
public boolean useVerbose() {
return this.verbose;
}
public ArrayList<String> getChannels() {
return this.channels;
}
}

View file

@ -0,0 +1,133 @@
package be.xrg.evilbotx;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class Storage {
static String fileName = "data.ebx";
static String dfName = "dsssseRs";
private Map<String, byte[]> data;
private boolean loaded = false;
private final String location;
public Storage() {
this(System.getProperty("user.dir") + "/");
}
public Storage(String location) {
this.location = location;
this.read();
if (!this.loaded) {
this.init();
}
}
@SuppressWarnings("unchecked")
private void read() {
File f = new File(this.location);
File ff = new File(f, Storage.fileName);
if (ff.exists()) {
try {
FileInputStream fi = new FileInputStream(ff);
byte[] b = new byte[(int) f.length()];
fi.read(b);
fi.close();
ObjectInputStream is = new ObjectInputStream(
new ByteArrayInputStream(b));
this.data = (HashMap<String, byte[]>) is.readObject();
this.loaded = true;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
private void write() {
try {
FileOutputStream f = new FileOutputStream(this.location
+ Storage.fileName);
f.write(Storage.toByteArr((Serializable) this.data));
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void init() {
boolean fail = false;
File f = new File(this.location);
File ff = new File(f, Storage.fileName);
if (!f.exists()) {
if (!f.mkdirs()) {
fail = true;
}
}
if (ff.exists()) {
try {
if (!(ff.delete() && ff.createNewFile())) {
fail = true;
}
} catch (IOException e) {
e.printStackTrace();
fail = true;
}
} else {
try {
if (!ff.createNewFile()) {
fail = true;
}
} catch (IOException e) {
e.printStackTrace();
fail = true;
}
}
this.data = new HashMap<String, byte[]>();
if (!fail) {
loaded = true;
} else {
System.exit(-2);
}
this.putData(385639, "FakeDataToPopulate", Storage.toByteArr("lolol"));
}
public boolean hasData(int ID, String appName) {
return this.data.containsKey(this.getUID(ID, appName));
}
public void putData(int ID, String appName, byte[] data) {
String uid = this.getUID(ID, appName);
this.data.put(uid, data);
this.write();
}
public byte[] getData(int ID, String appName) {
return this.data.get(this.getUID(ID, appName));
}
private String getUID(int ID, String appName) {
return Utilities.crc32(appName + ID);
}
public static byte[] toByteArr(Serializable o) {
byte[] b = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(o);
b = out.toByteArray();
objOut.close();
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
}

View file

@ -0,0 +1,182 @@
package be.xrg.evilbotx;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.zip.CRC32;
import org.apache.commons.lang3.StringEscapeUtils;
public class Utilities {
public static final String strEnc = "UTF-8";
public static boolean compat = false;
public static String[] getHTMLPage(String url) {
URL loc;
HttpURLConnection conn;
BufferedReader rd;
String line;
String[] ret = { "", "" };
try {
loc = new URL(url);
conn = (HttpURLConnection) loc.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
ret[0] += conn.getResponseCode();
while ((line = rd.readLine()) != null) {
ret[1] += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
ret[0] += "-1";
}
return ret;
}
public static String decodeHTMLEntities(String encoded) {
return StringEscapeUtils.unescapeHtml4(encoded);
}
public static String getPageTitle(String html) {
int[] f = new int[2];
f[0] = html.indexOf("<title>") + 7;
f[1] = html.indexOf("</title>");
return "" + html.substring(f[0], f[1]);
}
public static String intToTimeString(int seconds) {
boolean started = false;
String ret = "";
int amount = 86400;
if (seconds > amount) {
ret += (seconds / amount) + " day";
if (seconds/amount > 1) {
ret += "s";
}
ret += ", ";
seconds -= (seconds / amount) * amount;
started = true;
}
amount = 3600;
if (seconds > amount || started) {
ret += (seconds / amount) + " hour";
if (seconds/amount > 1) {
ret += "s";
}
ret += ", ";
seconds -= (seconds / amount) * amount;
started = true;
}
amount = 60;
if (seconds > amount || started) {
ret += (seconds / amount) + " minute";
if (seconds/amount > 1) {
ret += "s";
}
ret += ", ";
seconds -= (seconds / amount) * amount;
started = true;
}
ret += seconds + " second";
if (seconds > 1) {
ret += "s";
}
return ret;
}
public static void saveData(byte[] data, String modName, int modID) {
}
public static boolean hasData(String modName, int modID) {
return false;
}
public static byte[] loadData(String modName, int modID) {
return null;
}
public static String[] formatString(String[] a, int lineLength) {
String nextln = null;
boolean done = false;
ArrayList<String> r = new ArrayList<String>();
nextln = "";
for (int i = 0; i < lineLength; i++) {
nextln += "";
}
nextln += "";
r.add(nextln);
while (!done) {
for (String s : a) {
nextln = "";
int curl = 0;
String[] words = s.split(" ");
for (String w : words) {
if (curl + w.length() > lineLength) {
nextln += w;
} else {
nextln = Utilities.padString(nextln, lineLength + 1);
nextln += "";
r.add(nextln);
nextln = "";
}
}
nextln = Utilities.padString(nextln, lineLength + 1);
nextln += "";
r.add(nextln);
}
}
nextln = "";
for (int i = 0; i < lineLength; i++) {
nextln += "";
}
nextln += "";
r.add(nextln);
return (String[]) r.toArray();
}
public static String md5(String input) throws NoSuchAlgorithmException,
UnsupportedEncodingException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
if (input != null)
input = bToStr(md5.digest(input.getBytes(Utilities.strEnc)));
return input;
}
public static String crc32(String input) {
CRC32 crc32 = new CRC32();
if (input != null) {
crc32.update(input.getBytes());
input = Utilities.padOut(Long.toHexString(crc32.getValue()), 8);
}
return input;
}
public static String bToStr(byte[] in) {
char[] hexArray = "0123456789abcdef".toCharArray();
char[] hexChars = new char[in.length * 2];
int v;
for (int j = 0; j < in.length; j++) {
v = in[j] & 0xFF;
hexChars[j * 2] = hexArray[v / 16];
hexChars[j * 2 + 1] = hexArray[v % 16];
}
return new String(hexChars);
}
private static String padString(String ln, int lineLength) {
for (int i = ln.length(); i < lineLength; i++) {
ln += " ";
}
return ln;
}
private static String padOut(String input, int nChar) {
return String.format("%" + nChar + "s", input).replace(' ', '0');
}
}

View file

@ -0,0 +1,52 @@
package be.xrg.evilbotx;
import java.util.Iterator;
import java.util.Map.Entry;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.Listener;
import org.pircbotx.hooks.ListenerAdapter;
import be.xrg.evilbotx.parents.EBXComponent;
//This is meant to deal with raw types
@SuppressWarnings({ "unchecked", "rawtypes" })
public class XListener extends ListenerAdapter implements Listener {
private java.util.Map<String, EBXComponent> com = new java.util.HashMap<String, EBXComponent>();
public void onEvent(Event e) throws Exception {
super.onEvent(e);
Iterator<Entry<String, EBXComponent>> i = this.com.entrySet()
.iterator();
while (i.hasNext()) {
Entry<String, EBXComponent> z = i.next();
EBXComponent t = z.getValue();
String k = z.getKey();
if (t.wantEvent(e)) {
System.out.println(k);
t.handleEvent(e);
}
}
}
public void addComponent(EBXComponent c) {
String u = this.makeUniqueName(c);
System.out.println("AddComponent-" + u + " " + c.getComponentName());
if (!this.com.containsKey(u)) {
this.com.put(u, c);
}
}
public void removeComponent(EBXComponent c) {
String u = this.makeUniqueName(c);
if (!this.com.containsKey(u)) {
this.com.remove(u);
}
}
private String makeUniqueName(EBXComponent c) {
return Utilities.crc32(c.getClass().getName() + c.getComponentName()
+ c.getComponentID() + "some needless salt");
}
}

View file

@ -0,0 +1,84 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.ActionEvent;
import org.pircbotx.hooks.events.HalfOpEvent;
import org.pircbotx.hooks.events.JoinEvent;
import org.pircbotx.hooks.events.KickEvent;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.hooks.events.OpEvent;
import org.pircbotx.hooks.events.PartEvent;
import org.pircbotx.hooks.events.RemoveChannelBanEvent;
import org.pircbotx.hooks.events.SetChannelBanEvent;
import org.pircbotx.hooks.events.SuperOpEvent;
import org.pircbotx.hooks.events.TopicEvent;
import org.pircbotx.hooks.events.VoiceEvent;
import be.xrg.evilbotx.Storage;
import be.xrg.evilbotx.Utilities;
import be.xrg.evilbotx.parents.EBXComponent;
@SuppressWarnings("rawtypes")
public class ChannelStatsWatcher extends EBXComponent {
static Class[] q = { ActionEvent.class, HalfOpEvent.class, JoinEvent.class,
KickEvent.class, MessageEvent.class, OpEvent.class,
PartEvent.class, RemoveChannelBanEvent.class,
SetChannelBanEvent.class, SuperOpEvent.class, TopicEvent.class,
VoiceEvent.class };
public ChannelStatsWatcher(Storage s) {
super(s, q);
// TODO Auto-generated constructor stub
}
@Override
public void handleEvent(Event e) {
String j = Utilities.crc32(e.getBot().getLogin());
if (e instanceof MessageEvent) {
MessageEvent t = (MessageEvent) e;
this.inc(j, 0);
String b = t.getMessage();
if (b.equals("!stats")) {
}
} else if (e instanceof ActionEvent) {
// ActionEvent
} else if (e instanceof HalfOpEvent) {
// HalfOpEvent
} else if (e instanceof JoinEvent) {
// JoinEvent
} else if (e instanceof KickEvent) {
// KickEvent
} else if (e instanceof OpEvent) {
// OpEvent
} else if (e instanceof PartEvent) {
// PartEvent
} else if (e instanceof RemoveChannelBanEvent) {
// RemoveChannelBanEvent
} else if (e instanceof SetChannelBanEvent) {
// SetChannelBanEvent
} else if (e instanceof SuperOpEvent) {
// SuperOpEvent
} else if (e instanceof TopicEvent) {
// TopicEvent
} else if (e instanceof VoiceEvent) {
// VoiceEvent
}
}
private void inc(String p, int place) {
}
@Override
public String getComponentName() {
return "ChannelStats";
}
@Override
public int getComponentID() {
return 9001938;
}
}

View file

@ -0,0 +1,32 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
@SuppressWarnings("rawtypes")
public class CountdownCommand extends be.xrg.evilbotx.parents.EBXComponent {
public CountdownCommand(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
public void handleEvent(Event e) {
new be.xrg.evilbotx.special.CountdownThread((MessageEvent) e).run();
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
MessageEvent a = (MessageEvent) e;
return a.getMessage().equals("!countdown");
}
return false;
}
public String getComponentName() {
return "CountdownCommand";
}
public int getComponentID() {
return 98763235;
}
}

View file

@ -0,0 +1,220 @@
package be.xrg.evilbotx.components;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
import be.xrg.evilbotx.EvilBotX;
import be.xrg.evilbotx.Utilities;
@SuppressWarnings("rawtypes")
public class HackCommand extends be.xrg.evilbotx.parents.EBXComponent {
private Map<String, int[]> d;
private boolean l = false;
private String q;
private boolean r = false;
public HackCommand(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
@Override
public void handleEvent(Event e) {
MessageEvent a = (MessageEvent) e;
String b = a.getMessage();
if (b.equals("!hack")) {
hack(a);
} else if (b.equals("!hackstats")) {
hackStats(a);
} else if (b.equals("!hackcount")) {
hackCount(a);
}
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
return ((MessageEvent) e).getMessage().startsWith("!hack");
}
return false;
}
private void hack(MessageEvent e) {
this.ensureLoad();
int INTERVAL = 3600;
int ct = (int) (System.currentTimeMillis() / 1000);
String who = e.getUser().getNick().toLowerCase();
int i = (int) (Math.random() * 50 - 10);
if (!this.d.containsKey(who)) {
int[] t = new int[2];
t[0] = 0;
t[1] = ct - INTERVAL;
this.d.put(who, t);
}
int[] ud = this.d.get(who);
int tt = ud[0] + i;
String ms;
if (ud[1] + INTERVAL <= ct) {
if (tt < 0) {
tt = 0;
}
if (i <= 0 && ud[0] == 0) {
ms = "You were unable to hack anything. You still have 0 computers in your botnet.";
return;
} else if (i < -50) {
ms = "Looks like the IT department woke up. " + (i * -1)
+ " hosts lost. You now have " + tt
+ " computers in your botnet.";
} else if (i < -8) {
ms = "" + (-1 * i)
+ " of your compromised hosts were lost. You now have "
+ tt + " computers in your botnet.";
} else if (i < 0) {
ms = "" + (-1 * i)
+ " of your bots were cleaned. You now have " + tt
+ " computers in your botnet.";
} else if (i == 0) {
ms = who
+ ": You weren't able to hack any machines. You still have "
+ tt + " computers in your botnet.";
} else if (i > 30) {
ms = "You are a hacking god and owned " + i
+ " boxes. You now have " + tt
+ " computers in your botnet.";
} else if (i > 1) {
ms = "You hacked " + i + " d00dz. You now have " + tt
+ " computers in your botnet.";
} else {
ms = "You hacked " + i + " box. MUST HACK MORE.";
}
ud[0] = tt;
ud[1] = ct;
this.d.put(who, ud);
e.respond(ms);
this.r = false;
this.save();
} else {
int t = (ud[1] + INTERVAL) - ct;
e.respond("You're too tired to hack anything. Chill for "
+ Utilities.intToTimeString(t) + ".");
}
}
private void hackCount(MessageEvent e) {
this.ensureLoad();
String who = e.getUser().getNick();
String sta = "You have ";
if (this.d.containsKey(who)) {
int[] ud = this.d.get(who);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
sta += ud[0]
+ " computers in your botnet, and your last hack occured at "
+ df.format(ud[1] * (long) 1000) + ".";
} else {
sta += "not done any hacking.";
}
e.respond(sta);
}
private void hackStats(MessageEvent e) {
this.ensureLoad();
if (!this.r) {
int users = 0, boxes = 0, latest = 0, time = (int) (System
.currentTimeMillis() / 1000), leader = 0;
String recentName = "", leaderName = "";
Date dtime = new Date(System.currentTimeMillis());
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
for (Entry<String, int[]> entry : d.entrySet()) {
int[] ud = entry.getValue();
String key = entry.getKey();
users++;
boxes += ud[0];
if (leader < ud[0]) {
leader = ud[0];
leaderName = key;
}
if (latest < ud[1]) {
latest = ud[1];
recentName = key;
}
}
dtime = new Date(latest * (long) 1000);
this.q = "Currently tracking " + users + " users with " + boxes
+ " zombie PCs. Current leader is " + leaderName + " with "
+ leader + " machines. The most recent hack happened on "
+ df.format(dtime) + " and was done by " + recentName
+ ". (" + EvilBotX.VERSION + ", " + time + ")";
this.r = true;
}
e.respond(this.q);
}
private void ensureLoad() {
if (!this.l) {
this.load();
}
}
@Override
public String getComponentName() {
return "HackCommand";
}
@Override
public int getComponentID() {
return 2400062;
}
@SuppressWarnings("unchecked")
private void load() {
byte[] a = null;
try {
if (this.s.hasData(this.getComponentID(), this.getComponentName())) {
a = this.s.getData(this.getComponentID(),
this.getComponentName());
if (a != null) {
ObjectInputStream is = new ObjectInputStream(
new ByteArrayInputStream(a));
this.d = (HashMap<String, int[]>) is.readObject();
this.l = true;
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (!this.l) {
this.init();
}
}
private void init() {
this.d = new HashMap<String, int[]>();
this.l = true;
}
private void save() {
byte[] a = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(this.d);
a = out.toByteArray();
objOut.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
this.s.putData(this.getComponentID(), this.getComponentName(), a);
}
}

View file

@ -0,0 +1,35 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
@SuppressWarnings("rawtypes")
public class HelloWorldCommand extends be.xrg.evilbotx.parents.EBXComponent {
public HelloWorldCommand(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
public void handleEvent(Event e) {
MessageEvent t = (MessageEvent) e;
if (t.getMessage().startsWith("!hello")) {
t.getBot().sendMessage(t.getChannel(), "Hello world");
}
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
return ((MessageEvent) e).getMessage().equals("!hello");
}
return false;
}
public String getComponentName() {
return "HelloWorldCommand";
}
public int getComponentID() {
return 68752;
}
}

View file

@ -0,0 +1,68 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
@SuppressWarnings("rawtypes")
public class InsultCommand extends be.xrg.evilbotx.parents.EBXComponent {
public static String[] i = { "Nobody likes you.", "Poq Gai",
"I do not like your look, I promise thee", "Die in a fire",
"I desire that we be better strangers",
"If ignorance is bliss, you must be overjoyed", "GTFO",
"Besame el culo", "La reputisima madre que te remil pario",
"Jy pis my af", "Lay da yuen fay gay mm sai sou",
"Degenerate and base art thou", "Blöde fotze",
"You will live a long pathetic life", "Kusu o taberu na",
"You will get hit by a car later on",
"You are not worth another word, else I'd call you knave",
"Your face is as a book, where men may read strange matters",
"Everything you believe in is an illusion" };
public InsultCommand(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
@Override
public void handleEvent(Event e) {
MessageEvent t = (MessageEvent) e;
String b = t.getMessage();
if (b.startsWith("!insult")) {
String a = "";
if (b.contains(" ")) {
String[] c = b.split(" ");
if (c.length >= 1) {
a += c[1];
} else {
a += t.getUser().getNick();
}
} else {
a += t.getUser().getNick();
}
t.getBot().sendMessage(t.getChannel(),
a + ": " + InsultCommand.randInsult());
}
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
return ((MessageEvent) e).getMessage().startsWith("!insult");
}
return false;
}
@Override
public String getComponentName() {
// TODO Auto-generated method stub
return "InsultCommand";
}
@Override
public int getComponentID() {
// TODO Auto-generated method stub
return 0;
}
static String randInsult() {
return InsultCommand.i[(int) (Math.random() * InsultCommand.i.length)];
}
}

View file

@ -0,0 +1,195 @@
package be.xrg.evilbotx.components;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.JoinEvent;
import org.pircbotx.hooks.events.KickEvent;
import org.pircbotx.hooks.events.MessageEvent;
import org.pircbotx.hooks.events.NickChangeEvent;
import org.pircbotx.hooks.events.PartEvent;
import org.pircbotx.hooks.events.QuitEvent;
import be.xrg.evilbotx.Storage;
import be.xrg.evilbotx.Utilities;
/*
* 0 = first seen
* 1 = recently seen
*/
@SuppressWarnings("rawtypes")
public class SeenCommand extends be.xrg.evilbotx.parents.EBXComponent {
static Class[] q = { JoinEvent.class, KickEvent.class, MessageEvent.class,
NickChangeEvent.class, PartEvent.class, QuitEvent.class };
private Map<String, int[]> d;
private boolean l = false;
public SeenCommand(Storage s) {
super(s, SeenCommand.q);
}
public String getComponentName() {
return "SeenCommand";
}
public int getComponentID() {
return 83463;
}
public void handleEvent(Event e) {
String j = Utilities.crc32(e.getBot().getLogin());
if (e instanceof MessageEvent) {
MessageEvent t = (MessageEvent) e;
this.seen(j, t.getUser().getNick(), true);
String b = t.getMessage();
if (b.startsWith("!seen")) {
if (b.equalsIgnoreCase("!seenstats")) {
t.respond(this.seenStats());
} else if (b.length() > 6) {
String[] c = b.split(" ");
if (c.length >= 2) {
t.respond(this.checkSeen(j, c[1]));
}
}
}
} else if (e instanceof JoinEvent) {
this.seen(j, ((JoinEvent) e).getUser().getNick(), true);
} else if (e instanceof PartEvent) {
this.seenOff(j, ((PartEvent) e).getUser().getNick());
} else if (e instanceof QuitEvent) {
this.seenOff(j, ((QuitEvent) e).getUser().getNick());
} else if (e instanceof KickEvent) {
this.seenOff(j, ((KickEvent) e).getRecipient().getNick());
} else if (e instanceof NickChangeEvent) {
this.seenOff(j, ((NickChangeEvent) e).getOldNick());
this.seen(j, ((NickChangeEvent) e).getNewNick(), true);
}
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent || e instanceof JoinEvent
|| e instanceof PartEvent || e instanceof QuitEvent
|| e instanceof KickEvent || e instanceof NickChangeEvent) {
return true;
}
return false;
}
private void seen(String prefix, String user, boolean s) {
user = prefix + user.toLowerCase();
int a = (int) (System.currentTimeMillis() / 1000);
this.ensureLoad();
int[] b;
if (this.d.containsKey(user)) {
b = this.d.get(user);
} else {
b = new int[3];
b[0] = a;
}
b[1] = a;
b[2] = 1;
this.d.put(user, b);
if (s) {
this.save();
}
}
private void seenOff(String prefix, String user) {
user = user.toLowerCase();
this.seen(prefix, user, false);
int[] b = this.d.get(user);
b[2] = 0;
this.d.put(prefix + user.toLowerCase(), b);
this.save();
}
private String checkSeen(String p, String w) {
String a = p+ w.toLowerCase();
String seen = "";
int h = (int) (System.currentTimeMillis() / 1000);
if (this.d.containsKey(a)) {
int[] b = this.d.get(a);
if (b[2] == 0) {
seen += "I last saw " + w + " "
+ Utilities.intToTimeString(h - b[1]) + " ago.";
} else {
seen += w + " is currently online.";
}
seen += " I first saw " + w + " "
+ Utilities.intToTimeString(h - b[0]) + " ago.";
} else {
seen += "I have not seen " + w + ".";
}
return seen;
}
private String seenStats() {
int users = 0, online = 0, time = (int) (System.currentTimeMillis() / 1000);
for (Entry<String, int[]> entry : d.entrySet()) {
users++;
int[] v = entry.getValue();
if (v[2] != 0) {
online++;
}
}
return "I am currently tracking " + users + " nicks, " + online
+ " of whom are currently online. (AwesomeBot "
+ be.xrg.evilbotx.EvilBotX.VERSION + ", " + time + ")";
// return null;
}
private void ensureLoad() {
if (!l) {
this.load();
}
}
@SuppressWarnings("unchecked")
private void load() {
byte[] a = null;
try {
if (this.s.hasData(this.getComponentID(), this.getComponentName())) {
a = this.s.getData(this.getComponentID(),
this.getComponentName());
if (a != null) {
ObjectInputStream is = new ObjectInputStream(
new ByteArrayInputStream(a));
this.d = (HashMap<String, int[]>) is.readObject();
this.l = true;
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
if (!this.l) {
this.init();
}
}
private void init() {
this.d = new HashMap<String, int[]>();
this.l = true;
}
private void save() {
byte[] a = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(this.d);
a = out.toByteArray();
objOut.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
this.s.putData(this.getComponentID(), this.getComponentName(), a);
}
}

View file

@ -0,0 +1,50 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
@SuppressWarnings("rawtypes")
public class SlapCommand extends be.xrg.evilbotx.parents.EBXComponent {
public SlapCommand(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
public void handleEvent(Event e) {
if (e instanceof MessageEvent) {
MessageEvent t = (MessageEvent) e;
String b = t.getMessage();
if (b.startsWith("!slap")) {
String a = "slaps ";
if (b.contains(" ")) {
String[] c = b.split(" ");
if (c.length >= 1) {
a += c[1];
} else {
a += t.getUser().getNick();
}
} else {
a += t.getUser().getNick();
}
t.getBot().sendAction(t.getChannel(), a);
}
}
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
return ((MessageEvent) e).getMessage().startsWith("!slap");
}
return false;
}
@Override
public String getComponentName() {
return "SlapCommand";
}
@Override
public int getComponentID() {
return 462963;
}
}

View file

@ -0,0 +1,60 @@
package be.xrg.evilbotx.components;
import org.pircbotx.hooks.Event;
import org.pircbotx.hooks.events.MessageEvent;
import be.xrg.evilbotx.Utilities;
@SuppressWarnings("rawtypes")
public class YoutubeParser extends be.xrg.evilbotx.parents.EBXComponent {
public static String yt = "1,16[You4,16Tube1,16] ";
public YoutubeParser(be.xrg.evilbotx.Storage s) {
super(s, MessageEvent.class);
}
@Override
public void handleEvent(Event e) {
MessageEvent a = (MessageEvent) e;
String[] b = a.getMessage().split(" ");
for (String c : b) {
if (this.isYTLink(c)) {
String[] d = Utilities.getHTMLPage(c);
if (d[0].equals("200")) {
String f = Utilities.decodeHTMLEntities(Utilities
.getPageTitle(d[1]));
f = f.substring(0, f.length() - 10);
a.getBot()
.sendMessage(a.getChannel(), YoutubeParser.yt + f);
}
}
}
}
@Override
public String getComponentName() {
// TODO Auto-generated method stub
return "YoutubeParser";
}
@Override
public int getComponentID() {
return 438329;
}
protected boolean wantEventM(Event e) {
if (e instanceof MessageEvent) {
MessageEvent a = (MessageEvent) e;
return a.getMessage().contains("youtu");
}
return false;
}
private boolean isYTLink(String p) {
return ((p.startsWith("http://") || p.startsWith("https://")) && (p
.contains("://youtu.be/") || ((p
.contains("://youtube.com/watch?") || p
.contains("://www.youtube.com/watch?")) && p.contains("v="))));
}
}

View file

@ -0,0 +1,48 @@
package be.xrg.evilbotx.parents;
import java.util.ArrayList;
import java.util.Arrays;
import org.pircbotx.hooks.Event;
import be.xrg.evilbotx.Storage;
@SuppressWarnings("rawtypes")
public abstract class EBXComponent {
protected Storage s;
private ArrayList<Class> c;
private EBXComponent(Storage s) {
this.c = new ArrayList<Class>();
this.s = s;
}
public EBXComponent(Storage s, Class a) {
this(s);
this.c.add(a);
}
public EBXComponent(Storage s, Class[] a) {
this(s);
this.c.addAll(Arrays.asList(a));
}
public boolean wantEvent(Event e) {
for (Class a : this.c) {
if (a.isInstance(e)) {
return (true && this.wantEventM(e));
}
}
return false;
}
protected boolean wantEventM(Event e) {
return false;
}
public abstract void handleEvent(Event e);
public abstract String getComponentName();
public abstract int getComponentID();
}

View file

@ -0,0 +1,30 @@
package be.xrg.evilbotx.special;
import org.pircbotx.hooks.events.MessageEvent;
public class CountdownThread extends Thread {
public static final boolean load = true;
public static String[] countdown = { "5!", "4!", "3!", "2!", "1!",
"Smoke!!!!!! 8D--~~~~~~~~~~~~" };
@SuppressWarnings("rawtypes")
private MessageEvent e;
@SuppressWarnings("rawtypes")
public CountdownThread(MessageEvent e) {
System.out.println("Started new special.Countdown");
this.e = e;
}
public void run() {
System.out.println("Running special.Countdown");
for (int i = 0; i < CountdownThread.countdown.length; i++) {
e.getBot().sendMessage(e.getChannel(),
"3,14" + CountdownThread.countdown[i]);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}