From c937240fdd2036edd493debb76117165e4084e8b Mon Sep 17 00:00:00 2001 From: Matias Goldfeld <2000matu@gmail.com> Date: Thu, 28 Jan 2021 02:26:36 -0500 Subject: Started conversion to ppx_yojson_conv --- disml.opam | 6 +- lib/dune | 2 +- lib/http/http.ml | 62 ++++++++--------- lib/models/channel/channel.ml | 2 +- lib/models/channel/channel_t.ml | 16 ++--- lib/models/channel/channel_t.mli | 14 ++-- lib/models/channel/message/attachment.ml | 2 +- lib/models/channel/message/attachment.mli | 2 +- lib/models/channel/message/embed.ml | 14 ++-- lib/models/channel/message/embed.mli | 14 ++-- lib/models/channel/message/message.ml | 6 +- lib/models/channel/message/message_t.ml | 2 +- lib/models/channel/message/message_t.mli | 2 +- lib/models/channel/message/reaction_t.ml | 4 +- lib/models/channel/message/reaction_t.mli | 4 +- lib/models/emoji.ml | 4 +- lib/models/emoji.mli | 4 +- lib/models/event_models.ml | 106 +++++++++++++++--------------- lib/models/guild/ban_t.ml | 2 +- lib/models/guild/ban_t.mli | 2 +- lib/models/guild/guild.ml | 4 +- lib/models/guild/guild_t.ml | 6 +- lib/models/guild/guild_t.mli | 6 +- lib/models/guild/member.ml | 16 ++--- lib/models/guild/member_t.ml | 10 +-- lib/models/guild/member_t.mli | 10 +-- lib/models/guild/role_t.ml | 4 +- lib/models/guild/role_t.mli | 4 +- lib/models/id/channel_id.ml | 4 +- lib/models/id/channel_id_t.ml | 10 +-- lib/models/id/channel_id_t.mli | 2 +- lib/models/id/guild_id_t.ml | 10 +-- lib/models/id/guild_id_t.mli | 2 +- lib/models/id/message_id.ml | 12 +--- lib/models/id/message_id.mli | 2 +- lib/models/id/role_id.ml | 12 +--- lib/models/id/role_id.mli | 2 +- lib/models/id/user_id_t.ml | 14 +--- lib/models/id/user_id_t.mli | 2 +- lib/models/overwrites.ml | 2 +- lib/models/overwrites.mli | 2 +- lib/models/permissions.ml | 8 +-- lib/models/permissions.mli | 5 +- lib/models/snowflake.ml | 10 +-- lib/models/snowflake.mli | 2 +- lib/models/user/activity.ml | 2 +- lib/models/user/activity.mli | 2 +- lib/models/user/presence.ml | 2 +- lib/models/user/presence.mli | 2 +- lib/models/user/user.ml | 6 +- lib/models/user/user_t.ml | 4 +- lib/models/user/user_t.mli | 4 +- 52 files changed, 198 insertions(+), 255 deletions(-) diff --git a/disml.opam b/disml.opam index a6ce715..fc1631e 100644 --- a/disml.opam +++ b/disml.opam @@ -1,3 +1,7 @@ +version: "b499169-dirty" +version: "b499169-dirty" +version: "b499169-dirty" +version: "b499169-dirty" opam-version: "2.0" name: "disml" version: "0.2.5" @@ -27,7 +31,7 @@ depends: [ "core" {>= "v0.11.3"} "decompress" {<= "0.8.1"} "odoc" {with-doc & >= "1.3.0"} - "ppx_deriving_yojson" {>= "3.3"} + "ppx_yojson_conv" {>= "v0.14.0"} "ppx_sexp_conv" {>= "v0.11.2"} "websocket-async" {>= "2.12"} "yojson" {>= "1.6.0"} diff --git a/lib/dune b/lib/dune index fc44062..0a1ead3 100644 --- a/lib/dune +++ b/lib/dune @@ -23,6 +23,6 @@ cache client client_options disml dispatch endpoints event http opcode rl sharder ) (libraries checkseum.ocaml core async_ssl cohttp-async decompress logs yojson websocket-async ppx_deriving_yojson.runtime bitmasks) - (preprocess (pps ppx_sexp_conv ppx_deriving_yojson))) + (preprocess (pps ppx_sexp_conv ppx_yojson_conv))) (include_subdirs unqualified) diff --git a/lib/http/http.ml b/lib/http/http.ml index 157643c..7acd731 100644 --- a/lib/http/http.ml +++ b/lib/http/http.ml @@ -82,23 +82,23 @@ let get_gateway_bot () = Base.request `Get Endpoints.gateway_bot let get_channel channel_id = - Base.request `Get (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap)) + Base.request `Get (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson c |> wrap)) let modify_channel channel_id body = - Base.request ~body `Patch (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap)) + Base.request ~body `Patch (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson c |> wrap)) let delete_channel channel_id = - Base.request `Delete (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap)) + Base.request `Delete (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson c |> wrap)) let get_messages channel_id limit (kind, id) = Base.request ~query:[(kind, Int64.to_string id); ("limit", string_of_int limit)] `Get (Endpoints.channel_messages channel_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.of_yojson_exn) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.t_of_yojson) let get_message channel_id message_id = - Base.request `Get (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn + Base.request `Get (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.t_of_yojson let create_message ?(files=[]) channel_id body = - Base.request ~files ~body:body `Post (Endpoints.channel_messages channel_id) >>| Result.map ~f:Message_t.of_yojson_exn + Base.request ~files ~body:body `Post (Endpoints.channel_messages channel_id) >>| Result.map ~f:Message_t.t_of_yojson let create_reaction channel_id message_id emoji = Base.request `Put (Endpoints.channel_reaction_me channel_id message_id emoji) >>| Result.map ~f:ignore @@ -111,13 +111,13 @@ let delete_reaction channel_id message_id emoji user_id = let get_reactions channel_id message_id emoji = Base.request `Get (Endpoints.channel_reactions_get channel_id message_id emoji) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:User_t.of_yojson_exn) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:User_t.t_of_yojson) let delete_reactions channel_id message_id = Base.request `Delete (Endpoints.channel_reactions_delete channel_id message_id) >>| Result.map ~f:ignore let edit_message channel_id message_id body = - Base.request ~body `Patch (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn + Base.request ~body `Patch (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.t_of_yojson let delete_message channel_id message_id = Base.request `Delete (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:ignore @@ -142,7 +142,7 @@ let broadcast_typing channel_id = let get_pinned_messages channel_id = Base.request `Get (Endpoints.channel_pins channel_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.of_yojson_exn) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.t_of_yojson) let pin_message channel_id message_id = Base.request `Put (Endpoints.channel_pin channel_id message_id) >>| Result.map ~f:ignore @@ -158,52 +158,52 @@ let group_recipient_remove channel_id user_id = let get_emojis guild_id = Base.request `Get (Endpoints.guild_emojis guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Emoji.of_yojson_exn) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Emoji.t_of_yojson) let get_emoji guild_id emoji_id = - Base.request `Get (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn + Base.request `Get (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.t_of_yojson let create_emoji guild_id body = - Base.request ~body `Post (Endpoints.guild_emojis guild_id) >>| Result.map ~f:Emoji.of_yojson_exn + Base.request ~body `Post (Endpoints.guild_emojis guild_id) >>| Result.map ~f:Emoji.t_of_yojson let edit_emoji guild_id emoji_id body = - Base.request ~body `Patch (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn + Base.request ~body `Patch (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.t_of_yojson let delete_emoji guild_id emoji_id = Base.request `Delete (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:ignore let create_guild body = - Base.request ~body `Post Endpoints.guilds >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap)) + Base.request ~body `Post Endpoints.guilds >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson g |> wrap)) let get_guild guild_id = - Base.request `Get (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap)) + Base.request `Get (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson g |> wrap)) let edit_guild guild_id body = - Base.request ~body `Patch (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap)) + Base.request ~body `Patch (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson g |> wrap)) let delete_guild guild_id = Base.request `Delete (Endpoints.guild guild_id) >>| Result.map ~f:ignore let get_guild_channels guild_id = Base.request `Get (Endpoints.guild_channels guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Channel_t.(channel_wrapper_of_yojson_exn g |> wrap))) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Channel_t.(channel_wrapper_of_yojson g |> wrap))) let create_guild_channel guild_id body = - Base.request ~body `Post (Endpoints.guild_channels guild_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap)) + Base.request ~body `Post (Endpoints.guild_channels guild_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson c |> wrap)) let modify_guild_channel_positions guild_id body = Base.request ~body `Patch (Endpoints.guild_channels guild_id) >>| Result.map ~f:ignore let get_member guild_id user_id = - Base.request `Get (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id)) + Base.request `Get (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson m |> wrap ~guild_id)) let get_members guild_id = Base.request `Get (Endpoints.guild_members guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id))) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun m -> Member_t.(member_of_yojson m |> wrap ~guild_id))) let add_member guild_id user_id body = Base.request ~body `Put (Endpoints.guild_member guild_id user_id) - >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson_exn m |> wrap ~guild_id)) + >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson m |> wrap ~guild_id)) let edit_member guild_id user_id body = Base.request ~body `Patch (Endpoints.guild_member guild_id user_id) >>| Result.map ~f:ignore @@ -222,10 +222,10 @@ let remove_member_role guild_id user_id role_id = let get_bans guild_id = Base.request `Get (Endpoints.guild_bans guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Ban_t.of_yojson_exn) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Ban_t.t_of_yojson) let get_ban guild_id user_id = - Base.request `Get (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:Ban_t.of_yojson_exn + Base.request `Get (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:Ban_t.t_of_yojson let guild_ban_add guild_id user_id body = Base.request ~body `Put (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:ignore @@ -235,17 +235,17 @@ let guild_ban_remove guild_id user_id body = let get_roles guild_id = Base.request `Get (Endpoints.guild_roles guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id))) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson r |> wrap ~guild_id))) let guild_role_add guild_id body = - Base.request ~body `Post (Endpoints.guild_roles guild_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id)) + Base.request ~body `Post (Endpoints.guild_roles guild_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson r |> wrap ~guild_id)) let guild_roles_edit guild_id body = Base.request ~body `Patch (Endpoints.guild_roles guild_id) - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id))) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun r -> Role_t.(role_of_yojson r |> wrap ~guild_id))) let guild_role_edit guild_id role_id body = - Base.request ~body `Patch (Endpoints.guild_role guild_id role_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson_exn r |> wrap ~guild_id)) + Base.request ~body `Patch (Endpoints.guild_role guild_id role_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson r |> wrap ~guild_id)) let guild_role_remove guild_id role_id = Base.request `Delete (Endpoints.guild_role guild_id role_id) >>| Result.map ~f:ignore @@ -295,14 +295,14 @@ let delete_invite invite_code = Base.request `Delete (Endpoints.invite invite_code) let get_current_user () = - Base.request `Get Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn + Base.request `Get Endpoints.me >>| Result.map ~f:User_t.t_of_yojson let edit_current_user body = - Base.request ~body `Patch Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn + Base.request ~body `Patch Endpoints.me >>| Result.map ~f:User_t.t_of_yojson let get_guilds () = Base.request `Get Endpoints.me_guilds - >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap))) + >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Guild_t.(pre_of_yojson g |> wrap))) let leave_guild guild_id = Base.request `Delete (Endpoints.me_guild guild_id) >>| Result.map ~f:ignore @@ -320,7 +320,7 @@ let get_connections () = Base.request `Get Endpoints.me_connections let get_user user_id = - Base.request `Get (Endpoints.user user_id) >>| Result.map ~f:User_t.of_yojson_exn + Base.request `Get (Endpoints.user user_id) >>| Result.map ~f:User_t.t_of_yojson let get_voice_regions () = Base.request `Get Endpoints.regions diff --git a/lib/models/channel/channel.ml b/lib/models/channel/channel.ml index 4d7b29d..52eda02 100644 --- a/lib/models/channel/channel.ml +++ b/lib/models/channel/channel.ml @@ -6,7 +6,7 @@ exception No_message_found let send_message ?embed ?content ?file ?(tts=false) ch = let embed = match embed with - | Some e -> Embed.to_yojson e + | Some e -> Embed.yojson_of_t e | None -> `Null in let content = match content with | Some c -> `String c diff --git a/lib/models/channel/channel_t.ml b/lib/models/channel/channel_t.ml index e332c36..a103090 100644 --- a/lib/models/channel/channel_t.ml +++ b/lib/models/channel/channel_t.ml @@ -10,13 +10,13 @@ type group = { name: string option [@default None]; owner_id: User_id_t.t; recipients: User_t.t list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type dm = { id: Channel_id_t.t; last_message_id: Message_id.t option [@default None]; last_pin_timestamp: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type guild_text = { id: Channel_id_t.t; @@ -30,7 +30,7 @@ type guild_text = { nsfw: bool; slow_mode_timeout: int option [@default None]; permission_overwrites: Overwrites.t list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type guild_voice = { id: Channel_id_t.t; @@ -41,7 +41,7 @@ type guild_voice = { user_limit: int [@default -1]; bitrate: int option [@default None]; permission_overwrites: Overwrites.t list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type category = { id: Channel_id_t.t; @@ -49,7 +49,7 @@ type category = { position: int; name: string; permission_overwrites: Overwrites.t list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = [ | `Group of group @@ -57,7 +57,7 @@ type t = [ | `GuildText of guild_text | `GuildVoice of guild_voice | `Category of category -] [@@deriving sexp, yojson { strict = false; exn = true }] +] [@@deriving sexp, yojson] type channel_wrapper = { id: Channel_id_t.t; @@ -78,7 +78,7 @@ type channel_wrapper = { category_id: Channel_id_t.t option [@default None][@key "parent_id"]; last_pin_timestamp: string option [@default None]; permission_overwrites: Overwrites.t list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] let unwrap_as_guild_text {id;guild_id;position;name;topic;nsfw;last_message_id;slow_mode_timeout;category_id;last_pin_timestamp;permission_overwrites;_} = let position = Option.value_exn position in @@ -112,7 +112,7 @@ let wrap s = | 2 -> `GuildVoice (unwrap_as_guild_voice s) | 3 -> `Group (unwrap_as_group s) | 4 -> `Category (unwrap_as_category s) - | _ -> raise (Invalid_channel (channel_wrapper_to_yojson s)) + | _ -> raise (Invalid_channel (yojson_of_channel_wrapper s)) let get_id (c:t) = match c with | `Group g -> let `Channel_id id = g.id in id diff --git a/lib/models/channel/channel_t.mli b/lib/models/channel/channel_t.mli index c6c6a0b..f5d538b 100644 --- a/lib/models/channel/channel_t.mli +++ b/lib/models/channel/channel_t.mli @@ -9,14 +9,14 @@ type group = { name: string option; owner_id: User_id_t.t; recipients: User_t.t list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Represents a private channel with a single user. *) type dm = { id: Channel_id_t.t; last_message_id: Message_id.t option; last_pin_timestamp: string option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Represents a text channel in a guild. *) type guild_text = { @@ -31,7 +31,7 @@ type guild_text = { nsfw: bool; slow_mode_timeout: int option; permission_overwrites: Overwrites.t list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Represents a voice channel in a guild. *) type guild_voice = { @@ -43,7 +43,7 @@ type guild_voice = { user_limit: int; bitrate: int option; permission_overwrites: Overwrites.t list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Represents a guild category. *) type category = { @@ -52,7 +52,7 @@ type category = { position: int; name: string; permission_overwrites: Overwrites.t list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Wrapper variant for all channel types. *) type t = [ @@ -61,7 +61,7 @@ type t = [ | `GuildText of guild_text | `GuildVoice of guild_voice | `Category of category -] [@@deriving sexp, yojson { exn = true }] +] [@@deriving sexp, yojson] (** Intermediate used internally. *) type channel_wrapper = { @@ -83,7 +83,7 @@ type channel_wrapper = { category_id: Channel_id_t.t option; last_pin_timestamp: string option; permission_overwrites: Overwrites.t list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] val unwrap_as_guild_text : channel_wrapper -> guild_text diff --git a/lib/models/channel/message/attachment.ml b/lib/models/channel/message/attachment.ml index d720a81..cf52078 100644 --- a/lib/models/channel/message/attachment.ml +++ b/lib/models/channel/message/attachment.ml @@ -8,4 +8,4 @@ type t = { proxy_url: string; height: int [@default -1]; width: int [@default -1]; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/channel/message/attachment.mli b/lib/models/channel/message/attachment.mli index 56006dc..f935471 100644 --- a/lib/models/channel/message/attachment.mli +++ b/lib/models/channel/message/attachment.mli @@ -6,4 +6,4 @@ type t = { proxy_url: string; height: int; width: int; -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/channel/message/embed.ml b/lib/models/channel/message/embed.ml index 0dd7343..e7ebbcc 100644 --- a/lib/models/channel/message/embed.ml +++ b/lib/models/channel/message/embed.ml @@ -4,38 +4,38 @@ type footer = { text: string; icon_url: string option [@default None]; proxy_icon_url: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type image = { url: string option [@default None]; proxy_url: string option [@default None]; height: int option [@default None]; width: int option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type video = { url: string option [@default None]; height: int option [@default None]; width: int option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type provider = { name: string option [@default None]; url: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type author = { name: string option [@default None]; url: string option [@default None]; icon_url: string option [@default None]; proxy_icon_url: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type field = { name: string; value: string; inline: bool [@default false]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { title: string option [@default None]; @@ -51,7 +51,7 @@ type t = { provider: provider option [@default None]; author: author option [@default None]; fields: field list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] let default = { title = None; diff --git a/lib/models/channel/message/embed.mli b/lib/models/channel/message/embed.mli index fb86c94..17fea52 100644 --- a/lib/models/channel/message/embed.mli +++ b/lib/models/channel/message/embed.mli @@ -3,7 +3,7 @@ type footer = { text: string; icon_url: string option; proxy_icon_url: string option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** An image object belonging to an embed. *) type image = { @@ -11,20 +11,20 @@ type image = { proxy_url: string option; height: int option; width: int option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A video object belonging to an embed. *) type video = { url: string option; height: int option; width: int option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A provider object belonging to an embed. *) type provider = { name: string option; url: string option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** An author object belonging to an embed. *) type author = { @@ -32,14 +32,14 @@ type author = { url: string option; icon_url: string option; proxy_icon_url: string option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A field object belonging to an embed. *) type field = { name: string; value: string; inline: bool; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** An embed object. See this {{:https://leovoel.github.io/embed-visualizer/}embed visualiser} if you need help understanding each component. *) type t = { @@ -56,7 +56,7 @@ type t = { provider: provider option; author: author option; fields: field list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] (** An embed where all values are empty. *) val default : t diff --git a/lib/models/channel/message/message.ml b/lib/models/channel/message/message.ml index a94d15e..2aaa0da 100644 --- a/lib/models/channel/message/message.ml +++ b/lib/models/channel/message/message.ml @@ -15,7 +15,7 @@ let add_reaction msg (emoji:Emoji.t) = let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) = let `Message_id id = msg.id in let `Channel_id channel_id = msg.channel_id in - let `User_id user_id = user.id in + let user_id = User_id.get_id user.id in let e = match emoji.id with | Some i -> Printf.sprintf "%s:%Ld" emoji.name i | None -> emoji.name @@ -57,13 +57,13 @@ let reply_with ?embed ?content ?files ?tts ?(reply_mention=false) msg = let set_content msg cont = let `Message_id id = msg.id in let `Channel_id channel_id = msg.channel_id in - to_yojson { msg with content = cont; } + yojson_of_t { msg with content = cont; } |> Http.edit_message channel_id id let set_embed msg embed = let `Message_id id = msg.id in let `Channel_id channel_id = msg.channel_id in - to_yojson { msg with embeds = [embed]; } + yojson_of_t { msg with embeds = [embed]; } |> Http.edit_message channel_id id diff --git a/lib/models/channel/message/message_t.ml b/lib/models/channel/message/message_t.ml index 31fc88c..0f8e08e 100644 --- a/lib/models/channel/message/message_t.ml +++ b/lib/models/channel/message/message_t.ml @@ -20,4 +20,4 @@ type t = { pinned: bool; webhook_id: Snowflake.t option [@default None]; kind: int [@key "type"]; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/channel/message/message_t.mli b/lib/models/channel/message/message_t.mli index 907565c..ba8c62a 100644 --- a/lib/models/channel/message/message_t.mli +++ b/lib/models/channel/message/message_t.mli @@ -19,4 +19,4 @@ type t = { pinned: bool; (** Whether the message is pinned. *) webhook_id: Snowflake.t option; (** The webhook ID, if the message was sent by a webhook. *) kind: int; (** See {{:https://discordapp.com/developers/docs/resources/channel#message-object-message-types}the discord docs} for message type enumeration. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/channel/message/reaction_t.ml b/lib/models/channel/message/reaction_t.ml index e8ec5a0..b072b01 100644 --- a/lib/models/channel/message/reaction_t.ml +++ b/lib/models/channel/message/reaction_t.ml @@ -6,9 +6,9 @@ type reaction_event = { message_id: Message_id.t; guild_id: Guild_id_t.t option [@default None]; emoji: Emoji.partial_emoji; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] type t = { count: int; emoji: Emoji.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/channel/message/reaction_t.mli b/lib/models/channel/message/reaction_t.mli index f9b2a98..ace8f55 100644 --- a/lib/models/channel/message/reaction_t.mli +++ b/lib/models/channel/message/reaction_t.mli @@ -5,10 +5,10 @@ type reaction_event = { message_id: Message_id.t; guild_id: Guild_id_t.t option; emoji: Emoji.partial_emoji; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Represents a number of emojis used as a reaction on a message. *) type t = { count: int; emoji: Emoji.t; -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml index 09a51ab..f8490e8 100644 --- a/lib/models/emoji.ml +++ b/lib/models/emoji.ml @@ -3,7 +3,7 @@ open Core type partial_emoji = { id: Snowflake.t option [@default None]; name: string; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { id: Snowflake.t option [@default None]; @@ -13,4 +13,4 @@ type t = { require_colons: bool [@default false]; managed: bool [@default false]; animated: bool [@default false]; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/emoji.mli b/lib/models/emoji.mli index 935c13a..c159a0e 100644 --- a/lib/models/emoji.mli +++ b/lib/models/emoji.mli @@ -2,7 +2,7 @@ type partial_emoji = { id: Snowflake.t option; name: string; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A full emoji object. *) type t = { @@ -13,4 +13,4 @@ type t = { require_colons: bool; (** Whether the emoji must be wrapped in colons. Is false for unicode emojis. *) managed: bool; (** Whether the emoji is managed by an integration. *) animated: bool; (** Whether the emoji is animated. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/event_models.ml b/lib/models/event_models.ml index b9c417b..efaeeaa 100644 --- a/lib/models/event_models.ml +++ b/lib/models/event_models.ml @@ -4,7 +4,7 @@ module ChannelCreate = struct type t = Channel_t.t let deserialize ev = - Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) + Channel_t.(channel_wrapper_of_yojson ev |> wrap) let update_cache (cache:Cache.t) (t:t) = let module C = Cache.ChannelMap in @@ -35,7 +35,7 @@ module ChannelDelete = struct type t = Channel_t.t let deserialize ev = - Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) + Channel_t.(channel_wrapper_of_yojson ev |> wrap) let update_cache (cache:Cache.t) (t:t) = let module C = Cache.ChannelMap in @@ -61,7 +61,7 @@ module ChannelUpdate = struct type t = Channel_t.t let deserialize ev = - Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) + Channel_t.(channel_wrapper_of_yojson ev |> wrap) let update_cache (cache:Cache.t) (t:t) = let module C = Cache.ChannelMap in @@ -97,9 +97,9 @@ module ChannelPinsUpdate = struct type t = { channel_id: Channel_id.t ; last_pin_timestamp: string option [@default None] - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = let module C = Cache.ChannelMap in @@ -127,7 +127,7 @@ end type t = { channel_id: Channel_id.t; user: User_t.t; - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -138,7 +138,7 @@ end *) type t = { channel_id: Channel_id.t; user: User_t.t; - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] let deserialize = of_yojson_exn @@ -150,9 +150,9 @@ module GuildBanAdd = struct type t = { guild_id: Guild_id.t ; user: User_t.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -161,9 +161,9 @@ module GuildBanRemove = struct type t = { guild_id: Guild_id.t ; user: User_t.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -172,7 +172,7 @@ module GuildCreate = struct type t = Guild_t.t let deserialize ev = - Guild_t.(pre_of_yojson_exn ev |> wrap) + Guild_t.(pre_of_yojson ev |> wrap) let update_cache (cache:Cache.t) (t:t) = let open Channel_t in @@ -221,7 +221,7 @@ module GuildDelete = struct ; unavailable: bool } - let deserialize = Guild_t.unavailable_of_yojson_exn + let deserialize = Guild_t.unavailable_of_yojson let update_cache (cache:Cache.t) (t:t) = let open Channel_t in @@ -261,7 +261,7 @@ module GuildUpdate = struct type t = Guild_t.t let deserialize ev = - Guild_t.(pre_of_yojson_exn ev |> wrap) + Guild_t.(pre_of_yojson ev |> wrap) let update_cache (cache:Cache.t) t = let open Guild_t in @@ -275,9 +275,9 @@ module GuildEmojisUpdate = struct type t = { emojis: Emoji.t list ; guild_id: Guild_id.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -293,7 +293,7 @@ end module GuildMemberAdd = struct type t = Member_t.t - let deserialize = Member_t.of_yojson_exn + let deserialize = Member_t.t_of_yojson let update_cache (cache:Cache.t) (t:t) = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -311,9 +311,9 @@ module GuildMemberRemove = struct type t = { guild_id: Guild_id.t ; user: User_t.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -333,9 +333,9 @@ module GuildMemberUpdate = struct ; nick: string option ; roles: Role_id.t list ; user: User_t.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -356,9 +356,9 @@ module GuildMembersChunk = struct type t = { guild_id: Guild_id.t ; members: Member_t.member list - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = match Cache.GuildMap.find cache.guilds t.guild_id with @@ -386,9 +386,9 @@ module GuildRoleCreate = struct type t = { guild_id: Guild_id.t ; role: Role_t.role - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -407,9 +407,9 @@ module GuildRoleDelete = struct type t = { guild_id: Guild_id.t ; role_id: Role_id.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -427,9 +427,9 @@ module GuildRoleUpdate = struct type t = { guild_id: Guild_id.t ; role: Role_t.role - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = if Cache.GuildMap.mem cache.guilds t.guild_id then @@ -449,7 +449,7 @@ module MessageCreate = struct type t = Message_t.t let deserialize = - Message_t.of_yojson_exn + Message_t.t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -459,9 +459,9 @@ module MessageDelete = struct { id: Message_id.t ; channel_id: Channel_id.t ; guild_id: Guild_id.t option [@default None] - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -487,9 +487,9 @@ module MessageUpdate = struct ; pinned: bool option [@default None] ; webhook_id: Snowflake.t option [@default None] ; kind: int option [@default None][@key "type"] - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -499,9 +499,9 @@ module MessageDeleteBulk = struct { guild_id: Guild_id.t option [@default None] ; channel_id: Channel_id.t ; ids: Message_id.t list - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -509,7 +509,7 @@ end module PresenceUpdate = struct type t = Presence.t - let deserialize = Presence.of_yojson_exn + let deserialize = Presence.t_of_yojson let update_cache (cache:Cache.t) (t:t) = let id = t.user.id in @@ -520,7 +520,7 @@ end (* module PresencesReplace = struct type t = - let deserialize = of_yojson_exn + let deserialize = t_of_yojson end *) module ReactionAdd = struct @@ -530,9 +530,9 @@ module ReactionAdd = struct ; message_id: Message_id.t ; guild_id: Guild_id.t option [@default None] ; emoji: Emoji.partial_emoji - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -544,9 +544,9 @@ module ReactionRemove = struct ; message_id: Message_id.t ; guild_id: Guild_id.t option [@default None] ; emoji: Emoji.partial_emoji - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -556,9 +556,9 @@ module ReactionRemoveAll = struct { channel_id: Channel_id.t ; message_id: Message_id.t ; guild_id: Guild_id.t option [@default None] - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -570,9 +570,9 @@ module Ready = struct ; private_channels: Channel_id.t list ; guilds: Guild_t.unavailable list ; session_id: string - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) t = let unavailable_guilds = match List.map t.guilds ~f:(fun g -> g.id, g) |> Cache.GuildMap.of_alist with @@ -588,9 +588,9 @@ end module Resumed = struct type t = { trace: string option list [@key "_trace"] } - [@@deriving sexp, yojson { strict = false; exn = true }] + [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -601,9 +601,9 @@ module TypingStart = struct ; guild_id: Guild_id.t option [@default None] ; timestamp: int ; user_id: User_id.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end @@ -611,7 +611,7 @@ end module UserUpdate = struct type t = User_t.t - let deserialize = User_t.of_yojson_exn + let deserialize = User_t.t_of_yojson let update_cache (cache:Cache.t) t = let user = Some t in @@ -622,9 +622,9 @@ module WebhookUpdate = struct type t = { channel_id: Channel_id.t ; guild_id: Guild_id.t - } [@@deriving sexp, yojson { strict = false; exn = true }] + } [@@deriving sexp, yojson] - let deserialize = of_yojson_exn + let deserialize = t_of_yojson let update_cache (cache:Cache.t) _t = cache end diff --git a/lib/models/guild/ban_t.ml b/lib/models/guild/ban_t.ml index 2ebc91d..518b93e 100644 --- a/lib/models/guild/ban_t.ml +++ b/lib/models/guild/ban_t.ml @@ -3,4 +3,4 @@ open Core type t = { reason: string option [@default None]; user: User_t.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/guild/ban_t.mli b/lib/models/guild/ban_t.mli index 63d8ca8..37e5cfa 100644 --- a/lib/models/guild/ban_t.mli +++ b/lib/models/guild/ban_t.mli @@ -1,4 +1,4 @@ type t = { reason: string option; (** The reason for the ban. *) user: User_t.t; (** The banned user. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/guild/guild.ml b/lib/models/guild/guild.ml index 14861fe..f67d5c2 100644 --- a/lib/models/guild/guild.ml +++ b/lib/models/guild/guild.ml @@ -113,9 +113,7 @@ let unban_user ~id ?reason guild = let get_member ~(id:User_id_t.t) guild = match List.find ~f:(fun m -> User_id.compare m.user.id id = 0) guild.members with | Some m -> Deferred.Or_error.return m - | None -> - let `User_id id = id in - Http.get_member (get_id guild) id + | None -> Http.get_member (get_id guild) (User_id.get_id id) let get_channel ~(id:Channel_id_t.t) guild = let `Channel_id id = id in diff --git a/lib/models/guild/guild_t.ml b/lib/models/guild/guild_t.ml index afe3d19..4445ce2 100644 --- a/lib/models/guild/guild_t.ml +++ b/lib/models/guild/guild_t.ml @@ -3,7 +3,7 @@ open Core type unavailable = { id: Guild_id_t.t; unavailable: bool [@default false]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type pre = { id: Guild_id_t.t; @@ -31,7 +31,7 @@ type pre = { member_count: int option [@default None]; members: Member_t.member list [@default []]; channels: Channel_t.channel_wrapper list [@default []]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { id: Guild_id_t.t; @@ -59,7 +59,7 @@ type t = { member_count: int option [@default None]; members: Member_t.t list; channels: Channel_t.t list; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] let wrap ({id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel_id;system_channel_id;large;member_count;members;channels}:pre) = let `Guild_id id = id in diff --git a/lib/models/guild/guild_t.mli b/lib/models/guild/guild_t.mli index 7327be9..42a0669 100644 --- a/lib/models/guild/guild_t.mli +++ b/lib/models/guild/guild_t.mli @@ -1,7 +1,7 @@ type unavailable = { id: Guild_id_t.t; unavailable: bool; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Used internally. *) type pre = { @@ -30,7 +30,7 @@ type pre = { member_count: int option; members: Member_t.member list; channels: Channel_t.channel_wrapper list; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A Guild object *) type t = { @@ -59,7 +59,7 @@ type t = { member_count: int option; (** Total number of members in the guild. *) members: Member_t.t list; (** List of guild members. *) channels: Channel_t.t list; (** List of guild channels. *) -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] val wrap : pre -> t val get_id : t -> Snowflake.t \ No newline at end of file diff --git a/lib/models/guild/member.ml b/lib/models/guild/member.ml index c5a7455..e680ecc 100644 --- a/lib/models/guild/member.ml +++ b/lib/models/guild/member.ml @@ -2,19 +2,19 @@ include Member_t let add_role ~(role:Role_t.t) member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in let `Role_id role_id = role.id in Http.add_member_role guild_id user_id role_id let remove_role ~(role:Role_t.t) member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in let `Role_id role_id = role.id in Http.remove_member_role guild_id user_id role_id let ban ?(reason="") ?(days=0) member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in Http.guild_ban_add guild_id user_id (`Assoc [ ("delete-message-days", `Int days); ("reason", `String reason); @@ -22,7 +22,7 @@ let ban ?(reason="") ?(days=0) member = let kick ?reason member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in let payload = match reason with | Some r -> `Assoc [("reason", `String r)] | None -> `Null @@ -30,28 +30,28 @@ let kick ?reason member = let mute member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in Http.edit_member guild_id user_id (`Assoc [ ("mute", `Bool true); ]) let deafen member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in Http.edit_member guild_id user_id (`Assoc [ ("deaf", `Bool true); ]) let unmute member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in Http.edit_member guild_id user_id (`Assoc [ ("mute", `Bool false); ]) let undeafen member = let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in + let user_id = User_id.get_id member.user.id in Http.edit_member guild_id user_id (`Assoc [ ("deaf", `Bool false); ]) diff --git a/lib/models/guild/member_t.ml b/lib/models/guild/member_t.ml index 4e01b9a..0724e54 100644 --- a/lib/models/guild/member_t.ml +++ b/lib/models/guild/member_t.ml @@ -6,7 +6,7 @@ type partial_member = { joined_at: string; deaf: bool; mute: bool; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type member = { nick: string option [@default None]; @@ -15,19 +15,19 @@ type member = { deaf: bool; mute: bool; user: User_t.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type member_wrapper = { guild_id: Guild_id_t.t; user: User_t.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type member_update = { guild_id: Guild_id_t.t; roles: Role_id.t list [@default []]; user: User_t.t; nick: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { nick: string option [@default None]; @@ -37,7 +37,7 @@ type t = { mute: bool; user: User_t.t; guild_id: Guild_id_t.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] let wrap ~guild_id ({nick;roles;joined_at;deaf;mute;user}:member) = {nick;roles;joined_at;deaf;mute;user;guild_id = `Guild_id guild_id} \ No newline at end of file diff --git a/lib/models/guild/member_t.mli b/lib/models/guild/member_t.mli index abfc1af..170504f 100644 --- a/lib/models/guild/member_t.mli +++ b/lib/models/guild/member_t.mli @@ -4,7 +4,7 @@ type partial_member = { joined_at: string; deaf: bool; mute: bool; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] type member = { nick: string option; @@ -13,19 +13,19 @@ type member = { deaf: bool; mute: bool; user: User_t.t; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] type member_wrapper = { guild_id: Guild_id_t.t; user: User_t.t; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] type member_update = { guild_id: Guild_id_t.t; roles: Role_id.t list; user: User_t.t; nick: string option; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A member object. *) type t = { @@ -36,6 +36,6 @@ type t = { mute: bool; (** Whether the user is muted. *) user: User_t.t; (** The underlying user object for the member. *) guild_id: Guild_id_t.t; (** The guild ID in which the member exists. *) -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] val wrap : guild_id:Snowflake.t -> member -> t \ No newline at end of file diff --git a/lib/models/guild/role_t.ml b/lib/models/guild/role_t.ml index 2927c20..6f27483 100644 --- a/lib/models/guild/role_t.ml +++ b/lib/models/guild/role_t.ml @@ -9,7 +9,7 @@ type role = { permissions: Permissions.t; managed: bool; mentionable: bool; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { id: Role_id.t; @@ -21,7 +21,7 @@ type t = { managed: bool; mentionable: bool; guild_id: Guild_id_t.t; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] let wrap ~guild_id ({id;name;colour;hoist;position;permissions;managed;mentionable}:role) = {id;name;colour;hoist;position;permissions;managed;mentionable;guild_id = `Guild_id guild_id} \ No newline at end of file diff --git a/lib/models/guild/role_t.mli b/lib/models/guild/role_t.mli index 98c1559..630ba53 100644 --- a/lib/models/guild/role_t.mli +++ b/lib/models/guild/role_t.mli @@ -8,7 +8,7 @@ type role = { permissions: Permissions.t; managed: bool; mentionable: bool; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A role object. *) type t = { @@ -21,7 +21,7 @@ type t = { managed: bool; (** Whether the guild is managed by an integration. *) mentionable: bool; (** Whether the role can be mentioned. *) guild_id: Guild_id_t.t; (** The guild ID this role belongs to. *) -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** Convenience method to produce {!t} from {!role} and a snowflake. *) val wrap : guild_id:Snowflake.t -> role -> t \ No newline at end of file diff --git a/lib/models/id/channel_id.ml b/lib/models/id/channel_id.ml index 7c62d84..6c08711 100644 --- a/lib/models/id/channel_id.ml +++ b/lib/models/id/channel_id.ml @@ -6,7 +6,7 @@ exception No_message_found let send_message ?embed ?content ?files ?(tts=false) ?reply ch = let embed = match embed with - | Some e -> Embed.to_yojson e + | Some e -> Embed.yojson_of_t e | None -> `Null in let content = match content with | Some c -> `String c @@ -15,7 +15,7 @@ let send_message ?embed ?content ?files ?(tts=false) ?reply ch = | `Null, `Null -> raise Invalid_message | _ -> () in let message_reference = match reply with - | Some m -> `Assoc [("message_id", Message_id.to_yojson m)] + | Some m -> `Assoc [("message_id", Message_id.yojson_of_t m)] | None -> `Null in Http.create_message ?files (get_id ch) (`Assoc [ ("embed", embed); diff --git a/lib/models/id/channel_id_t.ml b/lib/models/id/channel_id_t.ml index c6b80ec..74588b1 100644 --- a/lib/models/id/channel_id_t.ml +++ b/lib/models/id/channel_id_t.ml @@ -1,15 +1,7 @@ open Core -type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp] +type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson] let compare (`Channel_id t) (`Channel_id t') = Int64.compare t t' -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/channel_id_t.mli b/lib/models/id/channel_id_t.mli index 72324a7..851fa8f 100644 --- a/lib/models/id/channel_id_t.mli +++ b/lib/models/id/channel_id_t.mli @@ -1,4 +1,4 @@ -type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }] +type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson] val compare : t -> t -> int val get_id : t -> Snowflake.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 b2fd202..6fc3777 100644 --- a/lib/models/id/guild_id_t.ml +++ b/lib/models/id/guild_id_t.ml @@ -1,15 +1,7 @@ open Core -type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp] +type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson] let compare (`Guild_id t) (`Guild_id t') = Int64.compare t t' -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/guild_id_t.mli b/lib/models/id/guild_id_t.mli index f4d415a..17bd951 100644 --- a/lib/models/id/guild_id_t.mli +++ b/lib/models/id/guild_id_t.mli @@ -1,4 +1,4 @@ -type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }] +type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson] val compare : t -> t -> int val get_id : t -> Snowflake.t \ No newline at end of file diff --git a/lib/models/id/message_id.ml b/lib/models/id/message_id.ml index 3c45e16..0de01f0 100644 --- a/lib/models/id/message_id.ml +++ b/lib/models/id/message_id.ml @@ -1,13 +1,3 @@ -open Core - -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) +type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson] let get_id (`Message_id id) = id \ No newline at end of file diff --git a/lib/models/id/message_id.mli b/lib/models/id/message_id.mli index 77a228a..90107b5 100644 --- a/lib/models/id/message_id.mli +++ b/lib/models/id/message_id.mli @@ -1,3 +1,3 @@ -type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }] +type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson] val get_id : t -> Snowflake.t \ No newline at end of file diff --git a/lib/models/id/role_id.ml b/lib/models/id/role_id.ml index 0bbf8be..a86253c 100644 --- a/lib/models/id/role_id.ml +++ b/lib/models/id/role_id.ml @@ -1,13 +1,3 @@ -open Core - -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) +type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson] let get_id (`Role_id id) = id \ No newline at end of file diff --git a/lib/models/id/role_id.mli b/lib/models/id/role_id.mli index e28e300..701e4a9 100644 --- a/lib/models/id/role_id.mli +++ b/lib/models/id/role_id.mli @@ -1,3 +1,3 @@ -type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }] +type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson] val get_id : t -> Snowflake.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 214fa14..fab0f00 100644 --- a/lib/models/id/user_id_t.ml +++ b/lib/models/id/user_id_t.ml @@ -1,15 +1,7 @@ open Core -type t = [ `User_id of Snowflake.t ] [@@deriving sexp] +type t = Snowflake.t [@@deriving sexp, yojson] -let compare (`User_id t) (`User_id t') = Int64.compare t t' +let compare t t' = Int64.compare t t' -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 +let get_id id = id \ No newline at end of file diff --git a/lib/models/id/user_id_t.mli b/lib/models/id/user_id_t.mli index e728b00..1bac390 100644 --- a/lib/models/id/user_id_t.mli +++ b/lib/models/id/user_id_t.mli @@ -1,4 +1,4 @@ -type t = [ `User_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }] +type t = Snowflake.t [@@deriving sexp, yojson] val compare : t -> t -> int val get_id : t -> Snowflake.t \ No newline at end of file diff --git a/lib/models/overwrites.ml b/lib/models/overwrites.ml index 4603c91..424a3aa 100644 --- a/lib/models/overwrites.ml +++ b/lib/models/overwrites.ml @@ -5,4 +5,4 @@ type t = ; kind: string [@key "type"] ; allow: Permissions.t ; deny: Permissions.t -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/overwrites.mli b/lib/models/overwrites.mli index ed823dc..cae4047 100644 --- a/lib/models/overwrites.mli +++ b/lib/models/overwrites.mli @@ -3,4 +3,4 @@ type t = ; kind: string ; allow: Permissions.t ; deny: Permissions.t -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/permissions.ml b/lib/models/permissions.ml index 7a0892b..1380594 100644 --- a/lib/models/permissions.ml +++ b/lib/models/permissions.ml @@ -39,13 +39,9 @@ end) let sexp_of_t = Core.Int.sexp_of_t let t_of_sexp = Core.Int.t_of_sexp -let of_yojson_exn j = create @@ Yojson.Safe.Util.to_int j +let t_of_yojson j = create @@ Yojson.Safe.Util.to_int j -let of_yojson j = - try Ok (of_yojson_exn j) - with Yojson.Safe.Util.Type_error (why,_) -> Error why - -let to_yojson t : Yojson.Safe.t = `Int t +let yojson_of_t t : Yojson.Safe.t = `Int t let of_seq seq = List.of_seq seq |> of_list diff --git a/lib/models/permissions.mli b/lib/models/permissions.mli index ce5913a..a023033 100644 --- a/lib/models/permissions.mli +++ b/lib/models/permissions.mli @@ -36,6 +36,5 @@ include BitMaskSet.S with type elt := elt val sexp_of_t : t -> Sexplib.Sexp.t val t_of_sexp : Sexplib.Sexp.t -> t -val of_yojson_exn : Yojson.Safe.t -> t -val of_yojson : Yojson.Safe.t -> (t, string) result -val to_yojson : t -> Yojson.Safe.t +val t_of_yojson : Yojson.Safe.t -> t +val yojson_of_t : t -> Yojson.Safe.t diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 868b2b9..92d94fa 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,14 +1,6 @@ open Core -type t = int64 [@@deriving sexp] - -let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int64.of_string - -let of_yojson d = - try Ok (of_yojson_exn d) - with Yojson.Safe.Util.Type_error (why,_) -> Error why - -let to_yojson s : Yojson.Safe.t = `String (Int64.to_string s) +type t = int64 [@@deriving sexp, yojson] let timestamp snowflake = Int64.((snowflake lsr 22) + 1_420_070_400_000L) diff --git a/lib/models/snowflake.mli b/lib/models/snowflake.mli index fd9c597..f2a56e3 100644 --- a/lib/models/snowflake.mli +++ b/lib/models/snowflake.mli @@ -1,6 +1,6 @@ open Core -type t = int64 [@@deriving sexp, yojson { exn = true }] +type t = int64 [@@deriving sexp, yojson] (** Convert a snowflake into a {!Core.Time.t} *) val time_of_t : t -> Time.t diff --git a/lib/models/user/activity.ml b/lib/models/user/activity.ml index 926c899..293de3b 100644 --- a/lib/models/user/activity.ml +++ b/lib/models/user/activity.ml @@ -4,4 +4,4 @@ type t = { name: string; kind: int [@key "type"]; url: string option [@default None]; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/user/activity.mli b/lib/models/user/activity.mli index 2757f54..1ddd4e7 100644 --- a/lib/models/user/activity.mli +++ b/lib/models/user/activity.mli @@ -3,4 +3,4 @@ type t = { name: string; (** The name of the activity. *) kind: int; (** 0 = Playing, 1 = Streaming, 2 = Listening, 3 = Watching *) url: string option; (** Stream URL. Only validated for kind = 1. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/user/presence.ml b/lib/models/user/presence.ml index d8683b7..8d5d205 100644 --- a/lib/models/user/presence.ml +++ b/lib/models/user/presence.ml @@ -5,4 +5,4 @@ type t = { game: Activity.t option [@default None]; status: string; activities: Activity.t list; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/user/presence.mli b/lib/models/user/presence.mli index ae01373..58a7c25 100644 --- a/lib/models/user/presence.mli +++ b/lib/models/user/presence.mli @@ -4,4 +4,4 @@ type t = { game: Activity.t option; (** The current activity of the user, if any. *) status: string; (** One of [online], [idle], [offline], or [dnd]. *) activities: Activity.t list; (** A list of all of the user's current activities. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/user/user.ml b/lib/models/user/user.ml index 0d76d23..8b14b76 100644 --- a/lib/models/user/user.ml +++ b/lib/models/user/user.ml @@ -5,19 +5,17 @@ let tag user = Printf.sprintf "%s#%s" user.username user.discriminator let mention user = - let `User_id id = user.id in - Printf.sprintf "<@%Ld>" id + Printf.sprintf "<@%Ld>" (User_id.get_id user.id) let default_avatar user = let avatar = Int64.(of_string user.discriminator % 5L) in Endpoints.cdn_default_avatar avatar let face user = - let `User_id id = user.id in match user.avatar with | Some avatar -> let ext = if String.is_substring ~substring:"a_" avatar then "gif" else "png" in - Endpoints.cdn_avatar id avatar ext + Endpoints.cdn_avatar (User_id.get_id user.id) avatar ext | None -> default_avatar user \ No newline at end of file diff --git a/lib/models/user/user_t.ml b/lib/models/user/user_t.ml index b68808d..8c367fc 100644 --- a/lib/models/user/user_t.ml +++ b/lib/models/user/user_t.ml @@ -6,7 +6,7 @@ type partial_user = { discriminator: string option [@default None]; avatar: string option [@default None]; bot: bool [@default false]; -} [@@deriving sexp, yojson { strict = false; exn = true }] +} [@@deriving sexp, yojson] type t = { id: User_id_t.t; @@ -14,4 +14,4 @@ type t = { discriminator: string; avatar: string option [@default None]; bot: bool [@default false]; -} [@@deriving sexp, yojson { strict = false; exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file diff --git a/lib/models/user/user_t.mli b/lib/models/user/user_t.mli index 78f7a28..e971531 100644 --- a/lib/models/user/user_t.mli +++ b/lib/models/user/user_t.mli @@ -5,7 +5,7 @@ type partial_user = { discriminator: string option; avatar: string option; bot: bool; -} [@@deriving sexp, yojson { exn = true }] +} [@@deriving sexp, yojson] (** A user object. *) type t = { @@ -14,4 +14,4 @@ type t = { discriminator: string; (** The 4 digits, as a string, that come after the '#' in a Discord username. *) avatar: string option; (** The hash of the user avatar, if they have one set. See {!User.face} to get the avatar URL. *) bot: bool; (** Whether the user is a bot. *) -} [@@deriving sexp, yojson { exn = true }] \ No newline at end of file +} [@@deriving sexp, yojson] \ No newline at end of file -- cgit v1.2.3