Search in sources :

Example 11 with ImplMessage

use of de.btobastian.javacord.entities.message.impl.ImplMessage in project Javacord by BtoBastian.

the class MessageReactionRemoveAllHandler method handle.

@Override
public void handle(JSONObject packet) {
    // {"message_id":"269166028959776768","channel_id":"81402706320699392"}
    String messageId = packet.getString("message_id");
    final Message message = api.getMessageById(messageId);
    if (message == null) {
        return;
    }
    final List<Reaction> reactions = message.getReactions();
    ((ImplMessage) message).removeAllReactionsFromCache();
    listenerExecutorService.submit(new Runnable() {

        @Override
        public void run() {
            List<ReactionRemoveAllListener> listeners = api.getListeners(ReactionRemoveAllListener.class);
            synchronized (listeners) {
                for (ReactionRemoveAllListener listener : listeners) {
                    try {
                        listener.onReactionRemoveAll(api, message, reactions);
                    } catch (Throwable t) {
                        logger.warn("Uncaught exception in ReactionRemoveAllListener!", t);
                    }
                }
            }
        }
    });
}
Also used : ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) Message(de.btobastian.javacord.entities.message.Message) ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) List(java.util.List) ReactionRemoveAllListener(de.btobastian.javacord.listener.message.ReactionRemoveAllListener) Reaction(de.btobastian.javacord.entities.message.Reaction)

Example 12 with ImplMessage

use of de.btobastian.javacord.entities.message.impl.ImplMessage in project Javacord by BtoBastian.

the class MessageUpdateHandler method handle.

@Override
public void handle(JSONObject packet) {
    String messageId = packet.getString("id");
    final Message message = api.getMessageById(messageId);
    if (message == null) {
        return;
    }
    final String oldContent = message.getContent();
    if (!packet.has("content")) {
        return;
    }
    ((ImplMessage) message).setContent(packet.getString("content"));
    listenerExecutorService.submit(new Runnable() {

        @Override
        public void run() {
            List<MessageEditListener> listeners = api.getListeners(MessageEditListener.class);
            synchronized (listeners) {
                for (MessageEditListener listener : listeners) {
                    try {
                        listener.onMessageEdit(api, message, oldContent);
                    } catch (Throwable t) {
                        logger.warn("Uncaught exception in MessageEditListener!", t);
                    }
                }
            }
        }
    });
}
Also used : MessageEditListener(de.btobastian.javacord.listener.message.MessageEditListener) Message(de.btobastian.javacord.entities.message.Message) ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) List(java.util.List)

Aggregations

Message (de.btobastian.javacord.entities.message.Message)12 ImplMessage (de.btobastian.javacord.entities.message.impl.ImplMessage)12 HttpResponse (com.mashape.unirest.http.HttpResponse)6 MessageReceiver (de.btobastian.javacord.entities.message.MessageReceiver)6 List (java.util.List)6 JSONException (org.json.JSONException)6 MultipartBody (com.mashape.unirest.request.body.MultipartBody)4 JSONObject (org.json.JSONObject)4 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)3 Reaction (de.btobastian.javacord.entities.message.Reaction)3 MalformedURLException (java.net.MalformedURLException)3 CustomEmoji (de.btobastian.javacord.entities.CustomEmoji)2 User (de.btobastian.javacord.entities.User)2 MessageCreateListener (de.btobastian.javacord.listener.message.MessageCreateListener)1 MessageDeleteListener (de.btobastian.javacord.listener.message.MessageDeleteListener)1 MessageEditListener (de.btobastian.javacord.listener.message.MessageEditListener)1 ReactionAddListener (de.btobastian.javacord.listener.message.ReactionAddListener)1 ReactionRemoveAllListener (de.btobastian.javacord.listener.message.ReactionRemoveAllListener)1 ReactionRemoveListener (de.btobastian.javacord.listener.message.ReactionRemoveListener)1