Added when server will be ready

This commit is contained in:
Norbi Peti 2017-05-15 01:52:09 +02:00
parent cf0d2e7d5d
commit 0bbb436992

View file

@ -1,5 +1,8 @@
package buttondevteam.discordplugin.listeners; package buttondevteam.discordplugin.listeners;
import java.util.ArrayList;
import java.util.Random;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase; import buttondevteam.discordplugin.commands.DiscordCommandBase;
import sx.blah.discord.api.events.IListener; import sx.blah.discord.api.events.IListener;
@ -10,6 +13,25 @@ import sx.blah.discord.handle.obj.IMessage;
public class CommandListener { public class CommandListener {
private static final String[] serverReadyStrings = new String[] { "In one week from now", // Ali
"Between now and the heat-death of the universe.", // Ghostise
"Soon™", "Ask again this time next month", // Ghostise
"In about 3 seconds", // Nicolai
};
private static final Random serverReadyRandom = new Random();
private static final ArrayList<Short> usableServerReadyStrings = new ArrayList<Short>(serverReadyStrings.length) {
private static final long serialVersionUID = 2213771460909848770L;
{
createUsableServerReadyStrings();
}
};
private static void createUsableServerReadyStrings() {
for (short i = 0; i < serverReadyStrings.length; i++)
usableServerReadyStrings.add(i);
}
public static IListener<?>[] getListeners() { public static IListener<?>[] getListeners() {
return new IListener[] { new IListener<MentionEvent>() { return new IListener[] { new IListener<MentionEvent>() {
@Override @Override
@ -30,6 +52,18 @@ public class CommandListener {
public void handle(MessageReceivedEvent event) { public void handle(MessageReceivedEvent event) {
if (DiscordPlugin.SafeMode) if (DiscordPlugin.SafeMode)
return; return;
if (event.getMessage().getContent().toLowerCase().contains("when will the server be open?")) {
int next;
/*
* if (serverReadyStrings.length <= lastServerReadyStrings.size()) { next = lastServerReadyStrings.get(0); lastServerReadyStrings.clear(); } else { next = (short) serverReadyRandom
* .nextInt(serverReadyStrings.length - lastServerReadyStrings.size()); for (short i = 0; i < lastServerReadyStrings.size(); i++) { short j = lastServerReadyStrings.get(i); if
* (next == j) next++; if (next >= serverReadyStrings.length) next = 0; } lastServerReadyStrings.add(next); }
*/
if (usableServerReadyStrings.size() == 0)
createUsableServerReadyStrings();
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
}
if (!event.getMessage().getChannel().isPrivate()) if (!event.getMessage().getChannel().isPrivate())
return; return;
if (event.getMessage().getAuthor().isBot()) if (event.getMessage().getAuthor().isBot())