diff options
Diffstat (limited to 'juick-xmpp/src')
-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 |