use of sx.blah.discord.util.RequestBuffer.RequestFuture in project Shadbot by Shadorc.
the class BotUtils method sendMessage.
public static RequestFuture<IMessage> sendMessage(MessageBuilder message, int retry) {
IGuild guild = message.getChannel().isPrivate() ? null : message.getChannel().getGuild();
long guildID = guild == null ? -1 : guild.getLongID();
if (retry == 0) {
LogUtils.infof("{Guild ID: %d} Abort attempt to send message (3 failed requests).", guildID);
return null;
}
if (!message.getChannel().getShard().isReady()) {
if (guild != null) {
LogUtils.infof("{Guild ID: %d} A message couldn't be sent because shard isn't ready, adding it to queue.", guildID);
ShardManager.getShadbotShard(guild.getShard()).queue(message);
}
return null;
}
return RequestBuffer.request(() -> {
try {
return message.send();
} catch (MissingPermissionsException err) {
BotUtils.sendMessage(TextUtils.missingPerm(err.getMissingPermissions()), message.getChannel());
LogUtils.infof("{Guild ID: %d} %s", guildID, err.getMessage());
} catch (DiscordException err) {
if (err.getMessage().contains("Message was unable to be sent (Discord didn't return a response)")) {
LogUtils.infof("{Guild ID: %d} A message could not be send because Discord didn't return a response, retrying.", guildID);
RequestFuture<IMessage> msgRequest = BotUtils.sendMessage(message, retry - 1);
if (msgRequest != null) {
return msgRequest.get();
}
} else if (err.getMessage().contains("Failed to make a 400 failed request after 5 tries!")) {
LogUtils.infof("{Guild ID: %d} %s", guildID, err.getMessage());
} else {
LogUtils.error(err, "An error occurred while sending message.");
}
}
return null;
});
}
use of sx.blah.discord.util.RequestBuffer.RequestFuture in project Shadbot by Shadorc.
the class HangmanManager method show.
private void show() {
List<String> missesList = charsTested.stream().filter(letter -> !word.contains(letter)).collect(Collectors.toList());
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorIcon(this.getAuthor().getAvatarURL()).withAuthorName("Hangman Game").withThumbnail("https://lh5.ggpht.com/nIoJylIWCj1gKv9dxtd4CFE2aeXvG7MbvP0BNFTtTFusYlxozJRQmHizsIDxydaa7DHT=w300").withDescription("Type letters or enter a word if you think you've guessed it.").appendField("Word", this.getRepresentation(word), false).appendField("Misses", FormatUtils.format(missesList, chr -> chr.toString().toUpperCase(), ", "), false);
if (this.isTaskDone()) {
embed.withFooterText("Finished.");
} else {
embed.withFooterText(String.format("Use %scancel to cancel this game (Automatically cancelled in %d min in case of inactivity)", this.getPrefix(), IDLE_MIN));
}
if (failsCount > 0) {
embed.withImage(IMG_LIST.get(Math.min(IMG_LIST.size(), failsCount) - 1));
}
RequestFuture<IMessage> msgRequest = message.send(embed.build());
if (msgRequest != null) {
msgRequest.get();
}
}
Aggregations