aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Anatoliy Sablin2017-11-06 17:08:05 +0300
committerGravatar Anatoliy Sablin2017-11-06 17:08:05 +0300
commitaec013888a71856b4ec5a3415c266cd07c0ba5c4 (patch)
tree54069155d0a2aa1bccb6ac59f94ff75403375275
parentbb2a47ea3c17f92c1d55d8b0d26cd26a880373d9 (diff)
Use new command processor.
-rw-r--r--juick-commands/src/main/java/com/juick/command/MessageListener.java3
-rw-r--r--juick-commands/src/main/java/com/juick/command/Ping.java12
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/JuickBot.java35
3 files changed, 49 insertions, 1 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/MessageListener.java b/juick-commands/src/main/java/com/juick/command/MessageListener.java
index 54d2c7e7..a041ae04 100644
--- a/juick-commands/src/main/java/com/juick/command/MessageListener.java
+++ b/juick-commands/src/main/java/com/juick/command/MessageListener.java
@@ -2,6 +2,7 @@ package com.juick.command;
import com.juick.User;
import rocks.xmpp.core.stanza.model.Message;
+import rocks.xmpp.core.stanza.model.Presence;
/**
* @author ma1uta
@@ -12,6 +13,8 @@ public interface MessageListener {
void sendMessage(Message message);
+ void sendPresence(Presence presence);
+
void messagePosted(com.juick.Message msg);
void userSubscribed(User from, User to);
diff --git a/juick-commands/src/main/java/com/juick/command/Ping.java b/juick-commands/src/main/java/com/juick/command/Ping.java
index 6298abf5..5507ffce 100644
--- a/juick-commands/src/main/java/com/juick/command/Ping.java
+++ b/juick-commands/src/main/java/com/juick/command/Ping.java
@@ -1,7 +1,11 @@
package com.juick.command;
import com.juick.User;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
+import rocks.xmpp.addr.Jid;
+import rocks.xmpp.core.stanza.model.Presence;
import java.util.regex.Pattern;
@@ -9,10 +13,14 @@ import java.util.regex.Pattern;
* @author ma1uta
*/
@Component
+@Getter
public class Ping implements Command {
private static final Pattern PATTERN = Pattern.compile("^ping$", Pattern.CASE_INSENSITIVE);
+ @Value("${xmppbot_jid}")
+ private Jid jid;
+
@Override
public Pattern pattern() {
return PATTERN;
@@ -25,6 +33,10 @@ public class Ping implements Command {
@Override
public String execute(User sender, MessageListener protocolListener, String command) {
+ Presence p = new Presence(Jid.of(sender.getJid()));
+ p.setFrom(getJid());
+ p.setPriority((byte) 10);
+ protocolListener.sendPresence(p);
return "PONG";
}
}
diff --git a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
index 15e1fe66..3965570f 100644
--- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
@@ -19,6 +19,8 @@ package com.juick.components;
import com.juick.Tag;
import com.juick.User;
+import com.juick.command.MessageListener;
+import com.juick.command.Processor;
import com.juick.components.s2s.StanzaListener;
import com.juick.formatters.PlainTextFormatter;
import com.juick.server.helpers.TagStats;
@@ -52,7 +54,7 @@ import java.util.stream.Collectors;
* @author ugnich
*/
@Component
-public class JuickBot implements StanzaListener, AutoCloseable {
+public class JuickBot implements StanzaListener, AutoCloseable, MessageListener {
private static final Logger logger = LoggerFactory.getLogger(JuickBot.class);
@@ -79,12 +81,15 @@ public class JuickBot implements StanzaListener, AutoCloseable {
private PrivacyQueriesService privacyQueriesService;
@Inject
private SubscriptionService subscriptionService;
+ @Inject
+ private Processor processor;
@PostConstruct
public void init() {
xmpp.addStanzaListener(this);
broadcastPresence(null);
pt = new PrettyTime(new Locale("ru"));
+ this.processor.setMessageListener(this);
}
public Jid getJid() {
@@ -290,6 +295,8 @@ public class JuickBot implements StanzaListener, AutoCloseable {
public Optional<String> processCommand(User user, Jid from, String input) throws InvocationTargetException,
IllegalAccessException, NoSuchMethodException {
+ return Optional.ofNullable(this.processor.execute(user, input));
+/*
Optional<Method> cmd = MethodUtils.getMethodsListWithAnnotation(getClass(), UserCommand.class).stream()
.filter(m -> Pattern.compile(m.getAnnotation(UserCommand.class).pattern(),
m.getAnnotation(UserCommand.class).patternFlags()).matcher(input).matches())
@@ -307,6 +314,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
.invoke(this, user, from, groups.toArray(new String[groups.size()])));
}
return Optional.empty();
+*/
}
public boolean incomingMessageJuick(User user_from, Message msg) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
String command = msg.getBody().trim();
@@ -602,6 +610,31 @@ public class JuickBot implements StanzaListener, AutoCloseable {
return "User not found";
}
+ @Override
+ public void sendStanza(Message message) {
+ router.sendStanza(message);
+ }
+
+ @Override
+ public void sendMessage(Message message) {
+ xmpp.sendOut(ClientMessage.from(message));
+ }
+
+ @Override
+ public void sendPresence(Presence presence) {
+ xmpp.sendOut(ClientPresence.from(presence));
+ }
+
+ @Override
+ public void messagePosted(com.juick.Message msg) {
+ //TODO
+ }
+
+ @Override
+ public void userSubscribed(User from, User to) {
+ //TODO
+ }
+
void sendReply(Jid jidTo, String txt) {
Message reply = new Message();
reply.setFrom(jid);