use of github.scarsz.discordsrv.dependencies.jda.api.entities.Message in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class OutboundToDiscordEvents method onAdvancementSend.
@Subscribe(priority = ListenerPriority.HIGHEST)
public void onAdvancementSend(AchievementMessagePostProcessEvent event) {
if (event.isCancelled()) {
return;
}
Debug.debug("Triggered onAdvancementSend");
Message message = event.getDiscordMessage();
if (!message.getContentRaw().contains("<ICA=")) {
return;
}
String text = message.getContentRaw();
Set<Integer> matches = new LinkedHashSet<>();
synchronized (RESEND_WITH_ATTACHMENT) {
for (int key : RESEND_WITH_ATTACHMENT.keySet()) {
if (text.contains("<ICA=" + key + ">")) {
matches.add(key);
}
}
}
event.setCancelled(true);
DiscordMessageContent content = new DiscordMessageContent(message);
for (int key : matches) {
AttachmentData data = RESEND_WITH_ATTACHMENT.remove(key);
if (data != null) {
content.addAttachment(data.getName(), data.getData());
}
}
TextChannel destinationChannel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(event.getChannel());
Debug.debug("onAdvancementSend sending message to discord");
if (event.isUsingWebhooks()) {
String webHookUrl = WebhookUtil.getWebhookUrlToUseForChannel(destinationChannel);
WebhookClient client = WebhookClient.withUrl(webHookUrl);
if (client == null) {
throw new NullPointerException("Unable to get the Webhook client URL for the TextChannel " + destinationChannel.getName());
}
client.send(content.toWebhookMessageBuilder().setUsername(event.getWebhookName()).setAvatarUrl(event.getWebhookAvatarUrl()).build());
client.close();
} else {
content.toJDAMessageRestAction(destinationChannel).queue();
}
}
use of github.scarsz.discordsrv.dependencies.jda.api.entities.Message in project Foundation by kangarko.
the class DiscordListener method flashMessage.
/**
* Send a message to the given channel for four seconds
*
* @param channel
* @param message
*/
protected final void flashMessage(TextChannel channel, String message) {
final String finalMessage = Common.stripColors(message);
Common.runAsync(() -> {
final Message sentMessage = channel.sendMessage(finalMessage).complete();
Common.runLaterAsync(4 * 20, () -> {
try {
channel.deleteMessageById(sentMessage.getIdLong()).complete();
} catch (final github.scarsz.discordsrv.dependencies.jda.api.exceptions.ErrorResponseException ex) {
// Silence if deleted already
if (!ex.getMessage().contains("Unknown Message"))
ex.printStackTrace();
}
});
});
}
use of github.scarsz.discordsrv.dependencies.jda.api.entities.Message in project Foundation by kangarko.
the class DiscordListener method editMessageById.
/**
* Edit the given message by ID
*
* @param channel
* @param messageId
* @param newMessage
*/
protected final void editMessageById(TextChannel channel, long messageId, String newMessage) {
Common.runAsync(() -> {
try {
final Message message = channel.retrieveMessageById(messageId).complete();
if (message != null) {
// Remove old message
channel.deleteMessageById(messageId).complete();
// Send a new one
final Message newSentMessage = channel.sendMessage(message.getAuthor().getName() + ": " + newMessage.replace("*", "\\*").replace("_", "\\_").replace("@", "\\@")).complete();
this.editedMessages.put(messageId, newSentMessage.getIdLong());
}
} catch (final Throwable t) {
if (!t.toString().contains("Unknown Message"))
t.printStackTrace();
}
});
}
use of github.scarsz.discordsrv.dependencies.jda.api.entities.Message in project Foundation by kangarko.
the class DiscordListener method removeAndWarn.
/**
* Removes the given message and sends a warning message from the bot
* shown for the given duration in seconds and then remove it.
*
* @param message
* @param warningMessage
* @param warningDurationSeconds how long to show the warning message
*/
protected final void removeAndWarn(Message message, String warningMessage, int warningDurationSeconds) {
message.delete().complete();
final MessageChannel channel = message.getChannel();
final Message channelWarningMessage = channel.sendMessage(warningMessage).complete();
channel.deleteMessageById(channelWarningMessage.getIdLong()).completeAfter(warningDurationSeconds, TimeUnit.SECONDS);
}
use of github.scarsz.discordsrv.dependencies.jda.api.entities.Message in project Foundation by kangarko.
the class DiscordSender method sendMessage.
@Override
public void sendMessage(String message) {
final String finalMessage = Common.stripColors(message);
Common.runAsync(() -> {
final Message sentMessage = channel.sendMessage(finalMessage).complete();
try {
// Automatically remove after a short while
channel.deleteMessageById(sentMessage.getIdLong()).completeAfter(4, TimeUnit.SECONDS);
} catch (final Throwable t) {
// Ignore already deleted messages
if (!t.toString().contains("Unknown Message"))
t.printStackTrace();
}
});
}
Aggregations