diff options
Diffstat (limited to 'juick-xmpp/src/main/java')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java index 71711dce2..6e89355ad 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java @@ -310,30 +310,15 @@ public class JuickBot implements StanzaListener, AutoCloseable { p.setPriority((byte) 10); xmpp.sendOut(ClientPresence.from(p)); - Message reply = new Message(); - reply.setFrom(xmpp.getJid()); - reply.setTo(m.getFrom()); - reply.setType(Message.Type.CHAT); - reply.setBody("PONG"); - xmpp.sendOut(ClientMessage.from(reply)); + sendReply(m.getFrom(), "PONG"); } private void commandHelp(Message m) { - Message reply = new Message(); - reply.setFrom(xmpp.getJid()); - reply.setTo(m.getFrom()); - reply.setType(Message.Type.CHAT); - reply.setBody(HELPTEXT); - xmpp.sendOut(ClientMessage.from(reply)); + sendReply(m.getFrom(), HELPTEXT); } private void commandLogin(Message m, User user_from) { - Message reply = new Message(); - reply.setFrom(xmpp.getJid()); - reply.setTo(m.getFrom()); - reply.setType(Message.Type.CHAT); - reply.setBody("http://juick.com/login?" + xmpp.userService.getHashByUID(user_from.getUid())); - xmpp.sendOut(ClientMessage.from(reply)); + sendReply(m.getFrom(), "http://juick.com/login?" + xmpp.userService.getHashByUID(user_from.getUid())); } private void commandPM(Message m, User user_from, String user_to, String body) { @@ -429,33 +414,28 @@ public class JuickBot implements StanzaListener, AutoCloseable { txt = "You don't have any users or tags in your blacklist."; } - Message reply = new Message(); - reply.setFrom(xmpp.getJid()); - reply.setTo(m.getFrom()); - reply.setType(Message.Type.CHAT); - reply.setBody(txt); - xmpp.sendOut(ClientMessage.from(reply)); + sendReply(m.getFrom(), txt); } boolean commandLast(Jid jidFrom) { User user = xmpp.userService.getUserByJID(jidFrom.asBareJid().toEscapedString()); - Message reply = new Message(); - reply.setFrom(xmpp.getJid()); - reply.setTo(jidFrom); - reply.setType(Message.Type.CHAT); - reply.setBody("Last messages: " + printMessages(xmpp.messagesService.getAll(user.getUid(), 0), true)); - xmpp.sendOut(ClientMessage.from(reply)); + sendReply(jidFrom, "Last messages:\n" + + printMessages(xmpp.messagesService.getAll(user.getUid(), 0), true)); return true; } private boolean commandMaintenance(Jid jidFrom) { + sendReply(jidFrom, "Комментирование временно недоступно"); + return true; + } + + void sendReply(Jid jidTo, String txt) { Message reply = new Message(); reply.setFrom(xmpp.getJid()); - reply.setTo(jidFrom); + reply.setTo(jidTo); reply.setType(Message.Type.CHAT); - reply.setBody("Комментирование временно недоступно"); + reply.setBody(txt); xmpp.sendOut(ClientMessage.from(reply)); - return true; } @Override |