Java 类net.dv8tion.jda.core.entities.MessageReaction 实例源码

项目:Supreme-Bot    文件:Standard.java   
public static final MessageReaction getReaction(Message message, String emoji) {
    if (message == null || emoji == null) {
        return null;
    }
    return message.getReactions().stream().filter((reaction) -> {
        return emoji.equals(reaction.getEmote().getName());
    }).findFirst().orElse(null);
}
项目:Supreme-Bot    文件:Standard.java   
public static final boolean isReacted(Message message, String emoji) {
    if (message == null || emoji == null) {
        return false;
    }
    final MessageReaction reaction = getReaction(message, emoji);
    if (reaction == null) {
        return false;
    }
    return reaction.getCount() > 1;
}
项目:Supreme-Bot    文件:Standard.java   
public static final boolean removeReaction(Message message, String emoji) {
    if (message == null || emoji == null) {
        return false;
    }
    final MessageReaction reaction = getReaction(message, emoji);
    if (reaction == null) {
        return true;
    }
    reaction.getUsers().stream().filter((user) -> !user.isBot()).forEach((user) -> {
        reaction.removeReaction(user).complete();
    });
    return true;
}
项目:Supreme-Bot    文件:ReactionListener.java   
public static boolean isReacted(MessageReaction messageReaction, String emoji) {
    if (messageReaction == null || emoji == null) {
        return false;
    }
    if (!emoji.equals(messageReaction.getEmote().getName())) {
        return false;
    }
    return messageReaction.getCount() > 1;
}
项目:Supreme-Bot    文件:ReactionListener.java   
public static boolean removeReaction(MessageReaction messageReaction) {
    if (messageReaction == null) {
        return false;
    }
    final User self = Standard.getSelfUser();
    messageReaction.getUsers().stream().filter((user) -> self.getIdLong() == user.getIdLong()).forEach((user) -> {
        messageReaction.removeReaction(user).complete();
    });
    return true;
}
项目:JDA    文件:MessageReactionHandler.java   
private void onAdd(MessageReaction reaction, User user)
{
    IEventManager manager = api.getEventManager();
    switch (reaction.getChannelType())
    {
        case TEXT:
            manager.handle(
                new GuildMessageReactionAddEvent(
                        api, responseNumber,
                        user, reaction));
            break;
        case GROUP:
            manager.handle(
                new GroupMessageReactionAddEvent(
                        api, responseNumber,
                        user, reaction));
            break;
        case PRIVATE:
            manager.handle(
                new PrivateMessageReactionAddEvent(
                        api, responseNumber,
                        user, reaction));
    }

    manager.handle(
        new MessageReactionAddEvent(
                api, responseNumber,
                user, reaction));
}
项目:JDA    文件:MessageReactionHandler.java   
private void onRemove(MessageReaction reaction, User user)
{
    IEventManager manager = api.getEventManager();
    switch (reaction.getChannelType())
    {
        case TEXT:
            manager.handle(
                new GuildMessageReactionRemoveEvent(
                        api, responseNumber,
                        user, reaction));
            break;
        case GROUP:
            manager.handle(
                new GroupMessageReactionRemoveEvent(
                        api, responseNumber,
                        user, reaction));
            break;
        case PRIVATE:
            manager.handle(
                new PrivateMessageReactionRemoveEvent(
                        api, responseNumber,
                        user, reaction));
    }

    manager.handle(
        new MessageReactionRemoveEvent(
                api, responseNumber,
                user, reaction));
}
项目:JDA    文件:ReactionPaginationAction.java   
protected static String getCode(MessageReaction reaction)
{
    MessageReaction.ReactionEmote emote = reaction.getReactionEmote();

    return emote.isEmote()
        ? emote.getName() + ":" + emote.getId()
        : MiscUtil.encodeUTF8(emote.getName());
}
项目:Shenron-Legacy    文件:GroupListener.java   
private Role getRole(Message message, MessageReaction reaction)
{
    GroupTrigger trigger = null;
    Pair<String, String> group = null;

    for (GroupTrigger tr : triggers)
    {
        if (message.getId().equals(tr.getMessageId()))
        {
            trigger = tr;
            break;
        }
    }

    if (trigger == null)
    {
        return null;
    }

    for (Pair<String, String> pair : trigger.getGroups())
    {
        if (pair.getKey().equals(reaction.getEmote().getId()))
        {
            group = pair;
            break;
        }
    }

    if (group == null)
    {
        return null;
    }

    List<Role> roles = message.getGuild().getRolesByName(group.getValue(), true);

    if (roles.size() == 0)
    {
        return null;
    }

    return roles.get(0);
}
项目:JDA    文件:GenericGroupMessageReactionEvent.java   
public GenericGroupMessageReactionEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, reaction.getMessageIdLong(), (Group) reaction.getChannel());
    this.issuer = user;
    this.reaction = reaction;
}
项目:JDA    文件:GenericGroupMessageReactionEvent.java   
public MessageReaction getReaction()
{
    return reaction;
}
项目:JDA    文件:GenericGroupMessageReactionEvent.java   
public MessageReaction.ReactionEmote getReactionEmote()
{
    return reaction.getReactionEmote();
}
项目:JDA    文件:GroupMessageReactionAddEvent.java   
public GroupMessageReactionAddEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:GroupMessageReactionRemoveEvent.java   
public GroupMessageReactionRemoveEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:MessageReactionHandler.java   
@Override
protected Long handleInternally(JSONObject content)
{
    JSONObject emoji = content.getJSONObject("emoji");

    final long userId    = content.getLong("user_id");
    final long messageId = content.getLong("message_id");
    final long channelId = content.getLong("channel_id");

    final Long emojiId = emoji.isNull("id") ? null : emoji.getLong("id");
    String emojiName = emoji.optString("name", null);
    final boolean emojiAnimated = emoji.optBoolean("animated");

    if (emojiId == null && emojiName == null)
    {
        WebSocketClient.LOG.debug("Received a reaction {} with no name nor id. json: {}",
            JDALogger.getLazyString(() -> add ? "add" : "remove"), content);
        return null;
    }

    User user = api.getUserById(userId);
    if (user == null)
        user = api.getFakeUserMap().get(userId);
    if (user == null)
    {
        api.getEventCache().cache(EventCache.Type.USER, userId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("Received a reaction for a user that JDA does not currently have cached");
        return null;
    }

    MessageChannel channel = api.getTextChannelById(channelId);
    if (channel == null)
    {
        channel = api.getPrivateChannelById(channelId);
    }
    if (channel == null)
    {
        channel = api.getFakePrivateChannelMap().get(channelId);
    }
    if (channel == null && api.getAccountType() == AccountType.CLIENT)
    {
        channel = api.asClient().getGroupById(channelId);
    }
    if (channel == null)
    {
        api.getEventCache().cache(EventCache.Type.CHANNEL, channelId, () -> handle(responseNumber, allContent));
        EventCache.LOG.debug("Received a reaction for a channel that JDA does not currently have cached");
        return null;
    }

    MessageReaction.ReactionEmote rEmote;
    if (emojiId != null)
    {
        Emote emote = api.getEmoteById(emojiId);
        if (emote == null)
        {
            if (emojiName != null)
            {
                emote = new EmoteImpl(emojiId, api).setAnimated(emojiAnimated).setName(emojiName);
            }
            else
            {
                WebSocketClient.LOG.debug("Received a reaction {} with a null name. json: {}",
                    JDALogger.getLazyString(() -> add ? "add" : "remove"), content);
                return null;
            }
        }
        rEmote = new MessageReaction.ReactionEmote(emote);
    }
    else
    {
        rEmote = new MessageReaction.ReactionEmote(emojiName, null, api);
    }
    MessageReaction reaction = new MessageReaction(channel, rEmote, messageId, user.equals(api.getSelfUser()), -1);

    if (add)
        onAdd(reaction, user);
    else
        onRemove(reaction, user);
    return null;
}
项目:JDA    文件:GuildMessageReactionAddEvent.java   
public GuildMessageReactionAddEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:GuildMessageReactionRemoveEvent.java   
public GuildMessageReactionRemoveEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:GenericPrivateMessageReactionEvent.java   
public GenericPrivateMessageReactionEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, reaction.getMessageIdLong(), (PrivateChannel) reaction.getChannel());
    this.issuer = user;
    this.reaction = reaction;
}
项目:JDA    文件:GenericPrivateMessageReactionEvent.java   
public MessageReaction getReaction()
{
    return reaction;
}
项目:JDA    文件:GenericPrivateMessageReactionEvent.java   
public MessageReaction.ReactionEmote getReactionEmote()
{
    return reaction.getReactionEmote();
}
项目:JDA    文件:PrivateMessageReactionAddEvent.java   
public PrivateMessageReactionAddEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:PrivateMessageReactionRemoveEvent.java   
public PrivateMessageReactionRemoveEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:MessageReactionAddEvent.java   
public MessageReactionAddEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:MessageReactionRemoveEvent.java   
public MessageReactionRemoveEvent(JDA api, long responseNumber, User user, MessageReaction reaction)
{
    super(api, responseNumber, user, reaction);
}
项目:JDA    文件:ReactionPaginationAction.java   
/**
 * Creates a new PaginationAction instance
 *
 * @param reaction
 *        The target {@link net.dv8tion.jda.core.entities.MessageReaction MessageReaction}
 */
public ReactionPaginationAction(MessageReaction reaction)
{
    super(reaction.getJDA(), Route.Messages.GET_REACTION_USERS.compile(reaction.getChannel().getId(), reaction.getMessageId(), getCode(reaction)), 1, 100, 100);
    this.reaction = reaction;
}
项目:JDA    文件:ReactionPaginationAction.java   
/**
 * The current target {@link net.dv8tion.jda.core.entities.MessageReaction MessageReaction}
 *
 * @return The current MessageReaction
 */
public MessageReaction getReaction()
{
    return reaction;
}
项目:Supreme-Bot    文件:ReactionListener.java   
void onReaction(MessageReaction reaction, AdvancedEmote emote, Guild guild, User user);