return (new URLMessage()).setLineString(this.getCommand()).setMessagetype(Message.MSG_ADD_HANDLER).setFrom(this).parse();
}
public int handleMessage(Message msg) {
HTTPServer.Data data = (HTTPServer.Data)msg.getFrom();
//Args args = new Args(data.request,data.response,data.session,msg,data);
final Args args = httpModule.createArgs(data,msg);
args.res.setHeader("content-type:","image/png");
boolean small = args.req.getValue("small","0").contains("1");
BufferedImage image = new BufferedImage((small ? 200 : 400),(small ? 16 : 25),BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
Color transparent = new Color(1f,1f,1f,1f);
g.setBackground(transparent);
g.setColor(transparent);
g.fillRect(0,0,image.getWidth(),image.getHeight());
g.setColor(Color.BLACK);
if(args.msg.getMsgParameter() > 0) {
String jid = args.msg.getMsgParameter(0);
Presence presence = bot.getPresenceOf(jid);
g.drawImage(getImage(presence),1,(small ? 0 : 5),null);
PresenceWrapper wrapper = null;
if(presence == null) {
for(String user : bot.presences.keySet()) {
if(StringUtils.parseBareAddress(user).equals(StringUtils.parseBareAddress(jid))) {
PresenceWrapper myWrapper = bot.presences.get(user);
if(wrapper == null || wrapper.date.before(myWrapper.date))
wrapper = myWrapper;
}
}
} else {
wrapper = bot.presences.get(presence.getFrom());
}
if(wrapper != null && wrapper.presence != presence)
wrapper = null;
StringBuffer buf = new StringBuffer();
if(!small) buf.append(jid).append(": ");
if(presence == null)
buf.append("Offline");
else {
if(presence.getType() == Presence.Type.AVAILABLE) {
buf.append(presence.getMode().toString());
//.append(" - ").append(presence.getStatus());
if(!small && presence.getStatus() != null)
g.drawString(presence.getStatus(),20,22);
} else {
buf.append("Offline");
if(presence.getStatus() != null)
buf.append(" ").append(presence.getStatus());
}
if(!small && wrapper != null) {
buf.append(" (since ").append(new SimpleDateFormat("HH:mm:ss").format(wrapper.date)).append(")");
}
}
g.drawString(buf.toString(),20,10);
} else {
g.drawString("ERROR: No JID ?!",20,10);
}
final ByteCounter byteCounter = new ByteCounter(); byteCounter.bytes = 0;
try {
ImageIO.write(image,"png",new OutputStream() {
public void write(int b) throws IOException {
args.res.print((char)b);
byteCounter.bytes++;
}
});
args.res.flush();
} catch (IOException e) {
e.printStackTrace();
}
msg.reply(new Message(Message.MSG_INTERN).setLineString("logsize " + byteCounter.bytes).parse());
return 1;
}
};
cmdH.setUserLevel(-1);
kernel.registerCommandHandler(cmdH);
cmdH = new StandAloneCommandHandler(getCommandPrefix() + "/statsImage") {
class ByteCounter {
public int bytes;
}
public StandAloneMessageHandler setUserLevel(int userlevel) {
separator = "/";
return super.setUserLevel(userlevel);
}
public Message getAddHandlerMessage() {
return (new URLMessage()).setLineString(this.getCommand()).setMessagetype(Message.MSG_ADD_HANDLER).setFrom(this).parse();
}
public final Color availablecolors[] = { Color.gray,Color.blue,Color.red,Color.green,Color.yellow,Color.cyan,Color.magenta,Color.darkGray,Color.lightGray,Color.orange,Color.pink };
public int handleMessage(Message msg) {
HTTPServer.Data data = (HTTPServer.Data)msg.getFrom();
//Args args = new Args(data.request,data.response,data.session,msg,data);
final Args args = httpModule.createArgs(data,msg);
if(args.msg.getMsgParameter() < 1) return 0;
String jid = args.msg.getMsgParameter(0).toLowerCase();
boolean showmodes = Boolean.parseBoolean(args.req.getValue("showmodes","true"));
boolean showgames = Boolean.parseBoolean(args.req.getValue("showgames","true"));
int width = Integer.parseInt(args.req.getValue("width","500"));