#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:
parent
0f1f7b4ead
commit
14c42614d8
2 changed files with 12 additions and 2 deletions
|
@ -126,8 +126,10 @@ public final class DPUtils {
|
||||||
* @return The string for mentioning the channel
|
* @return The string for mentioning the channel
|
||||||
*/
|
*/
|
||||||
public static String botmention() {
|
public static String botmention() {
|
||||||
if (DiscordPlugin.plugin == null) return "#bot";
|
IChannel channel;
|
||||||
return DiscordPlugin.plugin.CommandChannel().get().mention();
|
if (DiscordPlugin.plugin == null
|
||||||
|
|| (channel = DiscordPlugin.plugin.CommandChannel().get()) == null) return "#bot";
|
||||||
|
return channel.mention();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent> {
|
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) {
|
public void handle(ReadyEvent event) {
|
||||||
try {
|
try {
|
||||||
dc.changePresence(StatusType.DND, ActivityType.PLAYING, "booting");
|
dc.changePresence(StatusType.DND, ActivityType.PLAYING, "booting");
|
||||||
|
val tries = new AtomicInteger();
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
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) {
|
if (mainServer == null || devServer == null) {
|
||||||
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
mainServer = event.getClient().getGuildByID(125813020357165056L);
|
||||||
devServer = event.getClient().getGuildByID(219529124321034241L);
|
devServer = event.getClient().getGuildByID(219529124321034241L);
|
||||||
|
|
Loading…
Reference in a new issue