本文整理汇总了Java中sx.blah.discord.api.IDiscordClient.isReady方法的典型用法代码示例。如果您正苦于以下问题:Java IDiscordClient.isReady方法的具体用法?Java IDiscordClient.isReady怎么用?Java IDiscordClient.isReady使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sx.blah.discord.api.IDiscordClient
的用法示例。
在下文中一共展示了IDiscordClient.isReady方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import sx.blah.discord.api.IDiscordClient; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (clientRegistry.getClients().isEmpty()) {
log.warn("No bots to track data for");
}
for (Map.Entry<Bot, IDiscordClient> entry : clientRegistry.getClients().entrySet()) {
IDiscordClient client = entry.getValue();
if (client.isReady()) {
String botTag = "bot:" + entry.getKey().getName();
for (IShard shard : client.getShards()) {
String shardTag = "shard:" + shard.getInfo()[0];
long millis = shard.getResponseTime();
metricRegistry.timer("discord.ws.response[" + botTag + "," + shardTag + "]")
.update(millis, TimeUnit.MILLISECONDS);
}
for (IGuild guild : client.getGuilds()) {
String guildTag = "guild:" + guild.getStringID();
long online = guild.getUsers().stream()
.filter(user -> user.getPresence().getStatus() == StatusType.ONLINE)
.count();
long connected = guild.getUsers().stream()
.filter(user -> user.getPresence().getStatus() != StatusType.OFFLINE)
.count();
long joined = guild.getUsers().size();
String onlineMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:online]";
String connectedMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:connected]";
String joinedMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:joined]";
metricRegistry.histogram(onlineMetric).update(online);
metricRegistry.histogram(connectedMetric).update(connected);
metricRegistry.histogram(joinedMetric).update(joined);
}
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.getLogger("org.eclipse.jetty.websocket").setLevel(Level.WARN);
loggerContext.getLogger(Discord4J.class).setLevel(Level.DEBUG);
} else {
log.warn("Bot {} is not ready!", entry.getKey().getName());
}
}
}
示例2: health
import sx.blah.discord.api.IDiscordClient; //导入方法依赖的package包/类
@Override
public Health health() {
int count = 0;
int ready = 0;
Map<String, Object> details = new LinkedHashMap<>();
for (Map.Entry<Bot, IDiscordClient> entry : clientRegistry.getClients().entrySet()) {
count++;
Map<String, Object> bot = new LinkedHashMap<>();
IDiscordClient client = entry.getValue();
if (client.isReady()) {
ready++;
bot.put("status", "UP");
bot.put("id", client.getOurUser().getStringID());
bot.put("name", client.getOurUser().getName());
bot.put("shards", client.getShardCount());
bot.put("guilds", client.getGuilds().size());
bot.put("channels", client.getChannels().size());
bot.put("users", client.getUsers().size());
bot.put("roles", client.getRoles().size());
} else if (client.isLoggedIn()) {
bot.put("status", "OUT_OF_SERVICE");
} else {
bot.put("status", "DOWN");
}
details.put(entry.getKey().getName(), bot);
}
Health.Builder builder = count == 0 ? Health.unknown() : (count == ready ? Health.up() : Health.outOfService());
details.put("count", count);
details.put("ready", ready);
details.forEach(builder::withDetail);
return builder.build();
}
示例3: asContent
import sx.blah.discord.api.IDiscordClient; //导入方法依赖的package包/类
@Override
public String asContent(Map<String, Object> dataMap) {
IDiscordClient client = getSource().getClient();
String bot = (String) dataMap.get("bot");
if (bot == null || (client.isReady() && (ourBotId(client).equals(bot) || ourBotName(client).equals(bot)))) {
return String.format("[%s] Discord bot reconnect succeeded", ourBotName(client));
} else {
log.debug("Message filtered - neither {} nor {} matched {}", ourBotId(client), ourBotName(client), bot);
return null;
}
}
示例4: asContent
import sx.blah.discord.api.IDiscordClient; //导入方法依赖的package包/类
@Override
public String asContent(Map<String, Object> dataMap) {
IDiscordClient client = getSource().getClient();
String bot = (String) dataMap.get("bot");
if (bot == null || (client.isReady() && (ourBotId(client).equals(bot) || ourBotName(client).equals(bot)))) {
return String.format("[%s] Discord bot reconnect failed after %s%s", ourBotName(client),
inflect(getSource().getCurrentAttempt() + 1, "attempt"),
getSource().isShardAbandoned() ? " - No further reconnect attempts" : "");
} else {
log.debug("Message filtered - neither {} nor {} matched {}", ourBotId(client), ourBotName(client), bot);
return null;
}
}