aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-03-02 15:34:58 +0300
committerGravatar Vitaly Takmazov2017-03-02 15:34:58 +0300
commitdf77161eb015125f61e37a6bf744ff6f0aa93a14 (patch)
tree10b162af00deb4b9d2c5887ca83c69529fabb8a9 /juick-xmpp
parent74d903716950cdd543f1cc3b271c728ec5adc466 (diff)
juick-xmpp: commands refactoring
Diffstat (limited to 'juick-xmpp')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java46
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 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