maybe fix loading log channels
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s
This commit is contained in:
41
src/main/java/cc/fascinated/bat/common/ChannelUtils.java
Normal file
41
src/main/java/cc/fascinated/bat/common/ChannelUtils.java
Normal file
@ -0,0 +1,41 @@
|
||||
package cc.fascinated.bat.common;
|
||||
|
||||
import cc.fascinated.bat.service.DiscordService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@Log4j2
|
||||
public class ChannelUtils {
|
||||
/**
|
||||
* Gets the user with the given id
|
||||
*
|
||||
* @param id the id of the user
|
||||
* @param retries the amount of retries
|
||||
* @return the user with the given id
|
||||
*/
|
||||
private static TextChannel getTextChannel(String id, int retries) {
|
||||
if (retries >= 25) {
|
||||
log.error("Failed to find user \"{}\" after {} retries.", id, retries);
|
||||
return null;
|
||||
}
|
||||
TextChannel channel = DiscordService.JDA.getTextChannelById(id);
|
||||
if (channel == null) {
|
||||
return getTextChannel(id, retries + 1);
|
||||
}
|
||||
log.info("Found text channel \"{}\" after {} retries.", channel.getName(), retries);
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user with the given id
|
||||
*
|
||||
* @param id the id of the user
|
||||
* @return the user with the given id
|
||||
*/
|
||||
public static TextChannel getTextChannel(String id) {
|
||||
return getTextChannel(id, 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user