-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.java
89 lines (69 loc) · 3.37 KB
/
bot.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.lethalflame.bot;
import com.lethalflame.bot.Utlis.ClassUtlis;
import com.lethalflame.bot.Utlis.CommandExecutor;
import com.lethalflame.bot.listeners.messageListener;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.Compression;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import org.jetbrains.annotations.NotNull;
import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.util.HashMap;
public class bot {
public static JDABuilder builder;
public static HashMap<String, CommandExecutor> COMMANDS = new HashMap<>();
public static HashMap<String, CommandExecutor> ALIASES = new HashMap<>();
public static String b_Prefix = "!";
public static void main(String[] args) throws LoginException, IOException {
String token = ""; // Please insert bot token here
builder = JDABuilder.createDefault(token);
builder.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE);
builder.setBulkDeleteSplittingEnabled(false);
builder.setCompression(Compression.NONE);
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
builder.setActivity(Activity.watching("Bot made by: Flame"));
builder.addEventListeners(new messageListener());
builder.addEventListeners(new ListenerAdapter() {
@Override
public void onReady(@NotNull ReadyEvent event) {
System.out.println("Blacklist Bot Loaded.");
}
});
ClassUtlis.registerAllCommands();
for(CommandExecutor commandExecutor : COMMANDS.values()) {
if (commandExecutor.aliases() != null) {
for(String alias : commandExecutor.aliases()) {
ALIASES.put(alias.toLowerCase(), commandExecutor);
}
}
}
builder.build();
}
public static void executeCommand(String prefix, MessageReceivedEvent event) throws IOException {
String chatMessage = event.getMessage().getContentRaw();
String[] splitCommand = chatMessage.split(" ");
String command = splitCommand[0].replaceFirst("[" + prefix + "]", "");
String commandArgs = event.getMessage().getContentRaw().replace(prefix + command, "");
commandArgs = commandArgs.replaceFirst(" ", "");
String[] args = commandArgs.split(" ");
if (args.length == 1) {
if (args[0].isEmpty() || args[0].equals(" ") || args[0].equals(prefix + command) || args[0].equals(prefix)) {
args = new String[0];
}
}
if (COMMANDS.get(command.toLowerCase()) != null) {
if(!COMMANDS.get(command.toLowerCase()).exectue(args, event)) {
event.getChannel().sendMessage("This command is disabled").queue();
}
} else if (ALIASES.get(command.toLowerCase()) != null) {
if (!ALIASES.get(command.toLowerCase()).exectue(args, event)) {
event.getChannel().sendMessage("This command is disabled").queue();
}
}
}
}