From aec013888a71856b4ec5a3415c266cd07c0ba5c4 Mon Sep 17 00:00:00 2001 From: Anatoliy Sablin Date: Mon, 6 Nov 2017 17:08:05 +0300 Subject: Use new command processor. --- .../src/main/java/com/juick/command/MessageListener.java | 3 +++ juick-commands/src/main/java/com/juick/command/Ping.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'juick-commands') 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"; } } -- cgit v1.2.3