Skip to content

Commit

Permalink
lol snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Nov 14, 2019
1 parent 17c9865 commit 92355ee
Show file tree
Hide file tree
Showing 71 changed files with 4,070 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static <R> R require(final Class<? super R> type, final Object... param)
else {
if (args[1] instanceof JSONArray)
throw new IllegalArgumentException("Cannot instantiate from JSONArray!");
id = Snowflake.Trait.ID.extractValue((JSONObject) args[1]);
id = Snowflake.JSON.ID.extractValue((JSONObject) args[1]);
}

return ((Discord) args[0]).getCacheManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ default Optional<GuildChannelCategory.Updater> asGuildChannelCategoryUpdater() {
}
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.TwoStage<String, ChannelType> CHANNEL_TYPE = simple("type", JSONObject::getString, ChannelType::valueOf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default Optional<URL> getIconUrl() {
return wrapBindingValue(JSON.ICON);
}

interface JSON extends PrivateChannel.Trait, TextChannel.Trait {
interface JSON extends PrivateChannel.JSON, TextChannel.JSON {
JSONBinding.TwoStage<String, URL> ICON = simple("icon", JSONObject::getString, hash -> ImageHelper.GUILD_ICON.url(FileType.PNG, hash));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ default Invite.Builder createInviteBuilder() {
return Invite.builder(this);
}

interface JSON extends Channel.Trait {
interface JSON extends Channel.JSON {
JSONBinding.TwoStage<Long, Guild> GUILD = cache("guild_id", CacheManager::getGuildByID);
JSONBinding.OneStage<Integer> POSITION = identity("position", JSONObject::getInteger);
JSONBinding.TriStage<JSONObject, PermissionOverride> PERMISSION_OVERRIDES = serializableCollection("permission_overwrites", PermissionOverride.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static de.comroid.crystalshard.util.annotation.IntroducedBy.ImplementationSource.GETTER;
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.identity;

@JSONBindingLocation(GuildTextChannel.Trait.class)
@JSONBindingLocation(GuildTextChannel.JSON.class)
public interface GuildTextChannel extends GuildChannel, TextChannel {
// direct api methods
CompletableFuture<Collection<Webhook>> requestWebhooks();
Expand Down Expand Up @@ -59,7 +59,7 @@ static Builder builder(Guild guild) {
return Adapter.require(Builder.class, guild);
}

interface JSON extends GuildChannel.Trait, TextChannel.Trait {
interface JSON extends GuildChannel.JSON, TextChannel.JSON {
JSONBinding.OneStage<String> TOPIC = identity("topic", JSONObject::getString);
JSONBinding.OneStage<Boolean> NSFW = identity("nsfw", JSONObject::getBoolean);
JSONBinding.OneStage<Integer> MESSAGE_RATELIMIT = identity("rate_limit_per_user", JSONObject::getInteger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ default Optional<Integer> getUserLimit() {
return wrapBindingValue(JSON.USER_LIMIT);
}

interface JSON extends GuildChannel.Trait, VoiceChannel.Trait {
interface JSON extends GuildChannel.JSON, VoiceChannel.JSON {
JSONBinding.OneStage<Integer> USER_LIMIT = identity("user_limit", JSONObject::getInteger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ default Optional<User> getApplicationOwner() {
return wrapBindingValue(JSON.APPLICATION_OWNER);
}

interface JSON extends Channel.Trait {
interface JSON extends Channel.JSON {
JSONBinding.TriStage<JSONObject, User> RECIPIENTS = serializableCollection("recipients", User.class);
JSONBinding.TwoStage<Long, User> USER_OWNER = cache("owner_id", CacheManager::getUserByID);
JSONBinding.TwoStage<Long, User> APPLICATION_OWNER = cache("application_id", CacheManager::getUserByID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ default EntityType getEntityType() {
return EntityType.PRIVATE_TEXT_CHANNEL;
}

interface JSON extends PrivateChannel.Trait, TextChannel.Trait {
interface JSON extends PrivateChannel.JSON, TextChannel.JSON {
}

interface Builder extends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ default CompletableFuture<Message> requestMessage(long id) {
return Adapter.<Message>request(getAPI())
.endpoint(DiscordEndpoint.MESSAGE, getID(), id)
.method(RestMethod.GET)
.executeAsObject(data -> getAPI().getCacheManager()
.updateOrCreateAndGet(Message.class, id, data));
.executeAsObject(data -> Adapter.require(Message.class, getAPI(), data));
}

@IntroducedBy(value = API, docs = "https://discordapp.com/developers/docs/resources/channel#trigger-typing-indicator")
Expand All @@ -53,7 +52,7 @@ default Optional<Message> getLastMessage() {
return wrapBindingValue(JSON.LAST_MESSAGE_ID);
}

interface JSON extends Channel.Trait {
interface JSON extends Channel.JSON {
JSONBinding.TwoStage<String, Instant> LAST_PINNED_TIMESTAMP = simple("last_pin_timestamp", JSONObject::getString, Instant::parse);
JSONBinding.TwoStage<Long, Message> LAST_MESSAGE_ID = JSONBinding.cache("last_message_id", (cacheManager, id) -> cacheManager.getByID(Message.class, id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Default extends Channel.Default {
int BITRATE = 64000;
}

interface JSON extends Channel.Trait {
interface JSON extends Channel.JSON {
JSONBinding.OneStage<Integer> BITRATE = identity("bitrate", JSONObject::getInteger);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.require;

@MainAPI
@JSONBindingLocation(CustomEmoji.Trait.class)
@JSONBindingLocation(CustomEmoji.JSON.class)
public interface CustomEmoji extends Emoji, Mentionable, Snowflake, Cacheable {
@IntroducedBy(PRODUCTION)
Guild getGuild();
Expand Down Expand Up @@ -62,7 +62,7 @@ default Optional<Boolean> isAnimated() {
return wrapBindingValue(JSON.ANIMATED);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> NAME = identity("name", JSONObject::getString);
JSONBinding.TriStage<Long, Role> WHITELISTED_ROLES = mappingCollection("roles", JSONObject::getLong, (api, id) -> api.getCacheManager()
.getByID(Role.class, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.mappingCollection;
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.serializableCollection;

@JSONBindingLocation(Guild.Trait.class)
@JSONBindingLocation(Guild.JSON.class)
public interface Guild extends Snowflake, ListenerAttachable<ListenerSpec.AttachableTo.Guild>, Cacheable {
@IntroducedBy(API)
CompletableFuture<Collection<Webhook>> requestWebhooks();
Expand All @@ -73,7 +73,7 @@ default CompletableFuture<CustomEmoji> requestEmoji(long id) {
return Adapter.<CustomEmoji>request(getAPI())
.endpoint(DiscordEndpoint.CUSTOM_EMOJI_SPECIFIC, getID(), id)
.method(RestMethod.GET)
.executeAsObject(data -> getAPI().getCacheManager().updateOrCreateAndGet(CustomEmoji.class, id, data));
.executeAsObject(data -> Adapter.require(CustomEmoji.class, getAPI(), data));
}

@IntroducedBy(GETTER)
Expand Down Expand Up @@ -282,8 +282,7 @@ default CompletableFuture<GuildMember> requestGuildMember(User user) {
return Adapter.<GuildMember>request(getAPI())
.endpoint(DiscordEndpoint.GUILD_MEMBER, getID(), user.getID())
.method(RestMethod.GET)
.executeAsObject(data -> getAPI().getCacheManager()
.updateOrCreateAndGet(GuildMember.class, user.getID(), data));
.executeAsObject(data -> Adapter.require(GuildMember.class, getAPI(), data));
}

@IntroducedBy(value = API, docs = "https://discordapp.com/developers/docs/resources/guild#list-guild-members")
Expand All @@ -300,8 +299,7 @@ default CompletableFuture<Optional<Ban>> requestBan(User user) {
return Adapter.<Ban>request(getAPI())
.endpoint(DiscordEndpoint.BAN_SPECIFIC, getID(), user.getID())
.method(RestMethod.GET)
.executeAsObject(data -> getAPI().getCacheManager()
.updateOrCreateMemberAndGet(Guild.class, Ban.class, getID(), user.getID(), data))
.executeAsObject(data -> Adapter.require(Ban.class, getAPI(), data))
.thenApply(Optional::ofNullable);
}

Expand All @@ -328,8 +326,7 @@ default CompletableFuture<Guild.Embed> requestGuildEmbed() {
return Adapter.<Embed>request(getAPI())
.endpoint(DiscordEndpoint.GUILD_EMBED, getID())
.method(RestMethod.GET)
.executeAsObject(data -> getAPI().getCacheManager()
.updateOrCreateSingletonMemberAndGet(Guild.class, Embed.class, getID(), data));
.executeAsObject(data -> Adapter.require(Embed.class, getAPI(), data));
}

@IntroducedBy(value = API, docs = "https://discordapp.com/developers/docs/resources/guild#get-guild-vanity-url")
Expand Down Expand Up @@ -365,7 +362,7 @@ static Builder builder(Discord api) {
return Adapter.require(Builder.class, api);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> NAME = identity("name", JSONObject::getString);
JSONBinding.OneStage<String> ICON_HASH = identity("icon", JSONObject::getString);
JSONBinding.OneStage<String> SPLASH_HASH = identity("splash", JSONObject::getString);
Expand Down Expand Up @@ -404,7 +401,7 @@ interface JSON extends Snowflake.Trait {
JSONBinding.TwoStage<String, Locale> PREFERRED_LOCALE = simple("preferred_locale", JSONObject::getString, Locale::forLanguageTag);
}

@JSONBindingLocation(Embed.Trait.class)
@JSONBindingLocation(Embed.JSON.class)
interface Embed extends Cacheable, JsonDeserializable {
@CacheInformation.Marker
CacheInformation<Guild> CACHE_INFORMATION = makeSingletonCacheableInfo(Guild.class, Embed::getGuild);
Expand Down Expand Up @@ -438,7 +435,7 @@ interface Updater {
}
}

@JSONBindingLocation(Integration.Trait.class)
@JSONBindingLocation(Integration.JSON.class)
interface Integration extends Snowflake, JsonDeserializable, Cacheable {
@CacheInformation.Marker
CacheInformation<Guild> CACHE_INFORMATION = makeSingletonCacheableInfo(Guild.class, Integration::getGuild);
Expand Down Expand Up @@ -495,7 +492,7 @@ default Instant getSyncedAtTimestamp() {
return getBindingValue(JSON.SYNCED_AT);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> NAME = identity("name", JSONObject::getString);
JSONBinding.OneStage<String> TYPE = identity("type", JSONObject::getString);
JSONBinding.OneStage<Boolean> ENABLED = identity("enabled", JSONObject::getBoolean);
Expand Down Expand Up @@ -528,7 +525,7 @@ default CompletableFuture<Void> sync() {
.executeAsObject(data -> null);
}

@JSONBindingLocation(Account.Trait.class)
@JSONBindingLocation(Account.JSON.class)
interface Account extends JsonDeserializable {
default String getID() {
return getBindingValue(JSON.ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(Role.Trait.class)
@JSONBindingLocation(Role.JSON.class)
@IntroducedBy(value = API, docs = "https://discordapp.com/developers/docs/topics/permissions#role-object")
public interface Role extends Snowflake, PermissionOverridable, Mentionable, Cacheable, ListenerAttachable<ListenerSpec.AttachableTo.Role<? extends RoleEvent>> {
Comparator<Role> ROLE_COMPARATOR = Comparator.comparingInt(de.comroid.crystalshard.api.entity.guild.Role::getPosition);
Expand Down Expand Up @@ -100,7 +100,7 @@ default CompletableFuture<Void> delete() {
.deleteMember(Guild.class, Role.class, getGuild().getID(), getID()));
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> NAME = identity("name", JSONObject::getString);
JSONBinding.TwoStage<Integer, Color> COLOR = simple("color", JSONObject::getInteger, Color::new);
JSONBinding.OneStage<Boolean> HOIST = identity("hoist", JSONObject::getBoolean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.require;

@MainAPI
@JSONBindingLocation(Webhook.Trait.class)
@JSONBindingLocation(Webhook.JSON.class)
public interface Webhook extends MessageAuthor, Snowflake, Cacheable, ListenerAttachable<WebhookAttachableListener<? extends WebhookEvent>> {
@CacheInformation.Marker
CacheInformation<GuildTextChannel> CACHE_INFORMATION = makeSubcacheableInfo(GuildTextChannel.class, Webhook::getChannel);
Expand Down Expand Up @@ -92,8 +92,7 @@ static CompletableFuture<Webhook> requestWebhook(Discord api, long id) {
return Adapter.<Webhook>request(api)
.endpoint(DiscordEndpoint.WEBHOOK, id)
.method(RestMethod.GET)
.executeAsObject(data -> api.getCacheManager()
.updateOrCreateAndGet(Webhook.class, id, data));
.executeAsObject(data -> Adapter.require(Webhook.class, api, data));
}

@IntroducedBy(PRODUCTION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(Message.Trait.class)
@JSONBindingLocation(Message.JSON.class)
public interface Message extends Snowflake, Cacheable, ListenerAttachable<MessageAttachableListener<? extends MessageEvent>> {
@CacheInformation.Marker
CacheInformation<TextChannel> CACHE_INFORMATION = makeSubcacheableInfo(TextChannel.class, Message::getChannel);
Expand Down Expand Up @@ -172,7 +172,7 @@ default int getMessageFlags() {
return getBindingValue(JSON.FLAGS);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.TwoStage<Long, TextChannel> CHANNEL = cache("channel_id", (cache, id) -> cache.getChannelByID(id).flatMap(Channel::asTextChannel));
JSONBinding.TwoStage<Long, Guild> GUILD = cache("guild_id", CacheManager::getGuildByID);
JSONBinding.TwoStage<JSONObject, User> USER_AUTHOR = require("author", User.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(MessageApplication.Trait.class)
@JSONBindingLocation(MessageApplication.JSON.class)
public interface MessageApplication extends Snowflake {
default Optional<URL> getCoverImageURL() {
return wrapBindingValue(JSON.COVER_IMAGE_URL);
Expand All @@ -35,7 +35,7 @@ default String getName() {
return getBindingValue(JSON.NAME);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.TwoStage<String, URL> COVER_IMAGE_URL = simple("cover_image", JSONObject::getString, Util::createUrl$rethrow);
JSONBinding.OneStage<String> DESCRIPTION = identity("description", JSONObject::getString);
JSONBinding.TwoStage<String, URL> ICON_URL = simple("icon", JSONObject::getString, Util::createUrl$rethrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(MessageAttachment.Trait.class)
@JSONBindingLocation(MessageAttachment.JSON.class)
public interface MessageAttachment extends Snowflake {
default String getFilename() {
return getBindingValue(JSON.FILENAME);
Expand All @@ -41,7 +41,7 @@ default Optional<Integer> getWidth() {
return wrapBindingValue(JSON.WIDTH);
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> FILENAME = identity("filename", JSONObject::getString);
JSONBinding.OneStage<Integer> SIZE = identity("size", JSONObject::getInteger);
JSONBinding.TwoStage<String, URL> URL = simple("url", JSONObject::getString, Util::createUrl$rethrow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(User.Trait.class)
@JSONBindingLocation(User.JSON.class)
public interface User extends Messageable, MessageAuthor, Mentionable, Snowflake, Cacheable, ListenerAttachable<ListenerSpec.AttachableTo.User<? extends UserEvent>>, JsonDeserializable {
default String getUsername() {
return getBindingValue(JSON.USERNAME);
Expand Down Expand Up @@ -94,15 +94,14 @@ default String getDiscriminatedName() {
}

@IntroducedBy(value = API, docs = "https://discordapp.com/developers/docs/resources/user#get-user")
static CompletableFuture<User> requestUser(Discord api, long id) {
static CompletableFuture<User> requestUser(final Discord api, long id) {
return Adapter.<User>request(api)
.endpoint(DiscordEndpoint.USER, id)
.method(RestMethod.GET)
.executeAsObject(data -> api.getCacheManager()
.updateOrCreateAndGet(User.class, id, data));
.executeAsObject(data -> Adapter.require(User.class, api, data));
}

interface JSON extends Snowflake.Trait {
interface JSON extends Snowflake.JSON {
JSONBinding.OneStage<String> USERNAME = identity("username", JSONObject::getString);
JSONBinding.OneStage<String> DISCRIMINATOR = identity("discriminator", JSONObject::getString);
JSONBinding.OneStage<String> AVATAR_HASH = identity("avatar", JSONObject::getString);
Expand All @@ -116,7 +115,7 @@ interface JSON extends Snowflake.Trait {
}

@MainAPI
@JSONBindingLocation(Connection.Trait.class)
@JSONBindingLocation(Connection.JSON.class)
interface Connection extends JsonDeserializable {
default String getID() {
return getBindingValue(JSON.ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ default ListenerManager<L> detachNow() {
default ScheduledFuture<?> detachIn(long time, TimeUnit unit) {
return getAPI()
.getListenerThreadPool()
.getScheduler()
.schedule((Callable<ListenerManager<L>>) this::detachNow, time, unit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(ChannelMention.Trait.class)
@JSONBindingLocation(ChannelMention.JSON.class)
public interface ChannelMention extends JsonDeserializable {
@IntroducedBy(GETTER)
default Channel getChannel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.require;

@MainAPI
@JSONBindingLocation(Ban.Trait.class)
@JSONBindingLocation(Ban.JSON.class)
public interface Ban extends Cacheable, JsonDeserializable {
@CacheInformation.Marker
CacheInformation<User> CACHE_INFORMATION = makeSubcacheableInfo(User.class, Ban::getBannedUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static de.comroid.crystalshard.util.model.serialization.JSONBinding.simple;

@MainAPI
@JSONBindingLocation(Invite.Trait.class)
@JSONBindingLocation(Invite.JSON.class)
public interface Invite extends JsonDeserializable {
default String getInviteCode() {
return getBindingValue(JSON.INVITE_CODE);
Expand Down Expand Up @@ -82,7 +82,7 @@ interface JSON {
}

@MainAPI
@JSONBindingLocation(Metadata.Trait.class)
@JSONBindingLocation(Metadata.JSON.class)
interface Metadata extends JsonDeserializable {
default User getInviter() {
return getBindingValue(JSON.INVITER);
Expand Down
Loading

0 comments on commit 92355ee

Please sign in to comment.