This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
/
SubcommandsTest.java
50 lines (41 loc) · 1.88 KB
/
SubcommandsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package me.deprilula28.jdacmdframework.test;
import me.deprilula28.jdacmdframework.CommandContext;
import me.deprilula28.jdacmdframework.CommandFramework;
import me.deprilula28.jdacmdframework.Settings;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.User;
import java.util.stream.Stream;
public class SubcommandsTest {
public static void main(String[] args) throws Exception {
JDA jda = new JDABuilder(AccountType.BOT).setToken(args[0]).buildBlocking();
Settings settings = Settings.builder()
.prefix("!").async(true).protectMentionEveryone(true)
.build();
CommandFramework framework = new CommandFramework(jda, settings);
// Adding commands
framework.command("messagepurge", SubcommandsTest::messagepurge, cmd -> {
cmd.sub("user", SubcommandsTest::purgeUser);
});
framework.listenEvents();
}
private static String messagepurge(CommandContext context) {
context.getChannel().getHistory().retrievePast(context.nextInt()).queue(history -> {
history.forEach(cur -> cur.delete().queue());
context.send(String.format("Deleted %s messages!", history.size()));
});
return null;
}
private static String purgeUser(CommandContext context) {
User user = context.nextUser();
context.getChannel().getHistory().retrievePast(context.nextInt()).queue(history -> {
Stream<Message> delete = history.stream().filter(cur -> cur.getAuthor() == user);
long amount = delete.count();
delete.forEach(cur -> cur.delete().queue());
context.send(String.format("Deleted %s messages from %s!", amount, user.getAsMention()));
});
return null;
}
}