net.dv8tion.jda.api.entities.Emote Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.Emote. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnlockEmoteCommand.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {

    final GuildMessageReceivedEvent event = ctx.getEvent();
    final Message message = ctx.getMessage();

    if (ctx.getArgs().isEmpty()) {
        this.sendUsageInstructions(ctx);
        return;
    }

    final List<Emote> foundEmotes = FinderUtil.findEmotes(ctx.getArgsRaw(), ctx.getJDA());

    if (foundEmotes.isEmpty()) {
        sendMsg(event, "No emotes found");
        return;
    }

    final Emote emote = foundEmotes.get(0);

    if (cannotInteractWithEmote(event, emote)) return;
    emote.getManager().setRoles(Collections.emptySet()).queue();
    sendSuccess(message);
    sendMsg(event, "The emote " + emote.getAsMention() + " has been unlocked");
}
 
Example #2
Source File: UnlockEmoteCommand.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
static boolean cannotInteractWithEmote(GuildMessageReceivedEvent event, Emote emote) {
    if (emote == null) {
        sendMsg(event, "I cannot access that emote");

        return true;
    }

    if (emote.getGuild() == null || !emote.getGuild().equals(event.getGuild())) {
        sendMsg(event, "That emote does not exist on this server");
        return true;
    }

    if (emote.isManaged()) {
        sendMsg(event, "That emote is managed unfortunately, this means that I can't assign roles to it");
        return true;
    }

    return false;
}
 
Example #3
Source File: GuildEmojisUpdateHandler.java    From JDA with Apache License 2.0 6 votes vote down vote up
private void handleReplace(Emote oldEmote, Emote newEmote)
{
    if (oldEmote == null || newEmote == null) return;

    if (!Objects.equals(oldEmote.getName(), newEmote.getName()))
    {
        getJDA().handleEvent(
            new EmoteUpdateNameEvent(
                getJDA(), responseNumber,
                newEmote, oldEmote.getName()));
    }

    if (!CollectionUtils.isEqualCollection(oldEmote.getRoles(), newEmote.getRoles()))
    {
        getJDA().handleEvent(
            new EmoteUpdateRolesEvent(
                getJDA(), responseNumber,
                newEmote, oldEmote.getRoles()));
    }

}
 
Example #4
Source File: LockEmoteCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {

    final GuildMessageReceivedEvent event = ctx.getEvent();
    final Message message = ctx.getMessage();

    if (ctx.getArgs().isEmpty()) {
        this.sendUsageInstructions(ctx);
        return;
    }

    final List<Emote> mentionedEmotes = message.getEmotes();
    final List<Role> mentionedRoles = new ArrayList<>(message.getMentionedRoles());

    if (mentionedRoles.isEmpty()) {
        // Loop over the args and check if there are roles found in text
        ctx.getArgs().forEach(
            (arg) -> mentionedRoles.addAll(FinderUtil.findRoles(arg, ctx.getGuild()))
        );
    }

    if (mentionedEmotes.isEmpty() || mentionedRoles.isEmpty()) {
        this.sendUsageInstructions(ctx);
        return;
    }

    final Emote emote = mentionedEmotes.get(0);

    if (cannotInteractWithEmote(event, emote)) return;

    emote.getManager().setRoles(new HashSet<>(mentionedRoles)).queue();
    sendSuccess(message);
    final List<String> roleNames = mentionedRoles.stream().map(Role::getName).collect(Collectors.toList());

    sendMsg(event, "The emote " + emote.getAsMention() + " has been locked to users that have the " +
        "following roles: `" + String.join("`, `", roleNames) + "`");
}
 
Example #5
Source File: GenericEmoteUpdateEvent.java    From JDA with Apache License 2.0 5 votes vote down vote up
public GenericEmoteUpdateEvent(
        @Nonnull JDA api, long responseNumber, @Nonnull Emote emote,
        @Nullable T previous, @Nullable T next, @Nonnull String identifier)
{
    super(api, responseNumber, emote);
    this.previous = previous;
    this.next = next;
    this.identifier = identifier;
}
 
Example #6
Source File: EmoteRemovedEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public EmoteRemovedEvent(@Nonnull JDA api, long responseNumber, @Nonnull Emote emote)
{
    super(api, responseNumber, emote);
}
 
Example #7
Source File: GenericEmoteUpdateEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Emote getEntity()
{
    return getEmote();
}
 
Example #8
Source File: EmoteUpdateRolesEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public EmoteUpdateRolesEvent(@Nonnull JDA api, long responseNumber, @Nonnull Emote emote, @Nonnull List<Role> oldRoles)
{
    super(api, responseNumber, emote, oldRoles, emote.getRoles(), IDENTIFIER);
}
 
