diff options
| author | Adelyn Breelove <[email protected]> | 2019-01-24 13:30:01 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2019-01-24 13:30:01 -0700 |
| commit | 1dc92998ffcbb0481c26fa7fbf081ce3379f08d6 (patch) | |
| tree | c7f9acc6b7c9dd0bfaef3e703ca4cab82ee483af /lib/models | |
| parent | Start of an event dispatch rework (diff) | |
| download | disml-1dc92998ffcbb0481c26fa7fbf081ce3379f08d6.tar.xz disml-1dc92998ffcbb0481c26fa7fbf081ce3379f08d6.zip | |
More event dispatch work
Diffstat (limited to 'lib/models')
| -rw-r--r-- | lib/models/event_models.ml | 127 | ||||
| -rw-r--r-- | lib/models/id/channel_id.ml | 1 | ||||
| -rw-r--r-- | lib/models/id/channel_id_t.ml | 10 | ||||
| -rw-r--r-- | lib/models/id/guild_id.ml | 1 | ||||
| -rw-r--r-- | lib/models/id/guild_id.mli | 1 | ||||
| -rw-r--r-- | lib/models/id/guild_id_t.ml | 10 | ||||
| -rw-r--r-- | lib/models/id/message_id.ml | 10 | ||||
| -rw-r--r-- | lib/models/id/role_id.ml | 10 | ||||
| -rw-r--r-- | lib/models/id/user_id.ml | 1 | ||||
| -rw-r--r-- | lib/models/id/user_id.mli | 1 | ||||
| -rw-r--r-- | lib/models/id/user_id_t.ml | 10 | ||||
| -rw-r--r-- | lib/models/snowflake.mli | 9 | ||||
| -rw-r--r-- | lib/models/user/presence.ml | 4 | ||||
| -rw-r--r-- | lib/models/user/presence.mli | 4 |
14 files changed, 125 insertions, 74 deletions
diff --git a/lib/models/event_models.ml b/lib/models/event_models.ml index 6df9762..5355cb7 100644 --- a/lib/models/event_models.ml +++ b/lib/models/event_models.ml @@ -3,39 +3,45 @@ open Core module ChannelCreate = struct type t = { channel: Channel_t.t; - } [@@deriving sexp, yojson] + } [@@deriving sexp] - let deserialize = of_yojson_exn + let deserialize ev = + let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in + { channel; } end module ChannelDelete = struct type t = { channel: Channel_t.t; - } [@@deriving sexp, yojson] + } [@@deriving sexp] - let deserialize = of_yojson_exn + let deserialize ev = + let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in + { channel; } end module ChannelUpdate = struct type t = { channel: Channel_t.t; - } [@@deriving sexp, yojson] + } [@@deriving sexp] - let deserialize = of_yojson_exn + let deserialize ev = + let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in + { channel; } end module ChannelPinsUpdate = struct type t = { - channel_id: Channel_id_t.t; - last_pin_timestamp: string option; - } [@@deriving sexp, yojson] + channel_id: Channel_id.t; + last_pin_timestamp: string option [@default None]; + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end module ChannelRecipientAdd = struct type t = { - channel_id: Channel_id_t.t; + channel_id: Channel_id.t; user: User_t.t; } [@@deriving sexp, yojson] @@ -44,7 +50,7 @@ end module ChannelRecipientRemove = struct type t = { - channel_id: Channel_id_t.t; + channel_id: Channel_id.t; user: User_t.t; } [@@deriving sexp, yojson] @@ -53,7 +59,7 @@ end module GuildBanAdd = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; user: User_t.t; } [@@deriving sexp, yojson] @@ -62,7 +68,7 @@ end module GuildBanRemove = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; user: User_t.t; } [@@deriving sexp, yojson] @@ -72,25 +78,25 @@ end module GuildCreate = struct type t = { guild: Guild_t.t; - } [@@deriving sexp, yojson] + } [@@deriving sexp] - let deserialize = of_yojson_exn + let deserialize ev = + let guild = Guild_t.(pre_of_yojson_exn ev |> wrap) in + { guild; } end -(* TODO *) module GuildDelete = struct type t = { - foo: bool option [@default None]; - } [@@deriving sexp, yojson] + id: Guild_id.t; + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end -(* TODO *) module GuildUpdate = struct type t = { - foo: bool option [@default None]; - } [@@deriving sexp, yojson] + id: Guild_id.t; + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end @@ -98,7 +104,7 @@ end module GuildEmojisUpdate = struct type t = { emojis: Emoji.t list; - guild_id: Guild_id_t.t + guild_id: Guild_id.t } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -106,7 +112,7 @@ end module GuildMemberAdd = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; member: Member_t.t; } [@@deriving sexp, yojson] @@ -115,7 +121,7 @@ end module GuildMemberRemove = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; user: User_t.t; } [@@deriving sexp, yojson] @@ -124,7 +130,7 @@ end module GuildMemberUpdate = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; nick: string option; roles: Role_id.t list; user: User_t.t; @@ -135,7 +141,7 @@ end module GuildMembersChunk = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; members: (Snowflake.t * Member_t.t) list; } [@@deriving sexp, yojson] @@ -144,7 +150,7 @@ end module GuildRoleCreate = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; role: Role_t.t; } [@@deriving sexp, yojson] @@ -153,7 +159,7 @@ end module GuildRoleDelete = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; role_id: Role_id.t; } [@@deriving sexp, yojson] @@ -162,8 +168,8 @@ end module GuildRoleUpdate = struct type t = { - guild_id: Guild_id_t.t; - role: Role_t.t; + guild_id: Guild_id.t; + role: Role_t.role; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -171,7 +177,7 @@ end module GuildUnavailable = struct type t = { - guild_id: Guild_id_t.t; + guild_id: Guild_id.t; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -180,15 +186,18 @@ end module MessageCreate = struct type t = { message: Message_t.t; - } [@@deriving sexp, yojson] + } [@@deriving sexp] - let deserialize = of_yojson_exn + let deserialize ev = + let message = Message_t.of_yojson_exn ev in + { message; } end module MessageDelete = struct type t = { - channel_id: Channel_id_t.t; - message_id: Message_id.t; + id: Message_id.t; + channel_id: Channel_id.t; + guild_id: Guild_id.t option [@default None]; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -196,18 +205,18 @@ end module MessageUpdate = struct type t = { - id: Snowflake.t; + id: Message_id.t; author: User_t.t option [@default None]; - channel_id: Snowflake.t; + channel_id: Channel_id.t; member: Member_t.partial_member option [@default None]; - guild_id: Snowflake.t option [@default None]; + guild_id: Guild_id.t option [@default None]; content: string option [@default None]; timestamp: string option [@default None]; editedimestamp: string option [@default None]; tts: bool option [@default None]; mention_everyone: bool option [@default None]; - mentions: Snowflake.t list [@default []]; - role_mentions: Snowflake.t list [@default []]; + mentions: User_id.t list [@default []]; + role_mentions: Role_id.t list [@default []]; attachments: Attachment.t list [@default []]; embeds: Embed.t list [@default []]; reactions: Snowflake.t list [@default []]; @@ -222,7 +231,7 @@ end module MessageDeleteBulk = struct type t = { - channel_id: Channel_id_t.t; + channel_id: Channel_id.t; ids: Message_id.t list; } [@@deriving sexp, yojson] @@ -230,11 +239,7 @@ module MessageDeleteBulk = struct end module PresenceUpdate = struct - type t = { - guild_id: Guild_id_t.t option; - presence: Presence.t; - roles: Role_id.t list option; - } [@@deriving sexp, yojson] + include Presence let deserialize = of_yojson_exn end @@ -247,7 +252,11 @@ end *) module ReactionAdd = struct type t = { - reaction: Reaction_t.t; + user_id: User_id.t; + channel_id: Channel_id.t; + message_id: Message_id.t; + guild_id: Guild_id.t option [@default None]; + emoji: Emoji.partial_emoji; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -255,7 +264,11 @@ end module ReactionRemove = struct type t = { - reaction: Reaction_t.t; + user_id: User_id.t; + channel_id: Channel_id.t; + message_id: Message_id.t; + guild_id: Guild_id.t option [@default None]; + emoji: Emoji.partial_emoji; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -263,8 +276,9 @@ end module ReactionRemoveAll = struct type t = { - channel_id: Channel_id_t.t; + channel_id: Channel_id.t; message_id: Message_id.t; + guild_id: Guild_id.t option [@default None]; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -273,7 +287,7 @@ end module Ready = struct type t = { foo: bool option [@default None]; - } [@@deriving sexp, yojson] + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end @@ -281,17 +295,18 @@ end module Resumed = struct type t = { trace: string option list; - } [@@deriving sexp, yojson] + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end module TypingStart = struct type t = { - channel_id: Channel_id_t.t; + channel_id: Channel_id.t; + guild_id: Guild_id.t option [@default None]; timestamp: int; - user_id: User_id_t.t; - } [@@deriving sexp, yojson] + user_id: User_id.t; + } [@@deriving sexp, yojson { strict = false }] let deserialize = of_yojson_exn end @@ -306,8 +321,8 @@ end module WebhookUpdate = struct type t = { - channel_id: Channel_id_t.t; - guild_id: Guild_id_t.t; + channel_id: Channel_id.t; + guild_id: Guild_id.t; } [@@deriving sexp, yojson] let deserialize = of_yojson_exn diff --git a/lib/models/id/channel_id.ml b/lib/models/id/channel_id.ml index 1533728..67f81a5 100644 --- a/lib/models/id/channel_id.ml +++ b/lib/models/id/channel_id.ml @@ -1,3 +1,2 @@ include Channel_id_t - include Impl.Channel(Channel_id_t)
\ No newline at end of file diff --git a/lib/models/id/channel_id_t.ml b/lib/models/id/channel_id_t.ml index 2164b4f..26bd984 100644 --- a/lib/models/id/channel_id_t.ml +++ b/lib/models/id/channel_id_t.ml @@ -1,3 +1,11 @@ -type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson] +type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp] + +let of_yojson a : (t, string) result = + match Snowflake.of_yojson a with + | Ok id -> Ok (`Channel_id id) + | Error err -> Error err + +let of_yojson_exn a : t = `Channel_id (Snowflake.of_yojson_exn a) +let to_yojson (`Channel_id id) = (Snowflake.to_yojson id) let get_id (`Channel_id id) = id
\ No newline at end of file diff --git a/lib/models/id/guild_id.ml b/lib/models/id/guild_id.ml index 0242058..051006b 100644 --- a/lib/models/id/guild_id.ml +++ b/lib/models/id/guild_id.ml @@ -1 +1,2 @@ +include Guild_id_t include Impl.Guild(Guild_id_t)
\ No newline at end of file diff --git a/lib/models/id/guild_id.mli b/lib/models/id/guild_id.mli index ea9d509..670a903 100644 --- a/lib/models/id/guild_id.mli +++ b/lib/models/id/guild_id.mli @@ -1,2 +1,3 @@ +include module type of Guild_id_t include S.GuildImpl with type t := Guild_id_t.t
\ No newline at end of file diff --git a/lib/models/id/guild_id_t.ml b/lib/models/id/guild_id_t.ml index c67b9e5..d023058 100644 --- a/lib/models/id/guild_id_t.ml +++ b/lib/models/id/guild_id_t.ml @@ -1,3 +1,11 @@ -type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson] +type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp] + +let of_yojson a : (t, string) result = + match Snowflake.of_yojson a with + | Ok id -> Ok (`Guild_id id) + | Error err -> Error err + +let of_yojson_exn a : t = `Guild_id (Snowflake.of_yojson_exn a) +let to_yojson (`Guild_id id) = (Snowflake.to_yojson id) let get_id (`Guild_id id) = id
\ No newline at end of file diff --git a/lib/models/id/message_id.ml b/lib/models/id/message_id.ml index 377cadd..4a4fbb3 100644 --- a/lib/models/id/message_id.ml +++ b/lib/models/id/message_id.ml @@ -1,3 +1,11 @@ -type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson] +type t = [ `Message_id of Snowflake.t ] [@@deriving sexp] + +let of_yojson a : (t, string) result = + match Snowflake.of_yojson a with + | Ok id -> Ok (`Message_id id) + | Error err -> Error err + +let of_yojson_exn a : t = `Message_id (Snowflake.of_yojson_exn a) +let to_yojson (`Message_id id) = (Snowflake.to_yojson id) let get_id (`Message_id id) = id
\ No newline at end of file diff --git a/lib/models/id/role_id.ml b/lib/models/id/role_id.ml index a505f33..b3fa5a1 100644 --- a/lib/models/id/role_id.ml +++ b/lib/models/id/role_id.ml @@ -1,3 +1,11 @@ -type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson] +type t = [ `Role_id of Snowflake.t ] [@@deriving sexp] + +let of_yojson a : (t, string) result = + match Snowflake.of_yojson a with + | Ok id -> Ok (`Role_id id) + | Error err -> Error err + +let of_yojson_exn a : t = `Role_id (Snowflake.of_yojson_exn a) +let to_yojson (`Role_id id) = (Snowflake.to_yojson id) let get_id (`Role_id id) = id
\ No newline at end of file diff --git a/lib/models/id/user_id.ml b/lib/models/id/user_id.ml index aba1b17..77ce220 100644 --- a/lib/models/id/user_id.ml +++ b/lib/models/id/user_id.ml @@ -1 +1,2 @@ +include User_id_t include Impl.User(User_id_t)
\ No newline at end of file diff --git a/lib/models/id/user_id.mli b/lib/models/id/user_id.mli index 7fe822a..d7da91e 100644 --- a/lib/models/id/user_id.mli +++ b/lib/models/id/user_id.mli @@ -1,2 +1,3 @@ +include module type of User_id_t include S.UserImpl with type t := User_id_t.t
\ No newline at end of file diff --git a/lib/models/id/user_id_t.ml b/lib/models/id/user_id_t.ml index 8a6a265..5ed9f14 100644 --- a/lib/models/id/user_id_t.ml +++ b/lib/models/id/user_id_t.ml @@ -1,3 +1,11 @@ -type t = [ `User_id of Snowflake.t ] [@@deriving sexp, yojson] +type t = [ `User_id of Snowflake.t ] [@@deriving sexp] + +let of_yojson a : (t, string) result = + match Snowflake.of_yojson a with + | Ok id -> Ok (`User_id id) + | Error err -> Error err + +let of_yojson_exn a : t = `User_id (Snowflake.of_yojson_exn a) +let to_yojson (`User_id id) = (Snowflake.to_yojson id) let get_id (`User_id id) = id
\ No newline at end of file diff --git a/lib/models/snowflake.mli b/lib/models/snowflake.mli index 5bbd1ff..a6d42b5 100644 --- a/lib/models/snowflake.mli +++ b/lib/models/snowflake.mli @@ -1,13 +1,6 @@ open Core -type t = Int.t [@@deriving sexp] - -val of_yojson_exn : Yojson.Safe.json -> t - -val of_yojson : Yojson.Safe.json -> t Ppx_deriving_yojson_runtime.error_or - -val to_yojson : t -> Yojson.Safe.json +type t = Int.t [@@deriving sexp, yojson] val timestamp : t -> int - val timestamp_iso : t -> string
\ No newline at end of file diff --git a/lib/models/user/presence.ml b/lib/models/user/presence.ml index ab245a7..0b18a49 100644 --- a/lib/models/user/presence.ml +++ b/lib/models/user/presence.ml @@ -2,9 +2,9 @@ open Core type t = { user: User_t.partial_user; - roles: Snowflake.t list; + roles: Role_id.t list; game: Activity.t option [@default None]; - guild_id: Snowflake.t; + guild_id: Guild_id_t.t; status: string; activities: Activity.t list; } [@@deriving sexp, yojson { strict = false}]
\ No newline at end of file diff --git a/lib/models/user/presence.mli b/lib/models/user/presence.mli index 0582f66..13c8cf0 100644 --- a/lib/models/user/presence.mli +++ b/lib/models/user/presence.mli @@ -1,8 +1,8 @@ type t = { user: User_t.partial_user; - roles: Snowflake.t list; + roles: Role_id.t list; game: Activity.t option; - guild_id: Snowflake.t; + guild_id: Guild_id_t.t; status: string; activities: Activity.t list; } [@@deriving sexp, yojson]
\ No newline at end of file |