aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com
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 /juick-xmpp/src/main/java/com
parentbb2a47ea3c17f92c1d55d8b0d26cd26a880373d9 (diff)
Use new command processor.
Diffstat (limited to 'juick-xmpp/src/main/java/com')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/JuickBot.java35
1 files changed, 34 insertions, 1 deletions
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);