diff options
author | Vitaly Takmazov | 2018-01-30 14:23:50 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-01-30 14:23:50 +0300 |
commit | 2d6e1dc76e659b78b3103af2bcf1b7f13db62f0a (patch) | |
tree | 30f46c54d5ecd5bdac3de17998425288b96908c7 /juick-xmpp | |
parent | 1e5c0403d3339c40950106737ef17727d786f6d4 (diff) |
xmpp: D #message
Diffstat (limited to 'juick-xmpp')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/JuickBot.java | 23 | ||||
-rw-r--r-- | juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java | 2 |
2 files changed, 24 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 9855f958..42a5f8a6 100644 --- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java @@ -632,7 +632,30 @@ public class JuickBot implements StanzaListener, AutoCloseable { } return "Message not found"; } + @UserCommand(pattern = "^D #(\\d+)$", help = "D #1234 - Delete post", patternFlags = Pattern.CASE_INSENSITIVE) + public String commandDeletePost(User user, Jid from, String... args) { + int mid = Integer.valueOf(args[0]); + if (messagesService.deleteMessage(user.getUid(), mid)) { + return "Message deleted"; + } + return "This is not your message"; + } + @UserCommand(pattern = "^D #(\\d+)(\\.|\\-|\\/)(\\d+)$", help = "D #1234/5 - Delete comment", patternFlags = Pattern.CASE_INSENSITIVE) + public String commandDeleteReply(User user, Jid from, String... args) { + int mid = Integer.valueOf(args[0]); + int rid = Integer.valueOf(args[2]); + if (messagesService.deleteReply(user.getUid(), mid, rid)) { + return "Reply deleted"; + } else { + return "This is not your reply"; + } + } + /* + @UserCommand(pattern = "(^(D L|DL|D LAST)$", help = "D #1234/5 - Delete comment", patternFlags = Pattern.CASE_INSENSITIVE) + public String commandDeleteLast(User user, Jid from, String... args) { + } + */ void sendReply(Jid jidTo, String txt) { Message reply = new Message(); reply.setFrom(jid); diff --git a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java index 7f08602c..7c5a1a98 100644 --- a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java +++ b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java @@ -96,7 +96,7 @@ public class XMPPServerTests extends AbstractJUnit4SpringContextTests { public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG")); // subscription commands have two lines, others have 1 - assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(21)); + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(23)); } @Test |