#bot mention ch null handling, limiting tries

Won't try to get channels forever, since they may be set incorrectly
This commit is contained in:
Norbi Peti 2019-03-02 19:04:38 +01:00
parent 0f1f7b4ead
commit 14c42614d8
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 12 additions and 2 deletions

View file

@ -126,8 +126,10 @@ public final class DPUtils {
* @return The string for mentioning the channel
*/
public static String botmention() {
if (DiscordPlugin.plugin == null) return "#bot";
return DiscordPlugin.plugin.CommandChannel().get().mention();
IChannel channel;
if (DiscordPlugin.plugin == null
|| (channel = DiscordPlugin.plugin.CommandChannel().get()) == null) return "#bot";
return channel.mention();
}
}

View file

@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent> {
@ -116,7 +117,14 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
public void handle(ReadyEvent event) {
try {
dc.changePresence(StatusType.DND, ActivityType.PLAYING, "booting");
val tries = new AtomicInteger();
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
tries.incrementAndGet();
if (tries.get() > 10) { //5 seconds
task.cancel();
getLogger().severe("Main or dev server not found! Set ID and do /discord reset");
return;
}
if (mainServer == null || devServer == null) {
mainServer = event.getClient().getGuildByID(125813020357165056L);
devServer = event.getClient().getGuildByID(219529124321034241L);