From df77161eb015125f61e37a6bf744ff6f0aa93a14 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 2 Mar 2017 15:34:58 +0300 Subject: juick-xmpp: commands refactoring --- .../java/com/juick/components/s2s/JuickBot.java | 46 ++++++---------------- 1 file 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 71711dce..6e89355a 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 -- cgit v1.2.3