Preparations for public host

This commit adds a lot of new features, optimizations and bugfixes to prepare the bot to be hosted publicly. Updates include a prefix changing command, fixes with box generation to prevent softlocks in later levels, and making edits to game messages instead of sending a new message after each update. Smaller optimizations were made as well, such as removing games from the HashMap when a user quits to save memory.
This commit is contained in:
PocketMars
2020-06-30 09:40:28 -05:00
parent 89bd9a8f30
commit 79a09651ab
4 changed files with 113 additions and 26 deletions
+18 -2
View File
@@ -2,22 +2,38 @@ import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import javax.security.auth.login.LoginException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
public class Bot {
static String prefix = "!";
static HashMap<Guild, String> prefixes = new HashMap<Guild, String>();
public static void main(String[] args) throws LoginException, IOException {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = new String(Files.readAllBytes(Paths.get("token.txt")));
builder.setToken(token);
builder.setStatus(OnlineStatus.ONLINE);
builder.setActivity(Activity.playing("!play to play Sokoban!"));
builder.setActivity(Activity.playing("@Sokobot for info!"));
builder.addEventListeners(new Commands());
builder.build();
}
static void setPrefix(Guild guild, String prefix)
{
prefixes.put(guild, prefix);
}
static String getPrefix(Guild guild)
{
if (!prefixes.containsKey(guild))
{
return "!";
}
return prefixes.get(guild);
}
}