private CustomEmojiToken(MessageTokenizer tokenizer, int startIndex, int endIndex) { super(tokenizer, startIndex, endIndex); final String content = getContent(); final long emojiId = Long.parseUnsignedLong(content.substring(content.lastIndexOf(":") + 1, content.lastIndexOf('>'))); emoji = tokenizer.getClient().getGuilds().stream() .map(guild -> guild.getEmojiByID(emojiId)).filter(Objects::nonNull).findFirst() .orElse(null); }
@Override public boolean isDeleted() { return !this.equals(getGuild().getEmojiByID(getLongID())); }
/** * Converts a json {@link EmojiObject} to a {@link IEmoji}. * * @param guild The guild the emoji belongs to. * @param json The json object representing the emoji. * @return The converted emoji object. */ public static IEmoji getEmojiFromJSON(IGuild guild, EmojiObject json) { long id = Long.parseUnsignedLong(json.id); List<IRole> roles = Arrays.stream(json.roles) .map(role -> guild.getRoleByID(Long.parseUnsignedLong(role))) .collect(Collectors.toList()); EmojiImpl emoji = (EmojiImpl) guild.getEmojiByID(id); if (emoji != null) { emoji.setName(json.name); emoji.setRoles(roles); return emoji; } Cache<IRole> roleCache = new Cache<>((DiscordClientImpl) guild.getClient(), IRole.class); roleCache.putAll(roles); return new EmojiImpl(id, guild, json.name, roleCache, json.require_colons, json.managed, json.animated); }
case EMOJI_CREATE: case EMOJI_UPDATE: IEmoji emoji = guild.getEmojiByID(targetID);