Permalink
Browse files

SQL-based rollback

  • Loading branch information...
1 parent 0cc322b commit e0547ae09524db0a9d0100cb2405fcbc435da50b @Shockah Shockah committed Jul 3, 2012
Oops, something went wrong.
@@ -34,7 +34,7 @@ public void onEnable() {
Command.addCommands(this, cmd = new CmdTell());
ArrayList<String> lines = FileLine.read(new File("data","tell.cfg"));
- for (int i = 0; i < lines.size(); i += 4) addTell(lines.get(i),new LineMessage(Long.parseLong(lines.get(i+2)),lines.get(i+1),lines.get(i+3)));
+ for (int i = 0; i < lines.size(); i += 4) addTell(lines.get(i),new LineMessage(Long.parseLong(lines.get(i+2)),"",lines.get(i+1),lines.get(i+3)));
}
public void onDisable() {
Command.removeCommands(cmd);
@@ -92,7 +92,7 @@ public void doCommand(PircBotX bot, EType type, CommandCallback callback, Channe
String[] args = message.split(" ");
callback.type = EType.Notice;
if (args.length >= 3) {
- addTell(args[1],new LineMessage(sender.getNick(),StringTools.implode(args,2," ")));
+ addTell(args[1],new LineMessage("",sender.getNick(),StringTools.implode(args,2," ")));
callback.append("I'll pass that along");
return;
}
View
@@ -60,7 +60,7 @@ function sqlArray($result) {
function sql2json($data_sql) {
$json_str = "";
if ($total = sqlRows($data_sql)) {
- if ($total > 1) $json_str .= "[";
+ if ($total > 1) $json_str .= "{\"___\":[";
$row_count = 0;
while ($data = sqlArray($data_sql)) {
if (count($data) > 1) $json_str .= "{";
@@ -80,7 +80,7 @@ function sql2json($data_sql) {
if (count($data) > 1) $json_str .= "}";
if ($row_count < $total) $json_str .= ",";
}
- if ($total > 1) $json_str .= "]";
+ if ($total > 1) $json_str .= "]}";
} else $json_str = "{}";
return $json_str;
}
@@ -168,6 +168,7 @@ public static Config forChannel(String chan) {
return Data.config.getConfig(chan);
}
public static Config forChannel(Channel chan) {
+ if (chan == null) return Data.config;
return forChannel(chan.getName());
}
}
@@ -11,30 +11,41 @@
private static final HashMap<Byte,Class<? extends Line>> lineIDMap = new HashMap<Byte,Class<? extends Line>>();
private static final HashMap<Class<? extends Line>,Byte> lineClassMap = new HashMap<Class<? extends Line>,Byte>();
private static final SimpleDateFormat sdf;
+ protected static boolean withChannels = false;
static {
sdf = new SimpleDateFormat("[HH:mm:ss]");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
}
+ public static void setWithChannels(boolean b) {
+ withChannels = b;
+ }
+ public static boolean getWithChannels() {
+ return withChannels;
+ }
+
public final Date time;
+ public final String channel;
- public Line() {this(new Date());}
- public Line(long ms) {this(new Date(ms));}
- public Line(Date time) {
+ public Line(String channel) {this(new Date(),channel);}
+ public Line(long ms, String channel) {this(new Date(ms),channel);}
+ public Line(Date time, String channel) {
this.time = time;
+ this.channel = channel.toLowerCase();
}
public Line(BinBuffer buffer) {
- this(buffer.readXBytes(8));
+ this(buffer.readXBytes(8),buffer.readString());
}
public void save(BinBuffer buffer) {
buffer.writeXBytes(time.getTime(),8);
+ buffer.writeString(channel);
}
public String toString() {
- return sdf.format(time)+" "+getMessage();
+ return (withChannels ? "["+channel+"] " : " ")+sdf.format(time)+" "+getMessage();
}
public abstract String getMessage();
@@ -9,11 +9,11 @@
public class LineAction extends LineWithSender {
public final String text;
- public LineAction(String sender, String text) {this(new Date(),sender,text);}
- public LineAction(long ms, String sender, String text) {this(new Date(ms),sender,text);}
- public LineAction(ActionEvent<PircBotX> event) {this(new Date(),event.getUser().getNick(),event.getAction());}
- public LineAction(Date time, String sender, String text) {
- super(time,sender);
+ public LineAction(String channel, String sender, String text) {this(new Date(),channel,sender,text);}
+ public LineAction(long ms, String channel, String sender, String text) {this(new Date(ms),channel,sender,text);}
+ public LineAction(ActionEvent<PircBotX> event) {this(new Date(),event.getChannel().getName(),event.getUser().getNick(),event.getAction());}
+ public LineAction(Date time, String channel, String sender, String text) {
+ super(time,channel,sender);
this.text = text;
}
@@ -9,11 +9,11 @@
public class LineEnterLeave extends LineWithSender {
public final String text;
- public LineEnterLeave(String sender, String text) {this(new Date(),sender,text);}
- public LineEnterLeave(long ms, String sender, String text) {this(new Date(ms),sender,text);}
- public LineEnterLeave(ActionEvent<PircBotX> event) {this(new Date(),event.getUser().getNick(),event.getAction());}
- public LineEnterLeave(Date time, String sender, String text) {
- super(time,sender);
+ public LineEnterLeave(String channel, String sender, String text) {this(new Date(),channel,sender,text);}
+ public LineEnterLeave(long ms, String channel, String sender, String text) {this(new Date(ms),channel,sender,text);}
+ public LineEnterLeave(ActionEvent<PircBotX> event) {this(new Date(),event.getChannel().getName(),event.getUser().getNick(),event.getAction());}
+ public LineEnterLeave(Date time, String channel, String sender, String text) {
+ super(time,channel,sender);
this.text = text;
}
@@ -10,11 +10,11 @@
public final String target;
public final String text;
- public LineKick(String sender, String target, String text) {this(new Date(),sender,target,text);}
- public LineKick(long ms, String sender, String target, String text) {this(new Date(ms),sender,target,text);}
- public LineKick(KickEvent<PircBotX> event) {this(new Date(),event.getSource().getNick(),event.getRecipient().getNick(),event.getReason());}
- public LineKick(Date time, String sender, String target, String text) {
- super(time,sender);
+ public LineKick(String channel, String sender, String target, String text) {this(new Date(),channel,sender,target,text);}
+ public LineKick(long ms, String channel, String sender, String target, String text) {this(new Date(ms),channel,sender,target,text);}
+ public LineKick(KickEvent<PircBotX> event) {this(new Date(),event.getChannel().getName(),event.getSource().getNick(),event.getRecipient().getNick(),event.getReason());}
+ public LineKick(Date time, String channel, String sender, String target, String text) {
+ super(time,channel,sender);
this.target = target;
this.text = text;
}
@@ -9,11 +9,11 @@
public class LineMessage extends LineWithSender {
public final String text;
- public LineMessage(String sender, String text) {this(new Date(),sender,text);}
- public LineMessage(long ms, String sender, String text) {this(new Date(ms),sender,text);}
- public LineMessage(MessageEvent<PircBotX> event) {this(new Date(),event.getUser().getNick(),event.getMessage());}
- public LineMessage(Date time, String sender, String text) {
- super(time,sender);
+ public LineMessage(String channel, String sender, String text) {this(new Date(),channel,sender,text);}
+ public LineMessage(long ms, String channel, String sender, String text) {this(new Date(ms),channel,sender,text);}
+ public LineMessage(MessageEvent<PircBotX> event) {this(new Date(),event.getChannel().getName(),event.getUser().getNick(),event.getMessage());}
+ public LineMessage(Date time, String channel, String sender, String text) {
+ super(time,channel,sender);
this.text = text;
}
@@ -7,10 +7,10 @@
public class LineOther extends Line {
public final String text;
- public LineOther(String text) {this(new Date(),text);}
- public LineOther(long ms, String text) {this(new Date(ms),text);}
- public LineOther(Date time, String text) {
- super(time);
+ public LineOther(String channel, String text) {this(new Date(),channel,text);}
+ public LineOther(long ms, String channel, String text) {this(new Date(ms),channel,text);}
+ public LineOther(Date time, String channel, String text) {
+ super(time,channel);
this.text = text;
}
@@ -7,10 +7,10 @@
public abstract class LineWithSender extends Line {
public final String sender;
- public LineWithSender(String sender) {this(new Date(),sender);}
- public LineWithSender(long ms, String sender) {this(new Date(ms),sender);}
- public LineWithSender(Date time, String sender) {
- super(time);
+ public LineWithSender(String channel, String sender) {this(new Date(),channel,sender);}
+ public LineWithSender(long ms, String channel, String sender) {this(new Date(ms),channel,sender);}
+ public LineWithSender(Date time, String channel, String sender) {
+ super(time,channel);
this.sender = sender;
}
@@ -2,6 +2,9 @@
public class CriterionNumber extends Criterion {
public CriterionNumber(String column, Operation o, long value) {
+ this(column,o.toString(),value);
+ }
+ public CriterionNumber(String column, String o, long value) {
super(column+o+value);
}
@@ -2,6 +2,9 @@
public class CriterionStringEquals extends Criterion {
public CriterionStringEquals(String column, String value) {
- super(column+"='"+value.replace("\\","\\\\").replace("'","\\'")+"'");
+ this(column,value,true);
+ }
+ public CriterionStringEquals(String column, String value, boolean equals) {
+ super(column+(equals ? "=" : "<>")+"'"+value.replace("\\","\\\\").replace("'","\\'")+"'");
}
}

0 comments on commit e0547ae

Please sign in to comment.