diff options
| author | Matias Goldfeld <[email protected]> | 2021-02-07 20:21:47 -0500 |
|---|---|---|
| committer | Matias Goldfeld <[email protected]> | 2021-02-07 20:21:47 -0500 |
| commit | b2f081fff12093a7d3434859ebd621608dde6c7d (patch) | |
| tree | 5ea4f7d6ff82727d62b01fb2d234a4f8ab66aa2b | |
| parent | Removed generated version numbers (diff) | |
| download | disml-origin/HEAD.tar.xz disml-origin/HEAD.zip | |
Reverted earlier changes for goodHEADorigin/masterorigin/HEADmaster
61 files changed, 516 insertions, 449 deletions
@@ -27,7 +27,7 @@ depends: [ "core" {>= "v0.11.3"} "decompress" {<= "0.8.1"} "odoc" {with-doc & >= "1.3.0"} - "ppx_yojson_conv" {>= "v0.14.0"} + "ppx_deriving_yojson" {>= "3.3"} "ppx_sexp_conv" {>= "v0.11.2"} "websocket-async" {>= "2.12"} "yojson" {>= "1.6.0"} @@ -37,4 +37,4 @@ build: [ ["dune" "subst"] {pinned} ["dune" "build" "-p" name "-j" jobs] ["dune" "build" "@doc" "-p" name "-j" jobs] {with-doc} -] +]
\ No newline at end of file @@ -1,28 +1,28 @@ -(library - (name disml) - (public_name disml) - (synopsis "An OCaml library for interfacing with the Discord API") - (modules - activity - attachment - ban ban_t - channel channel_t channel_id channel_id_t - embed - emoji - guild guild_t guild_id guild_id_t - member member_t - message message_t message_id - overwrites - permissions - presence - reaction reaction_t - role role_t role_id - snowflake - user user_t user_id user_id_t - event_models - 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 bitmasks) - (preprocess (pps ppx_sexp_conv ppx_yojson_conv))) - -(include_subdirs unqualified) +(library
+ (name disml)
+ (public_name disml)
+ (synopsis "An OCaml library for interfacing with the Discord API")
+ (modules
+ activity
+ attachment
+ ban ban_t
+ channel channel_t channel_id channel_id_t
+ embed
+ emoji
+ guild guild_t guild_id guild_id_t
+ member member_t
+ message message_t message_id
+ overwrites
+ permissions
+ presence
+ reaction reaction_t
+ role role_t role_id
+ snowflake
+ user user_t user_id user_id_t
+ event_models
+ 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)))
+
+(include_subdirs unqualified)
diff --git a/lib/gateway/sharder.ml b/lib/gateway/sharder.ml index 31275b2..14763ca 100644 --- a/lib/gateway/sharder.ml +++ b/lib/gateway/sharder.ml @@ -130,7 +130,7 @@ module Shard = struct let request_guild_members ?(query="") ?(limit=0) ~guild shard =
let payload = `Assoc
- [ "guild_id", `String (Int64.to_string guild)
+ [ "guild_id", `String (Int.to_string guild)
; "query", `String query
; "limit", `Int limit
]
diff --git a/lib/http/endpoints.ml b/lib/http/endpoints.ml index 85b415c..8a2faea 100644 --- a/lib/http/endpoints.ml +++ b/lib/http/endpoints.ml @@ -3,62 +3,62 @@ open Printf let gateway = "/gateway"
let gateway_bot = "/gateway/bot"
-let channel = sprintf "/channels/%Ld"
-let channel_messages = sprintf "/channels/%Ld/messages"
-let channel_message = sprintf "/channels/%Ld/messages/%Ld"
-let channel_reaction_me = sprintf "/channels/%Ld/messages/%Ld/reactions/%s/@me"
-let channel_reaction = sprintf "/channels/%Ld/messages/%Ld/reactions/%s/%Ld"
-let channel_reactions_get = sprintf "/channels/%Ld/messages/%Ld/reactions/%s"
-let channel_reactions_delete = sprintf "/channels/%Ld/messages/%Ld/reactions"
-let channel_bulk_delete = sprintf "/channels/%Ld"
-let channel_permission = sprintf "/channels/%Ld/permissions/%Ld"
-let channel_permissions = sprintf "/channels/%Ld/permissions"
+let channel = sprintf "/channels/%d"
+let channel_messages = sprintf "/channels/%d/messages"
+let channel_message = sprintf "/channels/%d/messages/%d"
+let channel_reaction_me = sprintf "/channels/%d/messages/%d/reactions/%s/@me"
+let channel_reaction = sprintf "/channels/%d/messages/%d/reactions/%s/%d"
+let channel_reactions_get = sprintf "/channels/%d/messages/%d/reactions/%s"
+let channel_reactions_delete = sprintf "/channels/%d/messages/%d/reactions"
+let channel_bulk_delete = sprintf "/channels/%d"
+let channel_permission = sprintf "/channels/%d/permissions/%d"
+let channel_permissions = sprintf "/channels/%d/permissions"
let channels = "/channels"
-let channel_call_ring = sprintf "/channels/%Ld/call/ring"
-let channel_invites = sprintf "/channels/%Ld/invites"
-let channel_typing = sprintf "/channels/%Ld/typing"
-let channel_pins = sprintf "/channels/%Ld/pins"
-let channel_pin = sprintf "/channels/%Ld/pins/%Ld"
+let channel_call_ring = sprintf "/channels/%d/call/ring"
+let channel_invites = sprintf "/channels/%d/invites"
+let channel_typing = sprintf "/channels/%d/typing"
+let channel_pins = sprintf "/channels/%d/pins"
+let channel_pin = sprintf "/channels/%d/pins/%d"
let guilds = "/guilds"
-let guild = sprintf "/guilds/%Ld"
-let guild_channels = sprintf "/guilds/%Ld/channels"
-let guild_members = sprintf "/guilds/%Ld/members"
-let guild_member = sprintf "/guilds/%Ld/members/%Ld"
-let guild_member_role = sprintf "/guilds/%Ld/members/%Ld/roles/%Ld"
-let guild_bans = sprintf "/guilds/%Ld/bans"
-let guild_ban = sprintf "/guilds/%Ld/bans/%Ld"
-let guild_roles = sprintf "/guilds/%Ld/roles"
-let guild_role = sprintf "/guilds/%Ld/roles/%Ld"
-let guild_prune = sprintf "/guilds/%Ld/prune"
-let guild_voice_regions = sprintf "/guilds/%Ld/regions"
-let guild_invites = sprintf "/guilds/%Ld/invites"
-let guild_integrations = sprintf "/guilds/%Ld/integrations"
-let guild_integration = sprintf "/guilds/%Ld/integrations/%Ld"
-let guild_integration_sync = sprintf "/guilds/%Ld/integrations/%Ld/sync"
-let guild_embed = sprintf "/guilds/%Ld/embed"
-let guild_emojis = sprintf "/guilds/%Ld/emojis"
-let guild_emoji = sprintf "/guilds/%Ld/emojis/%Ld"
-let webhooks_guild = sprintf "/guilds/%Ld/webhooks"
-let webhooks_channel = sprintf "/channels/%Ld/webhooks"
-let webhook = sprintf "/webhooks/%Ld"
-let webhook_token = sprintf "/webhooks/%Ld/%s"
-let webhook_git = sprintf "/webhooks/%Ld/%s/github"
-let webhook_slack = sprintf "/webhooks/%Ld/%s/slack"
-let user = sprintf "/users/%Ld"
+let guild = sprintf "/guilds/%d"
+let guild_channels = sprintf "/guilds/%d/channels"
+let guild_members = sprintf "/guilds/%d/members"
+let guild_member = sprintf "/guilds/%d/members/%d"
+let guild_member_role = sprintf "/guilds/%d/members/%d/roles/%d"
+let guild_bans = sprintf "/guilds/%d/bans"
+let guild_ban = sprintf "/guilds/%d/bans/%d"
+let guild_roles = sprintf "/guilds/%d/roles"
+let guild_role = sprintf "/guilds/%d/roles/%d"
+let guild_prune = sprintf "/guilds/%d/prune"
+let guild_voice_regions = sprintf "/guilds/%d/regions"
+let guild_invites = sprintf "/guilds/%d/invites"
+let guild_integrations = sprintf "/guilds/%d/integrations"
+let guild_integration = sprintf "/guilds/%d/integrations/%d"
+let guild_integration_sync = sprintf "/guilds/%d/integrations/%d/sync"
+let guild_embed = sprintf "/guilds/%d/embed"
+let guild_emojis = sprintf "/guilds/%d/emojis"
+let guild_emoji = sprintf "/guilds/%d/emojis/%d"
+let webhooks_guild = sprintf "/guilds/%d/webhooks"
+let webhooks_channel = sprintf "/channels/%d/webhooks"
+let webhook = sprintf "/webhooks/%d"
+let webhook_token = sprintf "/webhooks/%d/%s"
+let webhook_git = sprintf "/webhooks/%d/%s/github"
+let webhook_slack = sprintf "/webhooks/%d/%s/slack"
+let user = sprintf "/users/%d"
let me = "/users/@me"
let me_guilds = "/users/@me/guilds"
-let me_guild = sprintf "/users/@me/guilds/%Ld"
+let me_guild = sprintf "/users/@me/guilds/%d"
let me_channels = "/users/@me/channels"
let me_connections = "/users/@me/connections"
let invite = sprintf "/invites/%s"
let regions = "/voice/regions"
let application_information = "/oauth2/applications/@me"
-let group_recipient = sprintf "/channels/%Ld/recipients/%Ld"
-let guild_me_nick = sprintf "/guilds/%Ld/members/@me/nick"
-let guild_vanity_url = sprintf "/guilds/%Ld/vanity-url"
-let guild_audit_logs = sprintf "/guilds/%Ld/audit-logs"
+let group_recipient = sprintf "/channels/%d/recipients/%d"
+let guild_me_nick = sprintf "/guilds/%d/members/@me/nick"
+let guild_vanity_url = sprintf "/guilds/%d/vanity-url"
+let guild_audit_logs = sprintf "/guilds/%d/audit-logs"
let cdn_embed_avatar = sprintf "/embed/avatars/%s.png"
let cdn_emoji = sprintf "/emojis/%s.%s"
-let cdn_icon = sprintf "/icons/%Ld/%s.%s"
-let cdn_avatar = sprintf "/avatars/%Ld/%s.%s"
-let cdn_default_avatar = sprintf "/embed/avatars/%Ld"
\ No newline at end of file +let cdn_icon = sprintf "/icons/%d/%s.%s"
+let cdn_avatar = sprintf "/avatars/%d/%s.%s"
+let cdn_default_avatar = sprintf "/embed/avatars/%d"
\ No newline at end of file diff --git a/lib/http/endpoints.mli b/lib/http/endpoints.mli index 413ac17..33e2ea5 100644 --- a/lib/http/endpoints.mli +++ b/lib/http/endpoints.mli @@ -2,62 +2,62 @@ val gateway : string
val gateway_bot : string
-val channel : int64 -> string
-val channel_messages : int64 -> string
-val channel_message : int64 -> int64 -> string
-val channel_reaction_me : int64 -> int64 -> string -> string
-val channel_reaction : int64 -> int64 -> string -> int64 -> string
-val channel_reactions_get : int64 -> int64 -> string -> string
-val channel_reactions_delete : int64 -> int64 -> string
-val channel_bulk_delete : int64 -> string
-val channel_permission : int64 -> int64 -> string
-val channel_permissions : int64 -> string
+val channel : int -> string
+val channel_messages : int -> string
+val channel_message : int -> int -> string
+val channel_reaction_me : int -> int -> string -> string
+val channel_reaction : int -> int -> string -> int -> string
+val channel_reactions_get : int -> int -> string -> string
+val channel_reactions_delete : int -> int -> string
+val channel_bulk_delete : int -> string
+val channel_permission : int -> int -> string
+val channel_permissions : int -> string
val channels : string
-val channel_call_ring : int64 -> string
-val channel_invites : int64 -> string
-val channel_typing : int64 -> string
-val channel_pins : int64 -> string
-val channel_pin : int64 -> int64 -> string
+val channel_call_ring : int -> string
+val channel_invites : int -> string
+val channel_typing : int -> string
+val channel_pins : int -> string
+val channel_pin : int -> int -> string
val guilds : string
-val guild : int64 -> string
-val guild_channels : int64 -> string
-val guild_members : int64 -> string
-val guild_member : int64 -> int64 -> string
-val guild_member_role : int64 -> int64 -> int64 -> string
-val guild_bans : int64 -> string
-val guild_ban : int64 -> int64 -> string
-val guild_roles : int64 -> string
-val guild_role : int64 -> int64 -> string
-val guild_prune : int64 -> string
-val guild_voice_regions : int64 -> string
-val guild_invites : int64 -> string
-val guild_integrations : int64 -> string
-val guild_integration : int64 -> int64 -> string
-val guild_integration_sync : int64 -> int64 -> string
-val guild_embed : int64 -> string
-val guild_emojis : int64 -> string
-val guild_emoji : int64 -> int64 -> string
-val webhooks_guild : int64 -> string
-val webhooks_channel : int64 -> string
-val webhook : int64 -> string
-val webhook_token : int64 -> string -> string
-val webhook_git : int64 -> string -> string
-val webhook_slack : int64 -> string -> string
-val user : int64 -> string
+val guild : int -> string
+val guild_channels : int -> string
+val guild_members : int -> string
+val guild_member : int -> int -> string
+val guild_member_role : int -> int -> int -> string
+val guild_bans : int -> string
+val guild_ban : int -> int -> string
+val guild_roles : int -> string
+val guild_role : int -> int -> string
+val guild_prune : int -> string
+val guild_voice_regions : int -> string
+val guild_invites : int -> string
+val guild_integrations : int -> string
+val guild_integration : int -> int -> string
+val guild_integration_sync : int -> int -> string
+val guild_embed : int -> string
+val guild_emojis : int -> string
+val guild_emoji : int -> int -> string
+val webhooks_guild : int -> string
+val webhooks_channel : int -> string
+val webhook : int -> string
+val webhook_token : int -> string -> string
+val webhook_git : int -> string -> string
+val webhook_slack : int -> string -> string
+val user : int -> string
val me : string
val me_guilds : string
-val me_guild : int64 -> string
+val me_guild : int -> string
val me_channels : string
val me_connections : string
val invite : string -> string
val regions : string
val application_information : string
-val group_recipient : int64 -> int64 -> string
-val guild_me_nick : int64 -> string
-val guild_vanity_url : int64 -> string
-val guild_audit_logs : int64 -> string
+val group_recipient : int -> int -> string
+val guild_me_nick : int -> string
+val guild_vanity_url : int -> string
+val guild_audit_logs : int -> string
val cdn_embed_avatar : string -> string
val cdn_emoji : string -> string -> string
-val cdn_icon : int64 -> string -> string -> string
-val cdn_avatar : int64 -> string -> string -> string
-val cdn_default_avatar : int64 -> string
\ No newline at end of file +val cdn_icon : int -> string -> string -> string
+val cdn_avatar : int -> string -> string -> string
+val cdn_default_avatar : int -> string
\ No newline at end of file diff --git a/lib/http/http.ml b/lib/http/http.ml index 7acd731..ec6cb2c 100644 --- a/lib/http/http.ml +++ b/lib/http/http.ml @@ -68,9 +68,9 @@ module Base = struct | `Post -> Cohttp_async.Client.post ~headers ~body uri
| `Put -> Cohttp_async.Client.put ~headers ~body uri)
>>= process_response path
- in if Int64.(limit.remaining > 0L) then process ()
+ in if limit.remaining > 0 then process ()
else
- let time = Time.(limit.reset |> Int63.of_int64_trunc |> Span.of_int63_seconds |> of_span_since_epoch) in
+ let time = Time.(Span.of_int_sec limit.reset |> of_span_since_epoch) in
Logs.debug (fun m -> m "Rate-limiting [Route: %s] [Duration: %d ms]" path Time.(diff time (Time.now ()) |> Span.to_ms |> Float.to_int) );
Clock.at time >>= process
end
@@ -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 c |> wrap))
+ Base.request `Get (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn 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 c |> wrap))
+ Base.request ~body `Patch (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn 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 c |> wrap))
+ Base.request `Delete (Endpoints.channel channel_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn 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.t_of_yojson)
+ Base.request ~query:[(kind, string_of_int 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)
let get_message channel_id message_id =
- Base.request `Get (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.t_of_yojson
+ Base.request `Get (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn
let create_message ?(files=[]) channel_id body =
- Base.request ~files ~body:body `Post (Endpoints.channel_messages channel_id) >>| Result.map ~f:Message_t.t_of_yojson
+ Base.request ~files ~body:body `Post (Endpoints.channel_messages channel_id) >>| Result.map ~f:Message_t.of_yojson_exn
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.t_of_yojson)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:User_t.of_yojson_exn)
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.t_of_yojson
+ Base.request ~body `Patch (Endpoints.channel_message channel_id message_id) >>| Result.map ~f:Message_t.of_yojson_exn
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.t_of_yojson)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Message_t.of_yojson_exn)
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.t_of_yojson)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Emoji.of_yojson_exn)
let get_emoji guild_id emoji_id =
- Base.request `Get (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.t_of_yojson
+ Base.request `Get (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn
let create_emoji guild_id body =
- Base.request ~body `Post (Endpoints.guild_emojis guild_id) >>| Result.map ~f:Emoji.t_of_yojson
+ Base.request ~body `Post (Endpoints.guild_emojis guild_id) >>| Result.map ~f:Emoji.of_yojson_exn
let edit_emoji guild_id emoji_id body =
- Base.request ~body `Patch (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.t_of_yojson
+ Base.request ~body `Patch (Endpoints.guild_emoji guild_id emoji_id) >>| Result.map ~f:Emoji.of_yojson_exn
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 g |> wrap))
+ Base.request ~body `Post Endpoints.guilds >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn g |> wrap))
let get_guild guild_id =
- Base.request `Get (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson g |> wrap))
+ Base.request `Get (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn 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 g |> wrap))
+ Base.request ~body `Patch (Endpoints.guild guild_id) >>| Result.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn 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 g |> wrap)))
+ >>| 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)))
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 c |> wrap))
+ Base.request ~body `Post (Endpoints.guild_channels guild_id) >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn 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 m |> wrap ~guild_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))
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 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_exn 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 m |> wrap ~guild_id))
+ >>| Result.map ~f:(fun m -> Member_t.(member_of_yojson_exn 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.t_of_yojson)
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:Ban_t.of_yojson_exn)
let get_ban guild_id user_id =
- Base.request `Get (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:Ban_t.t_of_yojson
+ Base.request `Get (Endpoints.guild_ban guild_id user_id) >>| Result.map ~f:Ban_t.of_yojson_exn
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 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_exn 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 r |> wrap ~guild_id))
+ Base.request ~body `Post (Endpoints.guild_roles guild_id) >>| Result.map ~f:(fun r -> Role_t.(role_of_yojson_exn 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 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_exn 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 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_exn 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.t_of_yojson
+ Base.request `Get Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn
let edit_current_user body =
- Base.request ~body `Patch Endpoints.me >>| Result.map ~f:User_t.t_of_yojson
+ Base.request ~body `Patch Endpoints.me >>| Result.map ~f:User_t.of_yojson_exn
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 g |> wrap)))
+ >>| Result.map ~f:(fun l -> Yojson.Safe.Util.to_list l |> List.map ~f:(fun g -> Guild_t.(pre_of_yojson_exn 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.t_of_yojson
+ Base.request `Get (Endpoints.user user_id) >>| Result.map ~f:User_t.of_yojson_exn
let get_voice_regions () =
Base.request `Get Endpoints.regions
diff --git a/lib/http/http.mli b/lib/http/http.mli index ce16d06..3468272 100644 --- a/lib/http/http.mli +++ b/lib/http/http.mli @@ -28,129 +28,129 @@ end val get_gateway : unit -> Yojson.Safe.t Deferred.Or_error.t
val get_gateway_bot : unit -> Yojson.Safe.t Deferred.Or_error.t
-val get_channel : int64 -> Channel_t.t Deferred.Or_error.t
+val get_channel : int -> Channel_t.t Deferred.Or_error.t
val modify_channel :
- int64 -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
-val delete_channel : int64 -> Channel_t.t Deferred.Or_error.t
-val get_messages : int64 -> int -> string * int64 -> Message_t.t list Deferred.Or_error.t
-val get_message : int64 -> int64 -> Message_t.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
+val delete_channel : int -> Channel_t.t Deferred.Or_error.t
+val get_messages : int -> int -> string * int -> Message_t.t list Deferred.Or_error.t
+val get_message : int -> int -> Message_t.t Deferred.Or_error.t
val create_message :
- ?files:(string * string) list -> int64 -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
+ ?files:(string * string) list -> int -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
val create_reaction :
- int64 -> int64 -> string -> unit Deferred.Or_error.t
+ int -> int -> string -> unit Deferred.Or_error.t
val delete_own_reaction :
- int64 -> int64 -> string -> unit Deferred.Or_error.t
+ int -> int -> string -> unit Deferred.Or_error.t
val delete_reaction :
- int64 -> int64 -> string -> int64 -> unit Deferred.Or_error.t
+ int -> int -> string -> int -> unit Deferred.Or_error.t
val get_reactions :
- int64 -> int64 -> string -> User_t.t list Deferred.Or_error.t
+ int -> int -> string -> User_t.t list Deferred.Or_error.t
val delete_reactions :
- int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
val edit_message :
- int64 ->
- int64 -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> Message_t.t Deferred.Or_error.t
val delete_message :
- int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
val bulk_delete :
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val edit_channel_permissions :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
-val get_channel_invites : int64 -> Yojson.Safe.t Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_channel_invites : int -> Yojson.Safe.t Deferred.Or_error.t
val create_channel_invite :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val delete_channel_permission :
- int64 -> int64 -> unit Deferred.Or_error.t
-val broadcast_typing : int64 -> unit Deferred.Or_error.t
-val get_pinned_messages : int64 -> Message_t.t list Deferred.Or_error.t
-val pin_message : int64 -> int64 -> unit Deferred.Or_error.t
-val unpin_message : int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
+val broadcast_typing : int -> unit Deferred.Or_error.t
+val get_pinned_messages : int -> Message_t.t list Deferred.Or_error.t
+val pin_message : int -> int -> unit Deferred.Or_error.t
+val unpin_message : int -> int -> unit Deferred.Or_error.t
val group_recipient_add :
- int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
val group_recipient_remove :
- int64 -> int64 -> unit Deferred.Or_error.t
-val get_emojis : int64 -> Emoji.t list Deferred.Or_error.t
-val get_emoji : int64 -> int64 -> Emoji.t Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
+val get_emojis : int -> Emoji.t list Deferred.Or_error.t
+val get_emoji : int -> int -> Emoji.t Deferred.Or_error.t
val create_emoji :
- int64 -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
val edit_emoji :
- int64 ->
- int64 -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
-val delete_emoji : int64 -> int64 -> unit Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> Emoji.t Deferred.Or_error.t
+val delete_emoji : int -> int -> unit Deferred.Or_error.t
val create_guild :
Yojson.Safe.t -> Guild_t.t Deferred.Or_error.t
-val get_guild : int64 -> Guild_t.t Deferred.Or_error.t
+val get_guild : int -> Guild_t.t Deferred.Or_error.t
val edit_guild :
- int64 -> Yojson.Safe.t -> Guild_t.t Deferred.Or_error.t
-val delete_guild : int64 -> unit Deferred.Or_error.t
-val get_guild_channels : int64 -> Channel_t.t list Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Guild_t.t Deferred.Or_error.t
+val delete_guild : int -> unit Deferred.Or_error.t
+val get_guild_channels : int -> Channel_t.t list Deferred.Or_error.t
val create_guild_channel :
- int64 -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Channel_t.t Deferred.Or_error.t
val modify_guild_channel_positions :
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
-val get_member : int64 -> int64 -> Member.t Deferred.Or_error.t
-val get_members : int64 -> Member.t list Deferred.Or_error.t
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_member : int -> int -> Member.t Deferred.Or_error.t
+val get_members : int -> Member.t list Deferred.Or_error.t
val add_member :
- int64 ->
- int64 -> Yojson.Safe.t -> Member.t Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> Member.t Deferred.Or_error.t
val edit_member :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val remove_member :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val change_nickname :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val add_member_role :
- int64 -> int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> int -> unit Deferred.Or_error.t
val remove_member_role :
- int64 -> int64 -> int64 -> unit Deferred.Or_error.t
-val get_bans : int64 -> Ban.t list Deferred.Or_error.t
-val get_ban : int64 -> int64 -> Ban.t Deferred.Or_error.t
+ int -> int -> int -> unit Deferred.Or_error.t
+val get_bans : int -> Ban.t list Deferred.Or_error.t
+val get_ban : int -> int -> Ban.t Deferred.Or_error.t
val guild_ban_add :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val guild_ban_remove :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
-val get_roles : int64 -> Role_t.t list Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
+val get_roles : int -> Role_t.t list Deferred.Or_error.t
val guild_role_add :
- int64 -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
val guild_roles_edit :
- int64 -> Yojson.Safe.t -> Role_t.t list Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Role_t.t list Deferred.Or_error.t
val guild_role_edit :
- int64 ->
- int64 -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> Role_t.t Deferred.Or_error.t
val guild_role_remove :
- int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
val guild_prune_count :
- int64 -> int -> int Deferred.Or_error.t
+ int -> int -> int Deferred.Or_error.t
val guild_prune_start :
- int64 -> int -> int Deferred.Or_error.t
+ int -> int -> int Deferred.Or_error.t
val get_guild_voice_regions :
- int64 -> Yojson.Safe.t Deferred.Or_error.t
-val get_guild_invites : int64 -> Yojson.Safe.t Deferred.Or_error.t
-val get_integrations : int64 -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t Deferred.Or_error.t
+val get_guild_invites : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_integrations : int -> Yojson.Safe.t Deferred.Or_error.t
val add_integration :
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val edit_integration :
- int64 ->
- int64 -> Yojson.Safe.t -> unit Deferred.Or_error.t
+ int ->
+ int -> Yojson.Safe.t -> unit Deferred.Or_error.t
val delete_integration :
- int64 -> int64 -> unit Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
val sync_integration :
- int64 -> int64 -> unit Deferred.Or_error.t
-val get_guild_embed : int64 -> Yojson.Safe.t Deferred.Or_error.t
+ int -> int -> unit Deferred.Or_error.t
+val get_guild_embed : int -> Yojson.Safe.t Deferred.Or_error.t
val edit_guild_embed :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
-val get_vanity_url : int64 -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_vanity_url : int -> Yojson.Safe.t Deferred.Or_error.t
val get_invite : string -> Yojson.Safe.t Deferred.Or_error.t
val delete_invite : string -> Yojson.Safe.t Deferred.Or_error.t
val get_current_user : unit -> User_t.t Deferred.Or_error.t
val edit_current_user :
Yojson.Safe.t -> User_t.t Deferred.Or_error.t
val get_guilds : unit -> Guild_t.t list Deferred.Or_error.t
-val leave_guild : int64 -> unit Deferred.Or_error.t
+val leave_guild : int -> unit Deferred.Or_error.t
val get_private_channels :
unit -> Yojson.Safe.t Deferred.Or_error.t
val create_dm :
@@ -158,32 +158,32 @@ val create_dm : val create_group_dm :
Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val get_connections : unit -> Yojson.Safe.t Deferred.Or_error.t
-val get_user : int64 -> User_t.t Deferred.Or_error.t
+val get_user : int -> User_t.t Deferred.Or_error.t
val get_voice_regions : unit -> Yojson.Safe.t Deferred.Or_error.t
val create_webhook :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
-val get_channel_webhooks : int64 -> Yojson.Safe.t Deferred.Or_error.t
-val get_guild_webhooks : int64 -> Yojson.Safe.t Deferred.Or_error.t
-val get_webhook : int64 -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+val get_channel_webhooks : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_guild_webhooks : int -> Yojson.Safe.t Deferred.Or_error.t
+val get_webhook : int -> Yojson.Safe.t Deferred.Or_error.t
val get_webhook_with_token :
- int64 -> string -> Yojson.Safe.t Deferred.Or_error.t
+ int -> string -> Yojson.Safe.t Deferred.Or_error.t
val edit_webhook :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val edit_webhook_with_token :
- int64 ->
+ int ->
string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
-val delete_webhook : int64 -> unit Deferred.Or_error.t
+val delete_webhook : int -> unit Deferred.Or_error.t
val delete_webhook_with_token :
- int64 -> string -> unit Deferred.Or_error.t
+ int -> string -> unit Deferred.Or_error.t
val execute_webhook :
- int64 ->
+ int ->
string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val execute_slack_webhook :
- int64 ->
+ int ->
string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val execute_git_webhook :
- int64 ->
+ int ->
string -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val get_audit_logs :
- int64 -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
+ int -> Yojson.Safe.t -> Yojson.Safe.t Deferred.Or_error.t
val get_application_info : unit -> Yojson.Safe.t Deferred.Or_error.t
\ No newline at end of file diff --git a/lib/http/rl.ml b/lib/http/rl.ml index 5f26012..9f149df 100644 --- a/lib/http/rl.ml +++ b/lib/http/rl.ml @@ -4,9 +4,9 @@ open Async module RouteMap = Map.Make(String) type rl = { - limit: int64; - remaining: int64; - reset: int64; + limit: int; + remaining: int; + reset: int; } [@@deriving sexp] (* TODO improve route getting, use Date header *) @@ -25,13 +25,13 @@ let rl_of_header h = let module C = Cohttp.Header in match C.get h "X-RateLimit-Limit", C.get h "X-RateLimit-Remaining", C.get h "X-RateLimit-Reset" with | Some lim, Some rem, Some re -> - let limit = Int64.of_string lim in - let remaining = Int64.of_string rem in - let reset = Int64.of_string re in + let limit = Int.of_string lim in + let remaining = Int.of_string rem in + let reset = Int.of_string re in Some { limit; remaining; reset; } | _ -> None -let default = { limit = 1L; remaining = 1L; reset = 0L; } +let default = { limit = 1; remaining = 1; reset = 0; } let empty : t = RouteMap.empty let update = RouteMap.update let find = RouteMap.find diff --git a/lib/http/rl.mli b/lib/http/rl.mli index f4a8d59..54bc5ee 100644 --- a/lib/http/rl.mli +++ b/lib/http/rl.mli @@ -8,9 +8,9 @@ module RouteMap : module type of Map.Make(String) (** Type representing ratelimit information. *) type rl = { - limit: int64; - remaining: int64; - reset: int64; + limit: int; + remaining: int; + reset: int; } [@@deriving sexp] (** Type representing the specific case of {!RouteMap}. *) diff --git a/lib/models/channel/channel.ml b/lib/models/channel/channel.ml index 52eda02..47cf500 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.yojson_of_t e
+ | Some e -> Embed.to_yojson e
| None -> `Null in
let content = match content with
| Some c -> `String c
@@ -33,13 +33,16 @@ let delete ch = let get_message ~id ch =
Http.get_message (get_id ch) id
-let get_messages ?(mode=`Around) ~id ?(limit=50) ch =
+let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
let kind = match mode with
- | `Around -> "around", id
- | `Before -> "before", id
- | `After -> "after", id
+ | `Around -> "around", limit
+ | `Before -> "before", limit
+ | `After -> "after", limit
in
- Http.get_messages (get_id ch) limit kind
+ let id = match id with
+ | Some id -> id
+ | None -> raise No_message_found in
+ Http.get_messages (get_id ch) id kind
let broadcast_typing ch =
Http.broadcast_typing (get_id ch)
@@ -48,5 +51,5 @@ let get_pins ch = Http.get_pinned_messages (get_id ch)
let bulk_delete msgs ch =
- let msgs = `List (List.map ~f:(fun id -> `Intlit (Int64.to_string id)) msgs) in
+ let msgs = `List (List.map ~f:(fun id -> `Int id) msgs) in
Http.bulk_delete (get_id ch) msgs
\ No newline at end of file diff --git a/lib/models/channel/channel.mli b/lib/models/channel/channel.mli index cb01533..0d7431b 100644 --- a/lib/models/channel/channel.mli +++ b/lib/models/channel/channel.mli @@ -36,7 +36,7 @@ val delete : t -> Channel_t.t Deferred.Or_error.t val get_message : id:Snowflake.t -> t -> Message_t.t Deferred.Or_error.t
val get_messages :
?mode:[ `Before | `After | `Around ] ->
- id:Snowflake.t ->
+ ?id:Snowflake.t ->
?limit:int ->
t ->
Message_t.t list Deferred.Or_error.t
diff --git a/lib/models/channel/channel_t.ml b/lib/models/channel/channel_t.ml index a103090..e332c36 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+] [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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 (yojson_of_channel_wrapper s))
+ | _ -> raise (Invalid_channel (channel_wrapper_to_yojson 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 f5d538b..c6c6a0b 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** Represents a guild category. *)
type category = {
@@ -52,7 +52,7 @@ type category = { position: int;
name: string;
permission_overwrites: Overwrites.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+] [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
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 cf52078..d720a81 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/channel/message/attachment.mli b/lib/models/channel/message/attachment.mli index f935471..56006dc 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/channel/message/embed.ml b/lib/models/channel/message/embed.ml index e7ebbcc..0dd7343 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type video = {
url: string option [@default None];
height: int option [@default None];
width: int option [@default None];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type provider = {
name: string option [@default None];
url: string option [@default None];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type field = {
name: string;
value: string;
inline: bool [@default false];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
let default = {
title = None;
diff --git a/lib/models/channel/message/embed.mli b/lib/models/channel/message/embed.mli index 17fea52..fb86c94 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** A video object belonging to an embed. *)
type video = {
url: string option;
height: int option;
width: int option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** A provider object belonging to an embed. *)
type provider = {
name: string option;
url: string option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** A field object belonging to an embed. *)
type field = {
name: string;
value: string;
inline: bool;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
(** 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 2aaa0da..7f03638 100644 --- a/lib/models/channel/message/message.ml +++ b/lib/models/channel/message/message.ml @@ -6,7 +6,7 @@ let add_reaction msg (emoji:Emoji.t) = let `Message_id id = msg.id in
let `Channel_id channel_id = msg.channel_id in
let e = match emoji.id with
- | Some i -> Printf.sprintf "%s:%Ld" emoji.name i
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.create_reaction channel_id id e
@@ -15,9 +15,9 @@ 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.get_id user.id in
+ let `User_id user_id = user.id in
let e = match emoji.id with
- | Some i -> Printf.sprintf "%s:%Ld" emoji.name i
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.delete_reaction channel_id id e user_id
@@ -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
- yojson_of_t { msg with content = cont; }
+ to_yojson { 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
- yojson_of_t { msg with embeds = [embed]; }
+ to_yojson { 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 0f8e08e..31fc88c 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ 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 ba8c62a..907565c 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ 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 b072b01..e8ec5a0 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]
+} [@@deriving sexp, yojson { exn = true }]
type t = {
count: int;
emoji: Emoji.t;
-} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ 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 ace8f55..f9b2a98 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]
+} [@@deriving sexp, yojson { exn = true }]
(** Represents a number of emojis used as a reaction on a message. *)
type t = {
count: int;
emoji: Emoji.t;
-} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml index f8490e8..09a51ab 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/emoji.mli b/lib/models/emoji.mli index c159a0e..935c13a 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/event_models.ml b/lib/models/event_models.ml index efaeeaa..40ff299 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 ev |> wrap)
+ Channel_t.(channel_wrapper_of_yojson_exn 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 ev |> wrap)
+ Channel_t.(channel_wrapper_of_yojson_exn 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 ev |> wrap)
+ Channel_t.(channel_wrapper_of_yojson_exn 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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
let deserialize = of_yojson_exn
@@ -138,7 +138,7 @@ end *) type t = {
channel_id: Channel_id.t;
user: User_t.t;
- } [@@deriving sexp, yojson]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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 ev |> wrap)
+ Guild_t.(pre_of_yojson_exn 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
+ let deserialize = Guild_t.unavailable_of_yojson_exn
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 ev |> wrap)
+ Guild_t.(pre_of_yojson_exn 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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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.t_of_yojson
+ let deserialize = Member_t.of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
let update_cache (cache:Cache.t) t =
if Cache.GuildMap.mem cache.guilds t.guild_id then
@@ -407,15 +407,15 @@ module GuildRoleDelete = struct type t =
{ guild_id: Guild_id.t
; role_id: Role_id.t
- } [@@deriving sexp, yojson]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
let update_cache (cache:Cache.t) t =
if Cache.GuildMap.mem cache.guilds t.guild_id then
let guilds = match Cache.GuildMap.find cache.guilds t.guild_id with
| Some g ->
- let roles = List.filter g.roles ~f:(fun r -> Int64.(Role_id.get_id r.id <> Role_id.get_id t.role_id)) in
+ let roles = List.filter g.roles ~f:(fun r -> Role_id.get_id r.id <> Role_id.get_id t.role_id) in
let data = { g with roles } in
Cache.GuildMap.set cache.guilds ~key:t.guild_id ~data
| None -> cache.guilds in
@@ -427,9 +427,9 @@ module GuildRoleUpdate = struct type t =
{ guild_id: Guild_id.t
; role: Role_t.role
- } [@@deriving sexp, yojson]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
let update_cache (cache:Cache.t) t =
if Cache.GuildMap.mem cache.guilds t.guild_id then
@@ -437,7 +437,7 @@ module GuildRoleUpdate = struct | Some g ->
let `Guild_id guild_id = t.guild_id in
let roles = List.map g.roles ~f:(fun r ->
- if Int64.(Role_id.get_id r.id = Role_id.get_id t.role.id) then Role_t.wrap ~guild_id t.role else r) in
+ if Role_id.get_id r.id = Role_id.get_id t.role.id then Role_t.wrap ~guild_id t.role else r) in
let data = { g with roles } in
Cache.GuildMap.set cache.guilds ~key:t.guild_id ~data
| None -> cache.guilds in
@@ -449,7 +449,7 @@ module MessageCreate = struct type t = Message_t.t
let deserialize =
- Message_t.t_of_yojson
+ Message_t.of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
let update_cache (cache:Cache.t) _t = cache
end
@@ -509,7 +509,7 @@ end module PresenceUpdate = struct
type t = Presence.t
- let deserialize = Presence.t_of_yojson
+ let deserialize = Presence.of_yojson_exn
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 = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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.t_of_yojson
+ let deserialize = User_t.of_yojson_exn
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]
+ } [@@deriving sexp, yojson { strict = false; exn = true }]
- let deserialize = t_of_yojson
+ let deserialize = of_yojson_exn
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 518b93e..2ebc91d 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/guild/ban_t.mli b/lib/models/guild/ban_t.mli index 37e5cfa..63d8ca8 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/guild/guild.ml b/lib/models/guild/guild.ml index f67d5c2..95485a4 100644 --- a/lib/models/guild/guild.ml +++ b/lib/models/guild/guild.ml @@ -89,7 +89,7 @@ let request_members guild = Http.get_members (get_id guild)
let set_afk_channel ~id guild = Http.edit_guild (get_id guild) (`Assoc [
- ("afk_channel_id", `Intlit (Int64.to_string id));
+ ("afk_channel_id", `Int id);
])
let set_afk_timeout ~timeout guild = Http.edit_guild (get_id guild) (`Assoc [
@@ -113,14 +113,16 @@ 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 -> Http.get_member (get_id guild) (User_id.get_id id)
+ | None ->
+ let `User_id id = id in
+ Http.get_member (get_id guild) id
let get_channel ~(id:Channel_id_t.t) guild =
let `Channel_id id = id in
- match List.find ~f:(fun c -> Int64.(Channel_t.get_id c = id)) guild.channels with
+ match List.find ~f:(fun c -> Channel_t.get_id c = id) guild.channels with
| Some c -> Deferred.Or_error.return c
| None -> Http.get_channel id
(* TODO add HTTP fallback *)
let get_role ~(id:Role_id.t) guild =
- List.find ~f:(fun r -> Int64.(Role_id.get_id r.id = Role_id.get_id id)) guild.roles
+ List.find ~f:(fun r -> Role_id.get_id r.id = Role_id.get_id id) guild.roles
diff --git a/lib/models/guild/guild_t.ml b/lib/models/guild/guild_t.ml index 4445ce2..afe3d19 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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 42a0669..7327be9 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
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 e680ecc..c5a7455 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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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.get_id member.user.id in
+ let `User_id user_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 0724e54..4e01b9a 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type member = {
nick: string option [@default None];
@@ -15,19 +15,19 @@ type member = { deaf: bool;
mute: bool;
user: User_t.t;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type member_wrapper = {
guild_id: Guild_id_t.t;
user: User_t.t;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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 170504f..abfc1af 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]
+} [@@deriving sexp, yojson { exn = true }]
type member = {
nick: string option;
@@ -13,19 +13,19 @@ type member = { deaf: bool;
mute: bool;
user: User_t.t;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
type member_wrapper = {
guild_id: Guild_id_t.t;
user: User_t.t;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
type member_update = {
guild_id: Guild_id_t.t;
roles: Role_id.t list;
user: User_t.t;
nick: string option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
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 6f27483..2927c20 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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 630ba53..98c1559 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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 6c08711..1ea7a46 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.yojson_of_t e
+ | Some e -> Embed.to_yojson 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.yojson_of_t m)]
+ | Some m -> `Assoc [("message_id", Message_id.to_yojson m)]
| None -> `Null in
Http.create_message ?files (get_id ch) (`Assoc [
("embed", embed);
@@ -33,13 +33,16 @@ let delete ch = let get_message ~id ch =
Http.get_message (get_id ch) id
-let get_messages ?(mode=`Around) ~id ?(limit=50) ch =
+let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
let kind = match mode with
- | `Around -> "around", id
- | `Before -> "before", id
- | `After -> "after", id
+ | `Around -> "around", limit
+ | `Before -> "before", limit
+ | `After -> "after", limit
in
- Http.get_messages (get_id ch) limit kind
+ let id = match id with
+ | Some id -> id
+ | None -> raise No_message_found in
+ Http.get_messages (get_id ch) id kind
let broadcast_typing ch =
Http.broadcast_typing (get_id ch)
@@ -48,5 +51,5 @@ let get_pins ch = Http.get_pinned_messages (get_id ch)
let bulk_delete msgs ch =
- let msgs = `List (List.map ~f:(fun id -> `Intlit (Int64.to_string id)) msgs) in
+ let msgs = `List (List.map ~f:(fun id -> `Int id) msgs) in
Http.bulk_delete (get_id ch) msgs
\ No newline at end of file diff --git a/lib/models/id/channel_id.mli b/lib/models/id/channel_id.mli index 5ecad0c..2dfff8f 100644 --- a/lib/models/id/channel_id.mli +++ b/lib/models/id/channel_id.mli @@ -37,7 +37,7 @@ val delete : t -> Channel_t.t Deferred.Or_error.t val get_message : id:Snowflake.t -> t -> Message_t.t Deferred.Or_error.t
val get_messages :
?mode:[ `Before | `After | `Around ] ->
- id:Snowflake.t ->
+ ?id:Snowflake.t ->
?limit:int ->
t ->
Message_t.t list Deferred.Or_error.t
diff --git a/lib/models/id/channel_id_t.ml b/lib/models/id/channel_id_t.ml index 74588b1..cea85e0 100644 --- a/lib/models/id/channel_id_t.ml +++ b/lib/models/id/channel_id_t.ml @@ -1,7 +1,15 @@ open Core
-type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson]
+type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp]
-let compare (`Channel_id t) (`Channel_id t') = Int64.compare t t'
+let compare (`Channel_id t) (`Channel_id t') = Int.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 851fa8f..72324a7 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]
+type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }]
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.ml b/lib/models/id/guild_id.ml index 1e0168f..d4db185 100644 --- a/lib/models/id/guild_id.ml +++ b/lib/models/id/guild_id.ml @@ -82,7 +82,7 @@ let request_members guild = Http.get_members (get_id guild)
let set_afk_channel ~id guild = Http.edit_guild (get_id guild) (`Assoc [
- ("afk_channel_id", `Intlit (Int64.to_string id));
+ ("afk_channel_id", `Int id);
])
let set_afk_timeout ~timeout guild = Http.edit_guild (get_id guild) (`Assoc [
diff --git a/lib/models/id/guild_id_t.ml b/lib/models/id/guild_id_t.ml index 6fc3777..a39c07d 100644 --- a/lib/models/id/guild_id_t.ml +++ b/lib/models/id/guild_id_t.ml @@ -1,7 +1,15 @@ open Core
-type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson]
+type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp]
-let compare (`Guild_id t) (`Guild_id t') = Int64.compare t t'
+let compare (`Guild_id t) (`Guild_id t') = Int.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 17bd951..f4d415a 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]
+type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }]
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 0de01f0..3c45e16 100644 --- a/lib/models/id/message_id.ml +++ b/lib/models/id/message_id.ml @@ -1,3 +1,13 @@ -type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson]
+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)
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 90107b5..77a228a 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]
+type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }]
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 a86253c..0bbf8be 100644 --- a/lib/models/id/role_id.ml +++ b/lib/models/id/role_id.ml @@ -1,3 +1,13 @@ -type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson]
+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)
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 701e4a9..e28e300 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]
+type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }]
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 fab0f00..cf1634a 100644 --- a/lib/models/id/user_id_t.ml +++ b/lib/models/id/user_id_t.ml @@ -1,7 +1,15 @@ open Core
-type t = Snowflake.t [@@deriving sexp, yojson]
+type t = [ `User_id of Snowflake.t ] [@@deriving sexp]
-let compare t t' = Int64.compare t t'
+let compare (`User_id t) (`User_id t') = Int.compare t t'
-let get_id id = id
\ No newline at end of file +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/id/user_id_t.mli b/lib/models/id/user_id_t.mli index 1bac390..e728b00 100644 --- a/lib/models/id/user_id_t.mli +++ b/lib/models/id/user_id_t.mli @@ -1,4 +1,4 @@ -type t = Snowflake.t [@@deriving sexp, yojson]
+type t = [ `User_id of Snowflake.t ] [@@deriving sexp, yojson { exn = true }]
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 424a3aa..4603c91 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/overwrites.mli b/lib/models/overwrites.mli index cae4047..ed823dc 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/permissions.ml b/lib/models/permissions.ml index 1380594..7a0892b 100644 --- a/lib/models/permissions.ml +++ b/lib/models/permissions.ml @@ -39,9 +39,13 @@ end) let sexp_of_t = Core.Int.sexp_of_t let t_of_sexp = Core.Int.t_of_sexp -let t_of_yojson j = create @@ Yojson.Safe.Util.to_int j +let of_yojson_exn j = create @@ Yojson.Safe.Util.to_int j -let yojson_of_t t : Yojson.Safe.t = `Int t +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 of_seq seq = List.of_seq seq |> of_list diff --git a/lib/models/permissions.mli b/lib/models/permissions.mli index a023033..ce5913a 100644 --- a/lib/models/permissions.mli +++ b/lib/models/permissions.mli @@ -36,5 +36,6 @@ include BitMaskSet.S with type elt := elt val sexp_of_t : t -> Sexplib.Sexp.t val t_of_sexp : Sexplib.Sexp.t -> t -val t_of_yojson : Yojson.Safe.t -> t -val yojson_of_t : t -> Yojson.Safe.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 diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 92d94fa..2bf2281 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,11 +1,19 @@ open Core
-type t = int64 [@@deriving sexp, yojson]
+type t = Int.t [@@deriving sexp]
-let timestamp snowflake = Int64.((snowflake lsr 22) + 1_420_070_400_000L)
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.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 (Int.to_string s)
+
+let timestamp snowflake = (snowflake lsr 22) + 1_420_070_400_000
let time_of_t snowflake =
- let t = timestamp snowflake |> Int64.to_float in
+ let t = timestamp snowflake |> float_of_int in
Time.(Span.of_ms t
|> of_span_since_epoch)
diff --git a/lib/models/snowflake.mli b/lib/models/snowflake.mli index f2a56e3..0c42e4a 100644 --- a/lib/models/snowflake.mli +++ b/lib/models/snowflake.mli @@ -1,12 +1,12 @@ open Core
-type t = int64 [@@deriving sexp, yojson]
+type t = Int.t [@@deriving sexp, yojson { exn = true }]
(** Convert a snowflake into a {!Core.Time.t} *)
val time_of_t : t -> Time.t
(** Convert a snowflake into a Unix timestamp. Millisecond precision. *)
-val timestamp : t -> int64
+val timestamp : t -> int
(** Convert a snowflake into an ISO8601 timestamp string. This is equivalent to calling [Snowflake.time_of_t snowflake |> Time.(to_string_iso8601_basic ~zone:Zone.utc)] *)
val timestamp_iso : t -> string
\ No newline at end of file diff --git a/lib/models/user/activity.ml b/lib/models/user/activity.ml index 293de3b..926c899 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/user/activity.mli b/lib/models/user/activity.mli index 1ddd4e7..2757f54 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/user/presence.ml b/lib/models/user/presence.ml index 8d5d205..d8683b7 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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/user/presence.mli b/lib/models/user/presence.mli index 58a7c25..ae01373 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/user/user.ml b/lib/models/user/user.ml index 8b14b76..b8c3b25 100644 --- a/lib/models/user/user.ml +++ b/lib/models/user/user.ml @@ -5,17 +5,19 @@ let tag user = Printf.sprintf "%s#%s" user.username user.discriminator
let mention user =
- Printf.sprintf "<@%Ld>" (User_id.get_id user.id)
+ let `User_id id = user.id in
+ Printf.sprintf "<@%d>" id
let default_avatar user =
- let avatar = Int64.(of_string user.discriminator % 5L) in
+ let avatar = Int.of_string user.discriminator % 5 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 (User_id.get_id user.id) avatar ext
+ Endpoints.cdn_avatar 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 8c367fc..b68808d 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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/user/user_t.mli b/lib/models/user/user_t.mli index e971531..78f7a28 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]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file |