Example #9
Source File: EmoteUpdateNameEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public EmoteUpdateNameEvent(@Nonnull JDA api, long responseNumber, @Nonnull Emote emote, @Nonnull String oldName)
{
    super(api, responseNumber, emote, oldName, emote.getName(), IDENTIFIER);
}
 
Example #10
Source File: EmoteAddedEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public EmoteAddedEvent(@Nonnull JDA api, long responseNumber, @Nonnull Emote emote)
{
    super(api, responseNumber, emote);
}
 
Example #11
Source File: GenericEmoteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public GenericEmoteEvent(@Nonnull JDA api, long responseNumber, @Nonnull Emote emote)
{
    super(api, responseNumber);
    this.emote = emote;
}
 
Example #12
Source File: GenericEmoteEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * The responsible {@link net.dv8tion.jda.api.entities.Emote Emote} for this event
 *
 * @return The emote
 */
@Nonnull
public Emote getEmote()
{
    return emote;
}
 
Example #13
Source File: GuildRoleDeleteHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    final long guildId = content.getLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;

    GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId);
    if (guild == null)
    {
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        EventCache.LOG.debug("GUILD_ROLE_DELETE was received for a Guild that is not yet cached: {}", content);
        return null;
    }

    final long roleId = content.getLong("role_id");
    Role removedRole = guild.getRolesView().remove(roleId);
    if (removedRole == null)
    {
        //getJDA().getEventCache().cache(EventCache.Type.ROLE, roleId, () -> handle(responseNumber, allContent));
        WebSocketClient.LOG.debug("GUILD_ROLE_DELETE was received for a Role that is not yet cached: {}", content);
        return null;
    }

    //Now that the role is removed from the Guild, remove it from all users and emotes.
    guild.getMembersView().forEach(m ->
    {
        MemberImpl member = (MemberImpl) m;
        member.getRoleSet().remove(removedRole);
    });

    for (Emote emote : guild.getEmoteCache())
    {
        EmoteImpl impl = (EmoteImpl) emote;
        if (impl.canProvideRoles())
            impl.getRoleSet().remove(removedRole);
    }

    getJDA().handleEvent(
        new RoleDeleteEvent(
            getJDA(), responseNumber,
            removedRole));
    getJDA().getEventCache().clear(EventCache.Type.ROLE, roleId);
    return null;
}
 
Example #14
Source File: MessageReactionClearEmoteHandler.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Override
protected Long handleInternally(DataObject content)
{
    long guildId = content.getUnsignedLong("guild_id");
    if (getJDA().getGuildSetupController().isLocked(guildId))
        return guildId;
    Guild guild = getJDA().getGuildById(guildId);
    if (guild == null)
    {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown guild {}", guildId);
        getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
        return null;
    }

    long channelId = content.getUnsignedLong("channel_id");
    TextChannel channel = guild.getTextChannelById(channelId);
    if (channel == null)
    {
        EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown channel {}", channelId);
        getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
        return null;
    }

    long messageId = content.getUnsignedInt("message_id");
    DataObject emoji = content.getObject("emoji");
    MessageReaction.ReactionEmote reactionEmote = null;
    if (emoji.isNull("id"))
    {
        reactionEmote = MessageReaction.ReactionEmote.fromUnicode(emoji.getString("name"), getJDA());
    }
    else
    {
        long emoteId = emoji.getUnsignedLong("emoji");
        Emote emote = getJDA().getEmoteById(emoteId);
        if (emote == null)
        {
            emote = new EmoteImpl(emoteId, getJDA())
                .setAnimated(emoji.getBoolean("animated"))
                .setName(emoji.getString("name", ""));
        }
        reactionEmote = MessageReaction.ReactionEmote.fromCustom(emote);
    }

    MessageReaction reaction = new MessageReaction(channel, reactionEmote, messageId, false, 0);
    getJDA().handleEvent(new GuildMessageReactionRemoveEmoteEvent(getJDA(), responseNumber, guild, channel, reaction, messageId));
    getJDA().handleEvent(new MessageReactionRemoveEmoteEvent(getJDA(), responseNumber, messageId, channel, reaction));
    return null;
}
 
Example #15
Source File: EmoteManagerImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Emote getEmote()
{
    return emote;
}
 
Example #16
Source File: EmoteManager.java    From JDA with Apache License 2.0 2 votes vote down vote up
/**
 * The target {@link net.dv8tion.jda.api.entities.Emote Emote}
 * that will be modified by this Manager
 *
 * @return The target Emote
 */
@Nonnull
Emote getEmote();