From d342c4cf9fe907d2107cd815f9988f8ad147218b Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Sat, 24 Nov 2018 09:51:03 -0700 Subject: Major structural changes --- lib/_sharder.mli | 138 ++++++++++++++ lib/channel.ml | 10 ++ lib/client.ml | 35 ++++ lib/client/client.ml | 116 ------------ lib/client/opcode.ml | 54 ------ lib/client/sharder.ml | 466 ------------------------------------------------ lib/client/sharder.mli | 138 -------------- lib/guild.ml | 10 ++ lib/message.ml | 12 ++ lib/model.ml | 26 +++ lib/model/channel.ml | 1 - lib/model/emoji.ml | 1 - lib/model/guild.ml | 26 --- lib/model/member.ml | 1 - lib/model/message.ml | 1 - lib/model/presence.ml | 1 - lib/model/role.ml | 1 - lib/model/user.ml | 26 --- lib/model/voiceState.ml | 1 - lib/opcode.ml | 54 ++++++ lib/s.ml | 4 + lib/sharder.ml | 267 +++++++++++++++++++++++++++ 22 files changed, 556 insertions(+), 833 deletions(-) create mode 100644 lib/_sharder.mli create mode 100644 lib/channel.ml create mode 100644 lib/client.ml delete mode 100644 lib/client/client.ml delete mode 100644 lib/client/opcode.ml delete mode 100644 lib/client/sharder.ml delete mode 100644 lib/client/sharder.mli create mode 100644 lib/guild.ml create mode 100644 lib/message.ml create mode 100644 lib/model.ml delete mode 100644 lib/model/channel.ml delete mode 100644 lib/model/emoji.ml delete mode 100644 lib/model/guild.ml delete mode 100644 lib/model/member.ml delete mode 100644 lib/model/message.ml delete mode 100644 lib/model/presence.ml delete mode 100644 lib/model/role.ml delete mode 100644 lib/model/user.ml delete mode 100644 lib/model/voiceState.ml create mode 100644 lib/opcode.ml create mode 100644 lib/s.ml create mode 100644 lib/sharder.ml (limited to 'lib') diff --git a/lib/_sharder.mli b/lib/_sharder.mli new file mode 100644 index 0000000..0fd16d6 --- /dev/null +++ b/lib/_sharder.mli @@ -0,0 +1,138 @@ +open Async + +(** +Record type for registering event handlers +*) +type handler = { + ready: (Yojson.Basic.json -> unit) option; + resumed: (Yojson.Basic.json -> unit) option; + channel_create: (Yojson.Basic.json -> unit) option; + channel_delete: (Yojson.Basic.json -> unit) option; + channel_update: (Yojson.Basic.json -> unit) option; + channel_pins_update: (Yojson.Basic.json -> unit) option; + guild_create: (Yojson.Basic.json -> unit) option; + guild_delete: (Yojson.Basic.json -> unit) option; + guild_update: (Yojson.Basic.json -> unit) option; + guild_ban_add: (Yojson.Basic.json -> unit) option; + guild_ban_remove: (Yojson.Basic.json -> unit) option; + guild_emojis_update: (Yojson.Basic.json -> unit) option; + guild_integrations_update: (Yojson.Basic.json -> unit) option; + guild_member_add: (Yojson.Basic.json -> unit) option; + guild_member_remove: (Yojson.Basic.json -> unit) option; + guild_member_update: (Yojson.Basic.json -> unit) option; + guild_members_chunk: (Yojson.Basic.json -> unit) option; + guild_role_create: (Yojson.Basic.json -> unit) option; + guild_role_delete: (Yojson.Basic.json -> unit) option; + guild_role_update: (Yojson.Basic.json -> unit) option; + message_create: (Yojson.Basic.json -> unit) option; + message_delete: (Yojson.Basic.json -> unit) option; + message_update: (Yojson.Basic.json -> unit) option; + message_delete_bulk: (Yojson.Basic.json -> unit) option; + message_reaction_add: (Yojson.Basic.json -> unit) option; + message_reaction_remove: (Yojson.Basic.json -> unit) option; + message_reaction_remove_all: (Yojson.Basic.json -> unit) option; + presence_update: (Yojson.Basic.json -> unit) option; + typing_start: (Yojson.Basic.json -> unit) option; + user_update: (Yojson.Basic.json -> unit) option; + voice_state_update: (Yojson.Basic.json -> unit) option; + voice_server_update: (Yojson.Basic.json -> unit) option; + webhooks_update: (Yojson.Basic.json -> unit) option; +} + +(** +Represents a single Shard. Manual creation is discouraged; use Sharder.start instead +*) +module Shard : sig + type t = { + mutable hb: unit Ivar.t option; + mutable seq: int; + mutable session: string option; + mutable handler: handler; + token: string; + shard: int * int; + write: string Pipe.Writer.t; + read: string Pipe.Reader.t; + ready: unit Ivar.t; + } + + val parse : + [< `Ok of string | `Eof] -> + Yojson.Basic.json + + val push_frame : + ?payload:Yojson.Basic.json -> + t -> + Opcode.t -> + t Deferred.t + + val heartbeat : + t -> + t Deferred.t + + val dispatch : + t -> + Yojson.Basic.json -> + t Deferred.t + + val set_status : + t -> + Yojson.Basic.json -> + t Deferred.t + + val request_guild_members : + guild:int -> + ?query:string -> + ?limit:int -> + t -> + t Deferred.t + + val initialize : + t -> + Yojson.Basic.json -> + t Deferred.t + + val handle_frame : + t -> + Yojson.Basic.json -> + t Deferred.t + + val create : + url:string -> + shards:int * int -> + token:string -> + handler: handler -> + unit -> + t Deferred.t +end + +type t = { + shards: Shard.t list; +} + +val start : + ?count:int -> + handler:handler -> + string -> + t Deferred.t + +val set_status : + t -> + Yojson.Basic.json -> + Shard.t list Deferred.t + +val set_status_with : + t -> + (Shard.t -> Yojson.Basic.json) -> + Shard.t list Deferred.t + +val request_guild_members : + guild:int -> + ?query:string -> + ?limit:int -> + t -> + Shard.t list Deferred.t + +val update_handler : + t -> + handler -> + unit \ No newline at end of file diff --git a/lib/channel.ml b/lib/channel.ml new file mode 100644 index 0000000..904bbde --- /dev/null +++ b/lib/channel.ml @@ -0,0 +1,10 @@ +type t = { + id: string; + name: string; +} + +let from_json term = + let module J = Yojson.Basic.Util in + let id = J.(member "id" term |> to_string) in + let name = J.(member "name" term |> to_string) in + { id; name; } diff --git a/lib/client.ml b/lib/client.ml new file mode 100644 index 0000000..7c2d532 --- /dev/null +++ b/lib/client.ml @@ -0,0 +1,35 @@ +open Async + +type t = { + sharder: Sharder.t Ivar.t; + handler: (string * Model.t) Pipe.Writer.t; + token: string; +} + +let make ~handler token = + { + sharder = Ivar.create (); + handler; + token; + } + +let start ?count client = + Sharder.start ?count ~handler:client.handler client.token + >>| fun sharder -> + Ivar.fill_if_empty client.sharder sharder; + client + +let set_status client status = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.set_status sharder status + +let set_status_with client f = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.set_status_with sharder f + +let request_guild_members ~guild ?query ?limit client = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.request_guild_members ~guild ?query ?limit sharder diff --git a/lib/client/client.ml b/lib/client/client.ml deleted file mode 100644 index 9877714..0000000 --- a/lib/client/client.ml +++ /dev/null @@ -1,116 +0,0 @@ -open Async - -type t = { - sharder: Sharder.t Ivar.t; - (* events: (Events.t, Core_kernel.write) Bvar.t list; *) - mutable handler: Sharder.handler; - token: string; -} - -let make ?handler token = - let handler = match handler with - | Some h -> h - | None -> begin - Sharder.{ - ready = None; - resumed = None; - channel_create = None; - channel_delete = None; - channel_update = None; - channel_pins_update = None; - guild_create = None; - guild_delete = None; - guild_update = None; - guild_ban_add = None; - guild_ban_remove = None; - guild_emojis_update = None; - guild_integrations_update = None; - guild_member_add = None; - guild_member_remove = None; - guild_member_update = None; - guild_members_chunk = None; - guild_role_create = None; - guild_role_delete = None; - guild_role_update = None; - message_create = None; - message_delete = None; - message_update = None; - message_delete_bulk = None; - message_reaction_add = None; - message_reaction_remove = None; - message_reaction_remove_all = None; - presence_update = None; - typing_start = None; - user_update = None; - voice_state_update = None; - voice_server_update = None; - webhooks_update = None; - } - end in - { - sharder = Ivar.create (); - handler; - token; - } - -let start ?count client = - Sharder.start ?count ~handler:client.handler client.token - >>| fun sharder -> - Ivar.fill_if_empty client.sharder sharder; - client - -let on ev client fn = - client.handler <- (match ev with - | "READY" -> { client.handler with ready = Some(fn) } - | "RESUMED" -> { client.handler with resumed = Some(fn) } - | "CHANNEL_CREATE" -> { client.handler with channel_create = Some(fn) } - | "CHANNEL_DELETE" -> { client.handler with channel_delete = Some(fn) } - | "CHANNEL_UPDATE" -> { client.handler with channel_update = Some(fn) } - | "CHANNEL_PINS_UPDATE" -> { client.handler with channel_pins_update = Some(fn) } - | "GUILD_CREATE" -> { client.handler with guild_create = Some(fn) } - | "GUILD_DELETE" -> { client.handler with guild_delete = Some(fn) } - | "GUILD_UPDATE" -> { client.handler with guild_update = Some(fn) } - | "GUILD_BAN_ADD" -> { client.handler with guild_ban_add = Some(fn) } - | "GUILD_BAN_REMOVE" -> { client.handler with guild_ban_remove = Some(fn) } - | "GUILD_EMOJIS_UPDATE" -> { client.handler with guild_emojis_update = Some(fn) } - | "GUILD_INTEGRATIONS_UPDATE" -> { client.handler with guild_integrations_update = Some(fn) } - | "GUILD_MEMBER_ADD" -> { client.handler with guild_member_add = Some(fn) } - | "GUILD_MEMBER_REMOVE" -> { client.handler with guild_member_remove = Some(fn) } - | "GUILD_MEMBER_UPDATE" -> { client.handler with guild_member_update = Some(fn) } - | "GUILD_MEMBERS_CHUNK" -> { client.handler with guild_members_chunk = Some(fn) } - | "GUILD_ROLE_CREATE" -> { client.handler with guild_role_create = Some(fn) } - | "GUILD_ROLE_DELETE" -> { client.handler with guild_role_delete = Some(fn) } - | "GUILD_ROLE_UPDATE" -> { client.handler with guild_role_update = Some(fn) } - | "MESSAGE_CREATE" -> { client.handler with message_create = Some(fn) } - | "MESSAGE_DELETE" -> { client.handler with message_delete = Some(fn) } - | "MESSAGE_UPDATE" -> { client.handler with message_update = Some(fn) } - | "MESSAGE_DELETE_BULK" -> { client.handler with message_delete_bulk = Some(fn) } - | "MESSAGE_REACTION_ADD" -> { client.handler with message_reaction_add = Some(fn) } - | "MESSAGE_REACTION_REMOVE" -> { client.handler with message_reaction_remove = Some(fn) } - | "MESSAGE_REACTION_REMOVE_ALL" -> { client.handler with message_reaction_remove_all = Some(fn) } - | "PRESENCE_UPDATE" -> { client.handler with presence_update = Some(fn) } - | "TYPING_START" -> { client.handler with typing_start = Some(fn) } - | "USER_UPDATE" -> { client.handler with user_update = Some(fn) } - | "VOICE_STATE_UPDATE" -> { client.handler with voice_state_update = Some(fn) } - | "VOICE_SERVER_UPDATE" -> { client.handler with voice_server_update = Some(fn) } - | "WEBHOOKS_UPDATE" -> { client.handler with webhooks_update = Some(fn) } - | _ -> client.handler); - match Ivar.peek client.sharder with - | Some s -> Sharder.update_handler s client.handler; - | None -> () - - -let set_status client status = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status sharder status - -let set_status_with client f = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status_with sharder f - -let request_guild_members ~guild ?query ?limit client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.request_guild_members ~guild ?query ?limit sharder \ No newline at end of file diff --git a/lib/client/opcode.ml b/lib/client/opcode.ml deleted file mode 100644 index 2462d05..0000000 --- a/lib/client/opcode.ml +++ /dev/null @@ -1,54 +0,0 @@ -type t = - | DISPATCH - | HEARTBEAT - | IDENTIFY - | STATUS_UPDATE - | VOICE_STATE_UPDATE - | RESUME - | RECONNECT - | REQUEST_GUILD_MEMBERS - | INVALID_SESSION - | HELLO - | HEARTBEAT_ACK - -exception Invalid_Opcode of int - -let to_int = function - | DISPATCH -> 0 - | HEARTBEAT -> 1 - | IDENTIFY -> 2 - | STATUS_UPDATE -> 3 - | VOICE_STATE_UPDATE -> 4 - | RESUME -> 6 - | RECONNECT -> 7 - | REQUEST_GUILD_MEMBERS -> 8 - | INVALID_SESSION -> 9 - | HELLO -> 10 - | HEARTBEAT_ACK -> 11 - -let from_int = function - | 0 -> DISPATCH - | 1 -> HEARTBEAT - | 2 -> IDENTIFY - | 3 -> STATUS_UPDATE - | 4 -> VOICE_STATE_UPDATE - | 6 -> RESUME - | 7 -> RECONNECT - | 8 -> REQUEST_GUILD_MEMBERS - | 9 -> INVALID_SESSION - | 10 -> HELLO - | 11 -> HEARTBEAT_ACK - | op -> raise (Invalid_Opcode op) - -let to_string = function - | DISPATCH -> "DISPATCH" - | HEARTBEAT -> "HEARTBEAT" - | IDENTIFY -> "IDENTIFY" - | STATUS_UPDATE -> "STATUS_UPDATE" - | VOICE_STATE_UPDATE -> "VOICE_STATE_UPDATE" - | RESUME -> "RESUME" - | RECONNECT -> "RECONNECT" - | REQUEST_GUILD_MEMBERS -> "REQUEST_GUILD_MEMBER" - | INVALID_SESSION -> "INVALID_SESSION" - | HELLO -> "HELLO" - | HEARTBEAT_ACK -> "HEARTBEAT_ACK" \ No newline at end of file diff --git a/lib/client/sharder.ml b/lib/client/sharder.ml deleted file mode 100644 index 8d735b0..0000000 --- a/lib/client/sharder.ml +++ /dev/null @@ -1,466 +0,0 @@ -open Async -open Core -open Websocket_async - -exception Invalid_Payload - -type handler = { - ready: (Yojson.Basic.json -> unit) option; - resumed: (Yojson.Basic.json -> unit) option; - channel_create: (Yojson.Basic.json -> unit) option; - channel_delete: (Yojson.Basic.json -> unit) option; - channel_update: (Yojson.Basic.json -> unit) option; - channel_pins_update: (Yojson.Basic.json -> unit) option; - guild_create: (Yojson.Basic.json -> unit) option; - guild_delete: (Yojson.Basic.json -> unit) option; - guild_update: (Yojson.Basic.json -> unit) option; - guild_ban_add: (Yojson.Basic.json -> unit) option; - guild_ban_remove: (Yojson.Basic.json -> unit) option; - guild_emojis_update: (Yojson.Basic.json -> unit) option; - guild_integrations_update: (Yojson.Basic.json -> unit) option; - guild_member_add: (Yojson.Basic.json -> unit) option; - guild_member_remove: (Yojson.Basic.json -> unit) option; - guild_member_update: (Yojson.Basic.json -> unit) option; - guild_members_chunk: (Yojson.Basic.json -> unit) option; (* Not sure if this should be exposed *) - guild_role_create: (Yojson.Basic.json -> unit) option; - guild_role_delete: (Yojson.Basic.json -> unit) option; - guild_role_update: (Yojson.Basic.json -> unit) option; - message_create: (Yojson.Basic.json -> unit) option; - message_delete: (Yojson.Basic.json -> unit) option; - message_update: (Yojson.Basic.json -> unit) option; - message_delete_bulk: (Yojson.Basic.json -> unit) option; - message_reaction_add: (Yojson.Basic.json -> unit) option; - message_reaction_remove: (Yojson.Basic.json -> unit) option; - message_reaction_remove_all: (Yojson.Basic.json -> unit) option; - presence_update: (Yojson.Basic.json -> unit) option; - typing_start: (Yojson.Basic.json -> unit) option; - user_update: (Yojson.Basic.json -> unit) option; - voice_state_update: (Yojson.Basic.json -> unit) option; - voice_server_update: (Yojson.Basic.json -> unit) option; - webhooks_update: (Yojson.Basic.json -> unit) option; -} - -module Shard = struct - type t = { - mutable hb: unit Ivar.t option; - mutable seq: int; - mutable session: string option; - mutable handler: handler; - token: string; - shard: int * int; - write: string Pipe.Writer.t; - read: string Pipe.Reader.t; - ready: unit Ivar.t; - } - - let identify_lock = Mutex.create () - - let parse frame = - match frame with - | `Ok s -> Yojson.Basic.from_string s - | `Eof -> raise Invalid_Payload (* This needs to go into reconnect code, or stop using client_ez and handle frames manually *) - - let push_frame ?payload shard ev = - print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; - let content = match payload with - | None -> "" - | Some p -> - Yojson.Basic.to_string @@ `Assoc [ - ("op", `Int (Opcode.to_int ev)); - ("d", p); - ] - in - Pipe.write shard.write content - >>| fun () -> - shard - - let heartbeat shard = - let seq = match shard.seq with - | 0 -> `Null - | i -> `Int i - in - let payload = `Assoc [ - ("op", `Int 1); - ("d", seq); - ] in - push_frame ~payload shard HEARTBEAT - - let dispatch shard payload = - let module J = Yojson.Basic.Util in - let seq = J.(member "s" payload |> to_int) in - shard.seq <- seq; - let t = J.(member "t" payload |> to_string) in - let data = J.member "d" payload in - let _ = match t with - | "READY" -> begin - Ivar.fill_if_empty shard.ready (); - let session = J.(member "session_id" data |> to_string) in - shard.session <- Some session; - match shard.handler.ready with - | Some f -> f data - | None -> () - end - | "RESUMED" -> begin - match shard.handler.resumed with - | Some f -> f data - | None -> () - end - | "CHANNEL_CREATE" -> begin - match shard.handler.channel_create with - | Some f -> f data - | None -> () - end - | "CHANNEL_DELETE" -> begin - match shard.handler.channel_delete with - | Some f -> f data - | None -> () - end - | "CHANNEL_UPDATE" -> begin - match shard.handler.channel_update with - | Some f -> f data - | None -> () - end - | "CHANNEL_PINS_UPDATE" -> begin - match shard.handler.channel_pins_update with - | Some f -> f data - | None -> () - end - | "GUILD_CREATE" -> begin - match shard.handler.guild_create with - | Some f -> f data - | None -> () - end - | "GUILD_DELETE" -> begin - match shard.handler.guild_delete with - | Some f -> f data - | None -> () - end - | "GUILD_UPDATE" -> begin - match shard.handler.guild_update with - | Some f -> f data - | None -> () - end - | "GUILD_BAN_ADD" -> begin - match shard.handler.guild_ban_add with - | Some f -> f data - | None -> () - end - | "GUILD_BAN_REMOVE" -> begin - match shard.handler.guild_ban_remove with - | Some f -> f data - | None -> () - end - | "GUILD_EMOJIS_UPDATE" -> begin - match shard.handler.guild_emojis_update with - | Some f -> f data - | None -> () - end - | "GUILD_INTEGRATIONS_UPDATE" -> begin - match shard.handler.guild_integrations_update with - | Some f -> f data - | None -> () - end - | "GUILD_MEMBER_ADD" -> begin - match shard.handler.guild_member_add with - | Some f -> f data - | None -> () - end - | "GUILD_MEMBER_REMOVE" -> begin - match shard.handler.guild_member_remove with - | Some f -> f data - | None -> () - end - | "GUILD_MEMBER_UPDATE" -> begin - match shard.handler.guild_member_update with - | Some f -> f data - | None -> () - end - | "GUILD_MEMBERS_CHUNK" -> begin - match shard.handler.guild_members_chunk with - | Some f -> f data - | None -> () - end - | "GUILD_ROLE_CREATE" -> begin - match shard.handler.guild_role_create with - | Some f -> f data - | None -> () - end - | "GUILD_ROLE_DELETE" -> begin - match shard.handler.guild_role_delete with - | Some f -> f data - | None -> () - end - | "GUILD_ROLE_UPDATE" -> begin - match shard.handler.guild_role_update with - | Some f -> f data - | None -> () - end - | "MESSAGE_CREATE" -> begin - match shard.handler.message_create with - | Some f -> f data - | None -> () - end - | "MESSAGE_DELETE" -> begin - match shard.handler.message_delete with - | Some f -> f data - | None -> () - end - | "MESSAGE_UPDATE" -> begin - match shard.handler.message_update with - | Some f -> f data - | None -> () - end - | "MESSAGE_DELETE_BULK" -> begin - match shard.handler.message_delete_bulk with - | Some f -> f data - | None -> () - end - | "MESSAGE_REACTION_ADD" -> begin - match shard.handler.message_reaction_add with - | Some f -> f data - | None -> () - end - | "MESSAGE_REACTION_REMOVE" -> begin - match shard.handler.message_reaction_remove with - | Some f -> f data - | None -> () - end - | "MESSAGE_REACTION_REMOVE_ALL" -> begin - match shard.handler.message_reaction_remove_all with - | Some f -> f data - | None -> () - end - | "PRESENCE_UPDATE" -> begin - match shard.handler.presence_update with - | Some f -> f data - | None -> () - end - | "TYPING_START" -> begin - match shard.handler.typing_start with - | Some f -> f data - | None -> () - end - | "USER_UPDATE" -> begin - match shard.handler.user_update with - | Some f -> f data - | None -> () - end - | "VOICE_STATE_UPDATE" -> begin - match shard.handler.voice_state_update with - | Some f -> f data - | None -> () - end - | "VOICE_SERVER_UPDATE" -> begin - match shard.handler.voice_server_update with - | Some f -> f data - | None -> () - end - | "WEBHOOKS_UPDATE" -> begin - match shard.handler.webhooks_update with - | Some f -> f data - | None -> () - end - | _ -> () - in - return shard - - let set_status shard status = - let payload = match status with - | `Assoc [("name", `String name); ("type", `Int t)] -> - `Assoc [ - ("status", `String "online"); - ("afk", `Bool false); - ("since", `Null); - ("game", `Assoc [ - ("name", `String name); - ("type", `Int t) - ]) - ] - | `String name -> - `Assoc [ - ("status", `String "online"); - ("afk", `Bool false); - ("since", `Null); - ("game", `Assoc [ - ("name", `String name); - ("type", `Int 0) - ]) - ] - | _ -> raise Invalid_Payload - in - Ivar.read shard.ready >>= fun _ -> - push_frame ~payload shard STATUS_UPDATE - - let request_guild_members ~guild ?(query="") ?(limit=0) shard = - let payload = `Assoc [ - ("guild_id", `String (string_of_int guild)); - ("query", `String query); - ("limit", `Int limit); - ] in - Ivar.read shard.ready >>= fun _ -> - push_frame ~payload shard REQUEST_GUILD_MEMBERS - - let initialize shard data = - let module J = Yojson.Basic.Util in - let hb = match shard.hb with - | None -> begin - let hb_interval = J.(member "heartbeat_interval" data |> to_int) in - let finished = Ivar.create () in - Clock.every' - ~continue_on_error:true - ~finished - (Core.Time.Span.create ~ms:hb_interval ()) - (fun () -> heartbeat shard >>= fun _ -> return ()); - finished - end - | Some s -> s - in - shard.hb <- Some hb; - Mutex.lock identify_lock; - let (cur, max) = shard.shard in - let shards = [`Int cur; `Int max] in - match shard.session with - | None -> - let payload = `Assoc [ - ("token", `String shard.token); - ("properties", `Assoc [ - ("$os", `String Sys.os_type); - ("$device", `String "dis.ml"); - ("$browser", `String "dis.ml") - ]); - ("compress", `Bool false); (* TODO add compression handling*) - ("large_threshold", `Int 250); - ("shard", `List shards); - ] in - push_frame ~payload shard IDENTIFY - | Some s -> - let payload = `Assoc [ - ("token", `String shard.token); - ("session_id", `String s); - ("seq", `Int shard.seq) - ] in - push_frame ~payload shard RESUME - >>| fun s -> - Clock.after (Core.Time.Span.create ~sec:5 ()) - >>| (fun _ -> Mutex.unlock identify_lock) - |> ignore; - s - - let handle_frame shard term = - let module J = Yojson.Basic.Util in - let op = J.(member "op" term |> to_int) - |> Opcode.from_int - in - match op with - | DISPATCH -> dispatch shard term - | HEARTBEAT -> heartbeat shard - | RECONNECT -> print_endline "OP 7"; return shard (* TODO reconnect *) - | INVALID_SESSION -> print_endline "OP 9"; return shard (* TODO invalid session *) - | HELLO -> initialize shard @@ J.member "d" term - | HEARTBEAT_ACK -> return shard - | opcode -> - print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode; - return shard - - let create ~url ~shards ~token ~handler () = - let open Core in - let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in - let extra_headers = Http.Base.process_request_headers () in - let host = Option.value_exn ~message:"no host in uri" Uri.(host uri) in - let port = - match Uri.port uri, Uri_services.tcp_port_of_uri uri with - | Some p, _ -> p - | None, Some p -> p - | _ -> 443 in - let scheme = Option.value_exn ~message:"no scheme in uri" Uri.(scheme uri) in - let tcp_fun (r,w) = - let (read, write) = client_ez - ~extra_headers - uri r w - in - let rec ev_loop shard = - Pipe.read read - >>= fun frame -> - handle_frame shard @@ parse frame - >>= fun shard -> - ev_loop shard - in - let shard = { - read; - write; - handler; - ready = Ivar.create (); - hb = None; - seq = 0; - shard = shards; - session = None; - token = token; - } - in - ev_loop shard |> ignore; - return shard - in - match Unix.getaddrinfo host (string_of_int port) [] with - | [] -> failwithf "DNS resolution failed for %s" host () - | { ai_addr; _ } :: _ -> - let addr = - match scheme, ai_addr with - | _, ADDR_UNIX path -> `Unix_domain_socket path - | "https", ADDR_INET (h, p) - | "wss", ADDR_INET (h, p) -> - let h = Ipaddr_unix.of_inet_addr h in - `OpenSSL (h, p, Conduit_async.V2.Ssl.Config.create ()) - | _, ADDR_INET (h, p) -> - let h = Ipaddr_unix.of_inet_addr h in - `TCP (h, p) - in - Conduit_async.V2.connect addr >>= tcp_fun -end - -type t = { - shards: Shard.t list; -} - -let start ?count ~handler token = - let module J = Yojson.Basic.Util in - Http.get_gateway_bot () >>= fun data -> - let url = J.(member "url" data |> to_string) in - let count = match count with - | Some c -> c - | None -> J.(member "shards" data |> to_int) - in - let shard_list = (0, count) in - let rec gen_shards l a = - match l with - | (id, total) when id >= total -> return a - | (id, total) -> - Shard.create ~url ~shards:(id, total) ~token ~handler () - >>= fun shard -> - let a = shard :: a in - gen_shards (id+1, total) a - in - gen_shards shard_list [] - >>| fun shards -> - { - shards; - } - -let set_status sharder status = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status shard status - ) sharder.shards - -let set_status_with sharder f = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status shard @@ f shard - ) sharder.shards - -let request_guild_members ~guild ?query ?limit sharder = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.request_guild_members ~guild ?query ?limit shard - ) sharder.shards - -let update_handler sharder handler = - List.iter ~f:(fun shard -> - shard.handler <- handler - ) sharder.shards \ No newline at end of file diff --git a/lib/client/sharder.mli b/lib/client/sharder.mli deleted file mode 100644 index 0fd16d6..0000000 --- a/lib/client/sharder.mli +++ /dev/null @@ -1,138 +0,0 @@ -open Async - -(** -Record type for registering event handlers -*) -type handler = { - ready: (Yojson.Basic.json -> unit) option; - resumed: (Yojson.Basic.json -> unit) option; - channel_create: (Yojson.Basic.json -> unit) option; - channel_delete: (Yojson.Basic.json -> unit) option; - channel_update: (Yojson.Basic.json -> unit) option; - channel_pins_update: (Yojson.Basic.json -> unit) option; - guild_create: (Yojson.Basic.json -> unit) option; - guild_delete: (Yojson.Basic.json -> unit) option; - guild_update: (Yojson.Basic.json -> unit) option; - guild_ban_add: (Yojson.Basic.json -> unit) option; - guild_ban_remove: (Yojson.Basic.json -> unit) option; - guild_emojis_update: (Yojson.Basic.json -> unit) option; - guild_integrations_update: (Yojson.Basic.json -> unit) option; - guild_member_add: (Yojson.Basic.json -> unit) option; - guild_member_remove: (Yojson.Basic.json -> unit) option; - guild_member_update: (Yojson.Basic.json -> unit) option; - guild_members_chunk: (Yojson.Basic.json -> unit) option; - guild_role_create: (Yojson.Basic.json -> unit) option; - guild_role_delete: (Yojson.Basic.json -> unit) option; - guild_role_update: (Yojson.Basic.json -> unit) option; - message_create: (Yojson.Basic.json -> unit) option; - message_delete: (Yojson.Basic.json -> unit) option; - message_update: (Yojson.Basic.json -> unit) option; - message_delete_bulk: (Yojson.Basic.json -> unit) option; - message_reaction_add: (Yojson.Basic.json -> unit) option; - message_reaction_remove: (Yojson.Basic.json -> unit) option; - message_reaction_remove_all: (Yojson.Basic.json -> unit) option; - presence_update: (Yojson.Basic.json -> unit) option; - typing_start: (Yojson.Basic.json -> unit) option; - user_update: (Yojson.Basic.json -> unit) option; - voice_state_update: (Yojson.Basic.json -> unit) option; - voice_server_update: (Yojson.Basic.json -> unit) option; - webhooks_update: (Yojson.Basic.json -> unit) option; -} - -(** -Represents a single Shard. Manual creation is discouraged; use Sharder.start instead -*) -module Shard : sig - type t = { - mutable hb: unit Ivar.t option; - mutable seq: int; - mutable session: string option; - mutable handler: handler; - token: string; - shard: int * int; - write: string Pipe.Writer.t; - read: string Pipe.Reader.t; - ready: unit Ivar.t; - } - - val parse : - [< `Ok of string | `Eof] -> - Yojson.Basic.json - - val push_frame : - ?payload:Yojson.Basic.json -> - t -> - Opcode.t -> - t Deferred.t - - val heartbeat : - t -> - t Deferred.t - - val dispatch : - t -> - Yojson.Basic.json -> - t Deferred.t - - val set_status : - t -> - Yojson.Basic.json -> - t Deferred.t - - val request_guild_members : - guild:int -> - ?query:string -> - ?limit:int -> - t -> - t Deferred.t - - val initialize : - t -> - Yojson.Basic.json -> - t Deferred.t - - val handle_frame : - t -> - Yojson.Basic.json -> - t Deferred.t - - val create : - url:string -> - shards:int * int -> - token:string -> - handler: handler -> - unit -> - t Deferred.t -end - -type t = { - shards: Shard.t list; -} - -val start : - ?count:int -> - handler:handler -> - string -> - t Deferred.t - -val set_status : - t -> - Yojson.Basic.json -> - Shard.t list Deferred.t - -val set_status_with : - t -> - (Shard.t -> Yojson.Basic.json) -> - Shard.t list Deferred.t - -val request_guild_members : - guild:int -> - ?query:string -> - ?limit:int -> - t -> - Shard.t list Deferred.t - -val update_handler : - t -> - handler -> - unit \ No newline at end of file diff --git a/lib/guild.ml b/lib/guild.ml new file mode 100644 index 0000000..904bbde --- /dev/null +++ b/lib/guild.ml @@ -0,0 +1,10 @@ +type t = { + id: string; + name: string; +} + +let from_json term = + let module J = Yojson.Basic.Util in + let id = J.(member "id" term |> to_string) in + let name = J.(member "name" term |> to_string) in + { id; name; } diff --git a/lib/message.ml b/lib/message.ml new file mode 100644 index 0000000..5b632d7 --- /dev/null +++ b/lib/message.ml @@ -0,0 +1,12 @@ +type t = { + id: string; + content: string; + channel: string; +} + +let from_json term = + let module J = Yojson.Basic.Util in + let id = J.(member "id" term |> to_string) in + let content = J.(member "content" term |> to_string) in + let channel = J.(member "channel_id" term |> to_string) in + { id; content; channel; } diff --git a/lib/model.ml b/lib/model.ml new file mode 100644 index 0000000..c44a289 --- /dev/null +++ b/lib/model.ml @@ -0,0 +1,26 @@ +module Make(M: S.Model) = struct + include M +end + +module Message = Make(Message) +module Guild = Make(Guild) +module Channel = Make(Channel) + +exception Type_Mismatch + +type t = + | Message of Message.t + | Guild of Guild.t + | Channel of Channel.t + +let to_message = function + | Message m -> m + | _ -> raise Type_Mismatch + +let to_guild = function + | Guild m -> m + | _ -> raise Type_Mismatch + +let to_channel = function + | Channel m -> m + | _ -> raise Type_Mismatch \ No newline at end of file diff --git a/lib/model/channel.ml b/lib/model/channel.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/channel.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/emoji.ml b/lib/model/emoji.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/emoji.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/guild.ml b/lib/model/guild.ml deleted file mode 100644 index 6345c17..0000000 --- a/lib/model/guild.ml +++ /dev/null @@ -1,26 +0,0 @@ -type t = { - afk_channel_id: int option; - afk_timeout: int; - application_id: int option; - channels: Channel.t list; - default_message_notifications: int; - emojis: Emoji.t list; - explicit_content_filter: int; - features: string list; - icon: string option; - id: int; - joined_at: string; - large: bool; - member_count: int; - members: Member.t list; - mfa_level: int; - name: string; - owner_id: int; - presences: Presence.t list; - region: string; - roles: Role.t list; - splash: string option; - system_channel_id: int option; - verification_level: int; - voice_states: VoiceState.t list; -} diff --git a/lib/model/member.ml b/lib/model/member.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/member.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/message.ml b/lib/model/message.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/message.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/presence.ml b/lib/model/presence.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/presence.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/role.ml b/lib/model/role.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/role.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/model/user.ml b/lib/model/user.ml deleted file mode 100644 index 182ea6a..0000000 --- a/lib/model/user.ml +++ /dev/null @@ -1,26 +0,0 @@ -type t = { - id: int; - username: string; - discriminator: string; - avatar: string option; - bot: bool; -} - -let from_json term = - let module J = Yojson.Basic.Util in - let id = J.member "id" term - |> J.to_string - |> int_of_string - in - let username = J.member "username" term - |> J.to_string in - let discriminator = J.member "discriminator" term - |> J.to_string in - let avatar = J.member "avatar" term - |> J.to_string_option in - let bot = J.member "bot" term - |> J.to_bool in - { id; username; discriminator; avatar; bot; } - -let tag user = - user.username ^ user.discriminator diff --git a/lib/model/voiceState.ml b/lib/model/voiceState.ml deleted file mode 100644 index eb6679e..0000000 --- a/lib/model/voiceState.ml +++ /dev/null @@ -1 +0,0 @@ -type t \ No newline at end of file diff --git a/lib/opcode.ml b/lib/opcode.ml new file mode 100644 index 0000000..2462d05 --- /dev/null +++ b/lib/opcode.ml @@ -0,0 +1,54 @@ +type t = + | DISPATCH + | HEARTBEAT + | IDENTIFY + | STATUS_UPDATE + | VOICE_STATE_UPDATE + | RESUME + | RECONNECT + | REQUEST_GUILD_MEMBERS + | INVALID_SESSION + | HELLO + | HEARTBEAT_ACK + +exception Invalid_Opcode of int + +let to_int = function + | DISPATCH -> 0 + | HEARTBEAT -> 1 + | IDENTIFY -> 2 + | STATUS_UPDATE -> 3 + | VOICE_STATE_UPDATE -> 4 + | RESUME -> 6 + | RECONNECT -> 7 + | REQUEST_GUILD_MEMBERS -> 8 + | INVALID_SESSION -> 9 + | HELLO -> 10 + | HEARTBEAT_ACK -> 11 + +let from_int = function + | 0 -> DISPATCH + | 1 -> HEARTBEAT + | 2 -> IDENTIFY + | 3 -> STATUS_UPDATE + | 4 -> VOICE_STATE_UPDATE + | 6 -> RESUME + | 7 -> RECONNECT + | 8 -> REQUEST_GUILD_MEMBERS + | 9 -> INVALID_SESSION + | 10 -> HELLO + | 11 -> HEARTBEAT_ACK + | op -> raise (Invalid_Opcode op) + +let to_string = function + | DISPATCH -> "DISPATCH" + | HEARTBEAT -> "HEARTBEAT" + | IDENTIFY -> "IDENTIFY" + | STATUS_UPDATE -> "STATUS_UPDATE" + | VOICE_STATE_UPDATE -> "VOICE_STATE_UPDATE" + | RESUME -> "RESUME" + | RECONNECT -> "RECONNECT" + | REQUEST_GUILD_MEMBERS -> "REQUEST_GUILD_MEMBER" + | INVALID_SESSION -> "INVALID_SESSION" + | HELLO -> "HELLO" + | HEARTBEAT_ACK -> "HEARTBEAT_ACK" \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml new file mode 100644 index 0000000..6c6456a --- /dev/null +++ b/lib/s.ml @@ -0,0 +1,4 @@ +module type Model = sig + type t + val from_json : Yojson.Basic.json -> t +end \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml new file mode 100644 index 0000000..9e2ef74 --- /dev/null +++ b/lib/sharder.ml @@ -0,0 +1,267 @@ +open Async +open Core +open Websocket_async + +exception Invalid_Payload + +module Shard = struct + type t = { + mutable hb: unit Ivar.t option; + mutable seq: int; + mutable session: string option; + handler: (string * Model.t) Pipe.Writer.t; + token: string; + shard: int * int; + write: string Pipe.Writer.t; + read: string Pipe.Reader.t; + ready: unit Ivar.t; + } + + let identify_lock = Mutex.create () + + let parse frame = + match frame with + | `Ok s -> Yojson.Basic.from_string s + | `Eof -> raise Invalid_Payload (* This needs to go into reconnect code, or stop using client_ez and handle frames manually *) + + let push_frame ?payload shard ev = + print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; + let content = match payload with + | None -> "" + | Some p -> + Yojson.Basic.to_string @@ `Assoc [ + ("op", `Int (Opcode.to_int ev)); + ("d", p); + ] + in + Pipe.write shard.write content + >>| fun () -> + shard + + let heartbeat shard = + let seq = match shard.seq with + | 0 -> `Null + | i -> `Int i + in + let payload = `Assoc [ + ("op", `Int 1); + ("d", seq); + ] in + push_frame ~payload shard HEARTBEAT + + let dispatch shard payload = + let module J = Yojson.Basic.Util in + let seq = J.(member "s" payload |> to_int) in + shard.seq <- seq; + let t = J.(member "t" payload |> to_string) in + let data = J.member "d" payload in + let _ = match t with + | "READY" -> + Ivar.fill_if_empty shard.ready (); + let session = J.(member "session_id" data |> to_string) in + shard.session <- Some session + | "MESSAGE_CREATE" -> + let msg = Model.Message.from_json data in + Pipe.write shard.handler (t, Message msg) >>> ignore + | "GUILD_CREATE" -> + let guild = Model.Guild.from_json data in + Pipe.write shard.handler (t, Guild guild) >>> ignore + | _ -> () + in + return shard + + let set_status shard status = + let payload = match status with + | `Assoc [("name", `String name); ("type", `Int t)] -> + `Assoc [ + ("status", `String "online"); + ("afk", `Bool false); + ("since", `Null); + ("game", `Assoc [ + ("name", `String name); + ("type", `Int t) + ]) + ] + | `String name -> + `Assoc [ + ("status", `String "online"); + ("afk", `Bool false); + ("since", `Null); + ("game", `Assoc [ + ("name", `String name); + ("type", `Int 0) + ]) + ] + | _ -> raise Invalid_Payload + in + Ivar.read shard.ready >>= fun _ -> + push_frame ~payload shard STATUS_UPDATE + + let request_guild_members ~guild ?(query="") ?(limit=0) shard = + let payload = `Assoc [ + ("guild_id", `String (string_of_int guild)); + ("query", `String query); + ("limit", `Int limit); + ] in + Ivar.read shard.ready >>= fun _ -> + push_frame ~payload shard REQUEST_GUILD_MEMBERS + + let initialize shard data = + let module J = Yojson.Basic.Util in + let hb = match shard.hb with + | None -> begin + let hb_interval = J.(member "heartbeat_interval" data |> to_int) in + let finished = Ivar.create () in + Clock.every' + ~continue_on_error:true + ~finished + (Core.Time.Span.create ~ms:hb_interval ()) + (fun () -> heartbeat shard >>= fun _ -> return ()); + finished + end + | Some s -> s + in + shard.hb <- Some hb; + Mutex.lock identify_lock; + let (cur, max) = shard.shard in + let shards = [`Int cur; `Int max] in + match shard.session with + | None -> + let payload = `Assoc [ + ("token", `String shard.token); + ("properties", `Assoc [ + ("$os", `String Sys.os_type); + ("$device", `String "dis.ml"); + ("$browser", `String "dis.ml") + ]); + ("compress", `Bool false); (* TODO add compression handling*) + ("large_threshold", `Int 250); + ("shard", `List shards); + ] in + push_frame ~payload shard IDENTIFY + | Some s -> + let payload = `Assoc [ + ("token", `String shard.token); + ("session_id", `String s); + ("seq", `Int shard.seq) + ] in + push_frame ~payload shard RESUME + >>| fun s -> + Clock.after (Core.Time.Span.create ~sec:5 ()) + >>| (fun _ -> Mutex.unlock identify_lock) + |> ignore; + s + + let handle_frame shard term = + let module J = Yojson.Basic.Util in + let op = J.(member "op" term |> to_int) + |> Opcode.from_int + in + match op with + | DISPATCH -> dispatch shard term + | HEARTBEAT -> heartbeat shard + | RECONNECT -> print_endline "OP 7"; return shard (* TODO reconnect *) + | INVALID_SESSION -> print_endline "OP 9"; return shard (* TODO invalid session *) + | HELLO -> initialize shard @@ J.member "d" term + | HEARTBEAT_ACK -> return shard + | opcode -> + print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode; + return shard + + let create ~url ~shards ~token ~handler () = + let open Core in + let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in + let extra_headers = Http.Base.process_request_headers () in + let host = Option.value_exn ~message:"no host in uri" Uri.(host uri) in + let port = + match Uri.port uri, Uri_services.tcp_port_of_uri uri with + | Some p, _ -> p + | None, Some p -> p + | _ -> 443 in + let scheme = Option.value_exn ~message:"no scheme in uri" Uri.(scheme uri) in + let tcp_fun (r,w) = + let (read, write) = client_ez + ~extra_headers + uri r w + in + let rec ev_loop shard = + Pipe.read read + >>= fun frame -> + handle_frame shard @@ parse frame + >>= fun shard -> + ev_loop shard + in + let shard = { + read; + write; + handler; + ready = Ivar.create (); + hb = None; + seq = 0; + shard = shards; + session = None; + token = token; + } + in + ev_loop shard |> ignore; + return shard + in + match Unix.getaddrinfo host (string_of_int port) [] with + | [] -> failwithf "DNS resolution failed for %s" host () + | { ai_addr; _ } :: _ -> + let addr = + match scheme, ai_addr with + | _, ADDR_UNIX path -> `Unix_domain_socket path + | "https", ADDR_INET (h, p) + | "wss", ADDR_INET (h, p) -> + let h = Ipaddr_unix.of_inet_addr h in + `OpenSSL (h, p, Conduit_async.V2.Ssl.Config.create ()) + | _, ADDR_INET (h, p) -> + let h = Ipaddr_unix.of_inet_addr h in + `TCP (h, p) + in + Conduit_async.V2.connect addr >>= tcp_fun +end + +type t = { + shards: Shard.t list; +} + +let start ?count ~handler token = + let module J = Yojson.Basic.Util in + Http.get_gateway_bot () >>= fun data -> + let url = J.(member "url" data |> to_string) in + let count = match count with + | Some c -> c + | None -> J.(member "shards" data |> to_int) + in + let shard_list = (0, count) in + let rec gen_shards l a = + match l with + | (id, total) when id >= total -> return a + | (id, total) -> + Shard.create ~url ~shards:(id, total) ~token ~handler () + >>= fun shard -> + let a = shard :: a in + gen_shards (id+1, total) a + in + gen_shards shard_list [] + >>| fun shards -> + { + shards; + } + +let set_status sharder status = + Deferred.all @@ List.map ~f:(fun shard -> + Shard.set_status shard status + ) sharder.shards + +let set_status_with sharder f = + Deferred.all @@ List.map ~f:(fun shard -> + Shard.set_status shard @@ f shard + ) sharder.shards + +let request_guild_members ~guild ?query ?limit sharder = + Deferred.all @@ List.map ~f:(fun shard -> + Shard.request_guild_members ~guild ?query ?limit shard + ) sharder.shards -- cgit v1.2.3 From 011e3224c0292dfcb0024daf474d4ef1e00b82f0 Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Sun, 25 Nov 2018 16:02:37 -0700 Subject: A lot is going on... --- lib/channel.ml | 10 ---------- lib/client.ml | 4 ++-- lib/guild.ml | 10 ---------- lib/message.ml | 12 ------------ lib/model.ml | 26 -------------------------- lib/models/attachment.ml | 9 +++++++++ lib/models/channel.ml | 17 +++++++++++++++++ lib/models/embed.ml | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/models/emoji.ml | 9 +++++++++ lib/models/guild.ml | 28 ++++++++++++++++++++++++++++ lib/models/member.ml | 8 ++++++++ lib/models/message.ml | 21 +++++++++++++++++++++ lib/models/reaction.ml | 4 ++++ lib/models/role.ml | 10 ++++++++++ lib/models/snowflake.ml | 16 ++++++++++++++++ lib/models/user.ml | 7 +++++++ lib/s.ml | 4 ---- lib/sharder.ml | 20 +++++--------------- 18 files changed, 180 insertions(+), 79 deletions(-) delete mode 100644 lib/channel.ml delete mode 100644 lib/guild.ml delete mode 100644 lib/message.ml delete mode 100644 lib/model.ml create mode 100644 lib/models/attachment.ml create mode 100644 lib/models/channel.ml create mode 100644 lib/models/embed.ml create mode 100644 lib/models/emoji.ml create mode 100644 lib/models/guild.ml create mode 100644 lib/models/member.ml create mode 100644 lib/models/message.ml create mode 100644 lib/models/reaction.ml create mode 100644 lib/models/role.ml create mode 100644 lib/models/snowflake.ml create mode 100644 lib/models/user.ml delete mode 100644 lib/s.ml (limited to 'lib') diff --git a/lib/channel.ml b/lib/channel.ml deleted file mode 100644 index 904bbde..0000000 --- a/lib/channel.ml +++ /dev/null @@ -1,10 +0,0 @@ -type t = { - id: string; - name: string; -} - -let from_json term = - let module J = Yojson.Basic.Util in - let id = J.(member "id" term |> to_string) in - let name = J.(member "name" term |> to_string) in - { id; name; } diff --git a/lib/client.ml b/lib/client.ml index 7c2d532..374287c 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -2,7 +2,7 @@ open Async type t = { sharder: Sharder.t Ivar.t; - handler: (string * Model.t) Pipe.Writer.t; + handler: string Pipe.Writer.t; token: string; } @@ -14,7 +14,7 @@ let make ~handler token = } let start ?count client = - Sharder.start ?count ~handler:client.handler client.token + Sharder.start ?count client.token >>| fun sharder -> Ivar.fill_if_empty client.sharder sharder; client diff --git a/lib/guild.ml b/lib/guild.ml deleted file mode 100644 index 904bbde..0000000 --- a/lib/guild.ml +++ /dev/null @@ -1,10 +0,0 @@ -type t = { - id: string; - name: string; -} - -let from_json term = - let module J = Yojson.Basic.Util in - let id = J.(member "id" term |> to_string) in - let name = J.(member "name" term |> to_string) in - { id; name; } diff --git a/lib/message.ml b/lib/message.ml deleted file mode 100644 index 5b632d7..0000000 --- a/lib/message.ml +++ /dev/null @@ -1,12 +0,0 @@ -type t = { - id: string; - content: string; - channel: string; -} - -let from_json term = - let module J = Yojson.Basic.Util in - let id = J.(member "id" term |> to_string) in - let content = J.(member "content" term |> to_string) in - let channel = J.(member "channel_id" term |> to_string) in - { id; content; channel; } diff --git a/lib/model.ml b/lib/model.ml deleted file mode 100644 index c44a289..0000000 --- a/lib/model.ml +++ /dev/null @@ -1,26 +0,0 @@ -module Make(M: S.Model) = struct - include M -end - -module Message = Make(Message) -module Guild = Make(Guild) -module Channel = Make(Channel) - -exception Type_Mismatch - -type t = - | Message of Message.t - | Guild of Guild.t - | Channel of Channel.t - -let to_message = function - | Message m -> m - | _ -> raise Type_Mismatch - -let to_guild = function - | Guild m -> m - | _ -> raise Type_Mismatch - -let to_channel = function - | Channel m -> m - | _ -> raise Type_Mismatch \ No newline at end of file diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml new file mode 100644 index 0000000..095743d --- /dev/null +++ b/lib/models/attachment.ml @@ -0,0 +1,9 @@ +type t = { + id: Snowflake.t; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option; +} \ No newline at end of file diff --git a/lib/models/channel.ml b/lib/models/channel.ml new file mode 100644 index 0000000..78051c3 --- /dev/null +++ b/lib/models/channel.ml @@ -0,0 +1,17 @@ +type t = { + id: Snowflake.t; + kind: int; + (* guild: Guild.t option; *) + position: int option; + permission_overwrites: (int list) option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: (User.t list) option; + icon: string option; + owner_id: Snowflake.t option; + application_id: Snowflake.t option; + parent_id: Snowflake.t option; +} \ No newline at end of file diff --git a/lib/models/embed.ml b/lib/models/embed.ml new file mode 100644 index 0000000..6ba1115 --- /dev/null +++ b/lib/models/embed.ml @@ -0,0 +1,44 @@ +type footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option; +} + +type image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option; +} + +type video = { + url: string option; + height: int option; + width: int option; +} + +type provider = { + name: string option; + url: string option; +} + +type field = { + name: string; + value: string; + inline: bool option; +} + +type t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: (field list) option; +} \ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml new file mode 100644 index 0000000..3d89867 --- /dev/null +++ b/lib/models/emoji.ml @@ -0,0 +1,9 @@ +type t = { + id: Snowflake.t; + name: string; + roles: (Role.t list) option; + user: User.t option; + require_colons: bool option; + managed: bool; + animated: bool; +} \ No newline at end of file diff --git a/lib/models/guild.ml b/lib/models/guild.ml new file mode 100644 index 0000000..364a4d5 --- /dev/null +++ b/lib/models/guild.ml @@ -0,0 +1,28 @@ +type t = { + id: Snowflake.t; + name: string; + icon: string; + splash: string; + owner: User.t; + region: string; + afk_channel: Channel.t option; + afk_timeout: int; + embed_enabled: bool; + embed_channel: Channel.t; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: Role.t list; + emojis: Emoji.t list; + features: string list; + mfa_level: int; + application_id: Snowflake.t option; + widget_enabled: bool option; + widget_channel: Channel.t option; + system_channel: Channel.t option; + large: bool; + unavailable: bool; + member_count: int; + members: Member.t list; + channels: Channel.t list; +} \ No newline at end of file diff --git a/lib/models/member.ml b/lib/models/member.ml new file mode 100644 index 0000000..1cbe50b --- /dev/null +++ b/lib/models/member.ml @@ -0,0 +1,8 @@ +type t = { + user: User.t; + nick: string option; + roles: Role.t list; + joined_at: string; + deaf: bool; + mute: bool; +} \ No newline at end of file diff --git a/lib/models/message.ml b/lib/models/message.ml new file mode 100644 index 0000000..6c2e80d --- /dev/null +++ b/lib/models/message.ml @@ -0,0 +1,21 @@ +type t = { + id: Snowflake.t; + author: User.t; + channel: Channel.t; + member: Member.t option; + guild: Guild.t option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: User.t list; + role_mentions: Role.t list; + attachments: Attachment.t list; + embeds: Embed.t list; + reactions: Reaction.t list; + nonce: Snowflake.t option; + pinned: bool; + webhook_id: Snowflake.t; + kind: int; +} \ No newline at end of file diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml new file mode 100644 index 0000000..b427505 --- /dev/null +++ b/lib/models/reaction.ml @@ -0,0 +1,4 @@ +type t = { + count: int; + emoji: Emoji.t; +} \ No newline at end of file diff --git a/lib/models/role.ml b/lib/models/role.ml new file mode 100644 index 0000000..debba60 --- /dev/null +++ b/lib/models/role.ml @@ -0,0 +1,10 @@ +type t = { + id: Snowflake.t; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool; +} \ No newline at end of file diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml new file mode 100644 index 0000000..ed80b62 --- /dev/null +++ b/lib/models/snowflake.ml @@ -0,0 +1,16 @@ +type t = { + id: int; + as_string: string; +} + +let to_int t = t.id +let to_string t = t.as_string + +let from_int i = { + id = i; + as_string = string_of_int i; +} +let from_string s = { + id = int_of_string s; + as_string = s; +} \ No newline at end of file diff --git a/lib/models/user.ml b/lib/models/user.ml new file mode 100644 index 0000000..05cf570 --- /dev/null +++ b/lib/models/user.ml @@ -0,0 +1,7 @@ +type t = { + id: Snowflake.t; + username: string; + discriminator: string; + avatar: string; + bot: bool; +} \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml deleted file mode 100644 index 6c6456a..0000000 --- a/lib/s.ml +++ /dev/null @@ -1,4 +0,0 @@ -module type Model = sig - type t - val from_json : Yojson.Basic.json -> t -end \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml index 9e2ef74..5d665b9 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -9,7 +9,6 @@ module Shard = struct mutable hb: unit Ivar.t option; mutable seq: int; mutable session: string option; - handler: (string * Model.t) Pipe.Writer.t; token: string; shard: int * int; write: string Pipe.Writer.t; @@ -55,19 +54,11 @@ module Shard = struct shard.seq <- seq; let t = J.(member "t" payload |> to_string) in let data = J.member "d" payload in - let _ = match t with - | "READY" -> + if t = "READY" then begin Ivar.fill_if_empty shard.ready (); let session = J.(member "session_id" data |> to_string) in shard.session <- Some session - | "MESSAGE_CREATE" -> - let msg = Model.Message.from_json data in - Pipe.write shard.handler (t, Message msg) >>> ignore - | "GUILD_CREATE" -> - let guild = Model.Guild.from_json data in - Pipe.write shard.handler (t, Guild guild) >>> ignore - | _ -> () - in + end; return shard let set_status shard status = @@ -168,7 +159,7 @@ module Shard = struct print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode; return shard - let create ~url ~shards ~token ~handler () = + let create ~url ~shards ~token () = let open Core in let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in let extra_headers = Http.Base.process_request_headers () in @@ -194,7 +185,6 @@ module Shard = struct let shard = { read; write; - handler; ready = Ivar.create (); hb = None; seq = 0; @@ -227,7 +217,7 @@ type t = { shards: Shard.t list; } -let start ?count ~handler token = +let start ?count token = let module J = Yojson.Basic.Util in Http.get_gateway_bot () >>= fun data -> let url = J.(member "url" data |> to_string) in @@ -240,7 +230,7 @@ let start ?count ~handler token = match l with | (id, total) when id >= total -> return a | (id, total) -> - Shard.create ~url ~shards:(id, total) ~token ~handler () + Shard.create ~url ~shards:(id, total) ~token () >>= fun shard -> let a = shard :: a in gen_shards (id+1, total) a -- cgit v1.2.3 From 048fe6388e84eaccb3440fe0d0c7101b3877701d Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Sun, 25 Nov 2018 16:13:59 -0700 Subject: Naming consistency --- lib/client.ml | 6 +++--- lib/sharder.ml | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index 374287c..e88b1d5 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -6,7 +6,7 @@ type t = { token: string; } -let make ~handler token = +let create ~handler token = { sharder = Ivar.create (); handler; @@ -19,12 +19,12 @@ let start ?count client = Ivar.fill_if_empty client.sharder sharder; client -let set_status client status = +let set_status ~status client = Ivar.read client.sharder >>= fun sharder -> Sharder.set_status sharder status -let set_status_with client f = +let set_status_with ~f client = Ivar.read client.sharder >>= fun sharder -> Sharder.set_status_with sharder f diff --git a/lib/sharder.ml b/lib/sharder.ml index 5d665b9..ccfb047 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -23,7 +23,7 @@ module Shard = struct | `Ok s -> Yojson.Basic.from_string s | `Eof -> raise Invalid_Payload (* This needs to go into reconnect code, or stop using client_ez and handle frames manually *) - let push_frame ?payload shard ev = + let push_frame ?payload ~ev shard = print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; let content = match payload with | None -> "" @@ -46,9 +46,9 @@ module Shard = struct ("op", `Int 1); ("d", seq); ] in - push_frame ~payload shard HEARTBEAT + push_frame ~payload ~ev:HEARTBEAT shard - let dispatch shard payload = + let dispatch ~payload shard = let module J = Yojson.Basic.Util in let seq = J.(member "s" payload |> to_int) in shard.seq <- seq; @@ -61,7 +61,7 @@ module Shard = struct end; return shard - let set_status shard status = + let set_status ~status shard = let payload = match status with | `Assoc [("name", `String name); ("type", `Int t)] -> `Assoc [ @@ -86,7 +86,7 @@ module Shard = struct | _ -> raise Invalid_Payload in Ivar.read shard.ready >>= fun _ -> - push_frame ~payload shard STATUS_UPDATE + push_frame ~payload ~ev:STATUS_UPDATE shard let request_guild_members ~guild ?(query="") ?(limit=0) shard = let payload = `Assoc [ @@ -95,9 +95,9 @@ module Shard = struct ("limit", `Int limit); ] in Ivar.read shard.ready >>= fun _ -> - push_frame ~payload shard REQUEST_GUILD_MEMBERS + push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard - let initialize shard data = + let initialize ~data shard = let module J = Yojson.Basic.Util in let hb = match shard.hb with | None -> begin @@ -129,31 +129,31 @@ module Shard = struct ("large_threshold", `Int 250); ("shard", `List shards); ] in - push_frame ~payload shard IDENTIFY + push_frame ~payload ~ev:IDENTIFY shard | Some s -> let payload = `Assoc [ ("token", `String shard.token); ("session_id", `String s); ("seq", `Int shard.seq) ] in - push_frame ~payload shard RESUME + push_frame ~payload ~ev:RESUME shard >>| fun s -> Clock.after (Core.Time.Span.create ~sec:5 ()) >>| (fun _ -> Mutex.unlock identify_lock) |> ignore; s - let handle_frame shard term = + let handle_frame ~f shard = let module J = Yojson.Basic.Util in - let op = J.(member "op" term |> to_int) + let op = J.(member "op" f |> to_int) |> Opcode.from_int in match op with - | DISPATCH -> dispatch shard term + | DISPATCH -> dispatch ~payload:f shard | HEARTBEAT -> heartbeat shard | RECONNECT -> print_endline "OP 7"; return shard (* TODO reconnect *) | INVALID_SESSION -> print_endline "OP 9"; return shard (* TODO invalid session *) - | HELLO -> initialize shard @@ J.member "d" term + | HELLO -> initialize ~data:(J.member "d" f) shard | HEARTBEAT_ACK -> return shard | opcode -> print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode; @@ -178,7 +178,7 @@ module Shard = struct let rec ev_loop shard = Pipe.read read >>= fun frame -> - handle_frame shard @@ parse frame + handle_frame ~f:(parse frame) shard >>= fun shard -> ev_loop shard in @@ -243,12 +243,12 @@ let start ?count token = let set_status sharder status = Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status shard status + Shard.set_status ~status shard ) sharder.shards let set_status_with sharder f = Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status shard @@ f shard + Shard.set_status ~status:(f shard) shard ) sharder.shards let request_guild_members ~guild ?query ?limit sharder = -- cgit v1.2.3 From ad8a13b186683cb1e6c5ef405df503f58b751ffa Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Sun, 25 Nov 2018 18:51:44 -0700 Subject: convert to client from client_ez --- lib/_sharder.mli | 138 ------------------------------------------------------- lib/sharder.ml | 41 ++++++++++------- 2 files changed, 25 insertions(+), 154 deletions(-) delete mode 100644 lib/_sharder.mli (limited to 'lib') diff --git a/lib/_sharder.mli b/lib/_sharder.mli deleted file mode 100644 index 0fd16d6..0000000 --- a/lib/_sharder.mli +++ /dev/null @@ -1,138 +0,0 @@ -open Async - -(** -Record type for registering event handlers -*) -type handler = { - ready: (Yojson.Basic.json -> unit) option; - resumed: (Yojson.Basic.json -> unit) option; - channel_create: (Yojson.Basic.json -> unit) option; - channel_delete: (Yojson.Basic.json -> unit) option; - channel_update: (Yojson.Basic.json -> unit) option; - channel_pins_update: (Yojson.Basic.json -> unit) option; - guild_create: (Yojson.Basic.json -> unit) option; - guild_delete: (Yojson.Basic.json -> unit) option; - guild_update: (Yojson.Basic.json -> unit) option; - guild_ban_add: (Yojson.Basic.json -> unit) option; - guild_ban_remove: (Yojson.Basic.json -> unit) option; - guild_emojis_update: (Yojson.Basic.json -> unit) option; - guild_integrations_update: (Yojson.Basic.json -> unit) option; - guild_member_add: (Yojson.Basic.json -> unit) option; - guild_member_remove: (Yojson.Basic.json -> unit) option; - guild_member_update: (Yojson.Basic.json -> unit) option; - guild_members_chunk: (Yojson.Basic.json -> unit) option; - guild_role_create: (Yojson.Basic.json -> unit) option; - guild_role_delete: (Yojson.Basic.json -> unit) option; - guild_role_update: (Yojson.Basic.json -> unit) option; - message_create: (Yojson.Basic.json -> unit) option; - message_delete: (Yojson.Basic.json -> unit) option; - message_update: (Yojson.Basic.json -> unit) option; - message_delete_bulk: (Yojson.Basic.json -> unit) option; - message_reaction_add: (Yojson.Basic.json -> unit) option; - message_reaction_remove: (Yojson.Basic.json -> unit) option; - message_reaction_remove_all: (Yojson.Basic.json -> unit) option; - presence_update: (Yojson.Basic.json -> unit) option; - typing_start: (Yojson.Basic.json -> unit) option; - user_update: (Yojson.Basic.json -> unit) option; - voice_state_update: (Yojson.Basic.json -> unit) option; - voice_server_update: (Yojson.Basic.json -> unit) option; - webhooks_update: (Yojson.Basic.json -> unit) option; -} - -(** -Represents a single Shard. Manual creation is discouraged; use Sharder.start instead -*) -module Shard : sig - type t = { - mutable hb: unit Ivar.t option; - mutable seq: int; - mutable session: string option; - mutable handler: handler; - token: string; - shard: int * int; - write: string Pipe.Writer.t; - read: string Pipe.Reader.t; - ready: unit Ivar.t; - } - - val parse : - [< `Ok of string | `Eof] -> - Yojson.Basic.json - - val push_frame : - ?payload:Yojson.Basic.json -> - t -> - Opcode.t -> - t Deferred.t - - val heartbeat : - t -> - t Deferred.t - - val dispatch : - t -> - Yojson.Basic.json -> - t Deferred.t - - val set_status : - t -> - Yojson.Basic.json -> - t Deferred.t - - val request_guild_members : - guild:int -> - ?query:string -> - ?limit:int -> - t -> - t Deferred.t - - val initialize : - t -> - Yojson.Basic.json -> - t Deferred.t - - val handle_frame : - t -> - Yojson.Basic.json -> - t Deferred.t - - val create : - url:string -> - shards:int * int -> - token:string -> - handler: handler -> - unit -> - t Deferred.t -end - -type t = { - shards: Shard.t list; -} - -val start : - ?count:int -> - handler:handler -> - string -> - t Deferred.t - -val set_status : - t -> - Yojson.Basic.json -> - Shard.t list Deferred.t - -val set_status_with : - t -> - (Shard.t -> Yojson.Basic.json) -> - Shard.t list Deferred.t - -val request_guild_members : - guild:int -> - ?query:string -> - ?limit:int -> - t -> - Shard.t list Deferred.t - -val update_handler : - t -> - handler -> - unit \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml index ccfb047..defcfe1 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -11,17 +11,17 @@ module Shard = struct mutable session: string option; token: string; shard: int * int; - write: string Pipe.Writer.t; - read: string Pipe.Reader.t; + write: Frame.t Pipe.Writer.t; + read: Frame.t Pipe.Reader.t; ready: unit Ivar.t; } let identify_lock = Mutex.create () - let parse frame = + let parse (frame:[`Ok of Frame.t | `Eof]) = match frame with - | `Ok s -> Yojson.Basic.from_string s - | `Eof -> raise Invalid_Payload (* This needs to go into reconnect code, or stop using client_ez and handle frames manually *) + | `Ok s -> Yojson.Basic.from_string s.content (* TODO Handler non-text frames *) + | `Eof -> raise Invalid_Payload (* TODO This needs to go into reconnect code, or stop using client_ez and handle frames manually *) let push_frame ?payload ~ev shard = print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; @@ -33,7 +33,7 @@ module Shard = struct ("d", p); ] in - Pipe.write shard.write content + Pipe.write shard.write @@ Frame.create ~content () >>| fun () -> shard @@ -156,7 +156,7 @@ module Shard = struct | HELLO -> initialize ~data:(J.member "d" f) shard | HEARTBEAT_ACK -> return shard | opcode -> - print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode; + print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; return shard let create ~url ~shards ~token () = @@ -170,17 +170,26 @@ module Shard = struct | None, Some p -> p | _ -> 443 in let scheme = Option.value_exn ~message:"no scheme in uri" Uri.(scheme uri) in - let tcp_fun (r,w) = - let (read, write) = client_ez + let tcp_fun (net_to_ws, ws_to_net) = + let (app_to_ws, write) = Pipe.create () in + let (read, ws_to_app) = Pipe.create () in + let initialized = Ivar.create () in + client + ~initialized ~extra_headers - uri r w - in - let rec ev_loop shard = - Pipe.read read + ~app_to_ws + ~ws_to_app + ~net_to_ws + ~ws_to_net + uri + >>> ignore; + Ivar.read initialized >>| fun () -> + let rec ev_loop ~reader shard = + Pipe.read reader >>= fun frame -> handle_frame ~f:(parse frame) shard >>= fun shard -> - ev_loop shard + ev_loop ~reader shard in let shard = { read; @@ -193,8 +202,8 @@ module Shard = struct token = token; } in - ev_loop shard |> ignore; - return shard + ev_loop ~reader:read shard |> ignore; + shard in match Unix.getaddrinfo host (string_of_int port) [] with | [] -> failwithf "DNS resolution failed for %s" host () -- cgit v1.2.3 From ffd7237f62ff8b286a05c9256ab90c92770241a9 Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Sun, 25 Nov 2018 20:30:11 -0700 Subject: More models, some dispatch rework starting --- lib/dispatch.ml | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/event.ml | 113 +++++++++++++++++++++++++++++++++++++++++++++++ lib/models/activity.ml | 1 + lib/models/ban.ml | 4 ++ lib/models/presence.ml | 8 ++++ 5 files changed, 242 insertions(+) create mode 100644 lib/dispatch.ml create mode 100644 lib/event.ml create mode 100644 lib/models/activity.ml create mode 100644 lib/models/ban.ml create mode 100644 lib/models/presence.ml (limited to 'lib') diff --git a/lib/dispatch.ml b/lib/dispatch.ml new file mode 100644 index 0000000..c6d717b --- /dev/null +++ b/lib/dispatch.ml @@ -0,0 +1,116 @@ +open Async + +type t = { + hello: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + ready: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + resumed: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + invalid_session: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + channel_create: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; + channel_update: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; + channel_delete: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; + channel_pins_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + guild_create: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; + guild_update: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; + guild_delete: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; + guild_ban_add: Ban.t Pipe.Reader.t * Ban.t Pipe.Writer.t; + guild_ban_remove: Ban.t Pipe.Reader.t * Ban.t Pipe.Writer.t; + guild_emojis_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + guild_integrations_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + guild_member_add: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; + guild_member_remove: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; + guild_member_update: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; + guild_members_chunk: (Member.t list) Pipe.Reader.t * (Member.t list) Pipe.Writer.t; + guild_role_create: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; + guild_role_update: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; + guild_role_delete: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; + message_create: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; + message_update: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; + message_delete: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; + message_bulk_delete: (Message.t list) Pipe.Reader.t * (Message.t list) Pipe.Writer.t; + message_reaction_add: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; + message_reaction_remove: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; + message_reaction_remove_all: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; + presence_update: Presence.t Pipe.Reader.t * Presence.t Pipe.Writer.t; + typing_start: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + user_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + voice_state_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + voice_server_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; + webhooks_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; +} + +let dispatcher = + { + hello = Pipe.create (); + ready = Pipe.create (); + resumed = Pipe.create (); + invalid_session = Pipe.create (); + channel_create = Pipe.create (); + channel_update = Pipe.create (); + channel_delete = Pipe.create (); + channel_pins_update = Pipe.create (); + guild_create = Pipe.create (); + guild_update = Pipe.create (); + guild_delete = Pipe.create (); + guild_ban_add = Pipe.create (); + guild_ban_remove = Pipe.create (); + guild_emojis_update = Pipe.create (); + guild_integrations_update = Pipe.create (); + guild_member_add = Pipe.create (); + guild_member_remove = Pipe.create (); + guild_member_update = Pipe.create (); + guild_members_chunk = Pipe.create (); + guild_role_create = Pipe.create (); + guild_role_update = Pipe.create (); + guild_role_delete = Pipe.create (); + message_create = Pipe.create (); + message_update = Pipe.create (); + message_delete = Pipe.create (); + message_bulk_delete = Pipe.create (); + message_reaction_add = Pipe.create (); + message_reaction_remove = Pipe.create (); + message_reaction_remove_all = Pipe.create (); + presence_update = Pipe.create (); + typing_start = Pipe.create (); + user_update = Pipe.create (); + voice_state_update = Pipe.create (); + voice_server_update = Pipe.create (); + webhooks_update = Pipe.create (); + } + +(* let write (ev:Event.t) = + let (read, _) = match ev with + | HELLO -> dispatcher.hello + | READY -> dispatcher.ready + | RESUMED -> dispatcher.resumed + | INVALID_SESSION -> dispatcher.invalid_session + | CHANNEL_CREATE -> dispatcher.channel_create + | CHANNEL_UPDATE -> dispatcher.channel_update + | CHANNEL_DELETE -> dispatcher.channel_delete + | CHANNEL_PINS_UPDATE -> dispatcher.channel_pins_update + | GUILD_CREATE -> dispatcher.guild_create + | GUILD_UPDATE -> dispatcher.guild_update + | GUILD_DELETE -> dispatcher.guild_delete + | GUILD_BAN_ADD -> dispatcher.guild_ban_add + | GUILD_BAN_REMOVE -> dispatcher.guild_ban_remove + | GUILD_EMOJIS_UPDATE -> dispatcher.guild_emojis_update + | GUILD_INTEGRATIONS_UPDATE -> dispatcher.guild_integrations_update + | GUILD_MEMBER_ADD -> dispatcher.guild_member_ad + | GUILD_MEMBER_REMOVE -> dispatcher.guild_member_remove + | GUILD_MEMBER_UPDATE -> dispatcher.guild_member_update + | GUILD_MEMBERS_CHUNK -> dispatcher.guild_members_chunk + | GUILD_ROLE_CREATE -> dispatcher.guild_role_create + | GUILD_ROLE_UPDATE -> dispatcher.guild_role_updatE + | GUILD_ROLE_DELETE -> dispatcher.guild_role_delete + | MESSAGE_CREATE -> dispatcher.message_create + | MESSAGE_UPDATE -> dispatcher.message_update + | MESSAGE_DELETE -> dispatcher.message_delete + | MESSAGE_BULK_DELETE -> dispatcher.message_bulk_delete + | MESSAGE_REACTION_ADD -> dispatcher.message_reaction_add + | MESSAGE_REACTION_REMOVE -> dispatcher.message_reaction_remove + | MESSAGE_REACTION_REMOVE_ALL -> dispatcher.message_reaction_remove_all + | PRESENCE_UPDATE -> dispatcher.presence_update + | TYPING_START -> dispatcher.typing_start + | USER_UPDATE -> dispatcher.user_update + | VOICE_STATE_UPDATE -> dispatcher.voice_state_update + | VOICE_SERVER_UPDATE -> dispatcher.voice_server_update + | WEBHOOKS_UPDATE -> dispatcher.webhooks_update *) \ No newline at end of file diff --git a/lib/event.ml b/lib/event.ml new file mode 100644 index 0000000..8b5b125 --- /dev/null +++ b/lib/event.ml @@ -0,0 +1,113 @@ +type t = +| HELLO +| READY +| RESUMED +| INVALID_SESSION +| CHANNEL_CREATE +| CHANNEL_UPDATE +| CHANNEL_DELETE +| CHANNEL_PINS_UPDATE +| GUILD_CREATE +| GUILD_UPDATE +| GUILD_DELETE +| GUILD_BAN_ADD +| GUILD_BAN_REMOVE +| GUILD_EMOJIS_UPDATE +| GUILD_INTEGRATIONS_UPDATE +| GUILD_MEMBER_ADD +| GUILD_MEMBER_REMOVE +| GUILD_MEMBER_UPDATE +| GUILD_MEMBERS_CHUNK +| GUILD_ROLE_CREATE +| GUILD_ROLE_UPDATE +| GUILD_ROLE_DELETE +| MESSAGE_CREATE +| MESSAGE_UPDATE +| MESSAGE_DELETE +| MESSAGE_BULK_DELETE +| MESSAGE_REACTION_ADD +| MESSAGE_REACTION_REMOVE +| MESSAGE_REACTION_REMOVE_ALL +| PRESENCE_UPDATE +| TYPING_START +| USER_UPDATE +| VOICE_STATE_UPDATE +| VOICE_SERVER_UPDATE +| WEBHOOKS_UPDATE + +exception Invalid_Event of string + +let from_string = function + | "HELLO" -> HELLO + | "READY" -> READY + | "RESUMED" -> RESUMED + | "INVALID_SESSION" -> INVALID_SESSION + | "CHANNEL_CREATE" -> CHANNEL_CREATE + | "CHANNEL_UPDATE" -> CHANNEL_UPDATE + | "CHANNEL_DELETE" -> CHANNEL_DELETE + | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE + | "GUILD_CREATE" -> GUILD_CREATE + | "GUILD_UPDATE" -> GUILD_UPDATE + | "GUILD_DELETE" -> GUILD_DELETE + | "GUILD_BAN_ADD" -> GUILD_BAN_ADD + | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE + | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE + | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE + | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD + | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE + | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE + | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK + | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE + | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE + | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE + | "MESSAGE_CREATE" -> MESSAGE_CREATE + | "MESSAGE_UPDATE" -> MESSAGE_UPDATE + | "MESSAGE_DELETE" -> MESSAGE_DELETE + | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE + | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD + | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE + | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL + | "PRESENCE_UPDATE" -> PRESENCE_UPDATE + | "TYPING_START" -> TYPING_START + | "USER_UPDATE" -> USER_UPDATE + | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE + | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE + | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE + | ev -> raise (Invalid_Event ev) + +let to_string = function + | HELLO -> "HELLO" + | READY -> "READY" + | RESUMED -> "RESUMED" + | INVALID_SESSION -> "INVALID_SESSION" + | CHANNEL_CREATE -> "CHANNEL_CREATE" + | CHANNEL_UPDATE -> "CHANNEL_UPDATE" + | CHANNEL_DELETE -> "CHANNEL_DELETE" + | CHANNEL_PINS_UPDATE -> "CHANNEL_PINS_UPDATE" + | GUILD_CREATE -> "GUILD_CREATE" + | GUILD_UPDATE -> "GUILD_UPDATE" + | GUILD_DELETE -> "GUILD_DELETE" + | GUILD_BAN_ADD -> "GUILD_BAN_ADD" + | GUILD_BAN_REMOVE -> "GUILD_BAN_REMOVE" + | GUILD_EMOJIS_UPDATE -> "GUILD_EMOJIS_UPDATE" + | GUILD_INTEGRATIONS_UPDATE -> "GUILD_INTEGRATIONS_UPDATE" + | GUILD_MEMBER_ADD -> "GUILD_MEMBER_ADD" + | GUILD_MEMBER_REMOVE -> "GUILD_MEMBER_REMOVE" + | GUILD_MEMBER_UPDATE -> "GUILD_MEMBER_UPDATE" + | GUILD_MEMBERS_CHUNK -> "GUILD_MEMBERS_CHUNK" + | GUILD_ROLE_CREATE -> "GUILD_ROLE_CREATE" + | GUILD_ROLE_UPDATE -> "GUILD_ROLE_UPDATE" + | GUILD_ROLE_DELETE -> "GUILD_ROLE_DELETE" + | MESSAGE_CREATE -> "MESSAGE_CREATE" + | MESSAGE_UPDATE -> "MESSAGE_UPDATE" + | MESSAGE_DELETE -> "MESSAGE_DELETE" + | MESSAGE_BULK_DELETE -> "MESSAGE_BULK_DELETE" + | MESSAGE_REACTION_ADD -> "MESSAGE_REACTION_ADD" + | MESSAGE_REACTION_REMOVE -> "MESSAGE_REACTION_REMOVE" + | MESSAGE_REACTION_REMOVE_ALL -> "MESSAGE_REACTION_REMOVE_ALL" + | PRESENCE_UPDATE -> "PRESENCE_UPDATE" + | TYPING_START -> "TYPING_START" + | USER_UPDATE -> "USER_UPDATE" + | VOICE_STATE_UPDATE -> "VOICE_STATE_UPDATE" + | VOICE_SERVER_UPDATE -> "VOICE_SERVER_UPDATE" + | WEBHOOKS_UPDATE -> "WEBHOOKS_UPDATE" \ No newline at end of file diff --git a/lib/models/activity.ml b/lib/models/activity.ml new file mode 100644 index 0000000..eb6679e --- /dev/null +++ b/lib/models/activity.ml @@ -0,0 +1 @@ +type t \ No newline at end of file diff --git a/lib/models/ban.ml b/lib/models/ban.ml new file mode 100644 index 0000000..510c2f5 --- /dev/null +++ b/lib/models/ban.ml @@ -0,0 +1,4 @@ +type t = { + id: Snowflake.t; + user: User.t; +} \ No newline at end of file diff --git a/lib/models/presence.ml b/lib/models/presence.ml new file mode 100644 index 0000000..7243f43 --- /dev/null +++ b/lib/models/presence.ml @@ -0,0 +1,8 @@ +type t = { + user: User.t; + roles: Role.t list; + game: Activity.t option; + guild: Guild.t; + status: string; + activities: Activity.t list; +} \ No newline at end of file -- cgit v1.2.3 From 77f522a5f3fd74749e7a2cd4c849e520f2b6ba89 Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Thu, 29 Nov 2018 06:16:23 -0700 Subject: Some sharding work, reconnect is mostly working --- lib/dispatch.ml | 152 +++++++++++++--------------------------------------- lib/sharder.ml | 161 ++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 136 insertions(+), 177 deletions(-) (limited to 'lib') diff --git a/lib/dispatch.ml b/lib/dispatch.ml index c6d717b..43ffe1f 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -1,116 +1,38 @@ -open Async +(* open Async *) -type t = { - hello: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - ready: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - resumed: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - invalid_session: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - channel_create: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; - channel_update: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; - channel_delete: Channel.t Pipe.Reader.t * Channel.t Pipe.Writer.t; - channel_pins_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - guild_create: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; - guild_update: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; - guild_delete: Guild.t Pipe.Reader.t * Guild.t Pipe.Writer.t; - guild_ban_add: Ban.t Pipe.Reader.t * Ban.t Pipe.Writer.t; - guild_ban_remove: Ban.t Pipe.Reader.t * Ban.t Pipe.Writer.t; - guild_emojis_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - guild_integrations_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - guild_member_add: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; - guild_member_remove: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; - guild_member_update: Member.t Pipe.Reader.t * Member.t Pipe.Writer.t; - guild_members_chunk: (Member.t list) Pipe.Reader.t * (Member.t list) Pipe.Writer.t; - guild_role_create: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; - guild_role_update: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; - guild_role_delete: (Role.t * Guild.t) Pipe.Reader.t * (Role.t * Guild.t) Pipe.Writer.t; - message_create: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; - message_update: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; - message_delete: Message.t Pipe.Reader.t * Message.t Pipe.Writer.t; - message_bulk_delete: (Message.t list) Pipe.Reader.t * (Message.t list) Pipe.Writer.t; - message_reaction_add: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; - message_reaction_remove: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; - message_reaction_remove_all: (Message.t * Reaction.t) Pipe.Reader.t * (Message.t * Reaction.t) Pipe.Writer.t; - presence_update: Presence.t Pipe.Reader.t * Presence.t Pipe.Writer.t; - typing_start: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - user_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - voice_state_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - voice_server_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; - webhooks_update: Yojson.Basic.json Pipe.Reader.t * Yojson.Basic.json Pipe.Writer.t; -} - -let dispatcher = - { - hello = Pipe.create (); - ready = Pipe.create (); - resumed = Pipe.create (); - invalid_session = Pipe.create (); - channel_create = Pipe.create (); - channel_update = Pipe.create (); - channel_delete = Pipe.create (); - channel_pins_update = Pipe.create (); - guild_create = Pipe.create (); - guild_update = Pipe.create (); - guild_delete = Pipe.create (); - guild_ban_add = Pipe.create (); - guild_ban_remove = Pipe.create (); - guild_emojis_update = Pipe.create (); - guild_integrations_update = Pipe.create (); - guild_member_add = Pipe.create (); - guild_member_remove = Pipe.create (); - guild_member_update = Pipe.create (); - guild_members_chunk = Pipe.create (); - guild_role_create = Pipe.create (); - guild_role_update = Pipe.create (); - guild_role_delete = Pipe.create (); - message_create = Pipe.create (); - message_update = Pipe.create (); - message_delete = Pipe.create (); - message_bulk_delete = Pipe.create (); - message_reaction_add = Pipe.create (); - message_reaction_remove = Pipe.create (); - message_reaction_remove_all = Pipe.create (); - presence_update = Pipe.create (); - typing_start = Pipe.create (); - user_update = Pipe.create (); - voice_state_update = Pipe.create (); - voice_server_update = Pipe.create (); - webhooks_update = Pipe.create (); - } - -(* let write (ev:Event.t) = - let (read, _) = match ev with - | HELLO -> dispatcher.hello - | READY -> dispatcher.ready - | RESUMED -> dispatcher.resumed - | INVALID_SESSION -> dispatcher.invalid_session - | CHANNEL_CREATE -> dispatcher.channel_create - | CHANNEL_UPDATE -> dispatcher.channel_update - | CHANNEL_DELETE -> dispatcher.channel_delete - | CHANNEL_PINS_UPDATE -> dispatcher.channel_pins_update - | GUILD_CREATE -> dispatcher.guild_create - | GUILD_UPDATE -> dispatcher.guild_update - | GUILD_DELETE -> dispatcher.guild_delete - | GUILD_BAN_ADD -> dispatcher.guild_ban_add - | GUILD_BAN_REMOVE -> dispatcher.guild_ban_remove - | GUILD_EMOJIS_UPDATE -> dispatcher.guild_emojis_update - | GUILD_INTEGRATIONS_UPDATE -> dispatcher.guild_integrations_update - | GUILD_MEMBER_ADD -> dispatcher.guild_member_ad - | GUILD_MEMBER_REMOVE -> dispatcher.guild_member_remove - | GUILD_MEMBER_UPDATE -> dispatcher.guild_member_update - | GUILD_MEMBERS_CHUNK -> dispatcher.guild_members_chunk - | GUILD_ROLE_CREATE -> dispatcher.guild_role_create - | GUILD_ROLE_UPDATE -> dispatcher.guild_role_updatE - | GUILD_ROLE_DELETE -> dispatcher.guild_role_delete - | MESSAGE_CREATE -> dispatcher.message_create - | MESSAGE_UPDATE -> dispatcher.message_update - | MESSAGE_DELETE -> dispatcher.message_delete - | MESSAGE_BULK_DELETE -> dispatcher.message_bulk_delete - | MESSAGE_REACTION_ADD -> dispatcher.message_reaction_add - | MESSAGE_REACTION_REMOVE -> dispatcher.message_reaction_remove - | MESSAGE_REACTION_REMOVE_ALL -> dispatcher.message_reaction_remove_all - | PRESENCE_UPDATE -> dispatcher.presence_update - | TYPING_START -> dispatcher.typing_start - | USER_UPDATE -> dispatcher.user_update - | VOICE_STATE_UPDATE -> dispatcher.voice_state_update - | VOICE_SERVER_UPDATE -> dispatcher.voice_server_update - | WEBHOOKS_UPDATE -> dispatcher.webhooks_update *) \ No newline at end of file +type dispatch_event = +| HELLO of Yojson.Basic.json +| READY of Yojson.Basic.json +| RESUMED of Yojson.Basic.json +| INVALID_SESSION of Yojson.Basic.json +| CHANNEL_CREATE of Channel.t +| CHANNEL_UPDATE of Channel.t +| CHANNEL_DELETE of Channel.t +| CHANNEL_PINS_UPDATE of Yojson.Basic.json +| GUILD_CREATE of Guild.t +| GUILD_UPDATE of Guild.t +| GUILD_DELETE of Guild.t +| GUILD_BAN_ADD of Ban.t +| GUILD_BAN_REMOVE of Ban.t +| GUILD_EMOJIS_UPDATE of Yojson.Basic.json +| GUILD_INTEGRATIONS_UPDATE of Yojson.Basic.json +| GUILD_MEMBER_ADD of Member.t +| GUILD_MEMBER_REMOVE of Member.t +| GUILD_MEMBER_UPDATE of Member.t +| GUILD_MEMBERS_CHUNK of Member.t list +| GUILD_ROLE_CREATE of Role.t * Guild.t +| GUILD_ROLE_UPDATE of Role.t * Guild.t +| GUILD_ROLE_DELETE of Role.t * Guild.t +| MESSAGE_CREATE of Message.t +| MESSAGE_UPDATE of Message.t +| MESSAGE_DELETE of Message.t +| MESSAGE_BULK_DELETE of Message.t list +| MESSAGE_REACTION_ADD of Message.t * Reaction.t +| MESSAGE_REACTION_REMOVE of Message.t * Reaction.t +| MESSAGE_REACTION_REMOVE_ALL of Message.t * Reaction.t list +| PRESENCE_UPDATE of Presence.t +| TYPING_START of Yojson.Basic.json +| USER_UPDATE of Yojson.Basic.json +| VOICE_STATE_UPDATE of Yojson.Basic.json +| VOICE_SERVER_UPDATE of Yojson.Basic.json +| WEBHOOKS_UPDATE of Yojson.Basic.json diff --git a/lib/sharder.ml b/lib/sharder.ml index defcfe1..74870bd 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -3,25 +3,39 @@ open Core open Websocket_async exception Invalid_Payload +exception Failure_to_Establish_Heartbeat module Shard = struct - type t = { - mutable hb: unit Ivar.t option; - mutable seq: int; - mutable session: string option; - token: string; - shard: int * int; - write: Frame.t Pipe.Writer.t; - read: Frame.t Pipe.Reader.t; + type shard = { + hb: unit Ivar.t option; + seq: int; + session: string option; + pipe: Frame.t Pipe.Reader.t * Frame.t Pipe.Writer.t; ready: unit Ivar.t; + token: string; + url: string; + id: int * int; + } + + type 'a t = { + mutable shard: 'a; + mutable binds: ('a -> unit) list; } let identify_lock = Mutex.create () + let bind ~f t = + t.binds <- f :: t.binds + let parse (frame:[`Ok of Frame.t | `Eof]) = match frame with - | `Ok s -> Yojson.Basic.from_string s.content (* TODO Handler non-text frames *) - | `Eof -> raise Invalid_Payload (* TODO This needs to go into reconnect code, or stop using client_ez and handle frames manually *) + | `Ok s -> begin + let open Frame.Opcode in + match s.opcode with + | Text -> Some (Yojson.Basic.from_string s.content) + | _ -> None + end + | `Eof -> None let push_frame ?payload ~ev shard = print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; @@ -33,33 +47,31 @@ module Shard = struct ("d", p); ] in - Pipe.write shard.write @@ Frame.create ~content () + let (_, write) = shard.pipe in + Pipe.write_if_open write @@ Frame.create ~content () >>| fun () -> shard let heartbeat shard = - let seq = match shard.seq with + let payload = match shard.seq with | 0 -> `Null | i -> `Int i in - let payload = `Assoc [ - ("op", `Int 1); - ("d", seq); - ] in push_frame ~payload ~ev:HEARTBEAT shard let dispatch ~payload shard = let module J = Yojson.Basic.Util in let seq = J.(member "s" payload |> to_int) in - shard.seq <- seq; let t = J.(member "t" payload |> to_string) in let data = J.member "d" payload in + let session = J.(member "session_id" data |> to_string_option) in if t = "READY" then begin Ivar.fill_if_empty shard.ready (); - let session = J.(member "session_id" data |> to_string) in - shard.session <- Some session end; - return shard + return { shard with + seq = seq; + session = session; + } let set_status ~status shard = let payload = match status with @@ -97,27 +109,30 @@ module Shard = struct Ivar.read shard.ready >>= fun _ -> push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard - let initialize ~data shard = + let initialize ?data shard = let module J = Yojson.Basic.Util in let hb = match shard.hb with | None -> begin - let hb_interval = J.(member "heartbeat_interval" data |> to_int) in - let finished = Ivar.create () in - Clock.every' - ~continue_on_error:true - ~finished - (Core.Time.Span.create ~ms:hb_interval ()) - (fun () -> heartbeat shard >>= fun _ -> return ()); - finished + match data with + | Some data -> + let hb_interval = J.(member "heartbeat_interval" data |> to_int) in + let finished = Ivar.create () in + Clock.every' + ~continue_on_error:true + ~finished + (Core.Time.Span.create ~ms:hb_interval ()) + (fun () -> heartbeat shard >>= fun _ -> return ()); + finished + | None -> raise Failure_to_Establish_Heartbeat end | Some s -> s in - shard.hb <- Some hb; - Mutex.lock identify_lock; - let (cur, max) = shard.shard in + let shard = { shard with hb = Some hb; } in + let (cur, max) = shard.id in let shards = [`Int cur; `Int max] in match shard.session with - | None -> + | None -> begin + Mutex.lock identify_lock; let payload = `Assoc [ ("token", `String shard.token); ("properties", `Assoc [ @@ -130,6 +145,12 @@ module Shard = struct ("shard", `List shards); ] in push_frame ~payload ~ev:IDENTIFY shard + >>| fun s -> begin + Clock.after (Core.Time.Span.create ~sec:5 ()) + >>> (fun _ -> Mutex.unlock identify_lock); + s + end + end | Some s -> let payload = `Assoc [ ("token", `String shard.token); @@ -137,11 +158,6 @@ module Shard = struct ("seq", `Int shard.seq) ] in push_frame ~payload ~ev:RESUME shard - >>| fun s -> - Clock.after (Core.Time.Span.create ~sec:5 ()) - >>| (fun _ -> Mutex.unlock identify_lock) - |> ignore; - s let handle_frame ~f shard = let module J = Yojson.Basic.Util in @@ -151,15 +167,21 @@ module Shard = struct match op with | DISPATCH -> dispatch ~payload:f shard | HEARTBEAT -> heartbeat shard - | RECONNECT -> print_endline "OP 7"; return shard (* TODO reconnect *) - | INVALID_SESSION -> print_endline "OP 9"; return shard (* TODO invalid session *) + | INVALID_SESSION -> begin + if J.(member "d" f |> to_bool) then + initialize shard + else begin + initialize { shard with session = None; } + end + end + | RECONNECT -> initialize shard | HELLO -> initialize ~data:(J.member "d" f) shard | HEARTBEAT_ACK -> return shard | opcode -> print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; return shard - let create ~url ~shards ~token () = + let rec create ~url ~shards ~token () = let open Core in let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in let extra_headers = Http.Base.process_request_headers () in @@ -184,26 +206,36 @@ module Shard = struct uri >>> ignore; Ivar.read initialized >>| fun () -> - let rec ev_loop ~reader shard = - Pipe.read reader + let rec ev_loop t = + let (read, _) = t.shard.pipe in + Pipe.read read >>= fun frame -> - handle_frame ~f:(parse frame) shard - >>= fun shard -> - ev_loop ~reader shard + (match parse frame with + | Some f -> begin + handle_frame ~f t.shard + >>| fun shard -> + t.shard <- shard; + t + end + | None -> recreate t.shard) + >>= fun t -> + List.iter ~f:(fun f -> f t.shard) t.binds; + ev_loop t in let shard = { - read; - write; + pipe = (read, write); ready = Ivar.create (); hb = None; seq = 0; - shard = shards; + id = shards; session = None; - token = token; + token; + url; } in - ev_loop ~reader:read shard |> ignore; - shard + let t = { shard; binds = []; } in + ev_loop t >>> ignore; + t in match Unix.getaddrinfo host (string_of_int port) [] with | [] -> failwithf "DNS resolution failed for %s" host () @@ -220,10 +252,17 @@ module Shard = struct `TCP (h, p) in Conduit_async.V2.connect addr >>= tcp_fun + and recreate shard = + print_endline "Reconnecting..."; + (match shard.hb with + | Some hb -> Ivar.fill_if_empty hb () + | None -> () + ); + create ~url:(shard.url) ~shards:(shard.id) ~token:(shard.token) () end type t = { - shards: Shard.t list; + mutable shards: (Shard.shard Shard.t) list; } let start ?count token = @@ -246,21 +285,19 @@ let start ?count token = in gen_shards shard_list [] >>| fun shards -> - { - shards; - } + { shards; } let set_status sharder status = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status ~status shard + Deferred.all @@ List.map ~f:(fun t -> + Shard.set_status ~status t.shard ) sharder.shards let set_status_with sharder f = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.set_status ~status:(f shard) shard + Deferred.all @@ List.map ~f:(fun t -> + Shard.set_status ~status:(f t.shard) t.shard ) sharder.shards let request_guild_members ~guild ?query ?limit sharder = - Deferred.all @@ List.map ~f:(fun shard -> - Shard.request_guild_members ~guild ?query ?limit shard + Deferred.all @@ List.map ~f:(fun t -> + Shard.request_guild_members ~guild ?query ?limit t.shard ) sharder.shards -- cgit v1.2.3 From 7e5604758c5326c2800ef48bdde64dec2ab37409 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 29 Nov 2018 10:23:20 -0700 Subject: hopefully fixes the shard changes not propogating on reconnect --- lib/sharder.ml | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 74870bd..27b3b41 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -204,25 +204,9 @@ module Shard = struct ~net_to_ws ~ws_to_net uri - >>> ignore; + >>> ignore; (* TODO this needs to error check and retry with backoff *) Ivar.read initialized >>| fun () -> - let rec ev_loop t = - let (read, _) = t.shard.pipe in - Pipe.read read - >>= fun frame -> - (match parse frame with - | Some f -> begin - handle_frame ~f t.shard - >>| fun shard -> - t.shard <- shard; - t - end - | None -> recreate t.shard) - >>= fun t -> - List.iter ~f:(fun f -> f t.shard) t.binds; - ev_loop t - in - let shard = { + { pipe = (read, write); ready = Ivar.create (); hb = None; @@ -232,10 +216,6 @@ module Shard = struct token; url; } - in - let t = { shard; binds = []; } in - ev_loop t >>> ignore; - t in match Unix.getaddrinfo host (string_of_int port) [] with | [] -> failwithf "DNS resolution failed for %s" host () @@ -262,7 +242,7 @@ module Shard = struct end type t = { - mutable shards: (Shard.shard Shard.t) list; + shards: (Shard.shard Shard.t) list; } let start ?count token = @@ -280,7 +260,25 @@ let start ?count token = | (id, total) -> Shard.create ~url ~shards:(id, total) ~token () >>= fun shard -> - let a = shard :: a in + let rec ev_loop t = + let (read, _) = t.shard.pipe in + Pipe.read read + >>= fun frame -> + (match parse frame with + | Some f -> begin + handle_frame ~f t.shard + >>| fun shard -> + t.shard <- shard; + t + end + | None -> recreate t.shard) + >>= fun t -> + List.iter ~f:(fun f -> f t.shard) t.binds; + ev_loop t + in + let t = { shard; binds = []; } in + ev_loop t >>> ignore; + let a = t :: a in gen_shards (id+1, total) a in gen_shards shard_list [] -- cgit v1.2.3 From b50ec1c46e8c73c7993898d52a567e1d662218cc Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 29 Nov 2018 10:27:06 -0700 Subject: Missed a couple things --- lib/sharder.ml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 27b3b41..1deae72 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -263,15 +263,16 @@ let start ?count token = let rec ev_loop t = let (read, _) = t.shard.pipe in Pipe.read read - >>= fun frame -> - (match parse frame with + >>| fun frame -> + let _ = match parse frame with | Some f -> begin handle_frame ~f t.shard - >>| fun shard -> + >>> fun shard -> t.shard <- shard; - t end - | None -> recreate t.shard) + | None -> t.shard <- recreate t.shard; + in + t >>= fun t -> List.iter ~f:(fun f -> f t.shard) t.binds; ev_loop t -- cgit v1.2.3 From a1e0eed9739c2006c8012a8a9e0f8cde5f3c250d Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 29 Nov 2018 10:29:27 -0700 Subject: Clean up a bit --- lib/sharder.ml | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 1deae72..7f66b4e 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -254,33 +254,32 @@ let start ?count token = | None -> J.(member "shards" data |> to_int) in let shard_list = (0, count) in + let rec ev_loop t = + let (read, _) = t.shard.pipe in + Pipe.read read + >>| fun frame -> + let _ = match parse frame with + | Some f -> begin + handle_frame ~f t.shard + >>> fun shard -> + t.shard <- shard; + end + | None -> t.shard <- recreate t.shard; + in + t + >>= fun t -> + List.iter ~f:(fun f -> f t.shard) t.binds; + ev_loop t + in let rec gen_shards l a = match l with | (id, total) when id >= total -> return a | (id, total) -> Shard.create ~url ~shards:(id, total) ~token () >>= fun shard -> - let rec ev_loop t = - let (read, _) = t.shard.pipe in - Pipe.read read - >>| fun frame -> - let _ = match parse frame with - | Some f -> begin - handle_frame ~f t.shard - >>> fun shard -> - t.shard <- shard; - end - | None -> t.shard <- recreate t.shard; - in - t - >>= fun t -> - List.iter ~f:(fun f -> f t.shard) t.binds; - ev_loop t - in let t = { shard; binds = []; } in ev_loop t >>> ignore; - let a = t :: a in - gen_shards (id+1, total) a + gen_shards (id+1, total) (t :: a) in gen_shards shard_list [] >>| fun shards -> -- cgit v1.2.3 From 473072f66e6c7e228b4f26730cbc7304941fb12b Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 29 Nov 2018 12:55:10 -0700 Subject: functors! --- lib/client.ml | 61 ++++--- lib/dis.ml | 0 lib/http.ml | 439 ++++++++++++++++++++++----------------------- lib/s.ml | 31 ++++ lib/sharder.ml | 549 +++++++++++++++++++++++++++++---------------------------- 5 files changed, 562 insertions(+), 518 deletions(-) delete mode 100644 lib/dis.ml create mode 100644 lib/s.ml (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index e88b1d5..7adaae3 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -1,35 +1,42 @@ open Async -type t = { - sharder: Sharder.t Ivar.t; - handler: string Pipe.Writer.t; - token: string; -} +module Make(T : S.Token) = struct + include T + + module Http = Http.Make(T) + module Sharder = Sharder.Make(Http) -let create ~handler token = - { - sharder = Ivar.create (); - handler; - token; + type t = { + sharder: Sharder.t Ivar.t; + handler: string Pipe.Writer.t; + token: string; } -let start ?count client = - Sharder.start ?count client.token - >>| fun sharder -> - Ivar.fill_if_empty client.sharder sharder; - client + let init ~handler () = + { + sharder = Ivar.create (); + handler; + token; + } -let set_status ~status client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status sharder status + let start ?count client = + Sharder.start ?count client.token + >>| fun sharder -> + Ivar.fill_if_empty client.sharder sharder; + client -let set_status_with ~f client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status_with sharder f + let set_status ~status client = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.set_status sharder status -let request_guild_members ~guild ?query ?limit client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.request_guild_members ~guild ?query ?limit sharder + let set_status_with ~f client = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.set_status_with sharder f + + let request_guild_members ~guild ?query ?limit client = + Ivar.read client.sharder + >>= fun sharder -> + Sharder.request_guild_members ~guild ?query ?limit sharder +end \ No newline at end of file diff --git a/lib/dis.ml b/lib/dis.ml deleted file mode 100644 index e69de29..0000000 diff --git a/lib/http.ml b/lib/http.ml index 8d0b679..a8e6b22 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -1,319 +1,322 @@ open Async open Cohttp -module Base = struct - exception Invalid_Method +module Make(T : S.Token) = struct + include T - let base_url = "https://discordapp.com/api/v7" - let cdn_url = "https://cdn.discordapp.com" + module Base = struct + exception Invalid_Method - let process_url path = - Uri.of_string (base_url ^ path) + let base_url = "https://discordapp.com/api/v7" + let cdn_url = "https://cdn.discordapp.com" - let process_request_body body = - body - |> Yojson.Basic.to_string - |> Cohttp_async.Body.of_string + let process_url path = + Uri.of_string (base_url ^ path) - let process_request_headers () = - let token = match Sys.getenv "DISCORD_TOKEN" with - | Some t -> t - | None -> failwith "Please provide a token" - in - let h = Header.init_with "User-Agent" "Dis.ml v0.1.0" in - let h = Header.add h "Authorization" ("Bot " ^ token) in - Header.add h "Content-Type" "application/json" + let process_request_body body = + body + |> Yojson.Basic.to_string + |> Cohttp_async.Body.of_string - (* TODO Finish processor *) - let process_response (_resp, body) = - body |> Cohttp_async.Body.to_string >>| Yojson.Basic.from_string + let process_request_headers () = + let h = Header.init () in + Header.add_list h [ + "User-Agent", "Dis.ml v0.1.0"; + "Authorization", ("Bot " ^ token); + "Content-Type", "application/json"; + ] - let request ?(body=`Null) m path = - let uri = process_url path in - let headers = process_request_headers () in - let body = process_request_body body in - (match m with - | `DELETE -> Cohttp_async.Client.delete ~headers ~body uri - | `GET -> Cohttp_async.Client.get ~headers uri - | `PATCH -> Cohttp_async.Client.patch ~headers ~body uri - | `POST -> Cohttp_async.Client.post ~headers ~body uri - | `PUT -> Cohttp_async.Client.put ~headers ~body uri - | _ -> raise Invalid_Method) - >>= process_response -end + (* TODO Finish processor *) + let process_response (_resp, body) = + body |> Cohttp_async.Body.to_string >>| Yojson.Basic.from_string -let get_gateway () = - Base.request `GET Endpoints.gateway + let request ?(body=`Null) m path = + let uri = process_url path in + let headers = process_request_headers () in + let body = process_request_body body in + (match m with + | `DELETE -> Cohttp_async.Client.delete ~headers ~body uri + | `GET -> Cohttp_async.Client.get ~headers uri + | `PATCH -> Cohttp_async.Client.patch ~headers ~body uri + | `POST -> Cohttp_async.Client.post ~headers ~body uri + | `PUT -> Cohttp_async.Client.put ~headers ~body uri + | _ -> raise Invalid_Method) + >>= process_response + end -let get_gateway_bot () = - Base.request `GET Endpoints.gateway_bot + let get_gateway () = + Base.request `GET Endpoints.gateway -let get_channel channel_id = - Base.request `GET (Endpoints.channel channel_id) + let get_gateway_bot () = + Base.request `GET Endpoints.gateway_bot -let modify_channel channel_id body = - Base.request ~body `PATCH (Endpoints.channel channel_id) + let get_channel channel_id = + Base.request `GET (Endpoints.channel channel_id) -let delete_channel channel_id = - Base.request `DELETE (Endpoints.channel channel_id) + let modify_channel channel_id body = + Base.request ~body `PATCH (Endpoints.channel channel_id) -let get_messages channel_id = - Base.request `GET (Endpoints.channel_messages channel_id) + let delete_channel channel_id = + Base.request `DELETE (Endpoints.channel channel_id) -let get_message channel_id message_id = - Base.request `GET (Endpoints.channel_message channel_id message_id) + let get_messages channel_id = + Base.request `GET (Endpoints.channel_messages channel_id) -let create_message channel_id body = - Base.request ~body:body `POST (Endpoints.channel_messages channel_id) + let get_message channel_id message_id = + Base.request `GET (Endpoints.channel_message channel_id message_id) -let create_reaction channel_id message_id emoji = - Base.request `PUT (Endpoints.channel_reaction_me channel_id message_id emoji) + let create_message channel_id body = + Base.request ~body:body `POST (Endpoints.channel_messages channel_id) -let delete_own_reaction channel_id message_id emoji = - Base.request `DELETE (Endpoints.channel_reaction_me channel_id message_id emoji) + let create_reaction channel_id message_id emoji = + Base.request `PUT (Endpoints.channel_reaction_me channel_id message_id emoji) -let delete_reaction channel_id message_id emoji user_id = - Base.request `DELETE (Endpoints.channel_reaction channel_id message_id emoji user_id) + let delete_own_reaction channel_id message_id emoji = + Base.request `DELETE (Endpoints.channel_reaction_me channel_id message_id emoji) -let get_reactions channel_id message_id emoji = - Base.request `GET (Endpoints.channel_reactions_get channel_id message_id emoji) + let delete_reaction channel_id message_id emoji user_id = + Base.request `DELETE (Endpoints.channel_reaction channel_id message_id emoji user_id) -let delete_reactions channel_id message_id = - Base.request `DELETE (Endpoints.channel_reactions_delete channel_id message_id) + let get_reactions channel_id message_id emoji = + Base.request `GET (Endpoints.channel_reactions_get channel_id message_id emoji) -let edit_message channel_id message_id body = - Base.request ~body `PATCH (Endpoints.channel_message channel_id message_id) + let delete_reactions channel_id message_id = + Base.request `DELETE (Endpoints.channel_reactions_delete channel_id message_id) -let delete_message channel_id message_id = - Base.request `DELETE (Endpoints.channel_message channel_id message_id) + let edit_message channel_id message_id body = + Base.request ~body `PATCH (Endpoints.channel_message channel_id message_id) -let bulk_delete channel_id body = - Base.request ~body `POST (Endpoints.channel_bulk_delete channel_id) + let delete_message channel_id message_id = + Base.request `DELETE (Endpoints.channel_message channel_id message_id) -let edit_channel_permissions channel_id overwrite_id body = - Base.request ~body `PUT (Endpoints.channel_permission channel_id overwrite_id) + let bulk_delete channel_id body = + Base.request ~body `POST (Endpoints.channel_bulk_delete channel_id) -let get_channel_invites channel_id = - Base.request `GET (Endpoints.channel_invites channel_id) + let edit_channel_permissions channel_id overwrite_id body = + Base.request ~body `PUT (Endpoints.channel_permission channel_id overwrite_id) -let create_channel_invite channel_id body = - Base.request ~body `POST (Endpoints.channel_invites channel_id) + let get_channel_invites channel_id = + Base.request `GET (Endpoints.channel_invites channel_id) -let delete_channel_permission channel_id overwrite_id = - Base.request `DELETE (Endpoints.channel_permission channel_id overwrite_id) + let create_channel_invite channel_id body = + Base.request ~body `POST (Endpoints.channel_invites channel_id) -let broadcast_typing channel_id = - Base.request `POST (Endpoints.channel_typing channel_id) + let delete_channel_permission channel_id overwrite_id = + Base.request `DELETE (Endpoints.channel_permission channel_id overwrite_id) -let get_pinned_messages channel_id = - Base.request `GET (Endpoints.channel_pins channel_id) + let broadcast_typing channel_id = + Base.request `POST (Endpoints.channel_typing channel_id) -let pin_message channel_id message_id = - Base.request `PUT (Endpoints.channel_pin channel_id message_id) + let get_pinned_messages channel_id = + Base.request `GET (Endpoints.channel_pins channel_id) -let unpin_message channel_id message_id = - Base.request `DELETE (Endpoints.channel_pin channel_id message_id) + let pin_message channel_id message_id = + Base.request `PUT (Endpoints.channel_pin channel_id message_id) -let group_recipient_add channel_id user_id = - Base.request `PUT (Endpoints.group_recipient channel_id user_id) + let unpin_message channel_id message_id = + Base.request `DELETE (Endpoints.channel_pin channel_id message_id) -let group_recipient_remove channel_id user_id = - Base.request `DELETE (Endpoints.group_recipient channel_id user_id) + let group_recipient_add channel_id user_id = + Base.request `PUT (Endpoints.group_recipient channel_id user_id) -let get_emojis guild_id = - Base.request `GET (Endpoints.guild_emojis guild_id) + let group_recipient_remove channel_id user_id = + Base.request `DELETE (Endpoints.group_recipient channel_id user_id) -let get_emoji guild_id emoji_id = - Base.request `GET (Endpoints.guild_emoji guild_id emoji_id) + let get_emojis guild_id = + Base.request `GET (Endpoints.guild_emojis guild_id) -let create_emoji guild_id body = - Base.request ~body `POST (Endpoints.guild_emojis guild_id) + let get_emoji guild_id emoji_id = + Base.request `GET (Endpoints.guild_emoji guild_id emoji_id) -let edit_emoji guild_id emoji_id body = - Base.request ~body `PATCH (Endpoints.guild_emoji guild_id emoji_id) + let create_emoji guild_id body = + Base.request ~body `POST (Endpoints.guild_emojis guild_id) -let delete_emoji guild_id emoji_id = - Base.request `DELETE (Endpoints.guild_emoji guild_id emoji_id) + let edit_emoji guild_id emoji_id body = + Base.request ~body `PATCH (Endpoints.guild_emoji guild_id emoji_id) -let create_guild body = - Base.request ~body `POST Endpoints.guilds + let delete_emoji guild_id emoji_id = + Base.request `DELETE (Endpoints.guild_emoji guild_id emoji_id) -let get_guild guild_id = - Base.request `GET (Endpoints.guild guild_id) + let create_guild body = + Base.request ~body `POST Endpoints.guilds -let edit_guild guild_id body = - Base.request ~body `PATCH (Endpoints.guild guild_id) + let get_guild guild_id = + Base.request `GET (Endpoints.guild guild_id) -let delete_guild guild_id = - Base.request `DELETE (Endpoints.guild guild_id) + let edit_guild guild_id body = + Base.request ~body `PATCH (Endpoints.guild guild_id) -let get_guild_channels guild_id = - Base.request `GET (Endpoints.guild_channels guild_id) + let delete_guild guild_id = + Base.request `DELETE (Endpoints.guild guild_id) -let create_guild_channel guild_id body = - Base.request ~body `POST (Endpoints.guild_channels guild_id) + let get_guild_channels guild_id = + Base.request `GET (Endpoints.guild_channels guild_id) -let modify_guild_channel_positions guild_id body = - Base.request ~body `PATCH (Endpoints.guild_channels guild_id) + let create_guild_channel guild_id body = + Base.request ~body `POST (Endpoints.guild_channels guild_id) -let get_member guild_id user_id = - Base.request `GET (Endpoints.guild_member guild_id user_id) + let modify_guild_channel_positions guild_id body = + Base.request ~body `PATCH (Endpoints.guild_channels guild_id) -let get_members guild_id = - Base.request `GET (Endpoints.guild_members guild_id) + let get_member guild_id user_id = + Base.request `GET (Endpoints.guild_member guild_id user_id) -let add_member guild_id user_id body = - Base.request ~body `PUT (Endpoints.guild_member guild_id user_id) + let get_members guild_id = + Base.request `GET (Endpoints.guild_members guild_id) -let edit_member guild_id user_id body = - Base.request ~body `PATCH (Endpoints.guild_member guild_id user_id) + let add_member guild_id user_id body = + Base.request ~body `PUT (Endpoints.guild_member guild_id user_id) -let remove_member guild_id user_id = - Base.request `DELETE (Endpoints.guild_member guild_id user_id) + let edit_member guild_id user_id body = + Base.request ~body `PATCH (Endpoints.guild_member guild_id user_id) -let change_nickname guild_id body = - Base.request ~body `PATCH (Endpoints.guild_me_nick guild_id) + let remove_member guild_id user_id = + Base.request `DELETE (Endpoints.guild_member guild_id user_id) -let add_member_role guild_id user_id role_id = - Base.request `PUT (Endpoints.guild_member_role guild_id user_id role_id) + let change_nickname guild_id body = + Base.request ~body `PATCH (Endpoints.guild_me_nick guild_id) -let remove_member_role guild_id user_id role_id = - Base.request `DELETE (Endpoints.guild_member_role guild_id user_id role_id) + let add_member_role guild_id user_id role_id = + Base.request `PUT (Endpoints.guild_member_role guild_id user_id role_id) -let get_bans guild_id = - Base.request `GET (Endpoints.guild_bans guild_id) + let remove_member_role guild_id user_id role_id = + Base.request `DELETE (Endpoints.guild_member_role guild_id user_id role_id) -let get_ban guild_id user_id = - Base.request `GET (Endpoints.guild_ban guild_id user_id) + let get_bans guild_id = + Base.request `GET (Endpoints.guild_bans guild_id) -let guild_ban_add guild_id user_id body = - Base.request ~body `PUT (Endpoints.guild_ban guild_id user_id) + let get_ban guild_id user_id = + Base.request `GET (Endpoints.guild_ban guild_id user_id) -let guild_ban_remove guild_id user_id = - Base.request `DELETE (Endpoints.guild_ban guild_id user_id) + let guild_ban_add guild_id user_id body = + Base.request ~body `PUT (Endpoints.guild_ban guild_id user_id) -let get_roles guild_id = - Base.request `GET (Endpoints.guild_roles guild_id) + let guild_ban_remove guild_id user_id = + Base.request `DELETE (Endpoints.guild_ban guild_id user_id) -let guild_role_add guild_id body = - Base.request ~body `POST (Endpoints.guild_roles guild_id) + let get_roles guild_id = + Base.request `GET (Endpoints.guild_roles guild_id) -let guild_roles_edit guild_id body = - Base.request ~body `PATCH (Endpoints.guild_roles guild_id) + let guild_role_add guild_id body = + Base.request ~body `POST (Endpoints.guild_roles guild_id) -let guild_role_edit guild_id role_id body = - Base.request ~body `PATCH (Endpoints.guild_role guild_id role_id) + let guild_roles_edit guild_id body = + Base.request ~body `PATCH (Endpoints.guild_roles guild_id) -let guild_role_remove guild_id role_id = - Base.request `DELETE (Endpoints.guild_role guild_id role_id) + let guild_role_edit guild_id role_id body = + Base.request ~body `PATCH (Endpoints.guild_role guild_id role_id) -let guild_prune_count guild_id = - Base.request `GET (Endpoints.guild_prune guild_id) + let guild_role_remove guild_id role_id = + Base.request `DELETE (Endpoints.guild_role guild_id role_id) -let guild_prune_start guild_id body = - Base.request ~body `POST (Endpoints.guild_prune guild_id) + let guild_prune_count guild_id = + Base.request `GET (Endpoints.guild_prune guild_id) -let get_guild_voice_regions guild_id = - Base.request `GET (Endpoints.guild_voice_regions guild_id) + let guild_prune_start guild_id body = + Base.request ~body `POST (Endpoints.guild_prune guild_id) -let get_guild_invites guild_id = - Base.request `GET (Endpoints.guild_invites guild_id) + let get_guild_voice_regions guild_id = + Base.request `GET (Endpoints.guild_voice_regions guild_id) -let get_integrations guild_id = - Base.request `GET (Endpoints.guild_integrations guild_id) + let get_guild_invites guild_id = + Base.request `GET (Endpoints.guild_invites guild_id) -let add_integration guild_id body = - Base.request ~body `POST (Endpoints.guild_integrations guild_id) + let get_integrations guild_id = + Base.request `GET (Endpoints.guild_integrations guild_id) -let edit_integration guild_id integration_id body = - Base.request ~body `POST (Endpoints.guild_integration guild_id integration_id) + let add_integration guild_id body = + Base.request ~body `POST (Endpoints.guild_integrations guild_id) -let delete_integration guild_id integration_id = - Base.request `DELETE (Endpoints.guild_integration guild_id integration_id) + let edit_integration guild_id integration_id body = + Base.request ~body `POST (Endpoints.guild_integration guild_id integration_id) -let sync_integration guild_id integration_id = - Base.request `POST (Endpoints.guild_integration_sync guild_id integration_id) + let delete_integration guild_id integration_id = + Base.request `DELETE (Endpoints.guild_integration guild_id integration_id) -let get_guild_embed guild_id = - Base.request `GET (Endpoints.guild_embed guild_id) + let sync_integration guild_id integration_id = + Base.request `POST (Endpoints.guild_integration_sync guild_id integration_id) -let edit_guild_embed guild_id body = - Base.request ~body `PATCH (Endpoints.guild_embed guild_id) + let get_guild_embed guild_id = + Base.request `GET (Endpoints.guild_embed guild_id) -let get_vanity_url guild_id = - Base.request `GET (Endpoints.guild_vanity_url guild_id) + let edit_guild_embed guild_id body = + Base.request ~body `PATCH (Endpoints.guild_embed guild_id) -let get_invite invite_code = - Base.request `GET (Endpoints.invite invite_code) + let get_vanity_url guild_id = + Base.request `GET (Endpoints.guild_vanity_url guild_id) -let delete_invite invite_code = - Base.request `DELETE (Endpoints.invite invite_code) + let get_invite invite_code = + Base.request `GET (Endpoints.invite invite_code) -let get_current_user () = - Base.request `GET Endpoints.me + let delete_invite invite_code = + Base.request `DELETE (Endpoints.invite invite_code) -let edit_current_user body = - Base.request ~body `PATCH Endpoints.me + let get_current_user () = + Base.request `GET Endpoints.me -let get_guilds () = - Base.request `GET Endpoints.me_guilds + let edit_current_user body = + Base.request ~body `PATCH Endpoints.me -let leave_guild guild_id = - Base.request `DELETE (Endpoints.me_guild guild_id) + let get_guilds () = + Base.request `GET Endpoints.me_guilds -let get_private_channels () = - Base.request `GET Endpoints.me_channels + let leave_guild guild_id = + Base.request `DELETE (Endpoints.me_guild guild_id) -let create_dm body = - Base.request ~body `POST Endpoints.me_channels + let get_private_channels () = + Base.request `GET Endpoints.me_channels -let create_group_dm body = - Base.request ~body `POST Endpoints.me_channels + let create_dm body = + Base.request ~body `POST Endpoints.me_channels -let get_connections () = - Base.request `GET Endpoints.me_connections + let create_group_dm body = + Base.request ~body `POST Endpoints.me_channels -let get_user user_id = - Base.request `GET (Endpoints.user user_id) + let get_connections () = + Base.request `GET Endpoints.me_connections -let get_voice_regions () = - Base.request `GET Endpoints.regions + let get_user user_id = + Base.request `GET (Endpoints.user user_id) -let create_webhook channel_id body = - Base.request ~body `POST (Endpoints.webhooks_channel channel_id) + let get_voice_regions () = + Base.request `GET Endpoints.regions -let get_channel_webhooks channel_id = - Base.request `GET (Endpoints.webhooks_channel channel_id) + let create_webhook channel_id body = + Base.request ~body `POST (Endpoints.webhooks_channel channel_id) -let get_guild_webhooks guild_id = - Base.request `GET (Endpoints.webhooks_guild guild_id) + let get_channel_webhooks channel_id = + Base.request `GET (Endpoints.webhooks_channel channel_id) -let get_webhook webhook_id = - Base.request `GET (Endpoints.webhook webhook_id) + let get_guild_webhooks guild_id = + Base.request `GET (Endpoints.webhooks_guild guild_id) -let get_webhook_with_token webhook_id token = - Base.request `GET (Endpoints.webhook_token webhook_id token) + let get_webhook webhook_id = + Base.request `GET (Endpoints.webhook webhook_id) -let edit_webhook webhook_id body = - Base.request ~body `PATCH (Endpoints.webhook webhook_id) + let get_webhook_with_token webhook_id token = + Base.request `GET (Endpoints.webhook_token webhook_id token) -let edit_webhook_with_token webhook_id token body = - Base.request ~body `PATCH (Endpoints.webhook_token webhook_id token) + let edit_webhook webhook_id body = + Base.request ~body `PATCH (Endpoints.webhook webhook_id) -let delete_webhook webhook_id = - Base.request `DELETE (Endpoints.webhook webhook_id) + let edit_webhook_with_token webhook_id token body = + Base.request ~body `PATCH (Endpoints.webhook_token webhook_id token) -let delete_webhook_with_token webhook_id token = - Base.request `DELETE (Endpoints.webhook_token webhook_id token) + let delete_webhook webhook_id = + Base.request `DELETE (Endpoints.webhook webhook_id) -let execute_webhook webhook_id token body = - Base.request ~body `POST (Endpoints.webhook_token webhook_id token) + let delete_webhook_with_token webhook_id token = + Base.request `DELETE (Endpoints.webhook_token webhook_id token) -let execute_slack_webhook webhook_id token body = - Base.request ~body `POST (Endpoints.webhook_slack webhook_id token) + let execute_webhook webhook_id token body = + Base.request ~body `POST (Endpoints.webhook_token webhook_id token) -let execute_git_webhook webhook_id token body = - Base.request ~body `POST (Endpoints.webhook_git webhook_id token) + let execute_slack_webhook webhook_id token body = + Base.request ~body `POST (Endpoints.webhook_slack webhook_id token) -let get_audit_logs guild_id body = - Base.request ~body `GET (Endpoints.guild_audit_logs guild_id) \ No newline at end of file + let execute_git_webhook webhook_id token body = + Base.request ~body `POST (Endpoints.webhook_git webhook_id token) + + let get_audit_logs guild_id body = + Base.request ~body `GET (Endpoints.guild_audit_logs guild_id) +end \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml new file mode 100644 index 0000000..92259a0 --- /dev/null +++ b/lib/s.ml @@ -0,0 +1,31 @@ +open Async +open Cohttp + +module type Token = sig + val token : string +end + +module type Http = sig + module Base : sig + exception Invalid_Method + + val base_url : string + + val process_url : string -> Uri.t + val process_request_body : Yojson.Basic.json -> Cohttp_async.Body.t + val process_request_headers : unit -> Headers.t + + val process_response : + Cohttp_async.Response.t * Cohttp_async.Body.t -> + Yojson.Basic.json + + val request : + ?body:Yojson.Basic.json -> + [ `Delete | `Get | `Patch | `Post | `Put ] -> + string -> + Yojson.Basic.json Deferred.t + end + + (* TODO add abstraction sigs *) + val token : string +end \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml index 7f66b4e..1fa97a0 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -2,300 +2,303 @@ open Async open Core open Websocket_async -exception Invalid_Payload -exception Failure_to_Establish_Heartbeat +module Make(H: S.Http) = struct + exception Invalid_Payload + exception Failure_to_Establish_Heartbeat -module Shard = struct - type shard = { - hb: unit Ivar.t option; - seq: int; - session: string option; - pipe: Frame.t Pipe.Reader.t * Frame.t Pipe.Writer.t; - ready: unit Ivar.t; - token: string; - url: string; - id: int * int; - } + let token = H.token - type 'a t = { - mutable shard: 'a; - mutable binds: ('a -> unit) list; - } + module Shard = struct + type shard = { + hb: unit Ivar.t option; + seq: int; + session: string option; + pipe: Frame.t Pipe.Reader.t * Frame.t Pipe.Writer.t; + ready: unit Ivar.t; + url: string; + id: int * int; + } - let identify_lock = Mutex.create () + type 'a t = { + mutable shard: 'a; + mutable binds: ('a -> unit) list; + } - let bind ~f t = - t.binds <- f :: t.binds + let identify_lock = Mutex.create () - let parse (frame:[`Ok of Frame.t | `Eof]) = - match frame with - | `Ok s -> begin - let open Frame.Opcode in - match s.opcode with - | Text -> Some (Yojson.Basic.from_string s.content) - | _ -> None - end - | `Eof -> None + let bind ~f t = + t.binds <- f :: t.binds - let push_frame ?payload ~ev shard = - print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; - let content = match payload with - | None -> "" - | Some p -> - Yojson.Basic.to_string @@ `Assoc [ - ("op", `Int (Opcode.to_int ev)); - ("d", p); - ] - in - let (_, write) = shard.pipe in - Pipe.write_if_open write @@ Frame.create ~content () - >>| fun () -> - shard + let parse (frame:[`Ok of Frame.t | `Eof]) = + match frame with + | `Ok s -> begin + let open Frame.Opcode in + match s.opcode with + | Text -> Some (Yojson.Basic.from_string s.content) + | _ -> None + end + | `Eof -> None - let heartbeat shard = - let payload = match shard.seq with - | 0 -> `Null - | i -> `Int i - in - push_frame ~payload ~ev:HEARTBEAT shard + let push_frame ?payload ~ev shard = + print_endline @@ "Pushing frame. OP: " ^ Opcode.to_string @@ ev; + let content = match payload with + | None -> "" + | Some p -> + Yojson.Basic.to_string @@ `Assoc [ + ("op", `Int (Opcode.to_int ev)); + ("d", p); + ] + in + let (_, write) = shard.pipe in + Pipe.write_if_open write @@ Frame.create ~content () + >>| fun () -> + shard - let dispatch ~payload shard = - let module J = Yojson.Basic.Util in - let seq = J.(member "s" payload |> to_int) in - let t = J.(member "t" payload |> to_string) in - let data = J.member "d" payload in - let session = J.(member "session_id" data |> to_string_option) in - if t = "READY" then begin - Ivar.fill_if_empty shard.ready (); - end; - return { shard with - seq = seq; - session = session; - } + let heartbeat shard = + let payload = match shard.seq with + | 0 -> `Null + | i -> `Int i + in + push_frame ~payload ~ev:HEARTBEAT shard - let set_status ~status shard = - let payload = match status with - | `Assoc [("name", `String name); ("type", `Int t)] -> - `Assoc [ - ("status", `String "online"); - ("afk", `Bool false); - ("since", `Null); - ("game", `Assoc [ - ("name", `String name); - ("type", `Int t) - ]) - ] - | `String name -> - `Assoc [ - ("status", `String "online"); - ("afk", `Bool false); - ("since", `Null); - ("game", `Assoc [ - ("name", `String name); - ("type", `Int 0) - ]) - ] - | _ -> raise Invalid_Payload - in - Ivar.read shard.ready >>= fun _ -> - push_frame ~payload ~ev:STATUS_UPDATE shard + let dispatch ~payload shard = + let module J = Yojson.Basic.Util in + let seq = J.(member "s" payload |> to_int) in + let t = J.(member "t" payload |> to_string) in + let data = J.member "d" payload in + let session = J.(member "session_id" data |> to_string_option) in + if t = "READY" then begin + Ivar.fill_if_empty shard.ready (); + end; + return { shard with + seq = seq; + session = session; + } - let request_guild_members ~guild ?(query="") ?(limit=0) shard = - let payload = `Assoc [ - ("guild_id", `String (string_of_int guild)); - ("query", `String query); - ("limit", `Int limit); - ] in - Ivar.read shard.ready >>= fun _ -> - push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard + let set_status ~status shard = + let payload = match status with + | `Assoc [("name", `String name); ("type", `Int t)] -> + `Assoc [ + ("status", `String "online"); + ("afk", `Bool false); + ("since", `Null); + ("game", `Assoc [ + ("name", `String name); + ("type", `Int t) + ]) + ] + | `String name -> + `Assoc [ + ("status", `String "online"); + ("afk", `Bool false); + ("since", `Null); + ("game", `Assoc [ + ("name", `String name); + ("type", `Int 0) + ]) + ] + | _ -> raise Invalid_Payload + in + Ivar.read shard.ready >>= fun _ -> + push_frame ~payload ~ev:STATUS_UPDATE shard - let initialize ?data shard = - let module J = Yojson.Basic.Util in - let hb = match shard.hb with - | None -> begin - match data with - | Some data -> - let hb_interval = J.(member "heartbeat_interval" data |> to_int) in - let finished = Ivar.create () in - Clock.every' - ~continue_on_error:true - ~finished - (Core.Time.Span.create ~ms:hb_interval ()) - (fun () -> heartbeat shard >>= fun _ -> return ()); - finished - | None -> raise Failure_to_Establish_Heartbeat - end - | Some s -> s - in - let shard = { shard with hb = Some hb; } in - let (cur, max) = shard.id in - let shards = [`Int cur; `Int max] in - match shard.session with - | None -> begin - Mutex.lock identify_lock; + let request_guild_members ~guild ?(query="") ?(limit=0) shard = let payload = `Assoc [ - ("token", `String shard.token); - ("properties", `Assoc [ - ("$os", `String Sys.os_type); - ("$device", `String "dis.ml"); - ("$browser", `String "dis.ml") - ]); - ("compress", `Bool false); (* TODO add compression handling*) - ("large_threshold", `Int 250); - ("shard", `List shards); + ("guild_id", `String (string_of_int guild)); + ("query", `String query); + ("limit", `Int limit); ] in - push_frame ~payload ~ev:IDENTIFY shard - >>| fun s -> begin - Clock.after (Core.Time.Span.create ~sec:5 ()) - >>> (fun _ -> Mutex.unlock identify_lock); - s + Ivar.read shard.ready >>= fun _ -> + push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard + + let initialize ?data shard = + let module J = Yojson.Basic.Util in + let hb = match shard.hb with + | None -> begin + match data with + | Some data -> + let hb_interval = J.(member "heartbeat_interval" data |> to_int) in + let finished = Ivar.create () in + Clock.every' + ~continue_on_error:true + ~finished + (Core.Time.Span.create ~ms:hb_interval ()) + (fun () -> heartbeat shard >>= fun _ -> return ()); + finished + | None -> raise Failure_to_Establish_Heartbeat end - end - | Some s -> - let payload = `Assoc [ - ("token", `String shard.token); - ("session_id", `String s); - ("seq", `Int shard.seq) - ] in - push_frame ~payload ~ev:RESUME shard + | Some s -> s + in + let shard = { shard with hb = Some hb; } in + let (cur, max) = shard.id in + let shards = [`Int cur; `Int max] in + match shard.session with + | None -> begin + Mutex.lock identify_lock; + let payload = `Assoc [ + ("token", `String shard.token); + ("properties", `Assoc [ + ("$os", `String Sys.os_type); + ("$device", `String "dis.ml"); + ("$browser", `String "dis.ml") + ]); + ("compress", `Bool false); (* TODO add compression handling*) + ("large_threshold", `Int 250); + ("shard", `List shards); + ] in + push_frame ~payload ~ev:IDENTIFY shard + >>| fun s -> begin + Clock.after (Core.Time.Span.create ~sec:5 ()) + >>> (fun _ -> Mutex.unlock identify_lock); + s + end + end + | Some s -> + let payload = `Assoc [ + ("token", `String shard.token); + ("session_id", `String s); + ("seq", `Int shard.seq) + ] in + push_frame ~payload ~ev:RESUME shard - let handle_frame ~f shard = - let module J = Yojson.Basic.Util in - let op = J.(member "op" f |> to_int) - |> Opcode.from_int - in - match op with - | DISPATCH -> dispatch ~payload:f shard - | HEARTBEAT -> heartbeat shard - | INVALID_SESSION -> begin - if J.(member "d" f |> to_bool) then - initialize shard - else begin - initialize { shard with session = None; } + let handle_frame ~f shard = + let module J = Yojson.Basic.Util in + let op = J.(member "op" f |> to_int) + |> Opcode.from_int + in + match op with + | DISPATCH -> dispatch ~payload:f shard + | HEARTBEAT -> heartbeat shard + | INVALID_SESSION -> begin + if J.(member "d" f |> to_bool) then + initialize shard + else begin + initialize { shard with session = None; } + end end - end - | RECONNECT -> initialize shard - | HELLO -> initialize ~data:(J.member "d" f) shard - | HEARTBEAT_ACK -> return shard - | opcode -> - print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; - return shard + | RECONNECT -> initialize shard + | HELLO -> initialize ~data:(J.member "d" f) shard + | HEARTBEAT_ACK -> return shard + | opcode -> + print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; + return shard - let rec create ~url ~shards ~token () = - let open Core in - let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in - let extra_headers = Http.Base.process_request_headers () in - let host = Option.value_exn ~message:"no host in uri" Uri.(host uri) in - let port = - match Uri.port uri, Uri_services.tcp_port_of_uri uri with - | Some p, _ -> p - | None, Some p -> p - | _ -> 443 in - let scheme = Option.value_exn ~message:"no scheme in uri" Uri.(scheme uri) in - let tcp_fun (net_to_ws, ws_to_net) = - let (app_to_ws, write) = Pipe.create () in - let (read, ws_to_app) = Pipe.create () in - let initialized = Ivar.create () in - client - ~initialized - ~extra_headers - ~app_to_ws - ~ws_to_app - ~net_to_ws - ~ws_to_net - uri - >>> ignore; (* TODO this needs to error check and retry with backoff *) - Ivar.read initialized >>| fun () -> - { - pipe = (read, write); - ready = Ivar.create (); - hb = None; - seq = 0; - id = shards; - session = None; - token; - url; - } - in - match Unix.getaddrinfo host (string_of_int port) [] with - | [] -> failwithf "DNS resolution failed for %s" host () - | { ai_addr; _ } :: _ -> - let addr = - match scheme, ai_addr with - | _, ADDR_UNIX path -> `Unix_domain_socket path - | "https", ADDR_INET (h, p) - | "wss", ADDR_INET (h, p) -> - let h = Ipaddr_unix.of_inet_addr h in - `OpenSSL (h, p, Conduit_async.V2.Ssl.Config.create ()) - | _, ADDR_INET (h, p) -> - let h = Ipaddr_unix.of_inet_addr h in - `TCP (h, p) + let rec create ~url ~shards ~token () = + let open Core in + let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in + let extra_headers = H.Base.process_request_headers () in + let host = Option.value_exn ~message:"no host in uri" Uri.(host uri) in + let port = + match Uri.port uri, Uri_services.tcp_port_of_uri uri with + | Some p, _ -> p + | None, Some p -> p + | _ -> 443 in + let scheme = Option.value_exn ~message:"no scheme in uri" Uri.(scheme uri) in + let tcp_fun (net_to_ws, ws_to_net) = + let (app_to_ws, write) = Pipe.create () in + let (read, ws_to_app) = Pipe.create () in + let initialized = Ivar.create () in + client + ~initialized + ~extra_headers + ~app_to_ws + ~ws_to_app + ~net_to_ws + ~ws_to_net + uri + >>> ignore; (* TODO this needs to error check and retry with backoff *) + Ivar.read initialized >>| fun () -> + { + pipe = (read, write); + ready = Ivar.create (); + hb = None; + seq = 0; + id = shards; + session = None; + token; + url; + } in - Conduit_async.V2.connect addr >>= tcp_fun - and recreate shard = - print_endline "Reconnecting..."; - (match shard.hb with - | Some hb -> Ivar.fill_if_empty hb () - | None -> () - ); - create ~url:(shard.url) ~shards:(shard.id) ~token:(shard.token) () -end + match Unix.getaddrinfo host (string_of_int port) [] with + | [] -> failwithf "DNS resolution failed for %s" host () + | { ai_addr; _ } :: _ -> + let addr = + match scheme, ai_addr with + | _, ADDR_UNIX path -> `Unix_domain_socket path + | "https", ADDR_INET (h, p) + | "wss", ADDR_INET (h, p) -> + let h = Ipaddr_unix.of_inet_addr h in + `OpenSSL (h, p, Conduit_async.V2.Ssl.Config.create ()) + | _, ADDR_INET (h, p) -> + let h = Ipaddr_unix.of_inet_addr h in + `TCP (h, p) + in + Conduit_async.V2.connect addr >>= tcp_fun + and recreate shard = + print_endline "Reconnecting..."; + (match shard.hb with + | Some hb -> Ivar.fill_if_empty hb () + | None -> () + ); + create ~url:(shard.url) ~shards:(shard.id) ~token:(shard.token) () + end -type t = { - shards: (Shard.shard Shard.t) list; -} + type t = { + shards: (Shard.shard Shard.t) list; + } -let start ?count token = - let module J = Yojson.Basic.Util in - Http.get_gateway_bot () >>= fun data -> - let url = J.(member "url" data |> to_string) in - let count = match count with - | Some c -> c - | None -> J.(member "shards" data |> to_int) - in - let shard_list = (0, count) in - let rec ev_loop t = - let (read, _) = t.shard.pipe in - Pipe.read read - >>| fun frame -> - let _ = match parse frame with - | Some f -> begin - handle_frame ~f t.shard - >>> fun shard -> - t.shard <- shard; - end - | None -> t.shard <- recreate t.shard; + let start ?count token = + let module J = Yojson.Basic.Util in + Http.get_gateway_bot () >>= fun data -> + let url = J.(member "url" data |> to_string) in + let count = match count with + | Some c -> c + | None -> J.(member "shards" data |> to_int) + in + let shard_list = (0, count) in + let rec ev_loop t = + let (read, _) = t.shard.pipe in + Pipe.read read + >>| fun frame -> + let _ = match parse frame with + | Some f -> begin + handle_frame ~f t.shard + >>> fun shard -> + t.shard <- shard; + end + | None -> t.shard <- recreate t.shard; + in + t + >>= fun t -> + List.iter ~f:(fun f -> f t.shard) t.binds; + ev_loop t + in + let rec gen_shards l a = + match l with + | (id, total) when id >= total -> return a + | (id, total) -> + Shard.create ~url ~shards:(id, total) ~token () + >>= fun shard -> + let t = { shard; binds = []; } in + ev_loop t >>> ignore; + gen_shards (id+1, total) (t :: a) in - t - >>= fun t -> - List.iter ~f:(fun f -> f t.shard) t.binds; - ev_loop t - in - let rec gen_shards l a = - match l with - | (id, total) when id >= total -> return a - | (id, total) -> - Shard.create ~url ~shards:(id, total) ~token () - >>= fun shard -> - let t = { shard; binds = []; } in - ev_loop t >>> ignore; - gen_shards (id+1, total) (t :: a) - in - gen_shards shard_list [] - >>| fun shards -> - { shards; } + gen_shards shard_list [] + >>| fun shards -> + { shards; } -let set_status sharder status = - Deferred.all @@ List.map ~f:(fun t -> - Shard.set_status ~status t.shard - ) sharder.shards + let set_status sharder status = + Deferred.all @@ List.map ~f:(fun t -> + Shard.set_status ~status t.shard + ) sharder.shards -let set_status_with sharder f = - Deferred.all @@ List.map ~f:(fun t -> - Shard.set_status ~status:(f t.shard) t.shard - ) sharder.shards + let set_status_with sharder f = + Deferred.all @@ List.map ~f:(fun t -> + Shard.set_status ~status:(f t.shard) t.shard + ) sharder.shards -let request_guild_members ~guild ?query ?limit sharder = - Deferred.all @@ List.map ~f:(fun t -> - Shard.request_guild_members ~guild ?query ?limit t.shard - ) sharder.shards + let request_guild_members ~guild ?query ?limit sharder = + Deferred.all @@ List.map ~f:(fun t -> + Shard.request_guild_members ~guild ?query ?limit t.shard + ) sharder.shards +end \ No newline at end of file -- cgit v1.2.3 From 18f4b7e8cada448f6fc15ee8ee18944dcb0b1676 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 29 Nov 2018 13:50:53 -0700 Subject: Try to make it a more properly structured lib --- lib/http.ml | 1 - lib/http.mli | 1 + lib/s.ml | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- lib/sharder.ml | 6 +++--- lib/sharder.mli | 1 + 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 lib/http.mli create mode 100644 lib/sharder.mli (limited to 'lib') diff --git a/lib/http.ml b/lib/http.ml index a8e6b22..8cc56fb 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -8,7 +8,6 @@ module Make(T : S.Token) = struct exception Invalid_Method let base_url = "https://discordapp.com/api/v7" - let cdn_url = "https://cdn.discordapp.com" let process_url path = Uri.of_string (base_url ^ path) diff --git a/lib/http.mli b/lib/http.mli new file mode 100644 index 0000000..caf2ad7 --- /dev/null +++ b/lib/http.mli @@ -0,0 +1 @@ +module Make(T: S.Token) : S.Http \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index 92259a0..454d2e7 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -27,5 +27,64 @@ module type Http = sig end (* TODO add abstraction sigs *) - val token : string +end + +module type Sharder = sig + exception Invalid_Payload + exception Failure_to_Establish_Heartbeat + + type t + + val start : + ?count:int -> + string -> + t Deferred.t + + val set_status : + status:Yojson.Basic.json -> + t -> + (Shard.shard Shard.t) list Deferred.t + + val set_status_with : + f:(Shard.shard -> Yojson.Basic.json) -> + t -> + (Shard.shard Shard.t) list Deferred.t + + val request_guild_members : + ?query:string -> + ?count:string -> + guild:Snowflake.t -> + t -> + (Shard.shard Shard.t) list Deferred.t + + module Shard : sig + type shard + type 'a t + + val bind : + f:('a -> unit) -> + 'a t -> + unit + + val heartbeat : + shard -> + shard Deferred.t + + val set_status : + status:Yojson.Basic.json -> + shard -> + shard Deferred.t + + val request_guild_members : + ?query:string -> + ?limit:int -> + guild:Snowflake.t + + val create : + url:string -> + shards:int * int -> + token:string -> + unit -> + t Deferred.t + end end \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml index 1fa97a0..0984050 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -104,7 +104,7 @@ module Make(H: S.Http) = struct let request_guild_members ~guild ?(query="") ?(limit=0) shard = let payload = `Assoc [ - ("guild_id", `String (string_of_int guild)); + ("guild_id", `String (Snowflake.to_string guild)); ("query", `String query); ("limit", `Int limit); ] in @@ -287,12 +287,12 @@ module Make(H: S.Http) = struct >>| fun shards -> { shards; } - let set_status sharder status = + let set_status ~status sharder = Deferred.all @@ List.map ~f:(fun t -> Shard.set_status ~status t.shard ) sharder.shards - let set_status_with sharder f = + let set_status_with ~f sharder = Deferred.all @@ List.map ~f:(fun t -> Shard.set_status ~status:(f t.shard) t.shard ) sharder.shards diff --git a/lib/sharder.mli b/lib/sharder.mli new file mode 100644 index 0000000..d872c8c --- /dev/null +++ b/lib/sharder.mli @@ -0,0 +1 @@ +module Make(H : S.Http) : S.Sharder \ No newline at end of file -- cgit v1.2.3 From eaccd45894e5b519bca82662d0b950b5f1d9c598 Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Thu, 29 Nov 2018 18:10:45 -0700 Subject: Fix all the errors from coding without merlin --- lib/client.ml | 8 +-- lib/http.ml | 9 ++- lib/http.mli | 2 +- lib/s.ml | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++------- lib/sharder.ml | 57 ++++++++------- 5 files changed, 226 insertions(+), 65 deletions(-) (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index 7adaae3..b27a2ee 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -2,7 +2,7 @@ open Async module Make(T : S.Token) = struct include T - + module Http = Http.Make(T) module Sharder = Sharder.Make(Http) @@ -20,7 +20,7 @@ module Make(T : S.Token) = struct } let start ?count client = - Sharder.start ?count client.token + Sharder.start ?count () >>| fun sharder -> Ivar.fill_if_empty client.sharder sharder; client @@ -28,12 +28,12 @@ module Make(T : S.Token) = struct let set_status ~status client = Ivar.read client.sharder >>= fun sharder -> - Sharder.set_status sharder status + Sharder.set_status ~status sharder let set_status_with ~f client = Ivar.read client.sharder >>= fun sharder -> - Sharder.set_status_with sharder f + Sharder.set_status_with ~f sharder let request_guild_members ~guild ?query ?limit client = Ivar.read client.sharder diff --git a/lib/http.ml b/lib/http.ml index 8cc56fb..6f14a22 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -1,7 +1,6 @@ -open Async -open Cohttp - module Make(T : S.Token) = struct + open Async + open Cohttp include T module Base = struct @@ -18,7 +17,7 @@ module Make(T : S.Token) = struct |> Cohttp_async.Body.of_string let process_request_headers () = - let h = Header.init () in + let h = Header.init () in Header.add_list h [ "User-Agent", "Dis.ml v0.1.0"; "Authorization", ("Bot " ^ token); @@ -26,7 +25,7 @@ module Make(T : S.Token) = struct ] (* TODO Finish processor *) - let process_response (_resp, body) = + let process_response ((_resp:Response.t), body) = body |> Cohttp_async.Body.to_string >>| Yojson.Basic.from_string let request ?(body=`Null) m path = diff --git a/lib/http.mli b/lib/http.mli index caf2ad7..858420a 100644 --- a/lib/http.mli +++ b/lib/http.mli @@ -1 +1 @@ -module Make(T: S.Token) : S.Http \ No newline at end of file +module Make(T : S.Token) : S.Http \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index 454d2e7..ce1bef7 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -6,6 +6,8 @@ module type Token = sig end module type Http = sig + val token : string + module Base : sig exception Invalid_Method @@ -13,20 +15,177 @@ module type Http = sig val process_url : string -> Uri.t val process_request_body : Yojson.Basic.json -> Cohttp_async.Body.t - val process_request_headers : unit -> Headers.t + val process_request_headers : unit -> Header.t val process_response : Cohttp_async.Response.t * Cohttp_async.Body.t -> - Yojson.Basic.json + Yojson.Basic.json Deferred.t val request : ?body:Yojson.Basic.json -> - [ `Delete | `Get | `Patch | `Post | `Put ] -> + [> `DELETE | `GET | `PATCH | `POST | `PUT ] -> string -> Yojson.Basic.json Deferred.t end - (* TODO add abstraction sigs *) + (* Auto-generated signatures *) + val get_gateway : unit -> Yojson.Basic.json Async.Deferred.t + val get_gateway_bot : unit -> Yojson.Basic.json Async.Deferred.t + val get_channel : string -> Yojson.Basic.json Async.Deferred.t + val modify_channel : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_channel : string -> Yojson.Basic.json Async.Deferred.t + val get_messages : string -> Yojson.Basic.json Async.Deferred.t + val get_message : string -> string -> Yojson.Basic.json Async.Deferred.t + val create_message : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val create_reaction : + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val delete_own_reaction : + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val delete_reaction : + string -> + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val get_reactions : + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val delete_reactions : + string -> string -> Yojson.Basic.json Async.Deferred.t + val edit_message : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_message : + string -> string -> Yojson.Basic.json Async.Deferred.t + val bulk_delete : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val edit_channel_permissions : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_channel_invites : string -> Yojson.Basic.json Async.Deferred.t + val create_channel_invite : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_channel_permission : + string -> string -> Yojson.Basic.json Async.Deferred.t + val broadcast_typing : string -> Yojson.Basic.json Async.Deferred.t + val get_pinned_messages : string -> Yojson.Basic.json Async.Deferred.t + val pin_message : string -> string -> Yojson.Basic.json Async.Deferred.t + val unpin_message : + string -> string -> Yojson.Basic.json Async.Deferred.t + val group_recipient_add : + string -> string -> Yojson.Basic.json Async.Deferred.t + val group_recipient_remove : + string -> string -> Yojson.Basic.json Async.Deferred.t + val get_emojis : string -> Yojson.Basic.json Async.Deferred.t + val get_emoji : string -> string -> Yojson.Basic.json Async.Deferred.t + val create_emoji : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val edit_emoji : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_emoji : string -> string -> Yojson.Basic.json Async.Deferred.t + val create_guild : + Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_guild : string -> Yojson.Basic.json Async.Deferred.t + val edit_guild : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_guild : string -> Yojson.Basic.json Async.Deferred.t + val get_guild_channels : string -> Yojson.Basic.json Async.Deferred.t + val create_guild_channel : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val modify_guild_channel_positions : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_member : string -> string -> Yojson.Basic.json Async.Deferred.t + val get_members : string -> Yojson.Basic.json Async.Deferred.t + val add_member : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val edit_member : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val remove_member : + string -> string -> Yojson.Basic.json Async.Deferred.t + val change_nickname : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val add_member_role : + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val remove_member_role : + string -> string -> string -> Yojson.Basic.json Async.Deferred.t + val get_bans : string -> Yojson.Basic.json Async.Deferred.t + val get_ban : string -> string -> Yojson.Basic.json Async.Deferred.t + val guild_ban_add : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val guild_ban_remove : + string -> string -> Yojson.Basic.json Async.Deferred.t + val get_roles : string -> Yojson.Basic.json Async.Deferred.t + val guild_role_add : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val guild_roles_edit : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val guild_role_edit : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val guild_role_remove : + string -> string -> Yojson.Basic.json Async.Deferred.t + val guild_prune_count : string -> Yojson.Basic.json Async.Deferred.t + val guild_prune_start : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_guild_voice_regions : + string -> Yojson.Basic.json Async.Deferred.t + val get_guild_invites : string -> Yojson.Basic.json Async.Deferred.t + val get_integrations : string -> Yojson.Basic.json Async.Deferred.t + val add_integration : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val edit_integration : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_integration : + string -> string -> Yojson.Basic.json Async.Deferred.t + val sync_integration : + string -> string -> Yojson.Basic.json Async.Deferred.t + val get_guild_embed : string -> Yojson.Basic.json Async.Deferred.t + val edit_guild_embed : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_vanity_url : string -> Yojson.Basic.json Async.Deferred.t + val get_invite : string -> Yojson.Basic.json Async.Deferred.t + val delete_invite : string -> Yojson.Basic.json Async.Deferred.t + val get_current_user : unit -> Yojson.Basic.json Async.Deferred.t + val edit_current_user : + Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_guilds : unit -> Yojson.Basic.json Async.Deferred.t + val leave_guild : string -> Yojson.Basic.json Async.Deferred.t + val get_private_channels : unit -> Yojson.Basic.json Async.Deferred.t + val create_dm : Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val create_group_dm : + Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_connections : unit -> Yojson.Basic.json Async.Deferred.t + val get_user : string -> Yojson.Basic.json Async.Deferred.t + val get_voice_regions : unit -> Yojson.Basic.json Async.Deferred.t + val create_webhook : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_channel_webhooks : string -> Yojson.Basic.json Async.Deferred.t + val get_guild_webhooks : string -> Yojson.Basic.json Async.Deferred.t + val get_webhook : string -> Yojson.Basic.json Async.Deferred.t + val get_webhook_with_token : + string -> string -> Yojson.Basic.json Async.Deferred.t + val edit_webhook : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val edit_webhook_with_token : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val delete_webhook : string -> Yojson.Basic.json Async.Deferred.t + val delete_webhook_with_token : + string -> string -> Yojson.Basic.json Async.Deferred.t + val execute_webhook : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val execute_slack_webhook : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val execute_git_webhook : + string -> + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + val get_audit_logs : + string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t end module type Sharder = sig @@ -37,29 +196,15 @@ module type Sharder = sig val start : ?count:int -> - string -> + unit -> t Deferred.t - val set_status : - status:Yojson.Basic.json -> - t -> - (Shard.shard Shard.t) list Deferred.t - - val set_status_with : - f:(Shard.shard -> Yojson.Basic.json) -> - t -> - (Shard.shard Shard.t) list Deferred.t - - val request_guild_members : - ?query:string -> - ?count:string -> - guild:Snowflake.t -> - t -> - (Shard.shard Shard.t) list Deferred.t - module Shard : sig type shard - type 'a t + type 'a t = { + mutable state: 'a; + mutable binds: ('a -> unit) list; + } val bind : f:('a -> unit) -> @@ -78,13 +223,31 @@ module type Sharder = sig val request_guild_members : ?query:string -> ?limit:int -> - guild:Snowflake.t + guild:Snowflake.t -> + shard -> + shard Deferred.t val create : url:string -> shards:int * int -> - token:string -> unit -> - t Deferred.t + shard Deferred.t end + + val set_status : + status:Yojson.Basic.json -> + t -> + Shard.shard list Deferred.t + + val set_status_with : + f:(Shard.shard -> Yojson.Basic.json) -> + t -> + Shard.shard list Deferred.t + + val request_guild_members : + ?query:string -> + ?limit:int -> + guild:Snowflake.t -> + t -> + Shard.shard list Deferred.t end \ No newline at end of file diff --git a/lib/sharder.ml b/lib/sharder.ml index 0984050..7b14884 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -1,8 +1,8 @@ -open Async -open Core -open Websocket_async - module Make(H: S.Http) = struct + open Async + open Core + open Websocket_async + exception Invalid_Payload exception Failure_to_Establish_Heartbeat @@ -20,7 +20,7 @@ module Make(H: S.Http) = struct } type 'a t = { - mutable shard: 'a; + mutable state: 'a; mutable binds: ('a -> unit) list; } @@ -75,7 +75,7 @@ module Make(H: S.Http) = struct session = session; } - let set_status ~status shard = + let set_status ~(status:Yojson.Basic.json) shard = let payload = match status with | `Assoc [("name", `String name); ("type", `Int t)] -> `Assoc [ @@ -102,7 +102,7 @@ module Make(H: S.Http) = struct Ivar.read shard.ready >>= fun _ -> push_frame ~payload ~ev:STATUS_UPDATE shard - let request_guild_members ~guild ?(query="") ?(limit=0) shard = + let request_guild_members ?(query="") ?(limit=0) ~guild shard = let payload = `Assoc [ ("guild_id", `String (Snowflake.to_string guild)); ("query", `String query); @@ -136,7 +136,7 @@ module Make(H: S.Http) = struct | None -> begin Mutex.lock identify_lock; let payload = `Assoc [ - ("token", `String shard.token); + ("token", `String token); ("properties", `Assoc [ ("$os", `String Sys.os_type); ("$device", `String "dis.ml"); @@ -155,7 +155,7 @@ module Make(H: S.Http) = struct end | Some s -> let payload = `Assoc [ - ("token", `String shard.token); + ("token", `String token); ("session_id", `String s); ("seq", `Int shard.seq) ] in @@ -183,7 +183,7 @@ module Make(H: S.Http) = struct print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; return shard - let rec create ~url ~shards ~token () = + let rec create ~url ~shards () = let open Core in let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in let extra_headers = H.Base.process_request_headers () in @@ -215,7 +215,6 @@ module Make(H: S.Http) = struct seq = 0; id = shards; session = None; - token; url; } in @@ -240,46 +239,46 @@ module Make(H: S.Http) = struct | Some hb -> Ivar.fill_if_empty hb () | None -> () ); - create ~url:(shard.url) ~shards:(shard.id) ~token:(shard.token) () + create ~url:(shard.url) ~shards:(shard.id) () end type t = { shards: (Shard.shard Shard.t) list; } - let start ?count token = + let start ?count () = let module J = Yojson.Basic.Util in - Http.get_gateway_bot () >>= fun data -> + H.get_gateway_bot () >>= fun data -> let url = J.(member "url" data |> to_string) in let count = match count with | Some c -> c | None -> J.(member "shards" data |> to_int) in let shard_list = (0, count) in - let rec ev_loop t = - let (read, _) = t.shard.pipe in + let rec ev_loop (t:Shard.shard Shard.t) = + let (read, _) = t.state.pipe in Pipe.read read - >>| fun frame -> - let _ = match parse frame with + >>= fun frame -> + let _ = match Shard.parse frame with | Some f -> begin - handle_frame ~f t.shard + Shard.handle_frame ~f t.state >>> fun shard -> - t.shard <- shard; + t.state <- shard; end - | None -> t.shard <- recreate t.shard; + | None -> Shard.recreate t.state >>> fun s -> t.state <- s; in - t + return t >>= fun t -> - List.iter ~f:(fun f -> f t.shard) t.binds; + List.iter ~f:(fun f -> f t.state) t.binds; ev_loop t in let rec gen_shards l a = match l with | (id, total) when id >= total -> return a | (id, total) -> - Shard.create ~url ~shards:(id, total) ~token () + Shard.create ~url ~shards:(id, total) () >>= fun shard -> - let t = { shard; binds = []; } in + let t = Shard.{ state = shard; binds = []; } in ev_loop t >>> ignore; gen_shards (id+1, total) (t :: a) in @@ -289,16 +288,16 @@ module Make(H: S.Http) = struct let set_status ~status sharder = Deferred.all @@ List.map ~f:(fun t -> - Shard.set_status ~status t.shard + Shard.set_status ~status t.state ) sharder.shards let set_status_with ~f sharder = Deferred.all @@ List.map ~f:(fun t -> - Shard.set_status ~status:(f t.shard) t.shard + Shard.set_status ~status:(f t.state) t.state ) sharder.shards - let request_guild_members ~guild ?query ?limit sharder = + let request_guild_members ?query ?limit ~guild sharder = Deferred.all @@ List.map ~f:(fun t -> - Shard.request_guild_members ~guild ?query ?limit t.shard + Shard.request_guild_members ~guild ?query ?limit t.state ) sharder.shards end \ No newline at end of file -- cgit v1.2.3 From 38a968c585f87736397fd5b576c51f7dbe5d393a Mon Sep 17 00:00:00 2001 From: Mishio595 Date: Fri, 30 Nov 2018 07:41:33 -0700 Subject: some improvements --- lib/sharder.ml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 7b14884..8e8c1f9 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -183,7 +183,7 @@ module Make(H: S.Http) = struct print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; return shard - let rec create ~url ~shards () = + let create ~url ~shards () = let open Core in let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in let extra_headers = H.Base.process_request_headers () in @@ -233,7 +233,8 @@ module Make(H: S.Http) = struct `TCP (h, p) in Conduit_async.V2.connect addr >>= tcp_fun - and recreate shard = + + let recreate shard = print_endline "Reconnecting..."; (match shard.hb with | Some hb -> Ivar.fill_if_empty hb () @@ -259,14 +260,14 @@ module Make(H: S.Http) = struct let (read, _) = t.state.pipe in Pipe.read read >>= fun frame -> - let _ = match Shard.parse frame with + (match Shard.parse frame with | Some f -> begin Shard.handle_frame ~f t.state >>> fun shard -> t.state <- shard; end | None -> Shard.recreate t.state >>> fun s -> t.state <- s; - in + ); return t >>= fun t -> List.iter ~f:(fun f -> f t.state) t.binds; -- cgit v1.2.3 From dd14dca65cc468d9bd7a537f2d9a0e07e53b7f07 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Fri, 30 Nov 2018 10:21:51 -0700 Subject: Fix the multiple reconnect issue --- lib/sharder.ml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 8e8c1f9..9b64bba 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -50,7 +50,7 @@ module Make(H: S.Http) = struct ] in let (_, write) = shard.pipe in - Pipe.write_if_open write @@ Frame.create ~content () + Pipe.write write @@ Frame.create ~content () >>| fun () -> shard @@ -118,13 +118,19 @@ module Make(H: S.Http) = struct match data with | Some data -> let hb_interval = J.(member "heartbeat_interval" data |> to_int) in - let finished = Ivar.create () in + let stop_hb = Ivar.create () in + let stopper i = + Ivar.read stop_hb + >>> fun () -> + Ivar.fill_if_empty i; + in + let stop = Deferred.create stopper in Clock.every' ~continue_on_error:true - ~finished + ~stop (Core.Time.Span.create ~ms:hb_interval ()) (fun () -> heartbeat shard >>= fun _ -> return ()); - finished + stop_hb | None -> raise Failure_to_Establish_Heartbeat end | Some s -> s @@ -263,12 +269,12 @@ module Make(H: S.Http) = struct (match Shard.parse frame with | Some f -> begin Shard.handle_frame ~f t.state - >>> fun shard -> - t.state <- shard; + >>| fun s -> (t.state <- s; t) end - | None -> Shard.recreate t.state >>> fun s -> t.state <- s; - ); - return t + | None -> begin + Shard.recreate t.state + >>| fun s -> (t.state <- s; t) + end) >>= fun t -> List.iter ~f:(fun f -> f t.state) t.binds; ev_loop t -- cgit v1.2.3 From d9fb404c8345cb71583f1fdc6988ad63de3002f2 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Mon, 3 Dec 2018 15:57:58 -0700 Subject: Add retry on connect fail logic --- lib/sharder.ml | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index 9b64bba..1c26d8c 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -122,7 +122,7 @@ module Make(H: S.Http) = struct let stopper i = Ivar.read stop_hb >>> fun () -> - Ivar.fill_if_empty i; + Ivar.fill_if_empty i () in let stop = Deferred.create stopper in Clock.every' @@ -189,6 +189,38 @@ module Make(H: S.Http) = struct print_endline @@ "Invalid Opcode: " ^ Opcode.to_string opcode; return shard + let rec make_client + ~initialized + ~extra_headers + ~app_to_ws + ~ws_to_app + ~net_to_ws + ~ws_to_net + uri = + client + ~initialized + ~extra_headers + ~app_to_ws + ~ws_to_app + ~net_to_ws + ~ws_to_net + uri + >>> fun res -> + match res with + | Ok () -> () + | Error _ -> + let backoff = Time.Span.create ~ms:500 () in + Clock.after backoff >>> (fun () -> + make_client + ~initialized + ~extra_headers + ~app_to_ws + ~ws_to_app + ~net_to_ws + ~ws_to_net + uri) + + let create ~url ~shards () = let open Core in let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in @@ -204,15 +236,14 @@ module Make(H: S.Http) = struct let (app_to_ws, write) = Pipe.create () in let (read, ws_to_app) = Pipe.create () in let initialized = Ivar.create () in - client + make_client ~initialized ~extra_headers ~app_to_ws ~ws_to_app ~net_to_ws ~ws_to_net - uri - >>> ignore; (* TODO this needs to error check and retry with backoff *) + uri; Ivar.read initialized >>| fun () -> { pipe = (read, write); -- cgit v1.2.3 From 260ccd9960b852b9c69b88e9840d5a8b22bb8e1d Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Wed, 12 Dec 2018 15:00:46 -0700 Subject: Work on event dispatch and add model derives --- lib/dispatch.ml | 121 ++++++++++++++++++--------- lib/http.ml | 4 +- lib/models/activity.ml | 5 +- lib/models/attachment.ml | 2 +- lib/models/ban.ml | 2 +- lib/models/channel.ml | 2 +- lib/models/embed.ml | 12 +-- lib/models/emoji.ml | 2 +- lib/models/guild.ml | 2 +- lib/models/member.ml | 2 +- lib/models/message.ml | 2 +- lib/models/presence.ml | 2 +- lib/models/reaction.ml | 2 +- lib/models/role.ml | 2 +- lib/models/snowflake.ml | 2 +- lib/models/user.ml | 2 +- lib/s.ml | 212 +++++++++++++++++++++++++---------------------- lib/sharder.ml | 14 ++-- 18 files changed, 226 insertions(+), 166 deletions(-) (limited to 'lib') diff --git a/lib/dispatch.ml b/lib/dispatch.ml index 43ffe1f..c75dc26 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -1,38 +1,85 @@ -(* open Async *) +open Core -type dispatch_event = -| HELLO of Yojson.Basic.json -| READY of Yojson.Basic.json -| RESUMED of Yojson.Basic.json -| INVALID_SESSION of Yojson.Basic.json -| CHANNEL_CREATE of Channel.t -| CHANNEL_UPDATE of Channel.t -| CHANNEL_DELETE of Channel.t -| CHANNEL_PINS_UPDATE of Yojson.Basic.json -| GUILD_CREATE of Guild.t -| GUILD_UPDATE of Guild.t -| GUILD_DELETE of Guild.t -| GUILD_BAN_ADD of Ban.t -| GUILD_BAN_REMOVE of Ban.t -| GUILD_EMOJIS_UPDATE of Yojson.Basic.json -| GUILD_INTEGRATIONS_UPDATE of Yojson.Basic.json -| GUILD_MEMBER_ADD of Member.t -| GUILD_MEMBER_REMOVE of Member.t -| GUILD_MEMBER_UPDATE of Member.t -| GUILD_MEMBERS_CHUNK of Member.t list -| GUILD_ROLE_CREATE of Role.t * Guild.t -| GUILD_ROLE_UPDATE of Role.t * Guild.t -| GUILD_ROLE_DELETE of Role.t * Guild.t -| MESSAGE_CREATE of Message.t -| MESSAGE_UPDATE of Message.t -| MESSAGE_DELETE of Message.t -| MESSAGE_BULK_DELETE of Message.t list -| MESSAGE_REACTION_ADD of Message.t * Reaction.t -| MESSAGE_REACTION_REMOVE of Message.t * Reaction.t -| MESSAGE_REACTION_REMOVE_ALL of Message.t * Reaction.t list -| PRESENCE_UPDATE of Presence.t -| TYPING_START of Yojson.Basic.json -| USER_UPDATE of Yojson.Basic.json -| VOICE_STATE_UPDATE of Yojson.Basic.json -| VOICE_SERVER_UPDATE of Yojson.Basic.json -| WEBHOOKS_UPDATE of Yojson.Basic.json +module Make(H : S.Handler) = struct + type dispatch_event = + | HELLO of Yojson.Safe.json + | READY of Yojson.Safe.json + | RESUMED of Yojson.Safe.json + | INVALID_SESSION of Yojson.Safe.json + | CHANNEL_CREATE of Channel.t + | CHANNEL_UPDATE of Channel.t + | CHANNEL_DELETE of Channel.t + | CHANNEL_PINS_UPDATE of Yojson.Safe.json + | GUILD_CREATE of Guild.t + | GUILD_UPDATE of Guild.t + | GUILD_DELETE of Guild.t + | GUILD_BAN_ADD of Ban.t + | GUILD_BAN_REMOVE of Ban.t + | GUILD_EMOJIS_UPDATE of Yojson.Safe.json + | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json + | GUILD_MEMBER_ADD of Member.t + | GUILD_MEMBER_REMOVE of Member.t + | GUILD_MEMBER_UPDATE of Member.t + | GUILD_MEMBERS_CHUNK of Member.t list + | GUILD_ROLE_CREATE of Role.t (* * Guild.t *) + | GUILD_ROLE_UPDATE of Role.t (* * Guild.t *) + | GUILD_ROLE_DELETE of Role.t (* * Guild.t *) + | MESSAGE_CREATE of Message.t + | MESSAGE_UPDATE of Message.t + | MESSAGE_DELETE of Message.t + | MESSAGE_BULK_DELETE of Message.t list + | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction.t + | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction.t + | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction.t list + | PRESENCE_UPDATE of Presence.t + | TYPING_START of Yojson.Safe.json + | USER_UPDATE of Yojson.Safe.json + | VOICE_STATE_UPDATE of Yojson.Safe.json + | VOICE_SERVER_UPDATE of Yojson.Safe.json + | WEBHOOKS_UPDATE of Yojson.Safe.json + + exception Invalid_event of string + + let event_of_string ~contents t = match t with + | "HELLO" -> HELLO contents + | "READY" -> READY contents + | "RESUMED" -> RESUMED contents + | "INVALID_SESSION" -> INVALID_SESSION contents + | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel.of_yojson_exn contents) + | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel.of_yojson_exn contents) + | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel.of_yojson_exn contents) + | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE contents + | "GUILD_CREATE" -> GUILD_CREATE (Guild.of_yojson_exn contents) + | "GUILD_UPDATE" -> GUILD_UPDATE (Guild.of_yojson_exn contents) + | "GUILD_DELETE" -> GUILD_DELETE (Guild.of_yojson_exn contents) + | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban.of_yojson_exn contents) + | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban.of_yojson_exn contents) + | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE contents + | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE contents + | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member.of_yojson_exn contents) + | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member.of_yojson_exn contents) + | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member.of_yojson_exn contents) + | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Member.of_yojson_exn m)) + | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role.of_yojson_exn contents) + | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role.of_yojson_exn contents) + | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role.of_yojson_exn contents) + | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message.of_yojson_exn contents) + | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message.of_yojson_exn contents) + | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message.of_yojson_exn contents) + | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Message.of_yojson_exn m)) + | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction.of_yojson_exn contents) + | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction.of_yojson_exn contents) + | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun r -> Reaction.of_yojson_exn r)) + | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence.of_yojson_exn contents) + | "TYPING_START" -> TYPING_START contents + | "USER_UPDATE" -> USER_UPDATE contents + | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE contents + | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE contents + | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE contents + | s -> raise (Invalid_event s) + + let dispatch ~ev contents = + let ctx = () in + event_of_string ~contents ev + |> H.handle_event ctx +end \ No newline at end of file diff --git a/lib/http.ml b/lib/http.ml index 6f14a22..3e10eb8 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -13,7 +13,7 @@ module Make(T : S.Token) = struct let process_request_body body = body - |> Yojson.Basic.to_string + |> Yojson.Safe.to_string |> Cohttp_async.Body.of_string let process_request_headers () = @@ -26,7 +26,7 @@ module Make(T : S.Token) = struct (* TODO Finish processor *) let process_response ((_resp:Response.t), body) = - body |> Cohttp_async.Body.to_string >>| Yojson.Basic.from_string + body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string let request ?(body=`Null) m path = let uri = process_url path in diff --git a/lib/models/activity.ml b/lib/models/activity.ml index eb6679e..80f1049 100644 --- a/lib/models/activity.ml +++ b/lib/models/activity.ml @@ -1 +1,4 @@ -type t \ No newline at end of file +type t = { + id: Snowflake.t; +} +[@@deriving yojson] \ No newline at end of file diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml index 095743d..595aa45 100644 --- a/lib/models/attachment.ml +++ b/lib/models/attachment.ml @@ -6,4 +6,4 @@ type t = { proxy_url: string; height: int option; width: int option; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/ban.ml b/lib/models/ban.ml index 510c2f5..ff0fb67 100644 --- a/lib/models/ban.ml +++ b/lib/models/ban.ml @@ -1,4 +1,4 @@ type t = { id: Snowflake.t; user: User.t; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/channel.ml b/lib/models/channel.ml index 78051c3..ac3e596 100644 --- a/lib/models/channel.ml +++ b/lib/models/channel.ml @@ -14,4 +14,4 @@ type t = { owner_id: Snowflake.t option; application_id: Snowflake.t option; parent_id: Snowflake.t option; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/embed.ml b/lib/models/embed.ml index 6ba1115..b4dc143 100644 --- a/lib/models/embed.ml +++ b/lib/models/embed.ml @@ -2,31 +2,31 @@ type footer = { text: string; icon_url: string option; proxy_icon_url: string option; -} +} [@@deriving yojson] type image = { url: string option; proxy_url: string option; height: int option; width: int option; -} +} [@@deriving yojson] type video = { url: string option; height: int option; width: int option; -} +} [@@deriving yojson] type provider = { name: string option; url: string option; -} +} [@@deriving yojson] type field = { name: string; value: string; inline: bool option; -} +} [@@deriving yojson] type t = { title: string option; @@ -41,4 +41,4 @@ type t = { video: video option; provider: provider option; fields: (field list) option; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml index 3d89867..cfbfe64 100644 --- a/lib/models/emoji.ml +++ b/lib/models/emoji.ml @@ -6,4 +6,4 @@ type t = { require_colons: bool option; managed: bool; animated: bool; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/guild.ml b/lib/models/guild.ml index 364a4d5..5f5855b 100644 --- a/lib/models/guild.ml +++ b/lib/models/guild.ml @@ -25,4 +25,4 @@ type t = { member_count: int; members: Member.t list; channels: Channel.t list; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/member.ml b/lib/models/member.ml index 1cbe50b..4621902 100644 --- a/lib/models/member.ml +++ b/lib/models/member.ml @@ -5,4 +5,4 @@ type t = { joined_at: string; deaf: bool; mute: bool; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/message.ml b/lib/models/message.ml index 6c2e80d..c578d9f 100644 --- a/lib/models/message.ml +++ b/lib/models/message.ml @@ -18,4 +18,4 @@ type t = { pinned: bool; webhook_id: Snowflake.t; kind: int; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/presence.ml b/lib/models/presence.ml index 7243f43..ed1bdb6 100644 --- a/lib/models/presence.ml +++ b/lib/models/presence.ml @@ -5,4 +5,4 @@ type t = { guild: Guild.t; status: string; activities: Activity.t list; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml index b427505..00bebe6 100644 --- a/lib/models/reaction.ml +++ b/lib/models/reaction.ml @@ -1,4 +1,4 @@ type t = { count: int; emoji: Emoji.t; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/role.ml b/lib/models/role.ml index debba60..0577342 100644 --- a/lib/models/role.ml +++ b/lib/models/role.ml @@ -7,4 +7,4 @@ type t = { permissions: int; managed: bool; mentionable: bool; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index ed80b62..ab723a7 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,7 +1,7 @@ type t = { id: int; as_string: string; -} +} [@@deriving yojson] let to_int t = t.id let to_string t = t.as_string diff --git a/lib/models/user.ml b/lib/models/user.ml index 05cf570..e6c5c69 100644 --- a/lib/models/user.ml +++ b/lib/models/user.ml @@ -4,4 +4,4 @@ type t = { discriminator: string; avatar: string; bot: bool; -} \ No newline at end of file +} [@@deriving yojson] \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index ce1bef7..eec72e1 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -1,10 +1,20 @@ open Async -open Cohttp module type Token = sig val token : string end +module type Client = sig + type context +end + +module type Handler = sig + val handle_event : + 'a -> + 'b -> + unit +end + module type Http = sig val token : string @@ -14,178 +24,178 @@ module type Http = sig val base_url : string val process_url : string -> Uri.t - val process_request_body : Yojson.Basic.json -> Cohttp_async.Body.t - val process_request_headers : unit -> Header.t + val process_request_body : Yojson.Safe.json -> Cohttp_async.Body.t + val process_request_headers : unit -> Cohttp.Header.t val process_response : Cohttp_async.Response.t * Cohttp_async.Body.t -> - Yojson.Basic.json Deferred.t + Yojson.Safe.json Deferred.t val request : - ?body:Yojson.Basic.json -> + ?body:Yojson.Safe.json -> [> `DELETE | `GET | `PATCH | `POST | `PUT ] -> string -> - Yojson.Basic.json Deferred.t + Yojson.Safe.json Deferred.t end (* Auto-generated signatures *) - val get_gateway : unit -> Yojson.Basic.json Async.Deferred.t - val get_gateway_bot : unit -> Yojson.Basic.json Async.Deferred.t - val get_channel : string -> Yojson.Basic.json Async.Deferred.t + val get_gateway : unit -> Yojson.Safe.json Async.Deferred.t + val get_gateway_bot : unit -> Yojson.Safe.json Async.Deferred.t + val get_channel : string -> Yojson.Safe.json Async.Deferred.t val modify_channel : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val delete_channel : string -> Yojson.Basic.json Async.Deferred.t - val get_messages : string -> Yojson.Basic.json Async.Deferred.t - val get_message : string -> string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val delete_channel : string -> Yojson.Safe.json Async.Deferred.t + val get_messages : string -> Yojson.Safe.json Async.Deferred.t + val get_message : string -> string -> Yojson.Safe.json Async.Deferred.t val create_message : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val create_reaction : - string -> string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t val delete_own_reaction : - string -> string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t val delete_reaction : string -> - string -> string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t val get_reactions : - string -> string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t val delete_reactions : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val edit_message : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val delete_message : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val bulk_delete : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val edit_channel_permissions : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_channel_invites : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_channel_invites : string -> Yojson.Safe.json Async.Deferred.t val create_channel_invite : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val delete_channel_permission : - string -> string -> Yojson.Basic.json Async.Deferred.t - val broadcast_typing : string -> Yojson.Basic.json Async.Deferred.t - val get_pinned_messages : string -> Yojson.Basic.json Async.Deferred.t - val pin_message : string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t + val broadcast_typing : string -> Yojson.Safe.json Async.Deferred.t + val get_pinned_messages : string -> Yojson.Safe.json Async.Deferred.t + val pin_message : string -> string -> Yojson.Safe.json Async.Deferred.t val unpin_message : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val group_recipient_add : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val group_recipient_remove : - string -> string -> Yojson.Basic.json Async.Deferred.t - val get_emojis : string -> Yojson.Basic.json Async.Deferred.t - val get_emoji : string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t + val get_emojis : string -> Yojson.Safe.json Async.Deferred.t + val get_emoji : string -> string -> Yojson.Safe.json Async.Deferred.t val create_emoji : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val edit_emoji : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val delete_emoji : string -> string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val delete_emoji : string -> string -> Yojson.Safe.json Async.Deferred.t val create_guild : - Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_guild : string -> Yojson.Basic.json Async.Deferred.t + Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_guild : string -> Yojson.Safe.json Async.Deferred.t val edit_guild : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val delete_guild : string -> Yojson.Basic.json Async.Deferred.t - val get_guild_channels : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val delete_guild : string -> Yojson.Safe.json Async.Deferred.t + val get_guild_channels : string -> Yojson.Safe.json Async.Deferred.t val create_guild_channel : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val modify_guild_channel_positions : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_member : string -> string -> Yojson.Basic.json Async.Deferred.t - val get_members : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_member : string -> string -> Yojson.Safe.json Async.Deferred.t + val get_members : string -> Yojson.Safe.json Async.Deferred.t val add_member : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val edit_member : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val remove_member : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val change_nickname : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val add_member_role : - string -> string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t val remove_member_role : - string -> string -> string -> Yojson.Basic.json Async.Deferred.t - val get_bans : string -> Yojson.Basic.json Async.Deferred.t - val get_ban : string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> string -> Yojson.Safe.json Async.Deferred.t + val get_bans : string -> Yojson.Safe.json Async.Deferred.t + val get_ban : string -> string -> Yojson.Safe.json Async.Deferred.t val guild_ban_add : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val guild_ban_remove : - string -> string -> Yojson.Basic.json Async.Deferred.t - val get_roles : string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t + val get_roles : string -> Yojson.Safe.json Async.Deferred.t val guild_role_add : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val guild_roles_edit : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val guild_role_edit : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val guild_role_remove : - string -> string -> Yojson.Basic.json Async.Deferred.t - val guild_prune_count : string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t + val guild_prune_count : string -> Yojson.Safe.json Async.Deferred.t val guild_prune_start : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val get_guild_voice_regions : - string -> Yojson.Basic.json Async.Deferred.t - val get_guild_invites : string -> Yojson.Basic.json Async.Deferred.t - val get_integrations : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json Async.Deferred.t + val get_guild_invites : string -> Yojson.Safe.json Async.Deferred.t + val get_integrations : string -> Yojson.Safe.json Async.Deferred.t val add_integration : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val edit_integration : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val delete_integration : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val sync_integration : - string -> string -> Yojson.Basic.json Async.Deferred.t - val get_guild_embed : string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t + val get_guild_embed : string -> Yojson.Safe.json Async.Deferred.t val edit_guild_embed : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_vanity_url : string -> Yojson.Basic.json Async.Deferred.t - val get_invite : string -> Yojson.Basic.json Async.Deferred.t - val delete_invite : string -> Yojson.Basic.json Async.Deferred.t - val get_current_user : unit -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_vanity_url : string -> Yojson.Safe.json Async.Deferred.t + val get_invite : string -> Yojson.Safe.json Async.Deferred.t + val delete_invite : string -> Yojson.Safe.json Async.Deferred.t + val get_current_user : unit -> Yojson.Safe.json Async.Deferred.t val edit_current_user : - Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_guilds : unit -> Yojson.Basic.json Async.Deferred.t - val leave_guild : string -> Yojson.Basic.json Async.Deferred.t - val get_private_channels : unit -> Yojson.Basic.json Async.Deferred.t - val create_dm : Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_guilds : unit -> Yojson.Safe.json Async.Deferred.t + val leave_guild : string -> Yojson.Safe.json Async.Deferred.t + val get_private_channels : unit -> Yojson.Safe.json Async.Deferred.t + val create_dm : Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val create_group_dm : - Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_connections : unit -> Yojson.Basic.json Async.Deferred.t - val get_user : string -> Yojson.Basic.json Async.Deferred.t - val get_voice_regions : unit -> Yojson.Basic.json Async.Deferred.t + Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_connections : unit -> Yojson.Safe.json Async.Deferred.t + val get_user : string -> Yojson.Safe.json Async.Deferred.t + val get_voice_regions : unit -> Yojson.Safe.json Async.Deferred.t val create_webhook : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val get_channel_webhooks : string -> Yojson.Basic.json Async.Deferred.t - val get_guild_webhooks : string -> Yojson.Basic.json Async.Deferred.t - val get_webhook : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val get_channel_webhooks : string -> Yojson.Safe.json Async.Deferred.t + val get_guild_webhooks : string -> Yojson.Safe.json Async.Deferred.t + val get_webhook : string -> Yojson.Safe.json Async.Deferred.t val get_webhook_with_token : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val edit_webhook : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val edit_webhook_with_token : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t - val delete_webhook : string -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + val delete_webhook : string -> Yojson.Safe.json Async.Deferred.t val delete_webhook_with_token : - string -> string -> Yojson.Basic.json Async.Deferred.t + string -> string -> Yojson.Safe.json Async.Deferred.t val execute_webhook : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val execute_slack_webhook : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val execute_git_webhook : string -> - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t val get_audit_logs : - string -> Yojson.Basic.json -> Yojson.Basic.json Async.Deferred.t + string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t end module type Sharder = sig @@ -216,7 +226,7 @@ module type Sharder = sig shard Deferred.t val set_status : - status:Yojson.Basic.json -> + status:Yojson.Safe.json -> shard -> shard Deferred.t @@ -235,12 +245,12 @@ module type Sharder = sig end val set_status : - status:Yojson.Basic.json -> + status:Yojson.Safe.json -> t -> Shard.shard list Deferred.t val set_status_with : - f:(Shard.shard -> Yojson.Basic.json) -> + f:(Shard.shard -> Yojson.Safe.json) -> t -> Shard.shard list Deferred.t diff --git a/lib/sharder.ml b/lib/sharder.ml index 1c26d8c..b1f5d62 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -34,7 +34,7 @@ module Make(H: S.Http) = struct | `Ok s -> begin let open Frame.Opcode in match s.opcode with - | Text -> Some (Yojson.Basic.from_string s.content) + | Text -> Some (Yojson.Safe.from_string s.content) | _ -> None end | `Eof -> None @@ -44,7 +44,7 @@ module Make(H: S.Http) = struct let content = match payload with | None -> "" | Some p -> - Yojson.Basic.to_string @@ `Assoc [ + Yojson.Safe.to_string @@ `Assoc [ ("op", `Int (Opcode.to_int ev)); ("d", p); ] @@ -62,7 +62,7 @@ module Make(H: S.Http) = struct push_frame ~payload ~ev:HEARTBEAT shard let dispatch ~payload shard = - let module J = Yojson.Basic.Util in + let module J = Yojson.Safe.Util in let seq = J.(member "s" payload |> to_int) in let t = J.(member "t" payload |> to_string) in let data = J.member "d" payload in @@ -75,7 +75,7 @@ module Make(H: S.Http) = struct session = session; } - let set_status ~(status:Yojson.Basic.json) shard = + let set_status ~(status:Yojson.Safe.json) shard = let payload = match status with | `Assoc [("name", `String name); ("type", `Int t)] -> `Assoc [ @@ -112,7 +112,7 @@ module Make(H: S.Http) = struct push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard let initialize ?data shard = - let module J = Yojson.Basic.Util in + let module J = Yojson.Safe.Util in let hb = match shard.hb with | None -> begin match data with @@ -168,7 +168,7 @@ module Make(H: S.Http) = struct push_frame ~payload ~ev:RESUME shard let handle_frame ~f shard = - let module J = Yojson.Basic.Util in + let module J = Yojson.Safe.Util in let op = J.(member "op" f |> to_int) |> Opcode.from_int in @@ -285,7 +285,7 @@ module Make(H: S.Http) = struct } let start ?count () = - let module J = Yojson.Basic.Util in + let module J = Yojson.Safe.Util in H.get_gateway_bot () >>= fun data -> let url = J.(member "url" data |> to_string) in let count = match count with -- cgit v1.2.3 From c046760eb599e42226c683aecbe33753dfc4d500 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Wed, 12 Dec 2018 15:23:14 -0700 Subject: Complete event dispatch --- lib/client.ml | 9 ++++----- lib/dispatch.ml | 2 +- lib/s.ml | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/sharder.ml | 5 +++-- lib/sharder.mli | 2 +- 5 files changed, 53 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index b27a2ee..018f3e6 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -1,21 +1,20 @@ open Async -module Make(T : S.Token) = struct +module Make(T : S.Token)(H : S.Handler) = struct include T module Http = Http.Make(T) - module Sharder = Sharder.Make(Http) + module Dispatch = Dispatch.Make(H) + module Sharder = Sharder.Make(Http)(Dispatch) type t = { sharder: Sharder.t Ivar.t; - handler: string Pipe.Writer.t; token: string; } - let init ~handler () = + let init () = { sharder = Ivar.create (); - handler; token; } diff --git a/lib/dispatch.ml b/lib/dispatch.ml index c75dc26..65c84ef 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -1,6 +1,6 @@ open Core -module Make(H : S.Handler) = struct +module Make(H : S.Handler) : S.Dispatch = struct type dispatch_event = | HELLO of Yojson.Safe.json | READY of Yojson.Safe.json diff --git a/lib/s.ml b/lib/s.ml index eec72e1..95eaee3 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -15,6 +15,50 @@ module type Handler = sig unit end +module type Dispatch = sig + type dispatch_event = + | HELLO of Yojson.Safe.json + | READY of Yojson.Safe.json + | RESUMED of Yojson.Safe.json + | INVALID_SESSION of Yojson.Safe.json + | CHANNEL_CREATE of Channel.t + | CHANNEL_UPDATE of Channel.t + | CHANNEL_DELETE of Channel.t + | CHANNEL_PINS_UPDATE of Yojson.Safe.json + | GUILD_CREATE of Guild.t + | GUILD_UPDATE of Guild.t + | GUILD_DELETE of Guild.t + | GUILD_BAN_ADD of Ban.t + | GUILD_BAN_REMOVE of Ban.t + | GUILD_EMOJIS_UPDATE of Yojson.Safe.json + | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json + | GUILD_MEMBER_ADD of Member.t + | GUILD_MEMBER_REMOVE of Member.t + | GUILD_MEMBER_UPDATE of Member.t + | GUILD_MEMBERS_CHUNK of Member.t list + | GUILD_ROLE_CREATE of Role.t (* * Guild.t *) + | GUILD_ROLE_UPDATE of Role.t (* * Guild.t *) + | GUILD_ROLE_DELETE of Role.t (* * Guild.t *) + | MESSAGE_CREATE of Message.t + | MESSAGE_UPDATE of Message.t + | MESSAGE_DELETE of Message.t + | MESSAGE_BULK_DELETE of Message.t list + | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction.t + | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction.t + | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction.t list + | PRESENCE_UPDATE of Presence.t + | TYPING_START of Yojson.Safe.json + | USER_UPDATE of Yojson.Safe.json + | VOICE_STATE_UPDATE of Yojson.Safe.json + | VOICE_SERVER_UPDATE of Yojson.Safe.json + | WEBHOOKS_UPDATE of Yojson.Safe.json + + exception Invalid_event of string + + val event_of_string : contents:Yojson.Safe.json -> string -> dispatch_event + val dispatch : ev:string -> Yojson.Safe.json -> unit +end + module type Http = sig val token : string diff --git a/lib/sharder.ml b/lib/sharder.ml index b1f5d62..e28a306 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -1,4 +1,4 @@ -module Make(H: S.Http) = struct +module Make(H: S.Http)(D : S.Dispatch) = struct open Async open Core open Websocket_async @@ -68,8 +68,9 @@ module Make(H: S.Http) = struct let data = J.member "d" payload in let session = J.(member "session_id" data |> to_string_option) in if t = "READY" then begin - Ivar.fill_if_empty shard.ready (); + Ivar.fill_if_empty shard.ready () end; + D.dispatch ~ev:t data; return { shard with seq = seq; session = session; diff --git a/lib/sharder.mli b/lib/sharder.mli index d872c8c..8d04c8d 100644 --- a/lib/sharder.mli +++ b/lib/sharder.mli @@ -1 +1 @@ -module Make(H : S.Http) : S.Sharder \ No newline at end of file +module Make(H : S.Http)(D : S.Dispatch) : S.Sharder \ No newline at end of file -- cgit v1.2.3 From 31fe810ad9679df6a5f83071717c94315058bfd4 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Wed, 12 Dec 2018 15:54:59 -0700 Subject: Fix Sharder.Make sig --- lib/sharder.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sharder.ml b/lib/sharder.ml index e28a306..6ac8584 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -1,4 +1,4 @@ -module Make(H: S.Http)(D : S.Dispatch) = struct +module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct open Async open Core open Websocket_async -- cgit v1.2.3 From c848b9cc265f5ac2bcc70bd73e1cc8945d512e34 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 13 Dec 2018 14:11:23 -0700 Subject: Add rate limit handling --- lib/http.ml | 42 +++++++++++++++++++++++++++++------------- lib/rl.ml | 29 +++++++++++++++++++++++++++++ lib/s.ml | 55 ++++++++++++++++++++++++++++--------------------------- 3 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 lib/rl.ml (limited to 'lib') diff --git a/lib/http.ml b/lib/http.ml index 3e10eb8..d2dff65 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -5,6 +5,9 @@ module Make(T : S.Token) = struct module Base = struct exception Invalid_Method + exception Bad_response_headers + + let rl = ref Rl.empty let base_url = "https://discordapp.com/api/v7" @@ -24,22 +27,35 @@ module Make(T : S.Token) = struct "Content-Type", "application/json"; ] - (* TODO Finish processor *) - let process_response ((_resp:Response.t), body) = + let process_response path ((resp:Response.t), body) = + (match Response.headers resp + |> Rl.rl_of_header with + | Some r -> Mvar.put (Rl.find_exn !rl path) r + | None -> raise Bad_response_headers) + >>= fun () -> body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string let request ?(body=`Null) m path = - let uri = process_url path in - let headers = process_request_headers () in - let body = process_request_body body in - (match m with - | `DELETE -> Cohttp_async.Client.delete ~headers ~body uri - | `GET -> Cohttp_async.Client.get ~headers uri - | `PATCH -> Cohttp_async.Client.patch ~headers ~body uri - | `POST -> Cohttp_async.Client.post ~headers ~body uri - | `PUT -> Cohttp_async.Client.put ~headers ~body uri - | _ -> raise Invalid_Method) - >>= process_response + rl := Rl.update ~f:(function + | None -> Mvar.create () + | Some r -> r + ) !rl path; + let limit = Rl.find_exn !rl path in + Mvar.take limit >>= fun limit -> + let process () = + let uri = process_url path in + let headers = process_request_headers () in + let body = process_request_body body in + (match m with + | `DELETE -> Cohttp_async.Client.delete ~headers ~body uri + | `GET -> Cohttp_async.Client.get ~headers uri + | `PATCH -> Cohttp_async.Client.patch ~headers ~body uri + | `POST -> Cohttp_async.Client.post ~headers ~body uri + | `PUT -> Cohttp_async.Client.put ~headers ~body uri + | _ -> raise Invalid_Method) + >>= process_response path + in if limit.remaining > 0 then process () + else Clock.at (Core.Time.(Span.of_int_sec limit.reset |> of_span_since_epoch)) >>= process end let get_gateway () = diff --git a/lib/rl.ml b/lib/rl.ml new file mode 100644 index 0000000..316abcf --- /dev/null +++ b/lib/rl.ml @@ -0,0 +1,29 @@ +open Core +open Async + +module RouteMap = Map.Make(String) + +type rl = { + limit: int; + remaining: int; + reset: int; +} + +type t = ((rl, read_write) Mvar.t) RouteMap.t + +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 = 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 update = RouteMap.update +let empty : t = RouteMap.empty +let find = RouteMap.find +let find_exn m s = match find m s with + | Some r -> r + | None -> raise (Not_found_s (String.sexp_of_t s)) \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index 95eaee3..9ac86ad 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -21,32 +21,32 @@ module type Dispatch = sig | READY of Yojson.Safe.json | RESUMED of Yojson.Safe.json | INVALID_SESSION of Yojson.Safe.json - | CHANNEL_CREATE of Channel.t - | CHANNEL_UPDATE of Channel.t - | CHANNEL_DELETE of Channel.t + | CHANNEL_CREATE of Channel_t.t + | CHANNEL_UPDATE of Channel_t.t + | CHANNEL_DELETE of Channel_t.t | CHANNEL_PINS_UPDATE of Yojson.Safe.json - | GUILD_CREATE of Guild.t - | GUILD_UPDATE of Guild.t - | GUILD_DELETE of Guild.t - | GUILD_BAN_ADD of Ban.t - | GUILD_BAN_REMOVE of Ban.t + | GUILD_CREATE of Guild_t.t + | GUILD_UPDATE of Guild_t.t + | GUILD_DELETE of Guild_t.t + | GUILD_BAN_ADD of Ban_t.t + | GUILD_BAN_REMOVE of Ban_t.t | GUILD_EMOJIS_UPDATE of Yojson.Safe.json | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json - | GUILD_MEMBER_ADD of Member.t - | GUILD_MEMBER_REMOVE of Member.t - | GUILD_MEMBER_UPDATE of Member.t - | GUILD_MEMBERS_CHUNK of Member.t list - | GUILD_ROLE_CREATE of Role.t (* * Guild.t *) - | GUILD_ROLE_UPDATE of Role.t (* * Guild.t *) - | GUILD_ROLE_DELETE of Role.t (* * Guild.t *) - | MESSAGE_CREATE of Message.t - | MESSAGE_UPDATE of Message.t - | MESSAGE_DELETE of Message.t - | MESSAGE_BULK_DELETE of Message.t list - | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction.t - | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction.t - | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction.t list - | PRESENCE_UPDATE of Presence.t + | GUILD_MEMBER_ADD of Member_t.t + | GUILD_MEMBER_REMOVE of Member_t.t + | GUILD_MEMBER_UPDATE of Member_t.t + | GUILD_MEMBERS_CHUNK of Member_t.t list + | GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *) + | GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *) + | GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *) + | MESSAGE_CREATE of Message_t.t + | MESSAGE_UPDATE of Message_t.t + | MESSAGE_DELETE of Message_t.t + | MESSAGE_BULK_DELETE of Message_t.t list + | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t + | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t + | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list + | PRESENCE_UPDATE of Presence_t.t | TYPING_START of Yojson.Safe.json | USER_UPDATE of Yojson.Safe.json | VOICE_STATE_UPDATE of Yojson.Safe.json @@ -55,8 +55,8 @@ module type Dispatch = sig exception Invalid_event of string - val event_of_string : contents:Yojson.Safe.json -> string -> dispatch_event - val dispatch : ev:string -> Yojson.Safe.json -> unit + val event_of_string : contents:string -> string -> dispatch_event + val dispatch : ev:string -> string -> unit end module type Http = sig @@ -72,6 +72,7 @@ module type Http = sig val process_request_headers : unit -> Cohttp.Header.t val process_response : + string -> Cohttp_async.Response.t * Cohttp_async.Body.t -> Yojson.Safe.json Deferred.t @@ -277,7 +278,7 @@ module type Sharder = sig val request_guild_members : ?query:string -> ?limit:int -> - guild:Snowflake.t -> + guild:Snowflake_t.t -> shard -> shard Deferred.t @@ -301,7 +302,7 @@ module type Sharder = sig val request_guild_members : ?query:string -> ?limit:int -> - guild:Snowflake.t -> + guild:Snowflake_t.t -> t -> Shard.shard list Deferred.t end \ No newline at end of file -- cgit v1.2.3 From 73d115ce6260e97f5f7ee47f743d842ffd292662 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 13 Dec 2018 14:11:54 -0700 Subject: Working on deriving types from json --- lib/client.ml | 25 +- lib/dispatch.ml | 116 +-- lib/models/activity.atd | 5 + lib/models/activity.ml | 4 - lib/models/activity_j.ml | 117 +++ lib/models/activity_j.mli | 47 + lib/models/activity_t.ml | 6 + lib/models/activity_t.mli | 6 + lib/models/attachment.atd | 11 + lib/models/attachment.ml | 9 - lib/models/attachment_j.ml | 456 +++++++++ lib/models/attachment_j.mli | 55 ++ lib/models/attachment_t.ml | 14 + lib/models/attachment_t.mli | 14 + lib/models/ban.atd | 6 + lib/models/ban.ml | 4 - lib/models/ban_j.ml | 235 +++++ lib/models/ban_j.mli | 47 + lib/models/ban_t.ml | 6 + lib/models/ban_t.mli | 6 + lib/models/channel.atd | 19 + lib/models/channel.ml | 17 - lib/models/channel_j.ml | 1136 +++++++++++++++++++++ lib/models/channel_j.mli | 84 ++ lib/models/channel_t.ml | 23 + lib/models/channel_t.mli | 23 + lib/models/embed.atd | 44 + lib/models/embed.ml | 44 - lib/models/embed_j.ml | 2283 +++++++++++++++++++++++++++++++++++++++++++ lib/models/embed_j.mli | 168 ++++ lib/models/embed_t.ml | 36 + lib/models/embed_t.mli | 36 + lib/models/emoji.atd | 12 + lib/models/emoji.ml | 9 - lib/models/emoji_j.ml | 701 +++++++++++++ lib/models/emoji_j.mli | 77 ++ lib/models/emoji_t.ml | 16 + lib/models/emoji_t.mli | 16 + lib/models/guild.atd | 36 + lib/models/guild.ml | 28 - lib/models/guild_j.ml | 1948 ++++++++++++++++++++++++++++++++++++ lib/models/guild_j.mli | 184 ++++ lib/models/guild_t.ml | 43 + lib/models/guild_t.mli | 43 + lib/models/member.atd | 11 + lib/models/member.ml | 8 - lib/models/member_j.ml | 448 +++++++++ lib/models/member_j.mli | 76 ++ lib/models/member_t.ml | 15 + lib/models/member_t.mli | 15 + lib/models/message.atd | 29 + lib/models/message.ml | 21 - lib/models/message_j.ml | 1314 +++++++++++++++++++++++++ lib/models/message_j.mli | 199 ++++ lib/models/message_t.ml | 38 + lib/models/message_t.mli | 38 + lib/models/presence.atd | 13 + lib/models/presence.ml | 8 - lib/models/presence_j.ml | 504 ++++++++++ lib/models/presence_j.mli | 120 +++ lib/models/presence_t.ml | 19 + lib/models/presence_t.mli | 19 + lib/models/reaction.atd | 6 + lib/models/reaction.ml | 4 - lib/models/reaction_j.ml | 180 ++++ lib/models/reaction_j.mli | 47 + lib/models/reaction_t.ml | 6 + lib/models/reaction_t.mli | 6 + lib/models/role.atd | 12 + lib/models/role.ml | 10 - lib/models/role_j.ml | 449 +++++++++ lib/models/role_j.mli | 56 ++ lib/models/role_t.ml | 15 + lib/models/role_t.mli | 15 + lib/models/snowflake.atd | 1 + lib/models/snowflake.ml | 16 - lib/models/snowflake_j.ml | 17 + lib/models/snowflake_j.mli | 25 + lib/models/snowflake_t.ml | 4 + lib/models/snowflake_t.mli | 4 + lib/models/user.atd | 9 + lib/models/user.ml | 7 - lib/models/user_j.ml | 368 +++++++ lib/models/user_j.mli | 53 + lib/models/user_t.ml | 12 + lib/models/user_t.mli | 12 + lib/sharder.ml | 5 +- 87 files changed, 12181 insertions(+), 268 deletions(-) create mode 100644 lib/models/activity.atd delete mode 100644 lib/models/activity.ml create mode 100644 lib/models/activity_j.ml create mode 100644 lib/models/activity_j.mli create mode 100644 lib/models/activity_t.ml create mode 100644 lib/models/activity_t.mli create mode 100644 lib/models/attachment.atd delete mode 100644 lib/models/attachment.ml create mode 100644 lib/models/attachment_j.ml create mode 100644 lib/models/attachment_j.mli create mode 100644 lib/models/attachment_t.ml create mode 100644 lib/models/attachment_t.mli create mode 100644 lib/models/ban.atd delete mode 100644 lib/models/ban.ml create mode 100644 lib/models/ban_j.ml create mode 100644 lib/models/ban_j.mli create mode 100644 lib/models/ban_t.ml create mode 100644 lib/models/ban_t.mli create mode 100644 lib/models/channel.atd delete mode 100644 lib/models/channel.ml create mode 100644 lib/models/channel_j.ml create mode 100644 lib/models/channel_j.mli create mode 100644 lib/models/channel_t.ml create mode 100644 lib/models/channel_t.mli create mode 100644 lib/models/embed.atd delete mode 100644 lib/models/embed.ml create mode 100644 lib/models/embed_j.ml create mode 100644 lib/models/embed_j.mli create mode 100644 lib/models/embed_t.ml create mode 100644 lib/models/embed_t.mli create mode 100644 lib/models/emoji.atd delete mode 100644 lib/models/emoji.ml create mode 100644 lib/models/emoji_j.ml create mode 100644 lib/models/emoji_j.mli create mode 100644 lib/models/emoji_t.ml create mode 100644 lib/models/emoji_t.mli create mode 100644 lib/models/guild.atd delete mode 100644 lib/models/guild.ml create mode 100644 lib/models/guild_j.ml create mode 100644 lib/models/guild_j.mli create mode 100644 lib/models/guild_t.ml create mode 100644 lib/models/guild_t.mli create mode 100644 lib/models/member.atd delete mode 100644 lib/models/member.ml create mode 100644 lib/models/member_j.ml create mode 100644 lib/models/member_j.mli create mode 100644 lib/models/member_t.ml create mode 100644 lib/models/member_t.mli create mode 100644 lib/models/message.atd delete mode 100644 lib/models/message.ml create mode 100644 lib/models/message_j.ml create mode 100644 lib/models/message_j.mli create mode 100644 lib/models/message_t.ml create mode 100644 lib/models/message_t.mli create mode 100644 lib/models/presence.atd delete mode 100644 lib/models/presence.ml create mode 100644 lib/models/presence_j.ml create mode 100644 lib/models/presence_j.mli create mode 100644 lib/models/presence_t.ml create mode 100644 lib/models/presence_t.mli create mode 100644 lib/models/reaction.atd delete mode 100644 lib/models/reaction.ml create mode 100644 lib/models/reaction_j.ml create mode 100644 lib/models/reaction_j.mli create mode 100644 lib/models/reaction_t.ml create mode 100644 lib/models/reaction_t.mli create mode 100644 lib/models/role.atd delete mode 100644 lib/models/role.ml create mode 100644 lib/models/role_j.ml create mode 100644 lib/models/role_j.mli create mode 100644 lib/models/role_t.ml create mode 100644 lib/models/role_t.mli create mode 100644 lib/models/snowflake.atd delete mode 100644 lib/models/snowflake.ml create mode 100644 lib/models/snowflake_j.ml create mode 100644 lib/models/snowflake_j.mli create mode 100644 lib/models/snowflake_t.ml create mode 100644 lib/models/snowflake_t.mli create mode 100644 lib/models/user.atd delete mode 100644 lib/models/user.ml create mode 100644 lib/models/user_j.ml create mode 100644 lib/models/user_j.mli create mode 100644 lib/models/user_t.ml create mode 100644 lib/models/user_t.mli (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index 018f3e6..9211281 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -8,34 +8,21 @@ module Make(T : S.Token)(H : S.Handler) = struct module Sharder = Sharder.Make(Http)(Dispatch) type t = { - sharder: Sharder.t Ivar.t; + sharder: Sharder.t; token: string; } - let init () = - { - sharder = Ivar.create (); - token; - } - - let start ?count client = + let start ?count () = Sharder.start ?count () >>| fun sharder -> - Ivar.fill_if_empty client.sharder sharder; - client + { sharder; token; } let set_status ~status client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status ~status sharder + Sharder.set_status ~status client.sharder let set_status_with ~f client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.set_status_with ~f sharder + Sharder.set_status_with ~f client.sharder let request_guild_members ~guild ?query ?limit client = - Ivar.read client.sharder - >>= fun sharder -> - Sharder.request_guild_members ~guild ?query ?limit sharder + Sharder.request_guild_members ~guild ?query ?limit client.sharder end \ No newline at end of file diff --git a/lib/dispatch.ml b/lib/dispatch.ml index 65c84ef..cb6e5d9 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -6,32 +6,32 @@ module Make(H : S.Handler) : S.Dispatch = struct | READY of Yojson.Safe.json | RESUMED of Yojson.Safe.json | INVALID_SESSION of Yojson.Safe.json - | CHANNEL_CREATE of Channel.t - | CHANNEL_UPDATE of Channel.t - | CHANNEL_DELETE of Channel.t + | CHANNEL_CREATE of Channel_t.t + | CHANNEL_UPDATE of Channel_t.t + | CHANNEL_DELETE of Channel_t.t | CHANNEL_PINS_UPDATE of Yojson.Safe.json - | GUILD_CREATE of Guild.t - | GUILD_UPDATE of Guild.t - | GUILD_DELETE of Guild.t - | GUILD_BAN_ADD of Ban.t - | GUILD_BAN_REMOVE of Ban.t + | GUILD_CREATE of Guild_t.t + | GUILD_UPDATE of Guild_t.t + | GUILD_DELETE of Guild_t.t + | GUILD_BAN_ADD of Ban_t.t + | GUILD_BAN_REMOVE of Ban_t.t | GUILD_EMOJIS_UPDATE of Yojson.Safe.json | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json - | GUILD_MEMBER_ADD of Member.t - | GUILD_MEMBER_REMOVE of Member.t - | GUILD_MEMBER_UPDATE of Member.t - | GUILD_MEMBERS_CHUNK of Member.t list - | GUILD_ROLE_CREATE of Role.t (* * Guild.t *) - | GUILD_ROLE_UPDATE of Role.t (* * Guild.t *) - | GUILD_ROLE_DELETE of Role.t (* * Guild.t *) - | MESSAGE_CREATE of Message.t - | MESSAGE_UPDATE of Message.t - | MESSAGE_DELETE of Message.t - | MESSAGE_BULK_DELETE of Message.t list - | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction.t - | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction.t - | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction.t list - | PRESENCE_UPDATE of Presence.t + | GUILD_MEMBER_ADD of Member_t.t + | GUILD_MEMBER_REMOVE of Member_t.t + | GUILD_MEMBER_UPDATE of Member_t.t + | GUILD_MEMBERS_CHUNK of Member_t.t list + | GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *) + | GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *) + | GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *) + | MESSAGE_CREATE of Message_t.t + | MESSAGE_UPDATE of Message_t.t + | MESSAGE_DELETE of Message_t.t + | MESSAGE_BULK_DELETE of Message_t.t list + | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t + | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t + | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list + | PRESENCE_UPDATE of Presence_t.t | TYPING_START of Yojson.Safe.json | USER_UPDATE of Yojson.Safe.json | VOICE_STATE_UPDATE of Yojson.Safe.json @@ -41,41 +41,41 @@ module Make(H : S.Handler) : S.Dispatch = struct exception Invalid_event of string let event_of_string ~contents t = match t with - | "HELLO" -> HELLO contents - | "READY" -> READY contents - | "RESUMED" -> RESUMED contents - | "INVALID_SESSION" -> INVALID_SESSION contents - | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel.of_yojson_exn contents) - | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel.of_yojson_exn contents) - | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel.of_yojson_exn contents) - | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE contents - | "GUILD_CREATE" -> GUILD_CREATE (Guild.of_yojson_exn contents) - | "GUILD_UPDATE" -> GUILD_UPDATE (Guild.of_yojson_exn contents) - | "GUILD_DELETE" -> GUILD_DELETE (Guild.of_yojson_exn contents) - | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban.of_yojson_exn contents) - | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban.of_yojson_exn contents) - | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE contents - | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE contents - | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member.of_yojson_exn contents) - | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member.of_yojson_exn contents) - | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member.of_yojson_exn contents) - | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Member.of_yojson_exn m)) - | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role.of_yojson_exn contents) - | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role.of_yojson_exn contents) - | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role.of_yojson_exn contents) - | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message.of_yojson_exn contents) - | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message.of_yojson_exn contents) - | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message.of_yojson_exn contents) - | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Message.of_yojson_exn m)) - | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction.of_yojson_exn contents) - | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction.of_yojson_exn contents) - | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun r -> Reaction.of_yojson_exn r)) - | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence.of_yojson_exn contents) - | "TYPING_START" -> TYPING_START contents - | "USER_UPDATE" -> USER_UPDATE contents - | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE contents - | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE contents - | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE contents + | "HELLO" -> HELLO (Yojson.Safe.from_string contents) + | "READY" -> READY (Yojson.Safe.from_string contents) + | "RESUMED" -> RESUMED (Yojson.Safe.from_string contents) + | "INVALID_SESSION" -> INVALID_SESSION (Yojson.Safe.from_string contents) + | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel_j.t_of_string contents) + | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel_j.t_of_string contents) + | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel_j.t_of_string contents) + | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_CREATE" -> GUILD_CREATE (Guild_j.t_of_string contents) + | "GUILD_UPDATE" -> GUILD_UPDATE (Guild_j.t_of_string contents) + | "GUILD_DELETE" -> GUILD_DELETE (Guild_j.t_of_string contents) + | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban_j.t_of_string contents) + | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban_j.t_of_string contents) + | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member_j.t_of_string contents) + | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member_j.t_of_string contents) + | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member_j.t_of_string contents) + (* | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Member_j.t_of_string m)) *) + | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role_j.t_of_string contents) + | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role_j.t_of_string contents) + | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role_j.t_of_string contents) + | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_j.t_of_string contents) + | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_j.t_of_string contents) + | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message_j.t_of_string contents) + (* | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Message_j.t_of_string m)) *) + | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_j.t_of_string contents) + | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_j.t_of_string contents) + (* | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun r -> Reaction_j.t_of_string r)) *) + | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence_j.t_of_string contents) + | "TYPING_START" -> TYPING_START (Yojson.Safe.from_string contents) + | "USER_UPDATE" -> USER_UPDATE (Yojson.Safe.from_string contents) + | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE (Yojson.Safe.from_string contents) + | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE (Yojson.Safe.from_string contents) + | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE (Yojson.Safe.from_string contents) | s -> raise (Invalid_event s) let dispatch ~ev contents = diff --git a/lib/models/activity.atd b/lib/models/activity.atd new file mode 100644 index 0000000..94b4b3c --- /dev/null +++ b/lib/models/activity.atd @@ -0,0 +1,5 @@ +type snowflake = abstract + +type t = { + id: snowflake; +} \ No newline at end of file diff --git a/lib/models/activity.ml b/lib/models/activity.ml deleted file mode 100644 index 80f1049..0000000 --- a/lib/models/activity.ml +++ /dev/null @@ -1,4 +0,0 @@ -type t = { - id: Snowflake.t; -} -[@@deriving yojson] \ No newline at end of file diff --git a/lib/models/activity_j.ml b/lib/models/activity_j.ml new file mode 100644 index 0000000..8a4eb2e --- /dev/null +++ b/lib/models/activity_j.ml @@ -0,0 +1,117 @@ +(* Auto-generated from "activity.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Activity_t.t = { id: snowflake } + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + ( + { + id = !field_id; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/activity_j.mli b/lib/models/activity_j.mli new file mode 100644 index 0000000..3c93cc1 --- /dev/null +++ b/lib/models/activity_j.mli @@ -0,0 +1,47 @@ +(* Auto-generated from "activity.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Activity_t.t = { id: snowflake } + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/activity_t.ml b/lib/models/activity_t.ml new file mode 100644 index 0000000..f9ba6a6 --- /dev/null +++ b/lib/models/activity_t.ml @@ -0,0 +1,6 @@ +(* Auto-generated from "activity.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { id: snowflake } diff --git a/lib/models/activity_t.mli b/lib/models/activity_t.mli new file mode 100644 index 0000000..f9ba6a6 --- /dev/null +++ b/lib/models/activity_t.mli @@ -0,0 +1,6 @@ +(* Auto-generated from "activity.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { id: snowflake } diff --git a/lib/models/attachment.atd b/lib/models/attachment.atd new file mode 100644 index 0000000..9757b49 --- /dev/null +++ b/lib/models/attachment.atd @@ -0,0 +1,11 @@ +type snowflake = abstract + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + ?height: int option; + ?width: int option; +} \ No newline at end of file diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml deleted file mode 100644 index 595aa45..0000000 --- a/lib/models/attachment.ml +++ /dev/null @@ -1,9 +0,0 @@ -type t = { - id: Snowflake.t; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int option; - width: int option; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/attachment_j.ml b/lib/models/attachment_j.ml new file mode 100644 index 0000000..28f909d --- /dev/null +++ b/lib/models/attachment_j.ml @@ -0,0 +1,456 @@ +(* Auto-generated from "attachment.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Attachment_t.t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"filename\":"; + ( + Yojson.Safe.write_string + ) + ob x.filename; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"size\":"; + ( + Yojson.Safe.write_int + ) + ob x.size; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x.url; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_url\":"; + ( + Yojson.Safe.write_string + ) + ob x.proxy_url; + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_filename = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_size = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_proxy_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_height = ref (None) in + let field_width = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 6 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_filename := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_size := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_proxy_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 6 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_filename := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_size := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_proxy_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "filename"; "size"; "url"; "proxy_url" |]; + ( + { + id = !field_id; + filename = !field_filename; + size = !field_size; + url = !field_url; + proxy_url = !field_proxy_url; + height = !field_height; + width = !field_width; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/attachment_j.mli b/lib/models/attachment_j.mli new file mode 100644 index 0000000..6b11b08 --- /dev/null +++ b/lib/models/attachment_j.mli @@ -0,0 +1,55 @@ +(* Auto-generated from "attachment.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Attachment_t.t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/attachment_t.ml b/lib/models/attachment_t.ml new file mode 100644 index 0000000..0485dcc --- /dev/null +++ b/lib/models/attachment_t.ml @@ -0,0 +1,14 @@ +(* Auto-generated from "attachment.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} diff --git a/lib/models/attachment_t.mli b/lib/models/attachment_t.mli new file mode 100644 index 0000000..0485dcc --- /dev/null +++ b/lib/models/attachment_t.mli @@ -0,0 +1,14 @@ +(* Auto-generated from "attachment.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} diff --git a/lib/models/ban.atd b/lib/models/ban.atd new file mode 100644 index 0000000..0a87338 --- /dev/null +++ b/lib/models/ban.atd @@ -0,0 +1,6 @@ +type user = abstract + +type t = { + ?reason: string option; + user: user; +} \ No newline at end of file diff --git a/lib/models/ban.ml b/lib/models/ban.ml deleted file mode 100644 index ff0fb67..0000000 --- a/lib/models/ban.ml +++ /dev/null @@ -1,4 +0,0 @@ -type t = { - id: Snowflake.t; - user: User.t; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/ban_j.ml b/lib/models/ban_j.ml new file mode 100644 index 0000000..e608f67 --- /dev/null +++ b/lib/models/ban_j.ml @@ -0,0 +1,235 @@ +(* Auto-generated from "ban.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = Ban_t.t = { reason: string option; user: user } + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.reason with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"reason\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_reason = ref (None) in + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reason := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reason := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user" |]; + ( + { + reason = !field_reason; + user = !field_user; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/ban_j.mli b/lib/models/ban_j.mli new file mode 100644 index 0000000..9449b5c --- /dev/null +++ b/lib/models/ban_j.mli @@ -0,0 +1,47 @@ +(* Auto-generated from "ban.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = Ban_t.t = { reason: string option; user: user } + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/ban_t.ml b/lib/models/ban_t.ml new file mode 100644 index 0000000..7d9c5a0 --- /dev/null +++ b/lib/models/ban_t.ml @@ -0,0 +1,6 @@ +(* Auto-generated from "ban.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = { reason: string option; user: user } diff --git a/lib/models/ban_t.mli b/lib/models/ban_t.mli new file mode 100644 index 0000000..7d9c5a0 --- /dev/null +++ b/lib/models/ban_t.mli @@ -0,0 +1,6 @@ +(* Auto-generated from "ban.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = { reason: string option; user: user } diff --git a/lib/models/channel.atd b/lib/models/channel.atd new file mode 100644 index 0000000..6ab58cf --- /dev/null +++ b/lib/models/channel.atd @@ -0,0 +1,19 @@ +type snowflake = abstract +type user = abstract + +type t = { + id: snowflake; + kind : int; + ?guild_id: snowflake option; + ?position: int option; + ?name: string option; + ?topic: string option; + ?nsfw: bool option; + ?bitrate: int option; + ?user_limit: int option; + ?recipients: user list option; + ?icon: string option; + ?owner_id: snowflake option; + ?application_id: snowflake option; + ?parent_id: snowflake option; +} \ No newline at end of file diff --git a/lib/models/channel.ml b/lib/models/channel.ml deleted file mode 100644 index ac3e596..0000000 --- a/lib/models/channel.ml +++ /dev/null @@ -1,17 +0,0 @@ -type t = { - id: Snowflake.t; - kind: int; - (* guild: Guild.t option; *) - position: int option; - permission_overwrites: (int list) option; - name: string option; - topic: string option; - nsfw: bool option; - bitrate: int option; - user_limit: int option; - recipients: (User.t list) option; - icon: string option; - owner_id: Snowflake.t option; - application_id: Snowflake.t option; - parent_id: Snowflake.t option; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/channel_j.ml b/lib/models/channel_j.ml new file mode 100644 index 0000000..7369230 --- /dev/null +++ b/lib/models/channel_j.ml @@ -0,0 +1,1136 @@ +(* Auto-generated from "channel.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Channel_t.t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_list ( + write_user + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + Atdgen_runtime.Oj_run.read_list ( + read_user + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_option ( + write__5 + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__5 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__5 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; + ( + Yojson.Safe.write_int + ) + ob x.kind; + (match x.guild_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.position with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"position\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.name with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.topic with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"topic\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.nsfw with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nsfw\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.bitrate with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"bitrate\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.user_limit with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user_limit\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.recipients with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"recipients\":"; + ( + write__5 + ) + ob x; + ); + (match x.icon with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.owner_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"owner_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.application_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"application_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.parent_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"parent_id\":"; + ( + write_snowflake + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_guild_id = ref (None) in + let field_position = ref (None) in + let field_name = ref (None) in + let field_topic = ref (None) in + let field_nsfw = ref (None) in + let field_bitrate = ref (None) in + let field_user_limit = ref (None) in + let field_recipients = ref (None) in + let field_icon = ref (None) in + let field_owner_id = ref (None) in + let field_application_id = ref (None) in + let field_parent_id = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 10 + ) + else ( + -1 + ) + ) + | 'n' -> ( + match String.unsafe_get s (pos+1) with + | 'a' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( + 5 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 11 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( + 13 + ) + else ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( + 9 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( + 8 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 12 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_position := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_topic := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nsfw := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bitrate := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user_limit := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_recipients := ( + Some ( + ( + read__5 + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_owner_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 12 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 13 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_parent_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 10 + ) + else ( + -1 + ) + ) + | 'n' -> ( + match String.unsafe_get s (pos+1) with + | 'a' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( + 5 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 11 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( + 13 + ) + else ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( + 9 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( + 8 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 12 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_position := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_topic := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nsfw := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bitrate := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user_limit := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_recipients := ( + Some ( + ( + read__5 + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_owner_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 12 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 13 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_parent_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "kind" |]; + ( + { + id = !field_id; + kind = !field_kind; + guild_id = !field_guild_id; + position = !field_position; + name = !field_name; + topic = !field_topic; + nsfw = !field_nsfw; + bitrate = !field_bitrate; + user_limit = !field_user_limit; + recipients = !field_recipients; + icon = !field_icon; + owner_id = !field_owner_id; + application_id = !field_application_id; + parent_id = !field_parent_id; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/channel_j.mli b/lib/models/channel_j.mli new file mode 100644 index 0000000..ec4048c --- /dev/null +++ b/lib/models/channel_j.mli @@ -0,0 +1,84 @@ +(* Auto-generated from "channel.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Channel_t.t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/channel_t.ml b/lib/models/channel_t.ml new file mode 100644 index 0000000..a5c9ce4 --- /dev/null +++ b/lib/models/channel_t.ml @@ -0,0 +1,23 @@ +(* Auto-generated from "channel.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} diff --git a/lib/models/channel_t.mli b/lib/models/channel_t.mli new file mode 100644 index 0000000..a5c9ce4 --- /dev/null +++ b/lib/models/channel_t.mli @@ -0,0 +1,23 @@ +(* Auto-generated from "channel.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} diff --git a/lib/models/embed.atd b/lib/models/embed.atd new file mode 100644 index 0000000..0d3aed4 --- /dev/null +++ b/lib/models/embed.atd @@ -0,0 +1,44 @@ +type footer = { + text: string; + ?icon_url: string option; + ?proxy_icon_url: string option; +} + +type image = { + ?url: string option; + ?proxy_url: string option; + ?height: int option; + ?width: int option; +} + +type video = { + ?url: string option; + ?height: int option; + ?width: int option; +} + +type provider = { + ?name: string option; + ?url: string option; +} + +type field = { + name: string; + value: string; + ?inline: bool option; +} + +type t = { + ?title: string option; + ?kind: string option; + ?description: string option; + ?url: string option; + ?timestamp: string option; + ?colour: int option; + ?footer: footer option; + ?image: image option; + ?thumbnail: image option; + ?video: video option; + ?provider: provider option; + ?fields: field list option; +} \ No newline at end of file diff --git a/lib/models/embed.ml b/lib/models/embed.ml deleted file mode 100644 index b4dc143..0000000 --- a/lib/models/embed.ml +++ /dev/null @@ -1,44 +0,0 @@ -type footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option; -} [@@deriving yojson] - -type image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option; -} [@@deriving yojson] - -type video = { - url: string option; - height: int option; - width: int option; -} [@@deriving yojson] - -type provider = { - name: string option; - url: string option; -} [@@deriving yojson] - -type field = { - name: string; - value: string; - inline: bool option; -} [@@deriving yojson] - -type t = { - title: string option; - kind: string option; - description: string option; - url: string option; - timestamp: string option; - colour: int option; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - fields: (field list) option; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/embed_j.ml b/lib/models/embed_j.ml new file mode 100644 index 0000000..560c517 --- /dev/null +++ b/lib/models/embed_j.ml @@ -0,0 +1,2283 @@ +(* Auto-generated from "embed.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type video = Embed_t.video = { + url: string option; + height: int option; + width: int option +} + +type provider = Embed_t.provider = { + name: string option; + url: string option +} + +type image = Embed_t.image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = Embed_t.footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = Embed_t.field = { + name: string; + value: string; + inline: bool option +} + +type t = Embed_t.t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} + +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_video : _ -> video -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_video ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_video ob x; + Bi_outbuf.contents ob +let read_video = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_url = ref (None) in + let field_height = ref (None) in + let field_width = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 2 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 2 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + url = !field_url; + height = !field_height; + width = !field_width; + } + : video) + ) +) +let video_of_string s = + read_video (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_provider : _ -> provider -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.name with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_provider ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_provider ob x; + Bi_outbuf.contents ob +let read_provider = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_name = ref (None) in + let field_url = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + name = !field_name; + url = !field_url; + } + : provider) + ) +) +let provider_of_string s = + read_provider (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_image : _ -> image -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.proxy_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_image ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_image ob x; + Bi_outbuf.contents ob +let read_image = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_url = ref (None) in + let field_proxy_url = ref (None) in + let field_height = ref (None) in + let field_width = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + url = !field_url; + proxy_url = !field_proxy_url; + height = !field_height; + width = !field_width; + } + : image) + ) +) +let image_of_string s = + read_image (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_footer : _ -> footer -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"text\":"; + ( + Yojson.Safe.write_string + ) + ob x.text; + (match x.icon_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.proxy_icon_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_icon_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_footer ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_footer ob x; + Bi_outbuf.contents ob +let read_footer = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_text = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_icon_url = ref (None) in + let field_proxy_icon_url = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_text := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_text := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "text" |]; + ( + { + text = !field_text; + icon_url = !field_icon_url; + proxy_icon_url = !field_proxy_icon_url; + } + : footer) + ) +) +let footer_of_string s = + read_footer (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_field : _ -> field -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"value\":"; + ( + Yojson.Safe.write_string + ) + ob x.value; + (match x.inline with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"inline\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_field ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_field ob x; + Bi_outbuf.contents ob +let read_field = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_value = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_inline = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_value := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_inline := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_value := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_inline := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "value" |]; + ( + { + name = !field_name; + value = !field_value; + inline = !field_inline; + } + : field) + ) +) +let field_of_string s = + read_field (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__8 = ( + Atdgen_runtime.Oj_run.write_list ( + write_field + ) +) +let string_of__8 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__8 ob x; + Bi_outbuf.contents ob +let read__8 = ( + Atdgen_runtime.Oj_run.read_list ( + read_field + ) +) +let _8_of_string s = + read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__9 = ( + Atdgen_runtime.Oj_run.write_option ( + write__8 + ) +) +let string_of__9 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__9 ob x; + Bi_outbuf.contents ob +let read__9 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__8 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__8 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _9_of_string s = + read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_option ( + write_provider + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_provider + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_provider + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_option ( + write_video + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_video + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_video + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_option ( + write_image + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_image + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_image + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + write_footer + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_footer + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_footer + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.title with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"title\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.kind with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"kind\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.description with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"description\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.timestamp with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.colour with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"colour\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.footer with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"footer\":"; + ( + write_footer + ) + ob x; + ); + (match x.image with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"image\":"; + ( + write_image + ) + ob x; + ); + (match x.thumbnail with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"thumbnail\":"; + ( + write_image + ) + ob x; + ); + (match x.video with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"video\":"; + ( + write_video + ) + ob x; + ); + (match x.provider with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"provider\":"; + ( + write_provider + ) + ob x; + ); + (match x.fields with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"fields\":"; + ( + write__8 + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_title = ref (None) in + let field_kind = ref (None) in + let field_description = ref (None) in + let field_url = ref (None) in + let field_timestamp = ref (None) in + let field_colour = ref (None) in + let field_footer = ref (None) in + let field_image = ref (None) in + let field_thumbnail = ref (None) in + let field_video = ref (None) in + let field_provider = ref (None) in + let field_fields = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 'v' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | 'f' -> ( + match String.unsafe_get s (pos+1) with + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( + 10 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 't' then ( + match String.unsafe_get s (pos+1) with + | 'h' -> ( + if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( + 8 + ) + else ( + -1 + ) + ) + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_title := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_kind := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_description := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_colour := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_footer := ( + Some ( + ( + read_footer + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_image := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_thumbnail := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_video := ( + Some ( + ( + read_video + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_provider := ( + Some ( + ( + read_provider + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_fields := ( + Some ( + ( + read__8 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 'v' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | 'f' -> ( + match String.unsafe_get s (pos+1) with + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( + 10 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 't' then ( + match String.unsafe_get s (pos+1) with + | 'h' -> ( + if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( + 8 + ) + else ( + -1 + ) + ) + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_title := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_kind := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_description := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_colour := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_footer := ( + Some ( + ( + read_footer + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_image := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_thumbnail := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_video := ( + Some ( + ( + read_video + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_provider := ( + Some ( + ( + read_provider + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_fields := ( + Some ( + ( + read__8 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + title = !field_title; + kind = !field_kind; + description = !field_description; + url = !field_url; + timestamp = !field_timestamp; + colour = !field_colour; + footer = !field_footer; + image = !field_image; + thumbnail = !field_thumbnail; + video = !field_video; + provider = !field_provider; + fields = !field_fields; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/embed_j.mli b/lib/models/embed_j.mli new file mode 100644 index 0000000..8872d89 --- /dev/null +++ b/lib/models/embed_j.mli @@ -0,0 +1,168 @@ +(* Auto-generated from "embed.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type video = Embed_t.video = { + url: string option; + height: int option; + width: int option +} + +type provider = Embed_t.provider = { + name: string option; + url: string option +} + +type image = Embed_t.image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = Embed_t.footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = Embed_t.field = { + name: string; + value: string; + inline: bool option +} + +type t = Embed_t.t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} + +val write_video : + Bi_outbuf.t -> video -> unit + (** Output a JSON value of type {!video}. *) + +val string_of_video : + ?len:int -> video -> string + (** Serialize a value of type {!video} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_video : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> video + (** Input JSON data of type {!video}. *) + +val video_of_string : + string -> video + (** Deserialize JSON data of type {!video}. *) + +val write_provider : + Bi_outbuf.t -> provider -> unit + (** Output a JSON value of type {!provider}. *) + +val string_of_provider : + ?len:int -> provider -> string + (** Serialize a value of type {!provider} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_provider : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> provider + (** Input JSON data of type {!provider}. *) + +val provider_of_string : + string -> provider + (** Deserialize JSON data of type {!provider}. *) + +val write_image : + Bi_outbuf.t -> image -> unit + (** Output a JSON value of type {!image}. *) + +val string_of_image : + ?len:int -> image -> string + (** Serialize a value of type {!image} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_image : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> image + (** Input JSON data of type {!image}. *) + +val image_of_string : + string -> image + (** Deserialize JSON data of type {!image}. *) + +val write_footer : + Bi_outbuf.t -> footer -> unit + (** Output a JSON value of type {!footer}. *) + +val string_of_footer : + ?len:int -> footer -> string + (** Serialize a value of type {!footer} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_footer : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> footer + (** Input JSON data of type {!footer}. *) + +val footer_of_string : + string -> footer + (** Deserialize JSON data of type {!footer}. *) + +val write_field : + Bi_outbuf.t -> field -> unit + (** Output a JSON value of type {!field}. *) + +val string_of_field : + ?len:int -> field -> string + (** Serialize a value of type {!field} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_field : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> field + (** Input JSON data of type {!field}. *) + +val field_of_string : + string -> field + (** Deserialize JSON data of type {!field}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/embed_t.ml b/lib/models/embed_t.ml new file mode 100644 index 0000000..9eb5059 --- /dev/null +++ b/lib/models/embed_t.ml @@ -0,0 +1,36 @@ +(* Auto-generated from "embed.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type video = { url: string option; height: int option; width: int option } + +type provider = { name: string option; url: string option } + +type image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = { name: string; value: string; inline: bool option } + +type t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} diff --git a/lib/models/embed_t.mli b/lib/models/embed_t.mli new file mode 100644 index 0000000..9eb5059 --- /dev/null +++ b/lib/models/embed_t.mli @@ -0,0 +1,36 @@ +(* Auto-generated from "embed.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type video = { url: string option; height: int option; width: int option } + +type provider = { name: string option; url: string option } + +type image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = { name: string; value: string; inline: bool option } + +type t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} diff --git a/lib/models/emoji.atd b/lib/models/emoji.atd new file mode 100644 index 0000000..877323b --- /dev/null +++ b/lib/models/emoji.atd @@ -0,0 +1,12 @@ +type snowflake = abstract +type user = abstract + +type t = { + ?id: snowflake option; + name: string; + ?roles: snowflake list option; + ?user: user option; + ?require_colons: bool option; + ?managed: bool option; + ?animated: bool option; +} \ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml deleted file mode 100644 index cfbfe64..0000000 --- a/lib/models/emoji.ml +++ /dev/null @@ -1,9 +0,0 @@ -type t = { - id: Snowflake.t; - name: string; - roles: (Role.t list) option; - user: User.t option; - require_colons: bool option; - managed: bool; - animated: bool; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/emoji_j.ml b/lib/models/emoji_j.ml new file mode 100644 index 0000000..d621de2 --- /dev/null +++ b/lib/models/emoji_j.ml @@ -0,0 +1,701 @@ +(* Auto-generated from "emoji.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Emoji_t.t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + write_user + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_user + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_user + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + write__2 + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__2 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__2 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + (match x.roles with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x; + ); + (match x.user with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x; + ); + (match x.require_colons with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"require_colons\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.managed with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"managed\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.animated with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"animated\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (None) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (None) in + let field_user = ref (None) in + let field_require_colons = ref (None) in + let field_managed = ref (None) in + let field_animated = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_roles := ( + Some ( + ( + read__2 + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user := ( + Some ( + ( + read_user + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_require_colons := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_managed := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_animated := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_roles := ( + Some ( + ( + read__2 + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user := ( + Some ( + ( + read_user + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_require_colons := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_managed := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_animated := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name" |]; + ( + { + id = !field_id; + name = !field_name; + roles = !field_roles; + user = !field_user; + require_colons = !field_require_colons; + managed = !field_managed; + animated = !field_animated; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/emoji_j.mli b/lib/models/emoji_j.mli new file mode 100644 index 0000000..596deeb --- /dev/null +++ b/lib/models/emoji_j.mli @@ -0,0 +1,77 @@ +(* Auto-generated from "emoji.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Emoji_t.t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/emoji_t.ml b/lib/models/emoji_t.ml new file mode 100644 index 0000000..333939d --- /dev/null +++ b/lib/models/emoji_t.ml @@ -0,0 +1,16 @@ +(* Auto-generated from "emoji.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} diff --git a/lib/models/emoji_t.mli b/lib/models/emoji_t.mli new file mode 100644 index 0000000..333939d --- /dev/null +++ b/lib/models/emoji_t.mli @@ -0,0 +1,16 @@ +(* Auto-generated from "emoji.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} diff --git a/lib/models/guild.atd b/lib/models/guild.atd new file mode 100644 index 0000000..c622eea --- /dev/null +++ b/lib/models/guild.atd @@ -0,0 +1,36 @@ +type snowflake = abstract +type user = abstract +type member = abstract +type role = abstract +type channel = abstract +type emoji = abstract + + +type t = { + id: snowflake; + name: string; + ?icon: string option; + ?splash: string option; + owner_id: snowflake; + region: string; + ?afk_channel_id: snowflake option; + afk_timeout: int; + ?embed_enabled: bool option; + ?embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + ?application_id: snowflake option; + ?widget_enabled: bool option; + ?widget_channel: channel option; + ?system_channel: channel option; + ?large: bool option; + ?unavailable: bool option; + ?member_count: int option; + ?members: member list option; + ?channels: channel list option; +} \ No newline at end of file diff --git a/lib/models/guild.ml b/lib/models/guild.ml deleted file mode 100644 index 5f5855b..0000000 --- a/lib/models/guild.ml +++ /dev/null @@ -1,28 +0,0 @@ -type t = { - id: Snowflake.t; - name: string; - icon: string; - splash: string; - owner: User.t; - region: string; - afk_channel: Channel.t option; - afk_timeout: int; - embed_enabled: bool; - embed_channel: Channel.t; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: Role.t list; - emojis: Emoji.t list; - features: string list; - mfa_level: int; - application_id: Snowflake.t option; - widget_enabled: bool option; - widget_channel: Channel.t option; - system_channel: Channel.t option; - large: bool; - unavailable: bool; - member_count: int; - members: Member.t list; - channels: Channel.t list; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/guild_j.ml b/lib/models/guild_j.ml new file mode 100644 index 0000000..9f7b069 --- /dev/null +++ b/lib/models/guild_j.ml @@ -0,0 +1,1948 @@ +(* Auto-generated from "guild.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = Guild_t.t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_role = ( + Role_j.write_t +) +let string_of_role ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_role ob x; + Bi_outbuf.contents ob +let read_role = ( + Role_j.read_t +) +let role_of_string s = + read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_member = ( + Member_j.write_t +) +let string_of_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_member ob x; + Bi_outbuf.contents ob +let read_member = ( + Member_j.read_t +) +let member_of_string s = + read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_emoji = ( + Emoji_j.write_t +) +let string_of_emoji ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_emoji ob x; + Bi_outbuf.contents ob +let read_emoji = ( + Emoji_j.read_t +) +let emoji_of_string s = + read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_channel = ( + Channel_j.write_t +) +let string_of_channel ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_channel ob x; + Bi_outbuf.contents ob +let read_channel = ( + Channel_j.read_t +) +let channel_of_string s = + read_channel (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__9 = ( + Atdgen_runtime.Oj_run.write_list ( + write_member + ) +) +let string_of__9 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__9 ob x; + Bi_outbuf.contents ob +let read__9 = ( + Atdgen_runtime.Oj_run.read_list ( + read_member + ) +) +let _9_of_string s = + read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__8 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__8 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__8 ob x; + Bi_outbuf.contents ob +let read__8 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _8_of_string s = + read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_option ( + write_channel + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_channel + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_channel + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_list ( + Yojson.Safe.write_string + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + Atdgen_runtime.Oj_run.read_list ( + Atdgen_runtime.Oj_run.read_string + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_list ( + write_emoji + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + Atdgen_runtime.Oj_run.read_list ( + read_emoji + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_list ( + write_role + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + Atdgen_runtime.Oj_run.read_list ( + read_role + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__11 = ( + Atdgen_runtime.Oj_run.write_list ( + write_channel + ) +) +let string_of__11 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__11 ob x; + Bi_outbuf.contents ob +let read__11 = ( + Atdgen_runtime.Oj_run.read_list ( + read_channel + ) +) +let _11_of_string s = + read__11 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__12 = ( + Atdgen_runtime.Oj_run.write_option ( + write__11 + ) +) +let string_of__12 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__12 ob x; + Bi_outbuf.contents ob +let read__12 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__11 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__11 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _12_of_string s = + read__12 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__10 = ( + Atdgen_runtime.Oj_run.write_option ( + write__9 + ) +) +let string_of__10 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__10 ob x; + Bi_outbuf.contents ob +let read__10 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__9 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__9 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _10_of_string s = + read__10 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + (match x.icon with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.splash with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"splash\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"owner_id\":"; + ( + write_snowflake + ) + ob x.owner_id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"region\":"; + ( + Yojson.Safe.write_string + ) + ob x.region; + (match x.afk_channel_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"afk_channel_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"afk_timeout\":"; + ( + Yojson.Safe.write_int + ) + ob x.afk_timeout; + (match x.embed_enabled with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embed_enabled\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.embed_channel_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embed_channel_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"verification_level\":"; + ( + Yojson.Safe.write_int + ) + ob x.verification_level; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"default_message_notifications\":"; + ( + Yojson.Safe.write_int + ) + ob x.default_message_notifications; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"explicit_content_filter\":"; + ( + Yojson.Safe.write_int + ) + ob x.explicit_content_filter; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__4 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"emojis\":"; + ( + write__5 + ) + ob x.emojis; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"features\":"; + ( + write__6 + ) + ob x.features; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mfa_level\":"; + ( + Yojson.Safe.write_int + ) + ob x.mfa_level; + (match x.application_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"application_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.widget_enabled with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"widget_enabled\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.widget_channel with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"widget_channel\":"; + ( + write_channel + ) + ob x; + ); + (match x.system_channel with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"system_channel\":"; + ( + write_channel + ) + ob x; + ); + (match x.large with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"large\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.unavailable with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"unavailable\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.member_count with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"member_count\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.members with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"members\":"; + ( + write__9 + ) + ob x; + ); + (match x.channels with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"channels\":"; + ( + write__11 + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_icon = ref (None) in + let field_splash = ref (None) in + let field_owner_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_region = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_afk_channel_id = ref (None) in + let field_afk_timeout = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_embed_enabled = ref (None) in + let field_embed_channel_id = ref (None) in + let field_verification_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_default_message_notifications = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_explicit_content_filter = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_emojis = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_features = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mfa_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_application_id = ref (None) in + let field_widget_enabled = ref (None) in + let field_widget_channel = ref (None) in + let field_system_channel = ref (None) in + let field_large = ref (None) in + let field_unavailable = ref (None) in + let field_member_count = ref (None) in + let field_members = ref (None) in + let field_channels = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'l' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 21 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 5 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( + 24 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( + 25 + ) + else ( + -1 + ) + ) + | 'f' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( + 15 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( + 16 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( + 7 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 22 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 12 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( + 23 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( + 8 + ) + else ( + -1 + ) + ) + | 14 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + match String.unsafe_get s (pos+1) with + | 'f' -> ( + if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 20 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( + match String.unsafe_get s (pos+7) with + | 'c' -> ( + if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 19 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( + 18 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 16 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( + 9 + ) + else ( + -1 + ) + ) + | 18 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( + 10 + ) + else ( + -1 + ) + ) + | 23 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( + 12 + ) + else ( + -1 + ) + ) + | 29 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_splash := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + field_owner_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 5 -> + field_region := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_afk_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 7 -> + field_afk_timeout := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 10 -> + field_verification_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 11 -> + field_default_message_notifications := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 12 -> + field_explicit_content_filter := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 13 -> + field_roles := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 14 -> + field_emojis := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 15 -> + field_features := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 16 -> + field_mfa_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 19 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 20 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_system_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 21 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_large := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 22 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_unavailable := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 23 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member_count := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 24 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_members := ( + Some ( + ( + read__9 + ) p lb + ) + ); + ) + | 25 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_channels := ( + Some ( + ( + read__11 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'l' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 21 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 5 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( + 24 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( + 25 + ) + else ( + -1 + ) + ) + | 'f' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( + 15 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( + 16 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( + 7 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 22 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 12 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( + 23 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( + 8 + ) + else ( + -1 + ) + ) + | 14 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + match String.unsafe_get s (pos+1) with + | 'f' -> ( + if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 20 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( + match String.unsafe_get s (pos+7) with + | 'c' -> ( + if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 19 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( + 18 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 16 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( + 9 + ) + else ( + -1 + ) + ) + | 18 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( + 10 + ) + else ( + -1 + ) + ) + | 23 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( + 12 + ) + else ( + -1 + ) + ) + | 29 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_splash := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + field_owner_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 5 -> + field_region := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_afk_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 7 -> + field_afk_timeout := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 10 -> + field_verification_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 11 -> + field_default_message_notifications := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 12 -> + field_explicit_content_filter := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 13 -> + field_roles := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 14 -> + field_emojis := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 15 -> + field_features := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 16 -> + field_mfa_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 19 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 20 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_system_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 21 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_large := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 22 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_unavailable := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 23 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member_count := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 24 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_members := ( + Some ( + ( + read__9 + ) p lb + ) + ); + ) + | 25 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_channels := ( + Some ( + ( + read__11 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xfff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "owner_id"; "region"; "afk_timeout"; "verification_level"; "default_message_notifications"; "explicit_content_filter"; "roles"; "emojis"; "features"; "mfa_level" |]; + ( + { + id = !field_id; + name = !field_name; + icon = !field_icon; + splash = !field_splash; + owner_id = !field_owner_id; + region = !field_region; + afk_channel_id = !field_afk_channel_id; + afk_timeout = !field_afk_timeout; + embed_enabled = !field_embed_enabled; + embed_channel_id = !field_embed_channel_id; + verification_level = !field_verification_level; + default_message_notifications = !field_default_message_notifications; + explicit_content_filter = !field_explicit_content_filter; + roles = !field_roles; + emojis = !field_emojis; + features = !field_features; + mfa_level = !field_mfa_level; + application_id = !field_application_id; + widget_enabled = !field_widget_enabled; + widget_channel = !field_widget_channel; + system_channel = !field_system_channel; + large = !field_large; + unavailable = !field_unavailable; + member_count = !field_member_count; + members = !field_members; + channels = !field_channels; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/guild_j.mli b/lib/models/guild_j.mli new file mode 100644 index 0000000..d430b2a --- /dev/null +++ b/lib/models/guild_j.mli @@ -0,0 +1,184 @@ +(* Auto-generated from "guild.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = Guild_t.t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_role : + Bi_outbuf.t -> role -> unit + (** Output a JSON value of type {!role}. *) + +val string_of_role : + ?len:int -> role -> string + (** Serialize a value of type {!role} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_role : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> role + (** Input JSON data of type {!role}. *) + +val role_of_string : + string -> role + (** Deserialize JSON data of type {!role}. *) + +val write_member : + Bi_outbuf.t -> member -> unit + (** Output a JSON value of type {!member}. *) + +val string_of_member : + ?len:int -> member -> string + (** Serialize a value of type {!member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> member + (** Input JSON data of type {!member}. *) + +val member_of_string : + string -> member + (** Deserialize JSON data of type {!member}. *) + +val write_emoji : + Bi_outbuf.t -> emoji -> unit + (** Output a JSON value of type {!emoji}. *) + +val string_of_emoji : + ?len:int -> emoji -> string + (** Serialize a value of type {!emoji} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_emoji : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji + (** Input JSON data of type {!emoji}. *) + +val emoji_of_string : + string -> emoji + (** Deserialize JSON data of type {!emoji}. *) + +val write_channel : + Bi_outbuf.t -> channel -> unit + (** Output a JSON value of type {!channel}. *) + +val string_of_channel : + ?len:int -> channel -> string + (** Serialize a value of type {!channel} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_channel : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> channel + (** Input JSON data of type {!channel}. *) + +val channel_of_string : + string -> channel + (** Deserialize JSON data of type {!channel}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/guild_t.ml b/lib/models/guild_t.ml new file mode 100644 index 0000000..9ffe83f --- /dev/null +++ b/lib/models/guild_t.ml @@ -0,0 +1,43 @@ +(* Auto-generated from "guild.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} diff --git a/lib/models/guild_t.mli b/lib/models/guild_t.mli new file mode 100644 index 0000000..9ffe83f --- /dev/null +++ b/lib/models/guild_t.mli @@ -0,0 +1,43 @@ +(* Auto-generated from "guild.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} diff --git a/lib/models/member.atd b/lib/models/member.atd new file mode 100644 index 0000000..ea00032 --- /dev/null +++ b/lib/models/member.atd @@ -0,0 +1,11 @@ +type snowflake = abstract +type user = abstract + +type t = { + user: user; + ?nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; +} \ No newline at end of file diff --git a/lib/models/member.ml b/lib/models/member.ml deleted file mode 100644 index 4621902..0000000 --- a/lib/models/member.ml +++ /dev/null @@ -1,8 +0,0 @@ -type t = { - user: User.t; - nick: string option; - roles: Role.t list; - joined_at: string; - deaf: bool; - mute: bool; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/member_j.ml b/lib/models/member_j.ml new file mode 100644 index 0000000..3826c93 --- /dev/null +++ b/lib/models/member_j.ml @@ -0,0 +1,448 @@ +(* Auto-generated from "member.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Member_t.t = { + user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; + (match x.nick with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nick\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"joined_at\":"; + ( + Yojson.Safe.write_string + ) + ob x.joined_at; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"deaf\":"; + ( + Yojson.Safe.write_bool + ) + ob x.deaf; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mute\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mute; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_nick = ref (None) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 5 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 5 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "joined_at"; "deaf"; "mute" |]; + ( + { + user = !field_user; + nick = !field_nick; + roles = !field_roles; + joined_at = !field_joined_at; + deaf = !field_deaf; + mute = !field_mute; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/member_j.mli b/lib/models/member_j.mli new file mode 100644 index 0000000..28c89fd --- /dev/null +++ b/lib/models/member_j.mli @@ -0,0 +1,76 @@ +(* Auto-generated from "member.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Member_t.t = { + user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/member_t.ml b/lib/models/member_t.ml new file mode 100644 index 0000000..1dd6ecd --- /dev/null +++ b/lib/models/member_t.ml @@ -0,0 +1,15 @@ +(* Auto-generated from "member.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} diff --git a/lib/models/member_t.mli b/lib/models/member_t.mli new file mode 100644 index 0000000..1dd6ecd --- /dev/null +++ b/lib/models/member_t.mli @@ -0,0 +1,15 @@ +(* Auto-generated from "member.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} diff --git a/lib/models/message.atd b/lib/models/message.atd new file mode 100644 index 0000000..88c60ec --- /dev/null +++ b/lib/models/message.atd @@ -0,0 +1,29 @@ +type snowflake = abstract +type user = abstract +type member = abstract +type role = abstract +type attachment = abstract +type embed = abstract +type reaction = abstract + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + ?member: member option; + ?guild_id: snowflake option; + content: string; + timestamp: string; + ?edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: user list; + role_mentions: role list; + attachments: attachment list; + embeds: embed list; + reactions: reaction list; + ?nonce: snowflake option; + pinned: bool; + webhook_id: snowflake; + kind : int; +} \ No newline at end of file diff --git a/lib/models/message.ml b/lib/models/message.ml deleted file mode 100644 index c578d9f..0000000 --- a/lib/models/message.ml +++ /dev/null @@ -1,21 +0,0 @@ -type t = { - id: Snowflake.t; - author: User.t; - channel: Channel.t; - member: Member.t option; - guild: Guild.t option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: User.t list; - role_mentions: Role.t list; - attachments: Attachment.t list; - embeds: Embed.t list; - reactions: Reaction.t list; - nonce: Snowflake.t option; - pinned: bool; - webhook_id: Snowflake.t; - kind: int; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/message_j.ml b/lib/models/message_j.ml new file mode 100644 index 0000000..79f33a1 --- /dev/null +++ b/lib/models/message_j.ml @@ -0,0 +1,1314 @@ +(* Auto-generated from "message.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type reaction = Reaction_t.t + +type member = Member_t.t + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = Message_t.t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: user list; + role_mentions: role list; + attachments: attachment list; + embeds: embed list; + reactions: reaction list; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake; + kind: int +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_role = ( + Role_j.write_t +) +let string_of_role ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_role ob x; + Bi_outbuf.contents ob +let read_role = ( + Role_j.read_t +) +let role_of_string s = + read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_reaction = ( + Reaction_j.write_t +) +let string_of_reaction ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_reaction ob x; + Bi_outbuf.contents ob +let read_reaction = ( + Reaction_j.read_t +) +let reaction_of_string s = + read_reaction (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_member = ( + Member_j.write_t +) +let string_of_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_member ob x; + Bi_outbuf.contents ob +let read_member = ( + Member_j.read_t +) +let member_of_string s = + read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_embed = ( + Embed_j.write_t +) +let string_of_embed ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_embed ob x; + Bi_outbuf.contents ob +let read_embed = ( + Embed_j.read_t +) +let embed_of_string s = + read_embed (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_attachment = ( + Attachment_j.write_t +) +let string_of_attachment ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_attachment ob x; + Bi_outbuf.contents ob +let read_attachment = ( + Attachment_j.read_t +) +let attachment_of_string s = + read_attachment (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__8 = ( + Atdgen_runtime.Oj_run.write_list ( + write_reaction + ) +) +let string_of__8 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__8 ob x; + Bi_outbuf.contents ob +let read__8 = ( + Atdgen_runtime.Oj_run.read_list ( + read_reaction + ) +) +let _8_of_string s = + read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_list ( + write_embed + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + Atdgen_runtime.Oj_run.read_list ( + read_embed + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_list ( + write_attachment + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + Atdgen_runtime.Oj_run.read_list ( + read_attachment + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_list ( + write_role + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + Atdgen_runtime.Oj_run.read_list ( + read_role + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_list ( + write_user + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + Atdgen_runtime.Oj_run.read_list ( + read_user + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_member + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_member + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_member + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"author\":"; + ( + write_user + ) + ob x.author; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"channel_id\":"; + ( + write_snowflake + ) + ob x.channel_id; + (match x.member with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"member\":"; + ( + write_member + ) + ob x; + ); + (match x.guild_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"content\":"; + ( + Yojson.Safe.write_string + ) + ob x.content; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x.timestamp; + (match x.edited_timestamp with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"edited_timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"tts\":"; + ( + Yojson.Safe.write_bool + ) + ob x.tts; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mention_everyone\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mention_everyone; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mentions\":"; + ( + write__4 + ) + ob x.mentions; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"role_mentions\":"; + ( + write__5 + ) + ob x.role_mentions; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"attachments\":"; + ( + write__6 + ) + ob x.attachments; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embeds\":"; + ( + write__7 + ) + ob x.embeds; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"reactions\":"; + ( + write__8 + ) + ob x.reactions; + (match x.nonce with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nonce\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"pinned\":"; + ( + Yojson.Safe.write_bool + ) + ob x.pinned; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"webhook_id\":"; + ( + write_snowflake + ) + ob x.webhook_id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; + ( + Yojson.Safe.write_int + ) + ob x.kind; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_author = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_channel_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_member = ref (None) in + let field_guild_id = ref (None) in + let field_content = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_timestamp = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_edited_timestamp = ref (None) in + let field_tts = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mention_everyone = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mentions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_role_mentions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_attachments = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_embeds = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_reactions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_nonce = ref (None) in + let field_pinned = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_webhook_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( + 8 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 18 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( + 15 + ) + else ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( + 16 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( + 10 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( + 12 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 16 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( + 7 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_author := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_channel_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member := ( + Some ( + ( + read_member + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 5 -> + field_content := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + field_timestamp := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_edited_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 8 -> + field_tts := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 9 -> + field_mention_everyone := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 10 -> + field_mentions := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 11 -> + field_role_mentions := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 12 -> + field_attachments := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 13 -> + field_embeds := ( + ( + read__7 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 14 -> + field_reactions := ( + ( + read__8 + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 15 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nonce := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 16 -> + field_pinned := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x1000; + | 17 -> + field_webhook_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x2000; + | 18 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4000; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( + 8 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 18 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( + 15 + ) + else ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( + 16 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( + 10 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( + 12 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 16 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( + 7 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_author := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_channel_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member := ( + Some ( + ( + read_member + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 5 -> + field_content := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + field_timestamp := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_edited_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 8 -> + field_tts := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 9 -> + field_mention_everyone := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 10 -> + field_mentions := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 11 -> + field_role_mentions := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 12 -> + field_attachments := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 13 -> + field_embeds := ( + ( + read__7 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 14 -> + field_reactions := ( + ( + read__8 + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 15 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nonce := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 16 -> + field_pinned := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x1000; + | 17 -> + field_webhook_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x2000; + | 18 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4000; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x7fff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "author"; "channel_id"; "content"; "timestamp"; "tts"; "mention_everyone"; "mentions"; "role_mentions"; "attachments"; "embeds"; "reactions"; "pinned"; "webhook_id"; "kind" |]; + ( + { + id = !field_id; + author = !field_author; + channel_id = !field_channel_id; + member = !field_member; + guild_id = !field_guild_id; + content = !field_content; + timestamp = !field_timestamp; + edited_timestamp = !field_edited_timestamp; + tts = !field_tts; + mention_everyone = !field_mention_everyone; + mentions = !field_mentions; + role_mentions = !field_role_mentions; + attachments = !field_attachments; + embeds = !field_embeds; + reactions = !field_reactions; + nonce = !field_nonce; + pinned = !field_pinned; + webhook_id = !field_webhook_id; + kind = !field_kind; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/message_j.mli b/lib/models/message_j.mli new file mode 100644 index 0000000..8f7ce13 --- /dev/null +++ b/lib/models/message_j.mli @@ -0,0 +1,199 @@ +(* Auto-generated from "message.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type reaction = Reaction_t.t + +type member = Member_t.t + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = Message_t.t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: user list; + role_mentions: role list; + attachments: attachment list; + embeds: embed list; + reactions: reaction list; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake; + kind: int +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_role : + Bi_outbuf.t -> role -> unit + (** Output a JSON value of type {!role}. *) + +val string_of_role : + ?len:int -> role -> string + (** Serialize a value of type {!role} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_role : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> role + (** Input JSON data of type {!role}. *) + +val role_of_string : + string -> role + (** Deserialize JSON data of type {!role}. *) + +val write_reaction : + Bi_outbuf.t -> reaction -> unit + (** Output a JSON value of type {!reaction}. *) + +val string_of_reaction : + ?len:int -> reaction -> string + (** Serialize a value of type {!reaction} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_reaction : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> reaction + (** Input JSON data of type {!reaction}. *) + +val reaction_of_string : + string -> reaction + (** Deserialize JSON data of type {!reaction}. *) + +val write_member : + Bi_outbuf.t -> member -> unit + (** Output a JSON value of type {!member}. *) + +val string_of_member : + ?len:int -> member -> string + (** Serialize a value of type {!member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> member + (** Input JSON data of type {!member}. *) + +val member_of_string : + string -> member + (** Deserialize JSON data of type {!member}. *) + +val write_embed : + Bi_outbuf.t -> embed -> unit + (** Output a JSON value of type {!embed}. *) + +val string_of_embed : + ?len:int -> embed -> string + (** Serialize a value of type {!embed} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_embed : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> embed + (** Input JSON data of type {!embed}. *) + +val embed_of_string : + string -> embed + (** Deserialize JSON data of type {!embed}. *) + +val write_attachment : + Bi_outbuf.t -> attachment -> unit + (** Output a JSON value of type {!attachment}. *) + +val string_of_attachment : + ?len:int -> attachment -> string + (** Serialize a value of type {!attachment} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_attachment : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> attachment + (** Input JSON data of type {!attachment}. *) + +val attachment_of_string : + string -> attachment + (** Deserialize JSON data of type {!attachment}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/message_t.ml b/lib/models/message_t.ml new file mode 100644 index 0000000..3d37442 --- /dev/null +++ b/lib/models/message_t.ml @@ -0,0 +1,38 @@ +(* Auto-generated from "message.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type reaction = Reaction_t.t + +type member = Member_t.t + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: user list; + role_mentions: role list; + attachments: attachment list; + embeds: embed list; + reactions: reaction list; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake; + kind: int +} diff --git a/lib/models/message_t.mli b/lib/models/message_t.mli new file mode 100644 index 0000000..3d37442 --- /dev/null +++ b/lib/models/message_t.mli @@ -0,0 +1,38 @@ +(* Auto-generated from "message.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type reaction = Reaction_t.t + +type member = Member_t.t + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: user list; + role_mentions: role list; + attachments: attachment list; + embeds: embed list; + reactions: reaction list; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake; + kind: int +} diff --git a/lib/models/presence.atd b/lib/models/presence.atd new file mode 100644 index 0000000..c455fec --- /dev/null +++ b/lib/models/presence.atd @@ -0,0 +1,13 @@ +type user = abstract +type role = abstract +type activity = abstract +type guild = abstract + +type t = { + user: user; + roles: role list; + ?game: activity option; + guild: guild; + status: string; + activities: activity list; +} \ No newline at end of file diff --git a/lib/models/presence.ml b/lib/models/presence.ml deleted file mode 100644 index ed1bdb6..0000000 --- a/lib/models/presence.ml +++ /dev/null @@ -1,8 +0,0 @@ -type t = { - user: User.t; - roles: Role.t list; - game: Activity.t option; - guild: Guild.t; - status: string; - activities: Activity.t list; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/presence_j.ml b/lib/models/presence_j.ml new file mode 100644 index 0000000..91ef86d --- /dev/null +++ b/lib/models/presence_j.ml @@ -0,0 +1,504 @@ +(* Auto-generated from "presence.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type role = Role_t.t + +type guild = Guild_t.t + +type activity = Activity_t.t + +type t = Presence_t.t = { + user: user; + roles: role list; + game: activity option; + guild: guild; + status: string; + activities: activity list +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_role = ( + Role_j.write_t +) +let string_of_role ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_role ob x; + Bi_outbuf.contents ob +let read_role = ( + Role_j.read_t +) +let role_of_string s = + read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_guild = ( + Guild_j.write_t +) +let string_of_guild ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_guild ob x; + Bi_outbuf.contents ob +let read_guild = ( + Guild_j.read_t +) +let guild_of_string s = + read_guild (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_activity = ( + Activity_j.write_t +) +let string_of_activity ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_activity ob x; + Bi_outbuf.contents ob +let read_activity = ( + Activity_j.read_t +) +let activity_of_string s = + read_activity (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_list ( + write_activity + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + Atdgen_runtime.Oj_run.read_list ( + read_activity + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_activity + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_activity + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_activity + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_list ( + write_role + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + Atdgen_runtime.Oj_run.read_list ( + read_role + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__1 + ) + ob x.roles; + (match x.game with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"game\":"; + ( + write_activity + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild\":"; + ( + write_guild + ) + ob x.guild; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"status\":"; + ( + Yojson.Safe.write_string + ) + ob x.status; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"activities\":"; + ( + write__3 + ) + ob x.activities; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_game = ref (None) in + let field_guild = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_status = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_activities = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | 10 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_roles := ( + ( + read__1 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_game := ( + Some ( + ( + read_activity + ) p lb + ) + ); + ) + | 3 -> + field_guild := ( + ( + read_guild + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_status := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_activities := ( + ( + read__3 + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | 10 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_roles := ( + ( + read__1 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_game := ( + Some ( + ( + read_activity + ) p lb + ) + ); + ) + | 3 -> + field_guild := ( + ( + read_guild + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_status := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_activities := ( + ( + read__3 + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "guild"; "status"; "activities" |]; + ( + { + user = !field_user; + roles = !field_roles; + game = !field_game; + guild = !field_guild; + status = !field_status; + activities = !field_activities; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/presence_j.mli b/lib/models/presence_j.mli new file mode 100644 index 0000000..9da05ec --- /dev/null +++ b/lib/models/presence_j.mli @@ -0,0 +1,120 @@ +(* Auto-generated from "presence.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type role = Role_t.t + +type guild = Guild_t.t + +type activity = Activity_t.t + +type t = Presence_t.t = { + user: user; + roles: role list; + game: activity option; + guild: guild; + status: string; + activities: activity list +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_role : + Bi_outbuf.t -> role -> unit + (** Output a JSON value of type {!role}. *) + +val string_of_role : + ?len:int -> role -> string + (** Serialize a value of type {!role} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_role : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> role + (** Input JSON data of type {!role}. *) + +val role_of_string : + string -> role + (** Deserialize JSON data of type {!role}. *) + +val write_guild : + Bi_outbuf.t -> guild -> unit + (** Output a JSON value of type {!guild}. *) + +val string_of_guild : + ?len:int -> guild -> string + (** Serialize a value of type {!guild} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_guild : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> guild + (** Input JSON data of type {!guild}. *) + +val guild_of_string : + string -> guild + (** Deserialize JSON data of type {!guild}. *) + +val write_activity : + Bi_outbuf.t -> activity -> unit + (** Output a JSON value of type {!activity}. *) + +val string_of_activity : + ?len:int -> activity -> string + (** Serialize a value of type {!activity} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_activity : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> activity + (** Input JSON data of type {!activity}. *) + +val activity_of_string : + string -> activity + (** Deserialize JSON data of type {!activity}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/presence_t.ml b/lib/models/presence_t.ml new file mode 100644 index 0000000..7a26905 --- /dev/null +++ b/lib/models/presence_t.ml @@ -0,0 +1,19 @@ +(* Auto-generated from "presence.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type role = Role_t.t + +type guild = Guild_t.t + +type activity = Activity_t.t + +type t = { + user: user; + roles: role list; + game: activity option; + guild: guild; + status: string; + activities: activity list +} diff --git a/lib/models/presence_t.mli b/lib/models/presence_t.mli new file mode 100644 index 0000000..7a26905 --- /dev/null +++ b/lib/models/presence_t.mli @@ -0,0 +1,19 @@ +(* Auto-generated from "presence.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type role = Role_t.t + +type guild = Guild_t.t + +type activity = Activity_t.t + +type t = { + user: user; + roles: role list; + game: activity option; + guild: guild; + status: string; + activities: activity list +} diff --git a/lib/models/reaction.atd b/lib/models/reaction.atd new file mode 100644 index 0000000..aa41483 --- /dev/null +++ b/lib/models/reaction.atd @@ -0,0 +1,6 @@ +type emoji = abstract + +type t = { + count: int; + emoji: emoji; +} \ No newline at end of file diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml deleted file mode 100644 index 00bebe6..0000000 --- a/lib/models/reaction.ml +++ /dev/null @@ -1,4 +0,0 @@ -type t = { - count: int; - emoji: Emoji.t; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/reaction_j.ml b/lib/models/reaction_j.ml new file mode 100644 index 0000000..fe91833 --- /dev/null +++ b/lib/models/reaction_j.ml @@ -0,0 +1,180 @@ +(* Auto-generated from "reaction.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = Reaction_t.t = { count: int; emoji: emoji } + +let write_emoji = ( + Emoji_j.write_t +) +let string_of_emoji ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_emoji ob x; + Bi_outbuf.contents ob +let read_emoji = ( + Emoji_j.read_t +) +let emoji_of_string s = + read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"count\":"; + ( + Yojson.Safe.write_int + ) + ob x.count; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"emoji\":"; + ( + write_emoji + ) + ob x.emoji; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_count = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_emoji = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 5 then ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_count := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_emoji := ( + ( + read_emoji + ) p lb + ); + bits0 := !bits0 lor 0x2; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 5 then ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_count := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_emoji := ( + ( + read_emoji + ) p lb + ); + bits0 := !bits0 lor 0x2; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "count"; "emoji" |]; + ( + { + count = !field_count; + emoji = !field_emoji; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/reaction_j.mli b/lib/models/reaction_j.mli new file mode 100644 index 0000000..0d6a598 --- /dev/null +++ b/lib/models/reaction_j.mli @@ -0,0 +1,47 @@ +(* Auto-generated from "reaction.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = Reaction_t.t = { count: int; emoji: emoji } + +val write_emoji : + Bi_outbuf.t -> emoji -> unit + (** Output a JSON value of type {!emoji}. *) + +val string_of_emoji : + ?len:int -> emoji -> string + (** Serialize a value of type {!emoji} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_emoji : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji + (** Input JSON data of type {!emoji}. *) + +val emoji_of_string : + string -> emoji + (** Deserialize JSON data of type {!emoji}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/reaction_t.ml b/lib/models/reaction_t.ml new file mode 100644 index 0000000..666030b --- /dev/null +++ b/lib/models/reaction_t.ml @@ -0,0 +1,6 @@ +(* Auto-generated from "reaction.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = { count: int; emoji: emoji } diff --git a/lib/models/reaction_t.mli b/lib/models/reaction_t.mli new file mode 100644 index 0000000..666030b --- /dev/null +++ b/lib/models/reaction_t.mli @@ -0,0 +1,6 @@ +(* Auto-generated from "reaction.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = { count: int; emoji: emoji } diff --git a/lib/models/role.atd b/lib/models/role.atd new file mode 100644 index 0000000..a6bdcba --- /dev/null +++ b/lib/models/role.atd @@ -0,0 +1,12 @@ +type snowflake = abstract + +type t = { + id: snowflake; + name: string; + colour : int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool; +} \ No newline at end of file diff --git a/lib/models/role.ml b/lib/models/role.ml deleted file mode 100644 index 0577342..0000000 --- a/lib/models/role.ml +++ /dev/null @@ -1,10 +0,0 @@ -type t = { - id: Snowflake.t; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/role_j.ml b/lib/models/role_j.ml new file mode 100644 index 0000000..a15b6cf --- /dev/null +++ b/lib/models/role_j.ml @@ -0,0 +1,449 @@ +(* Auto-generated from "role.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Role_t.t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"color\":"; + ( + Yojson.Safe.write_int + ) + ob x.colour; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"hoist\":"; + ( + Yojson.Safe.write_bool + ) + ob x.hoist; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"position\":"; + ( + Yojson.Safe.write_int + ) + ob x.position; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"permissions\":"; + ( + Yojson.Safe.write_int + ) + ob x.permissions; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"managed\":"; + ( + Yojson.Safe.write_bool + ) + ob x.managed; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mentionable\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mentionable; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_colour = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_hoist = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_position = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_permissions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_managed = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mentionable = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | 'h' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 4 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_colour := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_hoist := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_position := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + field_permissions := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 6 -> + field_managed := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 7 -> + field_mentionable := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x80; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | 'h' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 4 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_colour := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_hoist := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_position := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + field_permissions := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 6 -> + field_managed := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 7 -> + field_mentionable := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x80; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "colour"; "hoist"; "position"; "permissions"; "managed"; "mentionable" |]; + ( + { + id = !field_id; + name = !field_name; + colour = !field_colour; + hoist = !field_hoist; + position = !field_position; + permissions = !field_permissions; + managed = !field_managed; + mentionable = !field_mentionable; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/role_j.mli b/lib/models/role_j.mli new file mode 100644 index 0000000..b4ea78c --- /dev/null +++ b/lib/models/role_j.mli @@ -0,0 +1,56 @@ +(* Auto-generated from "role.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Role_t.t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/role_t.ml b/lib/models/role_t.ml new file mode 100644 index 0000000..a4e83c5 --- /dev/null +++ b/lib/models/role_t.ml @@ -0,0 +1,15 @@ +(* Auto-generated from "role.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} diff --git a/lib/models/role_t.mli b/lib/models/role_t.mli new file mode 100644 index 0000000..a4e83c5 --- /dev/null +++ b/lib/models/role_t.mli @@ -0,0 +1,15 @@ +(* Auto-generated from "role.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} diff --git a/lib/models/snowflake.atd b/lib/models/snowflake.atd new file mode 100644 index 0000000..98dc032 --- /dev/null +++ b/lib/models/snowflake.atd @@ -0,0 +1 @@ +type t = int \ No newline at end of file diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml deleted file mode 100644 index ab723a7..0000000 --- a/lib/models/snowflake.ml +++ /dev/null @@ -1,16 +0,0 @@ -type t = { - id: int; - as_string: string; -} [@@deriving yojson] - -let to_int t = t.id -let to_string t = t.as_string - -let from_int i = { - id = i; - as_string = string_of_int i; -} -let from_string s = { - id = int_of_string s; - as_string = s; -} \ No newline at end of file diff --git a/lib/models/snowflake_j.ml b/lib/models/snowflake_j.ml new file mode 100644 index 0000000..80f6f63 --- /dev/null +++ b/lib/models/snowflake_j.ml @@ -0,0 +1,17 @@ +(* Auto-generated from "snowflake.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Snowflake_t.t + +let write_t = ( + Yojson.Safe.write_int +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + Atdgen_runtime.Oj_run.read_int +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/snowflake_j.mli b/lib/models/snowflake_j.mli new file mode 100644 index 0000000..fed97a4 --- /dev/null +++ b/lib/models/snowflake_j.mli @@ -0,0 +1,25 @@ +(* Auto-generated from "snowflake.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Snowflake_t.t + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/snowflake_t.ml b/lib/models/snowflake_t.ml new file mode 100644 index 0000000..a7bdb08 --- /dev/null +++ b/lib/models/snowflake_t.ml @@ -0,0 +1,4 @@ +(* Auto-generated from "snowflake.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = int diff --git a/lib/models/snowflake_t.mli b/lib/models/snowflake_t.mli new file mode 100644 index 0000000..a7bdb08 --- /dev/null +++ b/lib/models/snowflake_t.mli @@ -0,0 +1,4 @@ +(* Auto-generated from "snowflake.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = int diff --git a/lib/models/user.atd b/lib/models/user.atd new file mode 100644 index 0000000..73e2ff9 --- /dev/null +++ b/lib/models/user.atd @@ -0,0 +1,9 @@ +type snowflake = abstract + +type t = { + id: snowflake; + username: string; + discriminator: string; + ?avatar: string option; + ~bot : bool; +} \ No newline at end of file diff --git a/lib/models/user.ml b/lib/models/user.ml deleted file mode 100644 index e6c5c69..0000000 --- a/lib/models/user.ml +++ /dev/null @@ -1,7 +0,0 @@ -type t = { - id: Snowflake.t; - username: string; - discriminator: string; - avatar: string; - bot: bool; -} [@@deriving yojson] \ No newline at end of file diff --git a/lib/models/user_j.ml b/lib/models/user_j.ml new file mode 100644 index 0000000..6eb93e6 --- /dev/null +++ b/lib/models/user_j.ml @@ -0,0 +1,368 @@ +(* Auto-generated from "user.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = User_t.t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"username\":"; + ( + Yojson.Safe.write_string + ) + ob x.username; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"discriminator\":"; + ( + Yojson.Safe.write_string + ) + ob x.discriminator; + (match x.avatar with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"avatar\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if x.bot <> false then ( + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"bot\":"; + ( + Yojson.Safe.write_bool + ) + ob x.bot; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_username = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_discriminator = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_avatar = ref (None) in + let field_bot = ref (false) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( + 4 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_username := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_discriminator := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_avatar := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bot := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( + 4 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_username := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_discriminator := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_avatar := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bot := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x7 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "username"; "discriminator" |]; + ( + { + id = !field_id; + username = !field_username; + discriminator = !field_discriminator; + avatar = !field_avatar; + bot = !field_bot; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/user_j.mli b/lib/models/user_j.mli new file mode 100644 index 0000000..0a1c6e1 --- /dev/null +++ b/lib/models/user_j.mli @@ -0,0 +1,53 @@ +(* Auto-generated from "user.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = User_t.t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/user_t.ml b/lib/models/user_t.ml new file mode 100644 index 0000000..b303aa3 --- /dev/null +++ b/lib/models/user_t.ml @@ -0,0 +1,12 @@ +(* Auto-generated from "user.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} diff --git a/lib/models/user_t.mli b/lib/models/user_t.mli new file mode 100644 index 0000000..b303aa3 --- /dev/null +++ b/lib/models/user_t.mli @@ -0,0 +1,12 @@ +(* Auto-generated from "user.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} diff --git a/lib/sharder.ml b/lib/sharder.ml index 6ac8584..7366fd9 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -70,7 +70,8 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct if t = "READY" then begin Ivar.fill_if_empty shard.ready () end; - D.dispatch ~ev:t data; + print_endline @@ Yojson.Safe.pretty_to_string data; + D.dispatch ~ev:t (Yojson.Safe.to_string data); return { shard with seq = seq; session = session; @@ -105,7 +106,7 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct let request_guild_members ?(query="") ?(limit=0) ~guild shard = let payload = `Assoc [ - ("guild_id", `String (Snowflake.to_string guild)); + ("guild_id", `String (Int.to_string guild)); ("query", `String query); ("limit", `Int limit); ] in -- cgit v1.2.3 From 179d9598fe62e2966471b312fd438e98ff3a272a Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Thu, 13 Dec 2018 15:50:37 -0700 Subject: Fix more dispatch issues --- lib/dispatch.ml | 6 +- lib/http.ml | 5 +- lib/models/activity.atd | 6 +- lib/models/activity_j.ml | 223 +++++++++++++++++++++---- lib/models/activity_j.mli | 24 +-- lib/models/activity_t.ml | 4 +- lib/models/activity_t.mli | 4 +- lib/models/member.atd | 8 +- lib/models/member_j.ml | 404 ++++++++++++++++++++++++++++++++++++++++------ lib/models/member_j.mli | 30 +++- lib/models/member_t.ml | 10 +- lib/models/member_t.mli | 10 +- lib/models/message.atd | 3 +- lib/models/message_j.ml | 46 ++++-- lib/models/message_j.mli | 50 ++++-- lib/models/message_t.ml | 6 +- lib/models/message_t.mli | 6 +- lib/models/presence.atd | 10 +- lib/models/presence_j.ml | 140 ++++++++-------- lib/models/presence_j.mli | 58 +++---- lib/models/presence_t.ml | 10 +- lib/models/presence_t.mli | 10 +- lib/models/user.atd | 4 + lib/models/user_j.ml | 100 ++++++++++++ lib/models/user_j.mli | 22 +++ lib/models/user_t.ml | 2 + lib/models/user_t.mli | 2 + lib/rl.ml | 3 +- lib/s.ml | 6 +- 29 files changed, 926 insertions(+), 286 deletions(-) (limited to 'lib') diff --git a/lib/dispatch.ml b/lib/dispatch.ml index cb6e5d9..a4341e1 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -59,17 +59,17 @@ module Make(H : S.Handler) : S.Dispatch = struct | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member_j.t_of_string contents) | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member_j.t_of_string contents) | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member_j.t_of_string contents) - (* | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Member_j.t_of_string m)) *) + | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Member_j.t_of_string)) | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role_j.t_of_string contents) | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role_j.t_of_string contents) | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role_j.t_of_string contents) | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_j.t_of_string contents) | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_j.t_of_string contents) | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message_j.t_of_string contents) - (* | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun m -> Message_j.t_of_string m)) *) + | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Message_j.t_of_string)) | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_j.t_of_string contents) | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_j.t_of_string contents) - (* | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.Util.to_list contents |> List.map ~f:(fun r -> Reaction_j.t_of_string r)) *) + | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Reaction_j.t_of_string)) | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence_j.t_of_string contents) | "TYPING_START" -> TYPING_START (Yojson.Safe.from_string contents) | "USER_UPDATE" -> USER_UPDATE (Yojson.Safe.from_string contents) diff --git a/lib/http.ml b/lib/http.ml index d2dff65..810bdc3 100644 --- a/lib/http.ml +++ b/lib/http.ml @@ -37,7 +37,10 @@ module Make(T : S.Token) = struct let request ?(body=`Null) m path = rl := Rl.update ~f:(function - | None -> Mvar.create () + | None -> + let r = Mvar.create () in + Mvar.set r Rl.default; + r | Some r -> r ) !rl path; let limit = Rl.find_exn !rl path in diff --git a/lib/models/activity.atd b/lib/models/activity.atd index 94b4b3c..8e02191 100644 --- a/lib/models/activity.atd +++ b/lib/models/activity.atd @@ -1,5 +1,5 @@ -type snowflake = abstract - type t = { - id: snowflake; + name: string; + kind : int; + ?url: string option; } \ No newline at end of file diff --git a/lib/models/activity_j.ml b/lib/models/activity_j.ml index 8a4eb2e..eb1a62e 100644 --- a/lib/models/activity_j.ml +++ b/lib/models/activity_j.ml @@ -1,22 +1,65 @@ (* Auto-generated from "activity.atd" *) [@@@ocaml.warning "-27-32-35-39"] -type snowflake = Snowflake_t.t +type t = Activity_t.t = { name: string; kind: int; url: string option } -type t = Activity_t.t = { id: snowflake } - -let write_snowflake = ( - Snowflake_j.write_t +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) ) -let string_of_snowflake ?(len = 1024) x = +let string_of__1 ?(len = 1024) x = let ob = Bi_outbuf.create len in - write_snowflake ob x; + write__1 ob x; Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) ) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_t : _ -> t -> _ = ( fun ob x -> Bi_outbuf.add_char ob '{'; @@ -25,11 +68,31 @@ let write_t : _ -> t -> _ = ( is_first := false else Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; ( - write_snowflake + Yojson.Safe.write_int ) - ob x.id; + ob x.kind; + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); Bi_outbuf.add_char ob '}'; ) let string_of_t ?(len = 1024) x = @@ -40,7 +103,9 @@ let read_t = ( fun p lb -> Yojson.Safe.read_space p lb; Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_url = ref (None) in let bits0 = ref 0 in try Yojson.Safe.read_space p lb; @@ -50,24 +115,69 @@ let read_t = ( fun s pos len -> if pos < 0 || len < 0 || pos + len > String.length s then invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) in let i = Yojson.Safe.map_ident p f lb in Atdgen_runtime.Oj_run.read_until_field_value p lb; ( match i with | 0 -> - field_id := ( + field_name := ( ( - read_snowflake + Atdgen_runtime.Oj_run.read_string ) p lb ); bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) | _ -> ( Yojson.Safe.skip_json p lb ) @@ -80,24 +190,69 @@ let read_t = ( fun s pos len -> if pos < 0 || len < 0 || pos + len > String.length s then invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) in let i = Yojson.Safe.map_ident p f lb in Atdgen_runtime.Oj_run.read_until_field_value p lb; ( match i with | 0 -> - field_id := ( + field_name := ( ( - read_snowflake + Atdgen_runtime.Oj_run.read_string ) p lb ); bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) | _ -> ( Yojson.Safe.skip_json p lb ) @@ -105,10 +260,12 @@ let read_t = ( done; assert false; with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "kind" |]; ( { - id = !field_id; + name = !field_name; + kind = !field_kind; + url = !field_url; } : t) ) diff --git a/lib/models/activity_j.mli b/lib/models/activity_j.mli index 3c93cc1..c179efb 100644 --- a/lib/models/activity_j.mli +++ b/lib/models/activity_j.mli @@ -1,29 +1,7 @@ (* Auto-generated from "activity.atd" *) [@@@ocaml.warning "-27-32-35-39"] -type snowflake = Snowflake_t.t - -type t = Activity_t.t = { id: snowflake } - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) +type t = Activity_t.t = { name: string; kind: int; url: string option } val write_t : Bi_outbuf.t -> t -> unit diff --git a/lib/models/activity_t.ml b/lib/models/activity_t.ml index f9ba6a6..6bb2049 100644 --- a/lib/models/activity_t.ml +++ b/lib/models/activity_t.ml @@ -1,6 +1,4 @@ (* Auto-generated from "activity.atd" *) [@@@ocaml.warning "-27-32-35-39"] -type snowflake = Snowflake_t.t - -type t = { id: snowflake } +type t = { name: string; kind: int; url: string option } diff --git a/lib/models/activity_t.mli b/lib/models/activity_t.mli index f9ba6a6..6bb2049 100644 --- a/lib/models/activity_t.mli +++ b/lib/models/activity_t.mli @@ -1,6 +1,4 @@ (* Auto-generated from "activity.atd" *) [@@@ocaml.warning "-27-32-35-39"] -type snowflake = Snowflake_t.t - -type t = { id: snowflake } +type t = { name: string; kind: int; url: string option } diff --git a/lib/models/member.atd b/lib/models/member.atd index ea00032..11d8b62 100644 --- a/lib/models/member.atd +++ b/lib/models/member.atd @@ -1,11 +1,15 @@ type snowflake = abstract type user = abstract -type t = { - user: user; +type partial_member = { ?nick: string option; roles: snowflake list; joined_at: string; deaf: bool; mute: bool; +} + +type t = { + inherit partial_member; + user: user; } \ No newline at end of file diff --git a/lib/models/member_j.ml b/lib/models/member_j.ml index 3826c93..7fd4aec 100644 --- a/lib/models/member_j.ml +++ b/lib/models/member_j.ml @@ -6,7 +6,15 @@ type user = User_t.t type snowflake = Snowflake_t.t type t = Member_t.t = { - user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = Member_t.partial_member = { nick: string option; roles: snowflake list; joined_at: string; @@ -115,15 +123,6 @@ let write_t : _ -> t -> _ = ( fun ob x -> Bi_outbuf.add_char ob '{'; let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user\":"; - ( - write_user - ) - ob x.user; (match x.nick with None -> () | Some x -> if !is_first then is_first := false @@ -171,6 +170,15 @@ let write_t : _ -> t -> _ = ( Yojson.Safe.write_bool ) ob x.mute; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; Bi_outbuf.add_char ob '}'; ) let string_of_t ?(len = 1024) x = @@ -181,12 +189,12 @@ let read_t = ( fun p lb -> Yojson.Safe.read_space p lb; Yojson.Safe.read_lcurl p lb; - let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_nick = ref (None) in let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in let bits0 = ref 0 in try Yojson.Safe.read_space p lb; @@ -201,7 +209,7 @@ let read_t = ( match String.unsafe_get s pos with | 'd' -> ( if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 4 + 3 ) else ( -1 @@ -209,7 +217,7 @@ let read_t = ( ) | 'm' -> ( if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 5 + 4 ) else ( -1 @@ -217,7 +225,7 @@ let read_t = ( ) | 'n' -> ( if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 1 + 0 ) else ( -1 @@ -225,7 +233,7 @@ let read_t = ( ) | 'u' -> ( if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 0 + 5 ) else ( -1 @@ -237,7 +245,7 @@ let read_t = ( ) | 5 -> ( if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 2 + 1 ) else ( -1 @@ -245,7 +253,7 @@ let read_t = ( ) | 9 -> ( if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 3 + 2 ) else ( -1 @@ -260,13 +268,6 @@ let read_t = ( ( match i with | 0 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> if not (Yojson.Safe.read_null_if_possible p lb) then ( field_nick := ( Some ( @@ -276,31 +277,38 @@ let read_t = ( ) ); ) - | 2 -> + | 1 -> field_roles := ( ( read__2 ) p lb ); - bits0 := !bits0 lor 0x2; - | 3 -> + bits0 := !bits0 lor 0x1; + | 2 -> field_joined_at := ( ( Atdgen_runtime.Oj_run.read_string ) p lb ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); bits0 := !bits0 lor 0x4; | 4 -> - field_deaf := ( + field_mute := ( ( Atdgen_runtime.Oj_run.read_bool ) p lb ); bits0 := !bits0 lor 0x8; | 5 -> - field_mute := ( + field_user := ( ( - Atdgen_runtime.Oj_run.read_bool + read_user ) p lb ); bits0 := !bits0 lor 0x10; @@ -321,7 +329,7 @@ let read_t = ( match String.unsafe_get s pos with | 'd' -> ( if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 4 + 3 ) else ( -1 @@ -329,7 +337,7 @@ let read_t = ( ) | 'm' -> ( if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 5 + 4 ) else ( -1 @@ -337,7 +345,7 @@ let read_t = ( ) | 'n' -> ( if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 1 + 0 ) else ( -1 @@ -345,7 +353,7 @@ let read_t = ( ) | 'u' -> ( if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 0 + 5 ) else ( -1 @@ -357,7 +365,7 @@ let read_t = ( ) | 5 -> ( if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 2 + 1 ) else ( -1 @@ -365,7 +373,7 @@ let read_t = ( ) | 9 -> ( if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 3 + 2 ) else ( -1 @@ -380,13 +388,6 @@ let read_t = ( ( match i with | 0 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> if not (Yojson.Safe.read_null_if_possible p lb) then ( field_nick := ( Some ( @@ -396,31 +397,38 @@ let read_t = ( ) ); ) - | 2 -> + | 1 -> field_roles := ( ( read__2 ) p lb ); - bits0 := !bits0 lor 0x2; - | 3 -> + bits0 := !bits0 lor 0x1; + | 2 -> field_joined_at := ( ( Atdgen_runtime.Oj_run.read_string ) p lb ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); bits0 := !bits0 lor 0x4; | 4 -> - field_deaf := ( + field_mute := ( ( Atdgen_runtime.Oj_run.read_bool ) p lb ); bits0 := !bits0 lor 0x8; | 5 -> - field_mute := ( + field_user := ( ( - Atdgen_runtime.Oj_run.read_bool + read_user ) p lb ); bits0 := !bits0 lor 0x10; @@ -431,18 +439,312 @@ let read_t = ( done; assert false; with Yojson.End_of_object -> ( - if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "joined_at"; "deaf"; "mute" |]; + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute"; "user" |]; ( { - user = !field_user; nick = !field_nick; roles = !field_roles; joined_at = !field_joined_at; deaf = !field_deaf; mute = !field_mute; + user = !field_user; } : t) ) ) let t_of_string s = read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_member : _ -> partial_member -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.nick with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nick\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"joined_at\":"; + ( + Yojson.Safe.write_string + ) + ob x.joined_at; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"deaf\":"; + ( + Yojson.Safe.write_bool + ) + ob x.deaf; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mute\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mute; + Bi_outbuf.add_char ob '}'; +) +let string_of_partial_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_member ob x; + Bi_outbuf.contents ob +let read_partial_member = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_nick = ref (None) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xf then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute" |]; + ( + { + nick = !field_nick; + roles = !field_roles; + joined_at = !field_joined_at; + deaf = !field_deaf; + mute = !field_mute; + } + : partial_member) + ) +) +let partial_member_of_string s = + read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/member_j.mli b/lib/models/member_j.mli index 28c89fd..f160b6d 100644 --- a/lib/models/member_j.mli +++ b/lib/models/member_j.mli @@ -6,7 +6,15 @@ type user = User_t.t type snowflake = Snowflake_t.t type t = Member_t.t = { - user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = Member_t.partial_member = { nick: string option; roles: snowflake list; joined_at: string; @@ -74,3 +82,23 @@ val t_of_string : string -> t (** Deserialize JSON data of type {!t}. *) +val write_partial_member : + Bi_outbuf.t -> partial_member -> unit + (** Output a JSON value of type {!partial_member}. *) + +val string_of_partial_member : + ?len:int -> partial_member -> string + (** Serialize a value of type {!partial_member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member + (** Input JSON data of type {!partial_member}. *) + +val partial_member_of_string : + string -> partial_member + (** Deserialize JSON data of type {!partial_member}. *) + diff --git a/lib/models/member_t.ml b/lib/models/member_t.ml index 1dd6ecd..6262e1b 100644 --- a/lib/models/member_t.ml +++ b/lib/models/member_t.ml @@ -6,7 +6,15 @@ type user = User_t.t type snowflake = Snowflake_t.t type t = { - user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = { nick: string option; roles: snowflake list; joined_at: string; diff --git a/lib/models/member_t.mli b/lib/models/member_t.mli index 1dd6ecd..6262e1b 100644 --- a/lib/models/member_t.mli +++ b/lib/models/member_t.mli @@ -6,7 +6,15 @@ type user = User_t.t type snowflake = Snowflake_t.t type t = { - user: user; + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = { nick: string option; roles: snowflake list; joined_at: string; diff --git a/lib/models/message.atd b/lib/models/message.atd index 88c60ec..1c90be9 100644 --- a/lib/models/message.atd +++ b/lib/models/message.atd @@ -1,6 +1,7 @@ type snowflake = abstract type user = abstract type member = abstract +type partial_member = abstract type role = abstract type attachment = abstract type embed = abstract @@ -10,7 +11,7 @@ type t = { id: snowflake; author: user; channel_id: snowflake; - ?member: member option; + ?member: partial_member option; ?guild_id: snowflake option; content: string; timestamp: string; diff --git a/lib/models/message_j.ml b/lib/models/message_j.ml index 79f33a1..206d69c 100644 --- a/lib/models/message_j.ml +++ b/lib/models/message_j.ml @@ -9,7 +9,7 @@ type role = Role_t.t type reaction = Reaction_t.t -type member = Member_t.t +type partial_member = Member_t.partial_member type embed = Embed_t.t @@ -19,7 +19,7 @@ type t = Message_t.t = { id: snowflake; author: user; channel_id: snowflake; - member: member option; + member: partial_member option; guild_id: snowflake option; content: string; timestamp: string; @@ -37,6 +37,8 @@ type t = Message_t.t = { kind: int } +type member = Member_t.t + let write_user = ( User_j.write_t ) @@ -85,18 +87,18 @@ let read_reaction = ( ) let reaction_of_string s = read_reaction (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_member = ( - Member_j.write_t +let write_partial_member = ( + Member_j.write_partial_member ) -let string_of_member ?(len = 1024) x = +let string_of_partial_member ?(len = 1024) x = let ob = Bi_outbuf.create len in - write_member ob x; + write_partial_member ob x; Bi_outbuf.contents ob -let read_member = ( - Member_j.read_t +let read_partial_member = ( + Member_j.read_partial_member ) -let member_of_string s = - read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let partial_member_of_string s = + read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_embed = ( Embed_j.write_t ) @@ -317,7 +319,7 @@ let _2_of_string s = read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write__1 = ( Atdgen_runtime.Oj_run.write_option ( - write_member + write_partial_member ) ) let string_of__1 ?(len = 1024) x = @@ -337,7 +339,7 @@ let read__1 = ( | "Some" -> Atdgen_runtime.Oj_run.read_until_field_value p lb; let x = ( - read_member + read_partial_member ) p lb in Yojson.Safe.read_space p lb; @@ -360,7 +362,7 @@ let read__1 = ( Yojson.Safe.read_comma p lb; Yojson.Safe.read_space p lb; let x = ( - read_member + read_partial_member ) p lb in Yojson.Safe.read_space p lb; @@ -410,7 +412,7 @@ let write_t : _ -> t -> _ = ( Bi_outbuf.add_char ob ','; Bi_outbuf.add_string ob "\"member\":"; ( - write_member + write_partial_member ) ob x; ); @@ -810,7 +812,7 @@ let read_t = ( field_member := ( Some ( ( - read_member + read_partial_member ) p lb ) ); @@ -1158,7 +1160,7 @@ let read_t = ( field_member := ( Some ( ( - read_member + read_partial_member ) p lb ) ); @@ -1312,3 +1314,15 @@ let read_t = ( ) let t_of_string s = read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_member = ( + Member_j.write_t +) +let string_of_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_member ob x; + Bi_outbuf.contents ob +let read_member = ( + Member_j.read_t +) +let member_of_string s = + read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/message_j.mli b/lib/models/message_j.mli index 8f7ce13..e3a3e5b 100644 --- a/lib/models/message_j.mli +++ b/lib/models/message_j.mli @@ -9,7 +9,7 @@ type role = Role_t.t type reaction = Reaction_t.t -type member = Member_t.t +type partial_member = Member_t.partial_member type embed = Embed_t.t @@ -19,7 +19,7 @@ type t = Message_t.t = { id: snowflake; author: user; channel_id: snowflake; - member: member option; + member: partial_member option; guild_id: snowflake option; content: string; timestamp: string; @@ -37,6 +37,8 @@ type t = Message_t.t = { kind: int } +type member = Member_t.t + val write_user : Bi_outbuf.t -> user -> unit (** Output a JSON value of type {!user}. *) @@ -117,25 +119,25 @@ val reaction_of_string : string -> reaction (** Deserialize JSON data of type {!reaction}. *) -val write_member : - Bi_outbuf.t -> member -> unit - (** Output a JSON value of type {!member}. *) +val write_partial_member : + Bi_outbuf.t -> partial_member -> unit + (** Output a JSON value of type {!partial_member}. *) -val string_of_member : - ?len:int -> member -> string - (** Serialize a value of type {!member} +val string_of_partial_member : + ?len:int -> partial_member -> string + (** Serialize a value of type {!partial_member} into a JSON string. @param len specifies the initial length of the buffer used internally. Default: 1024. *) -val read_member : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> member - (** Input JSON data of type {!member}. *) +val read_partial_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member + (** Input JSON data of type {!partial_member}. *) -val member_of_string : - string -> member - (** Deserialize JSON data of type {!member}. *) +val partial_member_of_string : + string -> partial_member + (** Deserialize JSON data of type {!partial_member}. *) val write_embed : Bi_outbuf.t -> embed -> unit @@ -197,3 +199,23 @@ val t_of_string : string -> t (** Deserialize JSON data of type {!t}. *) +val write_member : + Bi_outbuf.t -> member -> unit + (** Output a JSON value of type {!member}. *) + +val string_of_member : + ?len:int -> member -> string + (** Serialize a value of type {!member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> member + (** Input JSON data of type {!member}. *) + +val member_of_string : + string -> member + (** Deserialize JSON data of type {!member}. *) + diff --git a/lib/models/message_t.ml b/lib/models/message_t.ml index 3d37442..2442d76 100644 --- a/lib/models/message_t.ml +++ b/lib/models/message_t.ml @@ -9,7 +9,7 @@ type role = Role_t.t type reaction = Reaction_t.t -type member = Member_t.t +type partial_member = Member_t.partial_member type embed = Embed_t.t @@ -19,7 +19,7 @@ type t = { id: snowflake; author: user; channel_id: snowflake; - member: member option; + member: partial_member option; guild_id: snowflake option; content: string; timestamp: string; @@ -36,3 +36,5 @@ type t = { webhook_id: snowflake; kind: int } + +type member = Member_t.t diff --git a/lib/models/message_t.mli b/lib/models/message_t.mli index 3d37442..2442d76 100644 --- a/lib/models/message_t.mli +++ b/lib/models/message_t.mli @@ -9,7 +9,7 @@ type role = Role_t.t type reaction = Reaction_t.t -type member = Member_t.t +type partial_member = Member_t.partial_member type embed = Embed_t.t @@ -19,7 +19,7 @@ type t = { id: snowflake; author: user; channel_id: snowflake; - member: member option; + member: partial_member option; guild_id: snowflake option; content: string; timestamp: string; @@ -36,3 +36,5 @@ type t = { webhook_id: snowflake; kind: int } + +type member = Member_t.t diff --git a/lib/models/presence.atd b/lib/models/presence.atd index c455fec..da9b3fd 100644 --- a/lib/models/presence.atd +++ b/lib/models/presence.atd @@ -1,13 +1,13 @@ +type snowflake = abstract type user = abstract -type role = abstract +type partial_user = abstract type activity = abstract -type guild = abstract type t = { - user: user; - roles: role list; + user: partial_user; + roles: snowflake list; ?game: activity option; - guild: guild; + guild_id: snowflake; status: string; activities: activity list; } \ No newline at end of file diff --git a/lib/models/presence_j.ml b/lib/models/presence_j.ml index 91ef86d..b4ea497 100644 --- a/lib/models/presence_j.ml +++ b/lib/models/presence_j.ml @@ -3,17 +3,17 @@ type user = User_t.t -type role = Role_t.t +type snowflake = Snowflake_t.t -type guild = Guild_t.t +type partial_user = User_t.partial_user type activity = Activity_t.t type t = Presence_t.t = { - user: user; - roles: role list; + user: partial_user; + roles: snowflake list; game: activity option; - guild: guild; + guild_id: snowflake; status: string; activities: activity list } @@ -30,30 +30,30 @@ let read_user = ( ) let user_of_string s = read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_role = ( - Role_j.write_t +let write_snowflake = ( + Snowflake_j.write_t ) -let string_of_role ?(len = 1024) x = +let string_of_snowflake ?(len = 1024) x = let ob = Bi_outbuf.create len in - write_role ob x; + write_snowflake ob x; Bi_outbuf.contents ob -let read_role = ( - Role_j.read_t +let read_snowflake = ( + Snowflake_j.read_t ) -let role_of_string s = - read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_guild = ( - Guild_j.write_t +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_user = ( + User_j.write_partial_user ) -let string_of_guild ?(len = 1024) x = +let string_of_partial_user ?(len = 1024) x = let ob = Bi_outbuf.create len in - write_guild ob x; + write_partial_user ob x; Bi_outbuf.contents ob -let read_guild = ( - Guild_j.read_t +let read_partial_user = ( + User_j.read_partial_user ) -let guild_of_string s = - read_guild (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let partial_user_of_string s = + read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_activity = ( Activity_j.write_t ) @@ -141,7 +141,7 @@ let _2_of_string s = read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write__1 = ( Atdgen_runtime.Oj_run.write_list ( - write_role + write_snowflake ) ) let string_of__1 ?(len = 1024) x = @@ -150,7 +150,7 @@ let string_of__1 ?(len = 1024) x = Bi_outbuf.contents ob let read__1 = ( Atdgen_runtime.Oj_run.read_list ( - read_role + read_snowflake ) ) let _1_of_string s = @@ -165,7 +165,7 @@ let write_t : _ -> t -> _ = ( Bi_outbuf.add_char ob ','; Bi_outbuf.add_string ob "\"user\":"; ( - write_user + write_partial_user ) ob x.user; if !is_first then @@ -192,11 +192,11 @@ let write_t : _ -> t -> _ = ( is_first := false else Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"guild\":"; + Bi_outbuf.add_string ob "\"guild_id\":"; ( - write_guild + write_snowflake ) - ob x.guild; + ob x.guild_id; if !is_first then is_first := false else @@ -228,7 +228,7 @@ let read_t = ( let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_game = ref (None) in - let field_guild = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_guild_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_status = ref (Obj.magic (Sys.opaque_identity 0.0)) in let field_activities = ref (Obj.magic (Sys.opaque_identity 0.0)) in let bits0 = ref 0 in @@ -264,26 +264,12 @@ let read_t = ( ) ) | 5 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' then ( - 3 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) ) | 6 -> ( if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( @@ -293,6 +279,14 @@ let read_t = ( -1 ) ) + | 8 -> ( + if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) | 10 -> ( if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( 5 @@ -312,7 +306,7 @@ let read_t = ( | 0 -> field_user := ( ( - read_user + read_partial_user ) p lb ); bits0 := !bits0 lor 0x1; @@ -334,9 +328,9 @@ let read_t = ( ); ) | 3 -> - field_guild := ( + field_guild_id := ( ( - read_guild + read_snowflake ) p lb ); bits0 := !bits0 lor 0x4; @@ -390,26 +384,12 @@ let read_t = ( ) ) | 5 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' then ( - 3 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) ) | 6 -> ( if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( @@ -419,6 +399,14 @@ let read_t = ( -1 ) ) + | 8 -> ( + if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) | 10 -> ( if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( 5 @@ -438,7 +426,7 @@ let read_t = ( | 0 -> field_user := ( ( - read_user + read_partial_user ) p lb ); bits0 := !bits0 lor 0x1; @@ -460,9 +448,9 @@ let read_t = ( ); ) | 3 -> - field_guild := ( + field_guild_id := ( ( - read_guild + read_snowflake ) p lb ); bits0 := !bits0 lor 0x4; @@ -487,13 +475,13 @@ let read_t = ( done; assert false; with Yojson.End_of_object -> ( - if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "guild"; "status"; "activities" |]; + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "guild_id"; "status"; "activities" |]; ( { user = !field_user; roles = !field_roles; game = !field_game; - guild = !field_guild; + guild_id = !field_guild_id; status = !field_status; activities = !field_activities; } diff --git a/lib/models/presence_j.mli b/lib/models/presence_j.mli index 9da05ec..be68b3f 100644 --- a/lib/models/presence_j.mli +++ b/lib/models/presence_j.mli @@ -3,17 +3,17 @@ type user = User_t.t -type role = Role_t.t +type snowflake = Snowflake_t.t -type guild = Guild_t.t +type partial_user = User_t.partial_user type activity = Activity_t.t type t = Presence_t.t = { - user: user; - roles: role list; + user: partial_user; + roles: snowflake list; game: activity option; - guild: guild; + guild_id: snowflake; status: string; activities: activity list } @@ -38,45 +38,45 @@ val user_of_string : string -> user (** Deserialize JSON data of type {!user}. *) -val write_role : - Bi_outbuf.t -> role -> unit - (** Output a JSON value of type {!role}. *) +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) -val string_of_role : - ?len:int -> role -> string - (** Serialize a value of type {!role} +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} into a JSON string. @param len specifies the initial length of the buffer used internally. Default: 1024. *) -val read_role : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> role - (** Input JSON data of type {!role}. *) +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) -val role_of_string : - string -> role - (** Deserialize JSON data of type {!role}. *) +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) -val write_guild : - Bi_outbuf.t -> guild -> unit - (** Output a JSON value of type {!guild}. *) +val write_partial_user : + Bi_outbuf.t -> partial_user -> unit + (** Output a JSON value of type {!partial_user}. *) -val string_of_guild : - ?len:int -> guild -> string - (** Serialize a value of type {!guild} +val string_of_partial_user : + ?len:int -> partial_user -> string + (** Serialize a value of type {!partial_user} into a JSON string. @param len specifies the initial length of the buffer used internally. Default: 1024. *) -val read_guild : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> guild - (** Input JSON data of type {!guild}. *) +val read_partial_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user + (** Input JSON data of type {!partial_user}. *) -val guild_of_string : - string -> guild - (** Deserialize JSON data of type {!guild}. *) +val partial_user_of_string : + string -> partial_user + (** Deserialize JSON data of type {!partial_user}. *) val write_activity : Bi_outbuf.t -> activity -> unit diff --git a/lib/models/presence_t.ml b/lib/models/presence_t.ml index 7a26905..940d986 100644 --- a/lib/models/presence_t.ml +++ b/lib/models/presence_t.ml @@ -3,17 +3,17 @@ type user = User_t.t -type role = Role_t.t +type snowflake = Snowflake_t.t -type guild = Guild_t.t +type partial_user = User_t.partial_user type activity = Activity_t.t type t = { - user: user; - roles: role list; + user: partial_user; + roles: snowflake list; game: activity option; - guild: guild; + guild_id: snowflake; status: string; activities: activity list } diff --git a/lib/models/presence_t.mli b/lib/models/presence_t.mli index 7a26905..940d986 100644 --- a/lib/models/presence_t.mli +++ b/lib/models/presence_t.mli @@ -3,17 +3,17 @@ type user = User_t.t -type role = Role_t.t +type snowflake = Snowflake_t.t -type guild = Guild_t.t +type partial_user = User_t.partial_user type activity = Activity_t.t type t = { - user: user; - roles: role list; + user: partial_user; + roles: snowflake list; game: activity option; - guild: guild; + guild_id: snowflake; status: string; activities: activity list } diff --git a/lib/models/user.atd b/lib/models/user.atd index 73e2ff9..106b3b0 100644 --- a/lib/models/user.atd +++ b/lib/models/user.atd @@ -6,4 +6,8 @@ type t = { discriminator: string; ?avatar: string option; ~bot : bool; +} + +type partial_user = { + id: snowflake; } \ No newline at end of file diff --git a/lib/models/user_j.ml b/lib/models/user_j.ml index 6eb93e6..552a20d 100644 --- a/lib/models/user_j.ml +++ b/lib/models/user_j.ml @@ -11,6 +11,8 @@ type t = User_t.t = { bot: bool } +type partial_user = User_t.partial_user = { id: snowflake } + let write_snowflake = ( Snowflake_j.write_t ) @@ -366,3 +368,101 @@ let read_t = ( ) let t_of_string s = read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_user : _ -> partial_user -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + Bi_outbuf.add_char ob '}'; +) +let string_of_partial_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_user ob x; + Bi_outbuf.contents ob +let read_partial_user = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + ( + { + id = !field_id; + } + : partial_user) + ) +) +let partial_user_of_string s = + read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/user_j.mli b/lib/models/user_j.mli index 0a1c6e1..576768e 100644 --- a/lib/models/user_j.mli +++ b/lib/models/user_j.mli @@ -11,6 +11,8 @@ type t = User_t.t = { bot: bool } +type partial_user = User_t.partial_user = { id: snowflake } + val write_snowflake : Bi_outbuf.t -> snowflake -> unit (** Output a JSON value of type {!snowflake}. *) @@ -51,3 +53,23 @@ val t_of_string : string -> t (** Deserialize JSON data of type {!t}. *) +val write_partial_user : + Bi_outbuf.t -> partial_user -> unit + (** Output a JSON value of type {!partial_user}. *) + +val string_of_partial_user : + ?len:int -> partial_user -> string + (** Serialize a value of type {!partial_user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user + (** Input JSON data of type {!partial_user}. *) + +val partial_user_of_string : + string -> partial_user + (** Deserialize JSON data of type {!partial_user}. *) + diff --git a/lib/models/user_t.ml b/lib/models/user_t.ml index b303aa3..294cf0a 100644 --- a/lib/models/user_t.ml +++ b/lib/models/user_t.ml @@ -10,3 +10,5 @@ type t = { avatar: string option; bot: bool } + +type partial_user = { id: snowflake } diff --git a/lib/models/user_t.mli b/lib/models/user_t.mli index b303aa3..294cf0a 100644 --- a/lib/models/user_t.mli +++ b/lib/models/user_t.mli @@ -10,3 +10,5 @@ type t = { avatar: string option; bot: bool } + +type partial_user = { id: snowflake } diff --git a/lib/rl.ml b/lib/rl.ml index 316abcf..f0c15be 100644 --- a/lib/rl.ml +++ b/lib/rl.ml @@ -21,8 +21,9 @@ let rl_of_header h = Some { limit; remaining; reset; } | _ -> None -let update = RouteMap.update +let default = { limit = 1; remaining = 1; reset = 0; } let empty : t = RouteMap.empty +let update = RouteMap.update let find = RouteMap.find let find_exn m s = match find m s with | Some r -> r diff --git a/lib/s.ml b/lib/s.ml index 9ac86ad..32347cb 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -4,10 +4,6 @@ module type Token = sig val token : string end -module type Client = sig - type context -end - module type Handler = sig val handle_event : 'a -> @@ -56,7 +52,7 @@ module type Dispatch = sig exception Invalid_event of string val event_of_string : contents:string -> string -> dispatch_event - val dispatch : ev:string -> string -> unit + val dispatch : ev: -> string -> unit end module type Http = sig -- cgit v1.2.3 From af684566617ebce536e9f30693aa3e225af906c4 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Fri, 14 Dec 2018 10:52:36 -0700 Subject: There's a lot going on --- lib/client.ml | 6 +- lib/dispatch.ml | 85 +- lib/dispatch.mli | 1 + lib/event.ml | 185 ++-- lib/models.ml | 16 + lib/models/activity.atd | 5 - lib/models/activity.ml | 2 + lib/models/activity_j.ml | 274 ----- lib/models/activity_j.mli | 25 - lib/models/activity_t.ml | 4 - lib/models/activity_t.mli | 4 - lib/models/attachment.atd | 11 - lib/models/attachment.ml | 2 + lib/models/attachment_j.ml | 456 -------- lib/models/attachment_j.mli | 55 - lib/models/attachment_t.ml | 14 - lib/models/attachment_t.mli | 14 - lib/models/ban.atd | 6 - lib/models/ban.ml | 2 + lib/models/ban_j.ml | 235 ---- lib/models/ban_j.mli | 47 - lib/models/ban_t.ml | 6 - lib/models/ban_t.mli | 6 - lib/models/channel.atd | 19 - lib/models/channel.ml | 2 + lib/models/channel_j.ml | 1136 ------------------- lib/models/channel_j.mli | 84 -- lib/models/channel_t.ml | 23 - lib/models/channel_t.mli | 23 - lib/models/embed.atd | 44 - lib/models/embed.ml | 2 + lib/models/embed_j.ml | 2283 --------------------------------------- lib/models/embed_j.mli | 168 --- lib/models/embed_t.ml | 36 - lib/models/embed_t.mli | 36 - lib/models/emoji.atd | 12 - lib/models/emoji.ml | 2 + lib/models/emoji_j.ml | 701 ------------ lib/models/emoji_j.mli | 77 -- lib/models/emoji_t.ml | 16 - lib/models/emoji_t.mli | 16 - lib/models/gen/activity.atd | 5 + lib/models/gen/activity_j.ml | 274 +++++ lib/models/gen/activity_j.mli | 25 + lib/models/gen/activity_t.ml | 4 + lib/models/gen/activity_t.mli | 4 + lib/models/gen/attachment.atd | 11 + lib/models/gen/attachment_j.ml | 456 ++++++++ lib/models/gen/attachment_j.mli | 55 + lib/models/gen/attachment_t.ml | 14 + lib/models/gen/attachment_t.mli | 14 + lib/models/gen/ban.atd | 6 + lib/models/gen/ban_j.ml | 235 ++++ lib/models/gen/ban_j.mli | 47 + lib/models/gen/ban_t.ml | 6 + lib/models/gen/ban_t.mli | 6 + lib/models/gen/channel.atd | 19 + lib/models/gen/channel_j.ml | 1136 +++++++++++++++++++ lib/models/gen/channel_j.mli | 84 ++ lib/models/gen/channel_t.ml | 23 + lib/models/gen/channel_t.mli | 23 + lib/models/gen/embed.atd | 44 + lib/models/gen/embed_j.ml | 2283 +++++++++++++++++++++++++++++++++++++++ lib/models/gen/embed_j.mli | 168 +++ lib/models/gen/embed_t.ml | 36 + lib/models/gen/embed_t.mli | 36 + lib/models/gen/emoji.atd | 12 + lib/models/gen/emoji_j.ml | 701 ++++++++++++ lib/models/gen/emoji_j.mli | 77 ++ lib/models/gen/emoji_t.ml | 16 + lib/models/gen/emoji_t.mli | 16 + lib/models/gen/guild.atd | 36 + lib/models/gen/guild_j.ml | 1948 +++++++++++++++++++++++++++++++++ lib/models/gen/guild_j.mli | 184 ++++ lib/models/gen/guild_t.ml | 43 + lib/models/gen/guild_t.mli | 43 + lib/models/gen/member.atd | 15 + lib/models/gen/member_j.ml | 750 +++++++++++++ lib/models/gen/member_j.mli | 104 ++ lib/models/gen/member_t.ml | 23 + lib/models/gen/member_t.mli | 23 + lib/models/gen/message.atd | 29 + lib/models/gen/message_j.ml | 1363 +++++++++++++++++++++++ lib/models/gen/message_j.mli | 199 ++++ lib/models/gen/message_t.ml | 38 + lib/models/gen/message_t.mli | 38 + lib/models/gen/presence.atd | 13 + lib/models/gen/presence_j.ml | 492 +++++++++ lib/models/gen/presence_j.mli | 120 ++ lib/models/gen/presence_t.ml | 19 + lib/models/gen/presence_t.mli | 19 + lib/models/gen/reaction.atd | 6 + lib/models/gen/reaction_j.ml | 180 +++ lib/models/gen/reaction_j.mli | 47 + lib/models/gen/reaction_t.ml | 6 + lib/models/gen/reaction_t.mli | 6 + lib/models/gen/role.atd | 12 + lib/models/gen/role_j.ml | 449 ++++++++ lib/models/gen/role_j.mli | 56 + lib/models/gen/role_t.ml | 15 + lib/models/gen/role_t.mli | 15 + lib/models/gen/snowflake.atd | 1 + lib/models/gen/snowflake_j.ml | 17 + lib/models/gen/snowflake_j.mli | 25 + lib/models/gen/snowflake_t.ml | 4 + lib/models/gen/snowflake_t.mli | 4 + lib/models/gen/user.atd | 13 + lib/models/gen/user_j.ml | 468 ++++++++ lib/models/gen/user_j.mli | 75 ++ lib/models/gen/user_t.ml | 14 + lib/models/gen/user_t.mli | 14 + lib/models/guild.atd | 36 - lib/models/guild.ml | 2 + lib/models/guild_j.ml | 1948 --------------------------------- lib/models/guild_j.mli | 184 ---- lib/models/guild_t.ml | 43 - lib/models/guild_t.mli | 43 - lib/models/member.atd | 15 - lib/models/member.ml | 2 + lib/models/member_j.ml | 750 ------------- lib/models/member_j.mli | 104 -- lib/models/member_t.ml | 23 - lib/models/member_t.mli | 23 - lib/models/message.atd | 30 - lib/models/message.ml | 2 + lib/models/message_j.ml | 1328 ----------------------- lib/models/message_j.mli | 221 ---- lib/models/message_t.ml | 40 - lib/models/message_t.mli | 40 - lib/models/presence.atd | 13 - lib/models/presence.ml | 2 + lib/models/presence_j.ml | 492 --------- lib/models/presence_j.mli | 120 -- lib/models/presence_t.ml | 19 - lib/models/presence_t.mli | 19 - lib/models/reaction.atd | 6 - lib/models/reaction.ml | 2 + lib/models/reaction_j.ml | 180 --- lib/models/reaction_j.mli | 47 - lib/models/reaction_t.ml | 6 - lib/models/reaction_t.mli | 6 - lib/models/role.atd | 12 - lib/models/role.ml | 2 + lib/models/role_j.ml | 449 -------- lib/models/role_j.mli | 56 - lib/models/role_t.ml | 15 - lib/models/role_t.mli | 15 - lib/models/snowflake.atd | 1 - lib/models/snowflake.ml | 2 + lib/models/snowflake_j.ml | 17 - lib/models/snowflake_j.mli | 25 - lib/models/snowflake_t.ml | 4 - lib/models/snowflake_t.mli | 4 - lib/models/user.atd | 13 - lib/models/user.ml | 2 + lib/models/user_j.ml | 468 -------- lib/models/user_j.mli | 75 -- lib/models/user_t.ml | 14 - lib/models/user_t.mli | 14 - lib/s.ml | 52 +- lib/sharder.ml | 1 - 161 files changed, 12898 insertions(+), 12992 deletions(-) create mode 100644 lib/dispatch.mli create mode 100644 lib/models.ml delete mode 100644 lib/models/activity.atd create mode 100644 lib/models/activity.ml delete mode 100644 lib/models/activity_j.ml delete mode 100644 lib/models/activity_j.mli delete mode 100644 lib/models/activity_t.ml delete mode 100644 lib/models/activity_t.mli delete mode 100644 lib/models/attachment.atd create mode 100644 lib/models/attachment.ml delete mode 100644 lib/models/attachment_j.ml delete mode 100644 lib/models/attachment_j.mli delete mode 100644 lib/models/attachment_t.ml delete mode 100644 lib/models/attachment_t.mli delete mode 100644 lib/models/ban.atd create mode 100644 lib/models/ban.ml delete mode 100644 lib/models/ban_j.ml delete mode 100644 lib/models/ban_j.mli delete mode 100644 lib/models/ban_t.ml delete mode 100644 lib/models/ban_t.mli delete mode 100644 lib/models/channel.atd create mode 100644 lib/models/channel.ml delete mode 100644 lib/models/channel_j.ml delete mode 100644 lib/models/channel_j.mli delete mode 100644 lib/models/channel_t.ml delete mode 100644 lib/models/channel_t.mli delete mode 100644 lib/models/embed.atd create mode 100644 lib/models/embed.ml delete mode 100644 lib/models/embed_j.ml delete mode 100644 lib/models/embed_j.mli delete mode 100644 lib/models/embed_t.ml delete mode 100644 lib/models/embed_t.mli delete mode 100644 lib/models/emoji.atd create mode 100644 lib/models/emoji.ml delete mode 100644 lib/models/emoji_j.ml delete mode 100644 lib/models/emoji_j.mli delete mode 100644 lib/models/emoji_t.ml delete mode 100644 lib/models/emoji_t.mli create mode 100644 lib/models/gen/activity.atd create mode 100644 lib/models/gen/activity_j.ml create mode 100644 lib/models/gen/activity_j.mli create mode 100644 lib/models/gen/activity_t.ml create mode 100644 lib/models/gen/activity_t.mli create mode 100644 lib/models/gen/attachment.atd create mode 100644 lib/models/gen/attachment_j.ml create mode 100644 lib/models/gen/attachment_j.mli create mode 100644 lib/models/gen/attachment_t.ml create mode 100644 lib/models/gen/attachment_t.mli create mode 100644 lib/models/gen/ban.atd create mode 100644 lib/models/gen/ban_j.ml create mode 100644 lib/models/gen/ban_j.mli create mode 100644 lib/models/gen/ban_t.ml create mode 100644 lib/models/gen/ban_t.mli create mode 100644 lib/models/gen/channel.atd create mode 100644 lib/models/gen/channel_j.ml create mode 100644 lib/models/gen/channel_j.mli create mode 100644 lib/models/gen/channel_t.ml create mode 100644 lib/models/gen/channel_t.mli create mode 100644 lib/models/gen/embed.atd create mode 100644 lib/models/gen/embed_j.ml create mode 100644 lib/models/gen/embed_j.mli create mode 100644 lib/models/gen/embed_t.ml create mode 100644 lib/models/gen/embed_t.mli create mode 100644 lib/models/gen/emoji.atd create mode 100644 lib/models/gen/emoji_j.ml create mode 100644 lib/models/gen/emoji_j.mli create mode 100644 lib/models/gen/emoji_t.ml create mode 100644 lib/models/gen/emoji_t.mli create mode 100644 lib/models/gen/guild.atd create mode 100644 lib/models/gen/guild_j.ml create mode 100644 lib/models/gen/guild_j.mli create mode 100644 lib/models/gen/guild_t.ml create mode 100644 lib/models/gen/guild_t.mli create mode 100644 lib/models/gen/member.atd create mode 100644 lib/models/gen/member_j.ml create mode 100644 lib/models/gen/member_j.mli create mode 100644 lib/models/gen/member_t.ml create mode 100644 lib/models/gen/member_t.mli create mode 100644 lib/models/gen/message.atd create mode 100644 lib/models/gen/message_j.ml create mode 100644 lib/models/gen/message_j.mli create mode 100644 lib/models/gen/message_t.ml create mode 100644 lib/models/gen/message_t.mli create mode 100644 lib/models/gen/presence.atd create mode 100644 lib/models/gen/presence_j.ml create mode 100644 lib/models/gen/presence_j.mli create mode 100644 lib/models/gen/presence_t.ml create mode 100644 lib/models/gen/presence_t.mli create mode 100644 lib/models/gen/reaction.atd create mode 100644 lib/models/gen/reaction_j.ml create mode 100644 lib/models/gen/reaction_j.mli create mode 100644 lib/models/gen/reaction_t.ml create mode 100644 lib/models/gen/reaction_t.mli create mode 100644 lib/models/gen/role.atd create mode 100644 lib/models/gen/role_j.ml create mode 100644 lib/models/gen/role_j.mli create mode 100644 lib/models/gen/role_t.ml create mode 100644 lib/models/gen/role_t.mli create mode 100644 lib/models/gen/snowflake.atd create mode 100644 lib/models/gen/snowflake_j.ml create mode 100644 lib/models/gen/snowflake_j.mli create mode 100644 lib/models/gen/snowflake_t.ml create mode 100644 lib/models/gen/snowflake_t.mli create mode 100644 lib/models/gen/user.atd create mode 100644 lib/models/gen/user_j.ml create mode 100644 lib/models/gen/user_j.mli create mode 100644 lib/models/gen/user_t.ml create mode 100644 lib/models/gen/user_t.mli delete mode 100644 lib/models/guild.atd create mode 100644 lib/models/guild.ml delete mode 100644 lib/models/guild_j.ml delete mode 100644 lib/models/guild_j.mli delete mode 100644 lib/models/guild_t.ml delete mode 100644 lib/models/guild_t.mli delete mode 100644 lib/models/member.atd create mode 100644 lib/models/member.ml delete mode 100644 lib/models/member_j.ml delete mode 100644 lib/models/member_j.mli delete mode 100644 lib/models/member_t.ml delete mode 100644 lib/models/member_t.mli delete mode 100644 lib/models/message.atd create mode 100644 lib/models/message.ml delete mode 100644 lib/models/message_j.ml delete mode 100644 lib/models/message_j.mli delete mode 100644 lib/models/message_t.ml delete mode 100644 lib/models/message_t.mli delete mode 100644 lib/models/presence.atd create mode 100644 lib/models/presence.ml delete mode 100644 lib/models/presence_j.ml delete mode 100644 lib/models/presence_j.mli delete mode 100644 lib/models/presence_t.ml delete mode 100644 lib/models/presence_t.mli delete mode 100644 lib/models/reaction.atd create mode 100644 lib/models/reaction.ml delete mode 100644 lib/models/reaction_j.ml delete mode 100644 lib/models/reaction_j.mli delete mode 100644 lib/models/reaction_t.ml delete mode 100644 lib/models/reaction_t.mli delete mode 100644 lib/models/role.atd create mode 100644 lib/models/role.ml delete mode 100644 lib/models/role_j.ml delete mode 100644 lib/models/role_j.mli delete mode 100644 lib/models/role_t.ml delete mode 100644 lib/models/role_t.mli delete mode 100644 lib/models/snowflake.atd create mode 100644 lib/models/snowflake.ml delete mode 100644 lib/models/snowflake_j.ml delete mode 100644 lib/models/snowflake_j.mli delete mode 100644 lib/models/snowflake_t.ml delete mode 100644 lib/models/snowflake_t.mli delete mode 100644 lib/models/user.atd create mode 100644 lib/models/user.ml delete mode 100644 lib/models/user_j.ml delete mode 100644 lib/models/user_j.mli delete mode 100644 lib/models/user_t.ml delete mode 100644 lib/models/user_t.mli (limited to 'lib') diff --git a/lib/client.ml b/lib/client.ml index 9211281..229c9cc 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -1,10 +1,12 @@ open Async -module Make(T : S.Token)(H : S.Handler) = struct +module Make(T : S.Token)(H : S.Handler_f) = struct include T module Http = Http.Make(T) - module Dispatch = Dispatch.Make(H) + module Models = Models.Make(Http) + module Handler = H.Make(Models) + module Dispatch = Dispatch.Make(Handler) module Sharder = Sharder.Make(Http)(Dispatch) type t = { diff --git a/lib/dispatch.ml b/lib/dispatch.ml index a4341e1..c38afe2 100644 --- a/lib/dispatch.ml +++ b/lib/dispatch.ml @@ -1,85 +1,6 @@ -open Core - module Make(H : S.Handler) : S.Dispatch = struct - type dispatch_event = - | HELLO of Yojson.Safe.json - | READY of Yojson.Safe.json - | RESUMED of Yojson.Safe.json - | INVALID_SESSION of Yojson.Safe.json - | CHANNEL_CREATE of Channel_t.t - | CHANNEL_UPDATE of Channel_t.t - | CHANNEL_DELETE of Channel_t.t - | CHANNEL_PINS_UPDATE of Yojson.Safe.json - | GUILD_CREATE of Guild_t.t - | GUILD_UPDATE of Guild_t.t - | GUILD_DELETE of Guild_t.t - | GUILD_BAN_ADD of Ban_t.t - | GUILD_BAN_REMOVE of Ban_t.t - | GUILD_EMOJIS_UPDATE of Yojson.Safe.json - | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json - | GUILD_MEMBER_ADD of Member_t.t - | GUILD_MEMBER_REMOVE of Member_t.t - | GUILD_MEMBER_UPDATE of Member_t.t - | GUILD_MEMBERS_CHUNK of Member_t.t list - | GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *) - | GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *) - | GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *) - | MESSAGE_CREATE of Message_t.t - | MESSAGE_UPDATE of Message_t.t - | MESSAGE_DELETE of Message_t.t - | MESSAGE_BULK_DELETE of Message_t.t list - | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t - | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t - | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list - | PRESENCE_UPDATE of Presence_t.t - | TYPING_START of Yojson.Safe.json - | USER_UPDATE of Yojson.Safe.json - | VOICE_STATE_UPDATE of Yojson.Safe.json - | VOICE_SERVER_UPDATE of Yojson.Safe.json - | WEBHOOKS_UPDATE of Yojson.Safe.json - - exception Invalid_event of string - - let event_of_string ~contents t = match t with - | "HELLO" -> HELLO (Yojson.Safe.from_string contents) - | "READY" -> READY (Yojson.Safe.from_string contents) - | "RESUMED" -> RESUMED (Yojson.Safe.from_string contents) - | "INVALID_SESSION" -> INVALID_SESSION (Yojson.Safe.from_string contents) - | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel_j.t_of_string contents) - | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel_j.t_of_string contents) - | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel_j.t_of_string contents) - | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE (Yojson.Safe.from_string contents) - | "GUILD_CREATE" -> GUILD_CREATE (Guild_j.t_of_string contents) - | "GUILD_UPDATE" -> GUILD_UPDATE (Guild_j.t_of_string contents) - | "GUILD_DELETE" -> GUILD_DELETE (Guild_j.t_of_string contents) - | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban_j.t_of_string contents) - | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban_j.t_of_string contents) - | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE (Yojson.Safe.from_string contents) - | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE (Yojson.Safe.from_string contents) - | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member_j.t_of_string contents) - | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member_j.t_of_string contents) - | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member_j.t_of_string contents) - | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Member_j.t_of_string)) - | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role_j.t_of_string contents) - | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role_j.t_of_string contents) - | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role_j.t_of_string contents) - | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_j.t_of_string contents) - | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_j.t_of_string contents) - | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message_j.t_of_string contents) - | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Message_j.t_of_string)) - | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_j.t_of_string contents) - | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_j.t_of_string contents) - | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Reaction_j.t_of_string)) - | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence_j.t_of_string contents) - | "TYPING_START" -> TYPING_START (Yojson.Safe.from_string contents) - | "USER_UPDATE" -> USER_UPDATE (Yojson.Safe.from_string contents) - | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE (Yojson.Safe.from_string contents) - | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE (Yojson.Safe.from_string contents) - | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE (Yojson.Safe.from_string contents) - | s -> raise (Invalid_event s) - let dispatch ~ev contents = - let ctx = () in - event_of_string ~contents ev - |> H.handle_event ctx + print_endline (Yojson.Safe.prettify contents); + Event.event_of_string ~contents ev + |> H.handle_event end \ No newline at end of file diff --git a/lib/dispatch.mli b/lib/dispatch.mli new file mode 100644 index 0000000..100a34b --- /dev/null +++ b/lib/dispatch.mli @@ -0,0 +1 @@ +module Make(H : S.Handler) : S.Dispatch \ No newline at end of file diff --git a/lib/event.ml b/lib/event.ml index 8b5b125..6e35c75 100644 --- a/lib/event.ml +++ b/lib/event.ml @@ -1,113 +1,78 @@ -type t = -| HELLO -| READY -| RESUMED -| INVALID_SESSION -| CHANNEL_CREATE -| CHANNEL_UPDATE -| CHANNEL_DELETE -| CHANNEL_PINS_UPDATE -| GUILD_CREATE -| GUILD_UPDATE -| GUILD_DELETE -| GUILD_BAN_ADD -| GUILD_BAN_REMOVE -| GUILD_EMOJIS_UPDATE -| GUILD_INTEGRATIONS_UPDATE -| GUILD_MEMBER_ADD -| GUILD_MEMBER_REMOVE -| GUILD_MEMBER_UPDATE -| GUILD_MEMBERS_CHUNK -| GUILD_ROLE_CREATE -| GUILD_ROLE_UPDATE -| GUILD_ROLE_DELETE -| MESSAGE_CREATE -| MESSAGE_UPDATE -| MESSAGE_DELETE -| MESSAGE_BULK_DELETE -| MESSAGE_REACTION_ADD -| MESSAGE_REACTION_REMOVE -| MESSAGE_REACTION_REMOVE_ALL -| PRESENCE_UPDATE -| TYPING_START -| USER_UPDATE -| VOICE_STATE_UPDATE -| VOICE_SERVER_UPDATE -| WEBHOOKS_UPDATE +open Core -exception Invalid_Event of string +type t = +| HELLO of Yojson.Safe.json +| READY of Yojson.Safe.json +| RESUMED of Yojson.Safe.json +| INVALID_SESSION of Yojson.Safe.json +| CHANNEL_CREATE of Channel_t.t +| CHANNEL_UPDATE of Channel_t.t +| CHANNEL_DELETE of Channel_t.t +| CHANNEL_PINS_UPDATE of Yojson.Safe.json +| GUILD_CREATE of Guild_t.t +| GUILD_UPDATE of Guild_t.t +| GUILD_DELETE of Guild_t.t +| GUILD_BAN_ADD of Ban_t.t +| GUILD_BAN_REMOVE of Ban_t.t +| GUILD_EMOJIS_UPDATE of Yojson.Safe.json +| GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json +| GUILD_MEMBER_ADD of Member_t.t +| GUILD_MEMBER_REMOVE of Member_t.t +| GUILD_MEMBER_UPDATE of Member_t.t +| GUILD_MEMBERS_CHUNK of Member_t.t list +| GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *) +| GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *) +| GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *) +| MESSAGE_CREATE of Message_t.t +| MESSAGE_UPDATE of Message_t.t +| MESSAGE_DELETE of Message_t.t +| MESSAGE_BULK_DELETE of Message_t.t list +| MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t +| MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t +| MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list +| PRESENCE_UPDATE of Presence_t.t +| TYPING_START of Yojson.Safe.json +| USER_UPDATE of Yojson.Safe.json +| VOICE_STATE_UPDATE of Yojson.Safe.json +| VOICE_SERVER_UPDATE of Yojson.Safe.json +| WEBHOOKS_UPDATE of Yojson.Safe.json -let from_string = function - | "HELLO" -> HELLO - | "READY" -> READY - | "RESUMED" -> RESUMED - | "INVALID_SESSION" -> INVALID_SESSION - | "CHANNEL_CREATE" -> CHANNEL_CREATE - | "CHANNEL_UPDATE" -> CHANNEL_UPDATE - | "CHANNEL_DELETE" -> CHANNEL_DELETE - | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE - | "GUILD_CREATE" -> GUILD_CREATE - | "GUILD_UPDATE" -> GUILD_UPDATE - | "GUILD_DELETE" -> GUILD_DELETE - | "GUILD_BAN_ADD" -> GUILD_BAN_ADD - | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE - | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE - | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE - | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD - | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE - | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE - | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK - | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE - | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE - | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE - | "MESSAGE_CREATE" -> MESSAGE_CREATE - | "MESSAGE_UPDATE" -> MESSAGE_UPDATE - | "MESSAGE_DELETE" -> MESSAGE_DELETE - | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE - | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD - | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE - | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL - | "PRESENCE_UPDATE" -> PRESENCE_UPDATE - | "TYPING_START" -> TYPING_START - | "USER_UPDATE" -> USER_UPDATE - | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE - | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE - | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE - | ev -> raise (Invalid_Event ev) +exception Invalid_event of string -let to_string = function - | HELLO -> "HELLO" - | READY -> "READY" - | RESUMED -> "RESUMED" - | INVALID_SESSION -> "INVALID_SESSION" - | CHANNEL_CREATE -> "CHANNEL_CREATE" - | CHANNEL_UPDATE -> "CHANNEL_UPDATE" - | CHANNEL_DELETE -> "CHANNEL_DELETE" - | CHANNEL_PINS_UPDATE -> "CHANNEL_PINS_UPDATE" - | GUILD_CREATE -> "GUILD_CREATE" - | GUILD_UPDATE -> "GUILD_UPDATE" - | GUILD_DELETE -> "GUILD_DELETE" - | GUILD_BAN_ADD -> "GUILD_BAN_ADD" - | GUILD_BAN_REMOVE -> "GUILD_BAN_REMOVE" - | GUILD_EMOJIS_UPDATE -> "GUILD_EMOJIS_UPDATE" - | GUILD_INTEGRATIONS_UPDATE -> "GUILD_INTEGRATIONS_UPDATE" - | GUILD_MEMBER_ADD -> "GUILD_MEMBER_ADD" - | GUILD_MEMBER_REMOVE -> "GUILD_MEMBER_REMOVE" - | GUILD_MEMBER_UPDATE -> "GUILD_MEMBER_UPDATE" - | GUILD_MEMBERS_CHUNK -> "GUILD_MEMBERS_CHUNK" - | GUILD_ROLE_CREATE -> "GUILD_ROLE_CREATE" - | GUILD_ROLE_UPDATE -> "GUILD_ROLE_UPDATE" - | GUILD_ROLE_DELETE -> "GUILD_ROLE_DELETE" - | MESSAGE_CREATE -> "MESSAGE_CREATE" - | MESSAGE_UPDATE -> "MESSAGE_UPDATE" - | MESSAGE_DELETE -> "MESSAGE_DELETE" - | MESSAGE_BULK_DELETE -> "MESSAGE_BULK_DELETE" - | MESSAGE_REACTION_ADD -> "MESSAGE_REACTION_ADD" - | MESSAGE_REACTION_REMOVE -> "MESSAGE_REACTION_REMOVE" - | MESSAGE_REACTION_REMOVE_ALL -> "MESSAGE_REACTION_REMOVE_ALL" - | PRESENCE_UPDATE -> "PRESENCE_UPDATE" - | TYPING_START -> "TYPING_START" - | USER_UPDATE -> "USER_UPDATE" - | VOICE_STATE_UPDATE -> "VOICE_STATE_UPDATE" - | VOICE_SERVER_UPDATE -> "VOICE_SERVER_UPDATE" - | WEBHOOKS_UPDATE -> "WEBHOOKS_UPDATE" \ No newline at end of file +let event_of_string ~contents t = match t with + | "HELLO" -> HELLO (Yojson.Safe.from_string contents) + | "READY" -> READY (Yojson.Safe.from_string contents) + | "RESUMED" -> RESUMED (Yojson.Safe.from_string contents) + | "INVALID_SESSION" -> INVALID_SESSION (Yojson.Safe.from_string contents) + | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel_j.t_of_string contents) + | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel_j.t_of_string contents) + | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel_j.t_of_string contents) + | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_CREATE" -> GUILD_CREATE (Guild_j.t_of_string contents) + | "GUILD_UPDATE" -> GUILD_UPDATE (Guild_j.t_of_string contents) + | "GUILD_DELETE" -> GUILD_DELETE (Guild_j.t_of_string contents) + | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban_j.t_of_string contents) + | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban_j.t_of_string contents) + | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE (Yojson.Safe.from_string contents) + | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member_j.t_of_string contents) + | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member_j.t_of_string contents) + | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member_j.t_of_string contents) + | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Member_j.t_of_string)) + | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (Role_j.t_of_string contents) + | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (Role_j.t_of_string contents) + | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (Role_j.t_of_string contents) + | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_j.t_of_string contents) + | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_j.t_of_string contents) + | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message_j.t_of_string contents) + | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Message_j.t_of_string)) + | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_j.t_of_string contents) + | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_j.t_of_string contents) + | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Reaction_j.t_of_string)) + | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence_j.t_of_string contents) + | "TYPING_START" -> TYPING_START (Yojson.Safe.from_string contents) + | "USER_UPDATE" -> USER_UPDATE (Yojson.Safe.from_string contents) + | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE (Yojson.Safe.from_string contents) + | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE (Yojson.Safe.from_string contents) + | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE (Yojson.Safe.from_string contents) + | s -> raise (Invalid_event s) \ No newline at end of file diff --git a/lib/models.ml b/lib/models.ml new file mode 100644 index 0000000..1b23a21 --- /dev/null +++ b/lib/models.ml @@ -0,0 +1,16 @@ +module Make(H : S.Http) = struct + module Activity = Activity.Make(H) + module Attachment = Attachment.Make(H) + module Ban = Ban.Make(H) + module Channel = Channel.Make(H) + module Embed = Embed.Make(H) + module Emoji = Emoji.Make(H) + module Guild = Guild.Make(H) + module Member = Member.Make(H) + module Message = Message.Make(H) + module Presence = Presence.Make(H) + module Reaction = Reaction.Make(H) + module Role = Role.Make(H) + module Snowflake = Snowflake.Make(H) + module User = User.Make(H) +end \ No newline at end of file diff --git a/lib/models/activity.atd b/lib/models/activity.atd deleted file mode 100644 index 8e02191..0000000 --- a/lib/models/activity.atd +++ /dev/null @@ -1,5 +0,0 @@ -type t = { - name: string; - kind : int; - ?url: string option; -} \ No newline at end of file diff --git a/lib/models/activity.ml b/lib/models/activity.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/activity.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/activity_j.ml b/lib/models/activity_j.ml deleted file mode 100644 index eb1a62e..0000000 --- a/lib/models/activity_j.ml +++ /dev/null @@ -1,274 +0,0 @@ -(* Auto-generated from "activity.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type t = Activity_t.t = { name: string; kind: int; url: string option } - -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x.name; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"type\":"; - ( - Yojson.Safe.write_int - ) - ob x.kind; - (match x.url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_url = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 2 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 2 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "kind" |]; - ( - { - name = !field_name; - kind = !field_kind; - url = !field_url; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/activity_j.mli b/lib/models/activity_j.mli deleted file mode 100644 index c179efb..0000000 --- a/lib/models/activity_j.mli +++ /dev/null @@ -1,25 +0,0 @@ -(* Auto-generated from "activity.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type t = Activity_t.t = { name: string; kind: int; url: string option } - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/activity_t.ml b/lib/models/activity_t.ml deleted file mode 100644 index 6bb2049..0000000 --- a/lib/models/activity_t.ml +++ /dev/null @@ -1,4 +0,0 @@ -(* Auto-generated from "activity.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type t = { name: string; kind: int; url: string option } diff --git a/lib/models/activity_t.mli b/lib/models/activity_t.mli deleted file mode 100644 index 6bb2049..0000000 --- a/lib/models/activity_t.mli +++ /dev/null @@ -1,4 +0,0 @@ -(* Auto-generated from "activity.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type t = { name: string; kind: int; url: string option } diff --git a/lib/models/attachment.atd b/lib/models/attachment.atd deleted file mode 100644 index 9757b49..0000000 --- a/lib/models/attachment.atd +++ /dev/null @@ -1,11 +0,0 @@ -type snowflake = abstract - -type t = { - id: snowflake; - filename: string; - size: int; - url: string; - proxy_url: string; - ?height: int option; - ?width: int option; -} \ No newline at end of file diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/attachment.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/attachment_j.ml b/lib/models/attachment_j.ml deleted file mode 100644 index 28f909d..0000000 --- a/lib/models/attachment_j.ml +++ /dev/null @@ -1,456 +0,0 @@ -(* Auto-generated from "attachment.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = Attachment_t.t = { - id: snowflake; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int option; - width: int option -} - -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_int - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"filename\":"; - ( - Yojson.Safe.write_string - ) - ob x.filename; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"size\":"; - ( - Yojson.Safe.write_int - ) - ob x.size; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x.url; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"proxy_url\":"; - ( - Yojson.Safe.write_string - ) - ob x.proxy_url; - (match x.height with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"height\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.width with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"width\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_filename = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_size = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_proxy_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_height = ref (None) in - let field_width = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 3 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 6 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_filename := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_size := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - field_url := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 4 -> - field_proxy_url := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 3 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 6 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_filename := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_size := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - field_url := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 4 -> - field_proxy_url := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "filename"; "size"; "url"; "proxy_url" |]; - ( - { - id = !field_id; - filename = !field_filename; - size = !field_size; - url = !field_url; - proxy_url = !field_proxy_url; - height = !field_height; - width = !field_width; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/attachment_j.mli b/lib/models/attachment_j.mli deleted file mode 100644 index 6b11b08..0000000 --- a/lib/models/attachment_j.mli +++ /dev/null @@ -1,55 +0,0 @@ -(* Auto-generated from "attachment.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = Attachment_t.t = { - id: snowflake; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int option; - width: int option -} - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/attachment_t.ml b/lib/models/attachment_t.ml deleted file mode 100644 index 0485dcc..0000000 --- a/lib/models/attachment_t.ml +++ /dev/null @@ -1,14 +0,0 @@ -(* Auto-generated from "attachment.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int option; - width: int option -} diff --git a/lib/models/attachment_t.mli b/lib/models/attachment_t.mli deleted file mode 100644 index 0485dcc..0000000 --- a/lib/models/attachment_t.mli +++ /dev/null @@ -1,14 +0,0 @@ -(* Auto-generated from "attachment.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int option; - width: int option -} diff --git a/lib/models/ban.atd b/lib/models/ban.atd deleted file mode 100644 index 0a87338..0000000 --- a/lib/models/ban.atd +++ /dev/null @@ -1,6 +0,0 @@ -type user = abstract - -type t = { - ?reason: string option; - user: user; -} \ No newline at end of file diff --git a/lib/models/ban.ml b/lib/models/ban.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/ban.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/ban_j.ml b/lib/models/ban_j.ml deleted file mode 100644 index e608f67..0000000 --- a/lib/models/ban_j.ml +++ /dev/null @@ -1,235 +0,0 @@ -(* Auto-generated from "ban.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type t = Ban_t.t = { reason: string option; user: user } - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.reason with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"reason\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user\":"; - ( - write_user - ) - ob x.user; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_reason = ref (None) in - let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_reason := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_reason := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user" |]; - ( - { - reason = !field_reason; - user = !field_user; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/ban_j.mli b/lib/models/ban_j.mli deleted file mode 100644 index 9449b5c..0000000 --- a/lib/models/ban_j.mli +++ /dev/null @@ -1,47 +0,0 @@ -(* Auto-generated from "ban.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type t = Ban_t.t = { reason: string option; user: user } - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/ban_t.ml b/lib/models/ban_t.ml deleted file mode 100644 index 7d9c5a0..0000000 --- a/lib/models/ban_t.ml +++ /dev/null @@ -1,6 +0,0 @@ -(* Auto-generated from "ban.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type t = { reason: string option; user: user } diff --git a/lib/models/ban_t.mli b/lib/models/ban_t.mli deleted file mode 100644 index 7d9c5a0..0000000 --- a/lib/models/ban_t.mli +++ /dev/null @@ -1,6 +0,0 @@ -(* Auto-generated from "ban.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type t = { reason: string option; user: user } diff --git a/lib/models/channel.atd b/lib/models/channel.atd deleted file mode 100644 index 6ab58cf..0000000 --- a/lib/models/channel.atd +++ /dev/null @@ -1,19 +0,0 @@ -type snowflake = abstract -type user = abstract - -type t = { - id: snowflake; - kind : int; - ?guild_id: snowflake option; - ?position: int option; - ?name: string option; - ?topic: string option; - ?nsfw: bool option; - ?bitrate: int option; - ?user_limit: int option; - ?recipients: user list option; - ?icon: string option; - ?owner_id: snowflake option; - ?application_id: snowflake option; - ?parent_id: snowflake option; -} \ No newline at end of file diff --git a/lib/models/channel.ml b/lib/models/channel.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/channel.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/channel_j.ml b/lib/models/channel_j.ml deleted file mode 100644 index 7369230..0000000 --- a/lib/models/channel_j.ml +++ /dev/null @@ -1,1136 +0,0 @@ -(* Auto-generated from "channel.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Channel_t.t = { - id: snowflake; - kind: int; - guild_id: snowflake option; - position: int option; - name: string option; - topic: string option; - nsfw: bool option; - bitrate: int option; - user_limit: int option; - recipients: user list option; - icon: string option; - owner_id: snowflake option; - application_id: snowflake option; - parent_id: snowflake option -} - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__5 = ( - Atdgen_runtime.Oj_run.write_list ( - write_user - ) -) -let string_of__5 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__5 ob x; - Bi_outbuf.contents ob -let read__5 = ( - Atdgen_runtime.Oj_run.read_list ( - read_user - ) -) -let _5_of_string s = - read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__6 = ( - Atdgen_runtime.Oj_run.write_option ( - write__5 - ) -) -let string_of__6 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__6 ob x; - Bi_outbuf.contents ob -let read__6 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read__5 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read__5 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _6_of_string s = - read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__4 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_bool - ) -) -let string_of__4 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__4 ob x; - Bi_outbuf.contents ob -let read__4 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _4_of_string s = - read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_int - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - write_snowflake - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"type\":"; - ( - Yojson.Safe.write_int - ) - ob x.kind; - (match x.guild_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"guild_id\":"; - ( - write_snowflake - ) - ob x; - ); - (match x.position with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"position\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.name with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.topic with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"topic\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.nsfw with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"nsfw\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.bitrate with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"bitrate\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.user_limit with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user_limit\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.recipients with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"recipients\":"; - ( - write__5 - ) - ob x; - ); - (match x.icon with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"icon\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.owner_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"owner_id\":"; - ( - write_snowflake - ) - ob x; - ); - (match x.application_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"application_id\":"; - ( - write_snowflake - ) - ob x; - ); - (match x.parent_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"parent_id\":"; - ( - write_snowflake - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_guild_id = ref (None) in - let field_position = ref (None) in - let field_name = ref (None) in - let field_topic = ref (None) in - let field_nsfw = ref (None) in - let field_bitrate = ref (None) in - let field_user_limit = ref (None) in - let field_recipients = ref (None) in - let field_icon = ref (None) in - let field_owner_id = ref (None) in - let field_application_id = ref (None) in - let field_parent_id = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( - 10 - ) - else ( - -1 - ) - ) - | 'n' -> ( - match String.unsafe_get s (pos+1) with - | 'a' -> ( - if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( - 5 - ) - else ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 2 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 11 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( - 13 - ) - else ( - -1 - ) - ) - | 10 -> ( - match String.unsafe_get s pos with - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( - 9 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( - 8 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 12 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_guild_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_position := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_name := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_topic := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nsfw := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_bitrate := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_user_limit := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_recipients := ( - Some ( - ( - read__5 - ) p lb - ) - ); - ) - | 10 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 11 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_owner_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 12 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_application_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 13 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_parent_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( - 10 - ) - else ( - -1 - ) - ) - | 'n' -> ( - match String.unsafe_get s (pos+1) with - | 'a' -> ( - if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( - 5 - ) - else ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 2 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 11 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( - 13 - ) - else ( - -1 - ) - ) - | 10 -> ( - match String.unsafe_get s pos with - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( - 9 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( - 8 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 12 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_guild_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_position := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_name := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_topic := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nsfw := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_bitrate := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_user_limit := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_recipients := ( - Some ( - ( - read__5 - ) p lb - ) - ); - ) - | 10 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 11 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_owner_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 12 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_application_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 13 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_parent_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "kind" |]; - ( - { - id = !field_id; - kind = !field_kind; - guild_id = !field_guild_id; - position = !field_position; - name = !field_name; - topic = !field_topic; - nsfw = !field_nsfw; - bitrate = !field_bitrate; - user_limit = !field_user_limit; - recipients = !field_recipients; - icon = !field_icon; - owner_id = !field_owner_id; - application_id = !field_application_id; - parent_id = !field_parent_id; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/channel_j.mli b/lib/models/channel_j.mli deleted file mode 100644 index ec4048c..0000000 --- a/lib/models/channel_j.mli +++ /dev/null @@ -1,84 +0,0 @@ -(* Auto-generated from "channel.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Channel_t.t = { - id: snowflake; - kind: int; - guild_id: snowflake option; - position: int option; - name: string option; - topic: string option; - nsfw: bool option; - bitrate: int option; - user_limit: int option; - recipients: user list option; - icon: string option; - owner_id: snowflake option; - application_id: snowflake option; - parent_id: snowflake option -} - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/channel_t.ml b/lib/models/channel_t.ml deleted file mode 100644 index a5c9ce4..0000000 --- a/lib/models/channel_t.ml +++ /dev/null @@ -1,23 +0,0 @@ -(* Auto-generated from "channel.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - kind: int; - guild_id: snowflake option; - position: int option; - name: string option; - topic: string option; - nsfw: bool option; - bitrate: int option; - user_limit: int option; - recipients: user list option; - icon: string option; - owner_id: snowflake option; - application_id: snowflake option; - parent_id: snowflake option -} diff --git a/lib/models/channel_t.mli b/lib/models/channel_t.mli deleted file mode 100644 index a5c9ce4..0000000 --- a/lib/models/channel_t.mli +++ /dev/null @@ -1,23 +0,0 @@ -(* Auto-generated from "channel.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - kind: int; - guild_id: snowflake option; - position: int option; - name: string option; - topic: string option; - nsfw: bool option; - bitrate: int option; - user_limit: int option; - recipients: user list option; - icon: string option; - owner_id: snowflake option; - application_id: snowflake option; - parent_id: snowflake option -} diff --git a/lib/models/embed.atd b/lib/models/embed.atd deleted file mode 100644 index 0d3aed4..0000000 --- a/lib/models/embed.atd +++ /dev/null @@ -1,44 +0,0 @@ -type footer = { - text: string; - ?icon_url: string option; - ?proxy_icon_url: string option; -} - -type image = { - ?url: string option; - ?proxy_url: string option; - ?height: int option; - ?width: int option; -} - -type video = { - ?url: string option; - ?height: int option; - ?width: int option; -} - -type provider = { - ?name: string option; - ?url: string option; -} - -type field = { - name: string; - value: string; - ?inline: bool option; -} - -type t = { - ?title: string option; - ?kind: string option; - ?description: string option; - ?url: string option; - ?timestamp: string option; - ?colour: int option; - ?footer: footer option; - ?image: image option; - ?thumbnail: image option; - ?video: video option; - ?provider: provider option; - ?fields: field list option; -} \ No newline at end of file diff --git a/lib/models/embed.ml b/lib/models/embed.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/embed.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/embed_j.ml b/lib/models/embed_j.ml deleted file mode 100644 index 560c517..0000000 --- a/lib/models/embed_j.ml +++ /dev/null @@ -1,2283 +0,0 @@ -(* Auto-generated from "embed.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type video = Embed_t.video = { - url: string option; - height: int option; - width: int option -} - -type provider = Embed_t.provider = { - name: string option; - url: string option -} - -type image = Embed_t.image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option -} - -type footer = Embed_t.footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option -} - -type field = Embed_t.field = { - name: string; - value: string; - inline: bool option -} - -type t = Embed_t.t = { - title: string option; - kind: string option; - description: string option; - url: string option; - timestamp: string option; - colour: int option; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - fields: field list option -} - -let write__2 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_int - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_video : _ -> video -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.height with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"height\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.width with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"width\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_video ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_video ob x; - Bi_outbuf.contents ob -let read_video = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_url = ref (None) in - let field_height = ref (None) in - let field_width = ref (None) in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 2 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 2 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - ( - { - url = !field_url; - height = !field_height; - width = !field_width; - } - : video) - ) -) -let video_of_string s = - read_video (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_provider : _ -> provider -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.name with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_provider ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_provider ob x; - Bi_outbuf.contents ob -let read_provider = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_name = ref (None) in - let field_url = ref (None) in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_name := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_name := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - ( - { - name = !field_name; - url = !field_url; - } - : provider) - ) -) -let provider_of_string s = - read_provider (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_image : _ -> image -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.proxy_url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"proxy_url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.height with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"height\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.width with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"width\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_image ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_image ob x; - Bi_outbuf.contents ob -let read_image = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_url = ref (None) in - let field_proxy_url = ref (None) in - let field_height = ref (None) in - let field_width = ref (None) in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 3 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_proxy_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( - 3 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_proxy_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_height := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_width := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - ( - { - url = !field_url; - proxy_url = !field_proxy_url; - height = !field_height; - width = !field_width; - } - : image) - ) -) -let image_of_string s = - read_image (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_footer : _ -> footer -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"text\":"; - ( - Yojson.Safe.write_string - ) - ob x.text; - (match x.icon_url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"icon_url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.proxy_icon_url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"proxy_icon_url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_footer ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_footer ob x; - Bi_outbuf.contents ob -let read_footer = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_text = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_icon_url = ref (None) in - let field_proxy_icon_url = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( - 0 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_text := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_proxy_icon_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( - 0 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( - 1 - ) - else ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_text := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_proxy_icon_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "text" |]; - ( - { - text = !field_text; - icon_url = !field_icon_url; - proxy_icon_url = !field_proxy_icon_url; - } - : footer) - ) -) -let footer_of_string s = - read_footer (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_bool - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_field : _ -> field -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x.name; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"value\":"; - ( - Yojson.Safe.write_string - ) - ob x.value; - (match x.inline with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"inline\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_field ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_field ob x; - Bi_outbuf.contents ob -let read_field = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_value = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_inline = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_value := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_inline := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_value := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_inline := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "value" |]; - ( - { - name = !field_name; - value = !field_value; - inline = !field_inline; - } - : field) - ) -) -let field_of_string s = - read_field (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__8 = ( - Atdgen_runtime.Oj_run.write_list ( - write_field - ) -) -let string_of__8 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__8 ob x; - Bi_outbuf.contents ob -let read__8 = ( - Atdgen_runtime.Oj_run.read_list ( - read_field - ) -) -let _8_of_string s = - read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__9 = ( - Atdgen_runtime.Oj_run.write_option ( - write__8 - ) -) -let string_of__9 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__9 ob x; - Bi_outbuf.contents ob -let read__9 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read__8 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read__8 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _9_of_string s = - read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__7 = ( - Atdgen_runtime.Oj_run.write_option ( - write_provider - ) -) -let string_of__7 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__7 ob x; - Bi_outbuf.contents ob -let read__7 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_provider - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_provider - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _7_of_string s = - read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__6 = ( - Atdgen_runtime.Oj_run.write_option ( - write_video - ) -) -let string_of__6 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__6 ob x; - Bi_outbuf.contents ob -let read__6 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_video - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_video - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _6_of_string s = - read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__5 = ( - Atdgen_runtime.Oj_run.write_option ( - write_image - ) -) -let string_of__5 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__5 ob x; - Bi_outbuf.contents ob -let read__5 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_image - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_image - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _5_of_string s = - read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__4 = ( - Atdgen_runtime.Oj_run.write_option ( - write_footer - ) -) -let string_of__4 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__4 ob x; - Bi_outbuf.contents ob -let read__4 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_footer - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_footer - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _4_of_string s = - read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.title with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"title\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.kind with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"kind\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.description with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"description\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.url with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"url\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.timestamp with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"timestamp\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.colour with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"colour\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.footer with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"footer\":"; - ( - write_footer - ) - ob x; - ); - (match x.image with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"image\":"; - ( - write_image - ) - ob x; - ); - (match x.thumbnail with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"thumbnail\":"; - ( - write_image - ) - ob x; - ); - (match x.video with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"video\":"; - ( - write_video - ) - ob x; - ); - (match x.provider with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"provider\":"; - ( - write_provider - ) - ob x; - ); - (match x.fields with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"fields\":"; - ( - write__8 - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_title = ref (None) in - let field_kind = ref (None) in - let field_description = ref (None) in - let field_url = ref (None) in - let field_timestamp = ref (None) in - let field_colour = ref (None) in - let field_footer = ref (None) in - let field_image = ref (None) in - let field_thumbnail = ref (None) in - let field_video = ref (None) in - let field_provider = ref (None) in - let field_fields = ref (None) in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 3 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( - 1 - ) - else ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 'v' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( - 9 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( - 5 - ) - else ( - -1 - ) - ) - | 'f' -> ( - match String.unsafe_get s (pos+1) with - | 'i' -> ( - if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( - 10 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 't' then ( - match String.unsafe_get s (pos+1) with - | 'h' -> ( - if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( - 8 - ) - else ( - -1 - ) - ) - | 'i' -> ( - if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - ) - | 11 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_title := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_kind := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_description := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_timestamp := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_colour := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_footer := ( - Some ( - ( - read_footer - ) p lb - ) - ); - ) - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_image := ( - Some ( - ( - read_image - ) p lb - ) - ); - ) - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_thumbnail := ( - Some ( - ( - read_image - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_video := ( - Some ( - ( - read_video - ) p lb - ) - ); - ) - | 10 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_provider := ( - Some ( - ( - read_provider - ) p lb - ) - ); - ) - | 11 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_fields := ( - Some ( - ( - read__8 - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 3 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( - 3 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( - 1 - ) - else ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( - 0 - ) - else ( - -1 - ) - ) - | 'v' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( - 9 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( - 5 - ) - else ( - -1 - ) - ) - | 'f' -> ( - match String.unsafe_get s (pos+1) with - | 'i' -> ( - if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( - 10 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 't' then ( - match String.unsafe_get s (pos+1) with - | 'h' -> ( - if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( - 8 - ) - else ( - -1 - ) - ) - | 'i' -> ( - if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - ) - | 11 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_title := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_kind := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_description := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_url := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_timestamp := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_colour := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_footer := ( - Some ( - ( - read_footer - ) p lb - ) - ); - ) - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_image := ( - Some ( - ( - read_image - ) p lb - ) - ); - ) - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_thumbnail := ( - Some ( - ( - read_image - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_video := ( - Some ( - ( - read_video - ) p lb - ) - ); - ) - | 10 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_provider := ( - Some ( - ( - read_provider - ) p lb - ) - ); - ) - | 11 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_fields := ( - Some ( - ( - read__8 - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - ( - { - title = !field_title; - kind = !field_kind; - description = !field_description; - url = !field_url; - timestamp = !field_timestamp; - colour = !field_colour; - footer = !field_footer; - image = !field_image; - thumbnail = !field_thumbnail; - video = !field_video; - provider = !field_provider; - fields = !field_fields; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/embed_j.mli b/lib/models/embed_j.mli deleted file mode 100644 index 8872d89..0000000 --- a/lib/models/embed_j.mli +++ /dev/null @@ -1,168 +0,0 @@ -(* Auto-generated from "embed.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type video = Embed_t.video = { - url: string option; - height: int option; - width: int option -} - -type provider = Embed_t.provider = { - name: string option; - url: string option -} - -type image = Embed_t.image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option -} - -type footer = Embed_t.footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option -} - -type field = Embed_t.field = { - name: string; - value: string; - inline: bool option -} - -type t = Embed_t.t = { - title: string option; - kind: string option; - description: string option; - url: string option; - timestamp: string option; - colour: int option; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - fields: field list option -} - -val write_video : - Bi_outbuf.t -> video -> unit - (** Output a JSON value of type {!video}. *) - -val string_of_video : - ?len:int -> video -> string - (** Serialize a value of type {!video} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_video : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> video - (** Input JSON data of type {!video}. *) - -val video_of_string : - string -> video - (** Deserialize JSON data of type {!video}. *) - -val write_provider : - Bi_outbuf.t -> provider -> unit - (** Output a JSON value of type {!provider}. *) - -val string_of_provider : - ?len:int -> provider -> string - (** Serialize a value of type {!provider} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_provider : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> provider - (** Input JSON data of type {!provider}. *) - -val provider_of_string : - string -> provider - (** Deserialize JSON data of type {!provider}. *) - -val write_image : - Bi_outbuf.t -> image -> unit - (** Output a JSON value of type {!image}. *) - -val string_of_image : - ?len:int -> image -> string - (** Serialize a value of type {!image} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_image : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> image - (** Input JSON data of type {!image}. *) - -val image_of_string : - string -> image - (** Deserialize JSON data of type {!image}. *) - -val write_footer : - Bi_outbuf.t -> footer -> unit - (** Output a JSON value of type {!footer}. *) - -val string_of_footer : - ?len:int -> footer -> string - (** Serialize a value of type {!footer} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_footer : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> footer - (** Input JSON data of type {!footer}. *) - -val footer_of_string : - string -> footer - (** Deserialize JSON data of type {!footer}. *) - -val write_field : - Bi_outbuf.t -> field -> unit - (** Output a JSON value of type {!field}. *) - -val string_of_field : - ?len:int -> field -> string - (** Serialize a value of type {!field} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_field : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> field - (** Input JSON data of type {!field}. *) - -val field_of_string : - string -> field - (** Deserialize JSON data of type {!field}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/embed_t.ml b/lib/models/embed_t.ml deleted file mode 100644 index 9eb5059..0000000 --- a/lib/models/embed_t.ml +++ /dev/null @@ -1,36 +0,0 @@ -(* Auto-generated from "embed.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type video = { url: string option; height: int option; width: int option } - -type provider = { name: string option; url: string option } - -type image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option -} - -type footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option -} - -type field = { name: string; value: string; inline: bool option } - -type t = { - title: string option; - kind: string option; - description: string option; - url: string option; - timestamp: string option; - colour: int option; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - fields: field list option -} diff --git a/lib/models/embed_t.mli b/lib/models/embed_t.mli deleted file mode 100644 index 9eb5059..0000000 --- a/lib/models/embed_t.mli +++ /dev/null @@ -1,36 +0,0 @@ -(* Auto-generated from "embed.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type video = { url: string option; height: int option; width: int option } - -type provider = { name: string option; url: string option } - -type image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option -} - -type footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option -} - -type field = { name: string; value: string; inline: bool option } - -type t = { - title: string option; - kind: string option; - description: string option; - url: string option; - timestamp: string option; - colour: int option; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - fields: field list option -} diff --git a/lib/models/emoji.atd b/lib/models/emoji.atd deleted file mode 100644 index 877323b..0000000 --- a/lib/models/emoji.atd +++ /dev/null @@ -1,12 +0,0 @@ -type snowflake = abstract -type user = abstract - -type t = { - ?id: snowflake option; - name: string; - ?roles: snowflake list option; - ?user: user option; - ?require_colons: bool option; - ?managed: bool option; - ?animated: bool option; -} \ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/emoji.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/emoji_j.ml b/lib/models/emoji_j.ml deleted file mode 100644 index d621de2..0000000 --- a/lib/models/emoji_j.ml +++ /dev/null @@ -1,701 +0,0 @@ -(* Auto-generated from "emoji.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Emoji_t.t = { - id: snowflake option; - name: string; - roles: snowflake list option; - user: user option; - require_colons: bool option; - managed: bool option; - animated: bool option -} - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__5 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_bool - ) -) -let string_of__5 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__5 ob x; - Bi_outbuf.contents ob -let read__5 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _5_of_string s = - read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__4 = ( - Atdgen_runtime.Oj_run.write_option ( - write_user - ) -) -let string_of__4 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__4 ob x; - Bi_outbuf.contents ob -let read__4 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_user - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_user - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _4_of_string s = - read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_list ( - write_snowflake - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - Atdgen_runtime.Oj_run.read_list ( - read_snowflake - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_option ( - write__2 - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read__2 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read__2 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - write_snowflake - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x.name; - (match x.roles with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"roles\":"; - ( - write__2 - ) - ob x; - ); - (match x.user with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user\":"; - ( - write_user - ) - ob x; - ); - (match x.require_colons with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"require_colons\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.managed with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"managed\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.animated with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"animated\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (None) in - let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_roles = ref (None) in - let field_user = ref (None) in - let field_require_colons = ref (None) in - let field_managed = ref (None) in - let field_animated = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 2 - ) - else ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_roles := ( - Some ( - ( - read__2 - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_user := ( - Some ( - ( - read_user - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_require_colons := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_managed := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_animated := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 2 - ) - else ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 14 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_roles := ( - Some ( - ( - read__2 - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_user := ( - Some ( - ( - read_user - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_require_colons := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 5 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_managed := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_animated := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name" |]; - ( - { - id = !field_id; - name = !field_name; - roles = !field_roles; - user = !field_user; - require_colons = !field_require_colons; - managed = !field_managed; - animated = !field_animated; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/emoji_j.mli b/lib/models/emoji_j.mli deleted file mode 100644 index 596deeb..0000000 --- a/lib/models/emoji_j.mli +++ /dev/null @@ -1,77 +0,0 @@ -(* Auto-generated from "emoji.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Emoji_t.t = { - id: snowflake option; - name: string; - roles: snowflake list option; - user: user option; - require_colons: bool option; - managed: bool option; - animated: bool option -} - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/emoji_t.ml b/lib/models/emoji_t.ml deleted file mode 100644 index 333939d..0000000 --- a/lib/models/emoji_t.ml +++ /dev/null @@ -1,16 +0,0 @@ -(* Auto-generated from "emoji.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake option; - name: string; - roles: snowflake list option; - user: user option; - require_colons: bool option; - managed: bool option; - animated: bool option -} diff --git a/lib/models/emoji_t.mli b/lib/models/emoji_t.mli deleted file mode 100644 index 333939d..0000000 --- a/lib/models/emoji_t.mli +++ /dev/null @@ -1,16 +0,0 @@ -(* Auto-generated from "emoji.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake option; - name: string; - roles: snowflake list option; - user: user option; - require_colons: bool option; - managed: bool option; - animated: bool option -} diff --git a/lib/models/gen/activity.atd b/lib/models/gen/activity.atd new file mode 100644 index 0000000..8e02191 --- /dev/null +++ b/lib/models/gen/activity.atd @@ -0,0 +1,5 @@ +type t = { + name: string; + kind : int; + ?url: string option; +} \ No newline at end of file diff --git a/lib/models/gen/activity_j.ml b/lib/models/gen/activity_j.ml new file mode 100644 index 0000000..eb1a62e --- /dev/null +++ b/lib/models/gen/activity_j.ml @@ -0,0 +1,274 @@ +(* Auto-generated from "activity.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Activity_t.t = { name: string; kind: int; url: string option } + +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; + ( + Yojson.Safe.write_int + ) + ob x.kind; + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_url = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "kind" |]; + ( + { + name = !field_name; + kind = !field_kind; + url = !field_url; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/activity_j.mli b/lib/models/gen/activity_j.mli new file mode 100644 index 0000000..c179efb --- /dev/null +++ b/lib/models/gen/activity_j.mli @@ -0,0 +1,25 @@ +(* Auto-generated from "activity.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Activity_t.t = { name: string; kind: int; url: string option } + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/activity_t.ml b/lib/models/gen/activity_t.ml new file mode 100644 index 0000000..6bb2049 --- /dev/null +++ b/lib/models/gen/activity_t.ml @@ -0,0 +1,4 @@ +(* Auto-generated from "activity.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = { name: string; kind: int; url: string option } diff --git a/lib/models/gen/activity_t.mli b/lib/models/gen/activity_t.mli new file mode 100644 index 0000000..6bb2049 --- /dev/null +++ b/lib/models/gen/activity_t.mli @@ -0,0 +1,4 @@ +(* Auto-generated from "activity.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = { name: string; kind: int; url: string option } diff --git a/lib/models/gen/attachment.atd b/lib/models/gen/attachment.atd new file mode 100644 index 0000000..9757b49 --- /dev/null +++ b/lib/models/gen/attachment.atd @@ -0,0 +1,11 @@ +type snowflake = abstract + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + ?height: int option; + ?width: int option; +} \ No newline at end of file diff --git a/lib/models/gen/attachment_j.ml b/lib/models/gen/attachment_j.ml new file mode 100644 index 0000000..28f909d --- /dev/null +++ b/lib/models/gen/attachment_j.ml @@ -0,0 +1,456 @@ +(* Auto-generated from "attachment.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Attachment_t.t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"filename\":"; + ( + Yojson.Safe.write_string + ) + ob x.filename; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"size\":"; + ( + Yojson.Safe.write_int + ) + ob x.size; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x.url; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_url\":"; + ( + Yojson.Safe.write_string + ) + ob x.proxy_url; + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_filename = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_size = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_proxy_url = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_height = ref (None) in + let field_width = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 6 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_filename := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_size := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_proxy_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'z' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 6 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'f' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_filename := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_size := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_proxy_url := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "filename"; "size"; "url"; "proxy_url" |]; + ( + { + id = !field_id; + filename = !field_filename; + size = !field_size; + url = !field_url; + proxy_url = !field_proxy_url; + height = !field_height; + width = !field_width; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/attachment_j.mli b/lib/models/gen/attachment_j.mli new file mode 100644 index 0000000..6b11b08 --- /dev/null +++ b/lib/models/gen/attachment_j.mli @@ -0,0 +1,55 @@ +(* Auto-generated from "attachment.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Attachment_t.t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/attachment_t.ml b/lib/models/gen/attachment_t.ml new file mode 100644 index 0000000..0485dcc --- /dev/null +++ b/lib/models/gen/attachment_t.ml @@ -0,0 +1,14 @@ +(* Auto-generated from "attachment.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} diff --git a/lib/models/gen/attachment_t.mli b/lib/models/gen/attachment_t.mli new file mode 100644 index 0000000..0485dcc --- /dev/null +++ b/lib/models/gen/attachment_t.mli @@ -0,0 +1,14 @@ +(* Auto-generated from "attachment.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + filename: string; + size: int; + url: string; + proxy_url: string; + height: int option; + width: int option +} diff --git a/lib/models/gen/ban.atd b/lib/models/gen/ban.atd new file mode 100644 index 0000000..0a87338 --- /dev/null +++ b/lib/models/gen/ban.atd @@ -0,0 +1,6 @@ +type user = abstract + +type t = { + ?reason: string option; + user: user; +} \ No newline at end of file diff --git a/lib/models/gen/ban_j.ml b/lib/models/gen/ban_j.ml new file mode 100644 index 0000000..e608f67 --- /dev/null +++ b/lib/models/gen/ban_j.ml @@ -0,0 +1,235 @@ +(* Auto-generated from "ban.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = Ban_t.t = { reason: string option; user: user } + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.reason with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"reason\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_reason = ref (None) in + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reason := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reason := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user" |]; + ( + { + reason = !field_reason; + user = !field_user; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/ban_j.mli b/lib/models/gen/ban_j.mli new file mode 100644 index 0000000..9449b5c --- /dev/null +++ b/lib/models/gen/ban_j.mli @@ -0,0 +1,47 @@ +(* Auto-generated from "ban.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = Ban_t.t = { reason: string option; user: user } + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/ban_t.ml b/lib/models/gen/ban_t.ml new file mode 100644 index 0000000..7d9c5a0 --- /dev/null +++ b/lib/models/gen/ban_t.ml @@ -0,0 +1,6 @@ +(* Auto-generated from "ban.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = { reason: string option; user: user } diff --git a/lib/models/gen/ban_t.mli b/lib/models/gen/ban_t.mli new file mode 100644 index 0000000..7d9c5a0 --- /dev/null +++ b/lib/models/gen/ban_t.mli @@ -0,0 +1,6 @@ +(* Auto-generated from "ban.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type t = { reason: string option; user: user } diff --git a/lib/models/gen/channel.atd b/lib/models/gen/channel.atd new file mode 100644 index 0000000..6ab58cf --- /dev/null +++ b/lib/models/gen/channel.atd @@ -0,0 +1,19 @@ +type snowflake = abstract +type user = abstract + +type t = { + id: snowflake; + kind : int; + ?guild_id: snowflake option; + ?position: int option; + ?name: string option; + ?topic: string option; + ?nsfw: bool option; + ?bitrate: int option; + ?user_limit: int option; + ?recipients: user list option; + ?icon: string option; + ?owner_id: snowflake option; + ?application_id: snowflake option; + ?parent_id: snowflake option; +} \ No newline at end of file diff --git a/lib/models/gen/channel_j.ml b/lib/models/gen/channel_j.ml new file mode 100644 index 0000000..7369230 --- /dev/null +++ b/lib/models/gen/channel_j.ml @@ -0,0 +1,1136 @@ +(* Auto-generated from "channel.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Channel_t.t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_list ( + write_user + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + Atdgen_runtime.Oj_run.read_list ( + read_user + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_option ( + write__5 + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__5 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__5 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; + ( + Yojson.Safe.write_int + ) + ob x.kind; + (match x.guild_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.position with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"position\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.name with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.topic with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"topic\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.nsfw with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nsfw\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.bitrate with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"bitrate\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.user_limit with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user_limit\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.recipients with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"recipients\":"; + ( + write__5 + ) + ob x; + ); + (match x.icon with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.owner_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"owner_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.application_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"application_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.parent_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"parent_id\":"; + ( + write_snowflake + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_guild_id = ref (None) in + let field_position = ref (None) in + let field_name = ref (None) in + let field_topic = ref (None) in + let field_nsfw = ref (None) in + let field_bitrate = ref (None) in + let field_user_limit = ref (None) in + let field_recipients = ref (None) in + let field_icon = ref (None) in + let field_owner_id = ref (None) in + let field_application_id = ref (None) in + let field_parent_id = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 10 + ) + else ( + -1 + ) + ) + | 'n' -> ( + match String.unsafe_get s (pos+1) with + | 'a' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( + 5 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 11 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( + 13 + ) + else ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( + 9 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( + 8 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 12 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_position := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_topic := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nsfw := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bitrate := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user_limit := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_recipients := ( + Some ( + ( + read__5 + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_owner_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 12 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 13 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_parent_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 10 + ) + else ( + -1 + ) + ) + | 'n' -> ( + match String.unsafe_get s (pos+1) with + | 'a' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'w' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'c' then ( + 5 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 11 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'd' then ( + 13 + ) + else ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'p' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 's' then ( + 9 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 't' then ( + 8 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 12 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_position := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_topic := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nsfw := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bitrate := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user_limit := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_recipients := ( + Some ( + ( + read__5 + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_owner_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 12 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 13 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_parent_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "kind" |]; + ( + { + id = !field_id; + kind = !field_kind; + guild_id = !field_guild_id; + position = !field_position; + name = !field_name; + topic = !field_topic; + nsfw = !field_nsfw; + bitrate = !field_bitrate; + user_limit = !field_user_limit; + recipients = !field_recipients; + icon = !field_icon; + owner_id = !field_owner_id; + application_id = !field_application_id; + parent_id = !field_parent_id; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/channel_j.mli b/lib/models/gen/channel_j.mli new file mode 100644 index 0000000..ec4048c --- /dev/null +++ b/lib/models/gen/channel_j.mli @@ -0,0 +1,84 @@ +(* Auto-generated from "channel.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Channel_t.t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/channel_t.ml b/lib/models/gen/channel_t.ml new file mode 100644 index 0000000..a5c9ce4 --- /dev/null +++ b/lib/models/gen/channel_t.ml @@ -0,0 +1,23 @@ +(* Auto-generated from "channel.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} diff --git a/lib/models/gen/channel_t.mli b/lib/models/gen/channel_t.mli new file mode 100644 index 0000000..a5c9ce4 --- /dev/null +++ b/lib/models/gen/channel_t.mli @@ -0,0 +1,23 @@ +(* Auto-generated from "channel.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + kind: int; + guild_id: snowflake option; + position: int option; + name: string option; + topic: string option; + nsfw: bool option; + bitrate: int option; + user_limit: int option; + recipients: user list option; + icon: string option; + owner_id: snowflake option; + application_id: snowflake option; + parent_id: snowflake option +} diff --git a/lib/models/gen/embed.atd b/lib/models/gen/embed.atd new file mode 100644 index 0000000..0d3aed4 --- /dev/null +++ b/lib/models/gen/embed.atd @@ -0,0 +1,44 @@ +type footer = { + text: string; + ?icon_url: string option; + ?proxy_icon_url: string option; +} + +type image = { + ?url: string option; + ?proxy_url: string option; + ?height: int option; + ?width: int option; +} + +type video = { + ?url: string option; + ?height: int option; + ?width: int option; +} + +type provider = { + ?name: string option; + ?url: string option; +} + +type field = { + name: string; + value: string; + ?inline: bool option; +} + +type t = { + ?title: string option; + ?kind: string option; + ?description: string option; + ?url: string option; + ?timestamp: string option; + ?colour: int option; + ?footer: footer option; + ?image: image option; + ?thumbnail: image option; + ?video: video option; + ?provider: provider option; + ?fields: field list option; +} \ No newline at end of file diff --git a/lib/models/gen/embed_j.ml b/lib/models/gen/embed_j.ml new file mode 100644 index 0000000..560c517 --- /dev/null +++ b/lib/models/gen/embed_j.ml @@ -0,0 +1,2283 @@ +(* Auto-generated from "embed.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type video = Embed_t.video = { + url: string option; + height: int option; + width: int option +} + +type provider = Embed_t.provider = { + name: string option; + url: string option +} + +type image = Embed_t.image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = Embed_t.footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = Embed_t.field = { + name: string; + value: string; + inline: bool option +} + +type t = Embed_t.t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} + +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_video : _ -> video -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_video ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_video ob x; + Bi_outbuf.contents ob +let read_video = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_url = ref (None) in + let field_height = ref (None) in + let field_width = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 2 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 2 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + url = !field_url; + height = !field_height; + width = !field_width; + } + : video) + ) +) +let video_of_string s = + read_video (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_provider : _ -> provider -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.name with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_provider ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_provider ob x; + Bi_outbuf.contents ob +let read_provider = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_name = ref (None) in + let field_url = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_name := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + name = !field_name; + url = !field_url; + } + : provider) + ) +) +let provider_of_string s = + read_provider (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_image : _ -> image -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.proxy_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.height with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"height\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.width with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"width\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_image ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_image ob x; + Bi_outbuf.contents ob +let read_image = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_url = ref (None) in + let field_proxy_url = ref (None) in + let field_height = ref (None) in + let field_width = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'w' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'h' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'h' && String.unsafe_get s (pos+5) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'u' && String.unsafe_get s (pos+7) = 'r' && String.unsafe_get s (pos+8) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_height := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_width := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + url = !field_url; + proxy_url = !field_proxy_url; + height = !field_height; + width = !field_width; + } + : image) + ) +) +let image_of_string s = + read_image (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_footer : _ -> footer -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"text\":"; + ( + Yojson.Safe.write_string + ) + ob x.text; + (match x.icon_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.proxy_icon_url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"proxy_icon_url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_footer ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_footer ob x; + Bi_outbuf.contents ob +let read_footer = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_text = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_icon_url = ref (None) in + let field_proxy_icon_url = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_text := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'x' && String.unsafe_get s (pos+3) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'u' && String.unsafe_get s (pos+6) = 'r' && String.unsafe_get s (pos+7) = 'l' then ( + 1 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'x' && String.unsafe_get s (pos+4) = 'y' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = '_' && String.unsafe_get s (pos+11) = 'u' && String.unsafe_get s (pos+12) = 'r' && String.unsafe_get s (pos+13) = 'l' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_text := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_proxy_icon_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "text" |]; + ( + { + text = !field_text; + icon_url = !field_icon_url; + proxy_icon_url = !field_proxy_icon_url; + } + : footer) + ) +) +let footer_of_string s = + read_footer (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_field : _ -> field -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"value\":"; + ( + Yojson.Safe.write_string + ) + ob x.value; + (match x.inline with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"inline\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_field ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_field ob x; + Bi_outbuf.contents ob +let read_field = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_value = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_inline = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_value := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_inline := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_value := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_inline := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name"; "value" |]; + ( + { + name = !field_name; + value = !field_value; + inline = !field_inline; + } + : field) + ) +) +let field_of_string s = + read_field (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__8 = ( + Atdgen_runtime.Oj_run.write_list ( + write_field + ) +) +let string_of__8 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__8 ob x; + Bi_outbuf.contents ob +let read__8 = ( + Atdgen_runtime.Oj_run.read_list ( + read_field + ) +) +let _8_of_string s = + read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__9 = ( + Atdgen_runtime.Oj_run.write_option ( + write__8 + ) +) +let string_of__9 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__9 ob x; + Bi_outbuf.contents ob +let read__9 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__8 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__8 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _9_of_string s = + read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_option ( + write_provider + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_provider + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_provider + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_option ( + write_video + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_video + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_video + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_option ( + write_image + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_image + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_image + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + write_footer + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_footer + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_footer + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.title with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"title\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.kind with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"kind\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.description with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"description\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.url with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"url\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.timestamp with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.colour with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"colour\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.footer with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"footer\":"; + ( + write_footer + ) + ob x; + ); + (match x.image with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"image\":"; + ( + write_image + ) + ob x; + ); + (match x.thumbnail with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"thumbnail\":"; + ( + write_image + ) + ob x; + ); + (match x.video with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"video\":"; + ( + write_video + ) + ob x; + ); + (match x.provider with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"provider\":"; + ( + write_provider + ) + ob x; + ); + (match x.fields with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"fields\":"; + ( + write__8 + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_title = ref (None) in + let field_kind = ref (None) in + let field_description = ref (None) in + let field_url = ref (None) in + let field_timestamp = ref (None) in + let field_colour = ref (None) in + let field_footer = ref (None) in + let field_image = ref (None) in + let field_thumbnail = ref (None) in + let field_video = ref (None) in + let field_provider = ref (None) in + let field_fields = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 'v' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | 'f' -> ( + match String.unsafe_get s (pos+1) with + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( + 10 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 't' then ( + match String.unsafe_get s (pos+1) with + | 'h' -> ( + if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( + 8 + ) + else ( + -1 + ) + ) + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_title := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_kind := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_description := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_colour := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_footer := ( + Some ( + ( + read_footer + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_image := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_thumbnail := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_video := ( + Some ( + ( + read_video + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_provider := ( + Some ( + ( + read_provider + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_fields := ( + Some ( + ( + read__8 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 3 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'l' then ( + 3 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'k' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'e' then ( + 0 + ) + else ( + -1 + ) + ) + | 'v' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'o' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | 'f' -> ( + match String.unsafe_get s (pos+1) with + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'r' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'r' then ( + 10 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 't' then ( + match String.unsafe_get s (pos+1) with + | 'h' -> ( + if String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'b' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'l' then ( + 8 + ) + else ( + -1 + ) + ) + | 'i' -> ( + if String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'p' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_title := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_kind := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_description := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_url := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_colour := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_footer := ( + Some ( + ( + read_footer + ) p lb + ) + ); + ) + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_image := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_thumbnail := ( + Some ( + ( + read_image + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_video := ( + Some ( + ( + read_video + ) p lb + ) + ); + ) + | 10 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_provider := ( + Some ( + ( + read_provider + ) p lb + ) + ); + ) + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_fields := ( + Some ( + ( + read__8 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + title = !field_title; + kind = !field_kind; + description = !field_description; + url = !field_url; + timestamp = !field_timestamp; + colour = !field_colour; + footer = !field_footer; + image = !field_image; + thumbnail = !field_thumbnail; + video = !field_video; + provider = !field_provider; + fields = !field_fields; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/embed_j.mli b/lib/models/gen/embed_j.mli new file mode 100644 index 0000000..8872d89 --- /dev/null +++ b/lib/models/gen/embed_j.mli @@ -0,0 +1,168 @@ +(* Auto-generated from "embed.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type video = Embed_t.video = { + url: string option; + height: int option; + width: int option +} + +type provider = Embed_t.provider = { + name: string option; + url: string option +} + +type image = Embed_t.image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = Embed_t.footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = Embed_t.field = { + name: string; + value: string; + inline: bool option +} + +type t = Embed_t.t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} + +val write_video : + Bi_outbuf.t -> video -> unit + (** Output a JSON value of type {!video}. *) + +val string_of_video : + ?len:int -> video -> string + (** Serialize a value of type {!video} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_video : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> video + (** Input JSON data of type {!video}. *) + +val video_of_string : + string -> video + (** Deserialize JSON data of type {!video}. *) + +val write_provider : + Bi_outbuf.t -> provider -> unit + (** Output a JSON value of type {!provider}. *) + +val string_of_provider : + ?len:int -> provider -> string + (** Serialize a value of type {!provider} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_provider : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> provider + (** Input JSON data of type {!provider}. *) + +val provider_of_string : + string -> provider + (** Deserialize JSON data of type {!provider}. *) + +val write_image : + Bi_outbuf.t -> image -> unit + (** Output a JSON value of type {!image}. *) + +val string_of_image : + ?len:int -> image -> string + (** Serialize a value of type {!image} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_image : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> image + (** Input JSON data of type {!image}. *) + +val image_of_string : + string -> image + (** Deserialize JSON data of type {!image}. *) + +val write_footer : + Bi_outbuf.t -> footer -> unit + (** Output a JSON value of type {!footer}. *) + +val string_of_footer : + ?len:int -> footer -> string + (** Serialize a value of type {!footer} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_footer : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> footer + (** Input JSON data of type {!footer}. *) + +val footer_of_string : + string -> footer + (** Deserialize JSON data of type {!footer}. *) + +val write_field : + Bi_outbuf.t -> field -> unit + (** Output a JSON value of type {!field}. *) + +val string_of_field : + ?len:int -> field -> string + (** Serialize a value of type {!field} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_field : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> field + (** Input JSON data of type {!field}. *) + +val field_of_string : + string -> field + (** Deserialize JSON data of type {!field}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/embed_t.ml b/lib/models/gen/embed_t.ml new file mode 100644 index 0000000..9eb5059 --- /dev/null +++ b/lib/models/gen/embed_t.ml @@ -0,0 +1,36 @@ +(* Auto-generated from "embed.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type video = { url: string option; height: int option; width: int option } + +type provider = { name: string option; url: string option } + +type image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = { name: string; value: string; inline: bool option } + +type t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} diff --git a/lib/models/gen/embed_t.mli b/lib/models/gen/embed_t.mli new file mode 100644 index 0000000..9eb5059 --- /dev/null +++ b/lib/models/gen/embed_t.mli @@ -0,0 +1,36 @@ +(* Auto-generated from "embed.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type video = { url: string option; height: int option; width: int option } + +type provider = { name: string option; url: string option } + +type image = { + url: string option; + proxy_url: string option; + height: int option; + width: int option +} + +type footer = { + text: string; + icon_url: string option; + proxy_icon_url: string option +} + +type field = { name: string; value: string; inline: bool option } + +type t = { + title: string option; + kind: string option; + description: string option; + url: string option; + timestamp: string option; + colour: int option; + footer: footer option; + image: image option; + thumbnail: image option; + video: video option; + provider: provider option; + fields: field list option +} diff --git a/lib/models/gen/emoji.atd b/lib/models/gen/emoji.atd new file mode 100644 index 0000000..877323b --- /dev/null +++ b/lib/models/gen/emoji.atd @@ -0,0 +1,12 @@ +type snowflake = abstract +type user = abstract + +type t = { + ?id: snowflake option; + name: string; + ?roles: snowflake list option; + ?user: user option; + ?require_colons: bool option; + ?managed: bool option; + ?animated: bool option; +} \ No newline at end of file diff --git a/lib/models/gen/emoji_j.ml b/lib/models/gen/emoji_j.ml new file mode 100644 index 0000000..d621de2 --- /dev/null +++ b/lib/models/gen/emoji_j.ml @@ -0,0 +1,701 @@ +(* Auto-generated from "emoji.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Emoji_t.t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_option ( + write_user + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_user + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_user + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + write__2 + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__2 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__2 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + (match x.roles with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x; + ); + (match x.user with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x; + ); + (match x.require_colons with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"require_colons\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.managed with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"managed\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.animated with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"animated\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (None) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (None) in + let field_user = ref (None) in + let field_require_colons = ref (None) in + let field_managed = ref (None) in + let field_animated = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_roles := ( + Some ( + ( + read__2 + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user := ( + Some ( + ( + read_user + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_require_colons := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_managed := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_animated := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 2 + ) + else ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 14 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'q' && String.unsafe_get s (pos+3) = 'u' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'c' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'n' && String.unsafe_get s (pos+13) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_roles := ( + Some ( + ( + read__2 + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_user := ( + Some ( + ( + read_user + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_require_colons := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 5 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_managed := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_animated := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "name" |]; + ( + { + id = !field_id; + name = !field_name; + roles = !field_roles; + user = !field_user; + require_colons = !field_require_colons; + managed = !field_managed; + animated = !field_animated; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/emoji_j.mli b/lib/models/gen/emoji_j.mli new file mode 100644 index 0000000..596deeb --- /dev/null +++ b/lib/models/gen/emoji_j.mli @@ -0,0 +1,77 @@ +(* Auto-generated from "emoji.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Emoji_t.t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/emoji_t.ml b/lib/models/gen/emoji_t.ml new file mode 100644 index 0000000..333939d --- /dev/null +++ b/lib/models/gen/emoji_t.ml @@ -0,0 +1,16 @@ +(* Auto-generated from "emoji.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} diff --git a/lib/models/gen/emoji_t.mli b/lib/models/gen/emoji_t.mli new file mode 100644 index 0000000..333939d --- /dev/null +++ b/lib/models/gen/emoji_t.mli @@ -0,0 +1,16 @@ +(* Auto-generated from "emoji.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake option; + name: string; + roles: snowflake list option; + user: user option; + require_colons: bool option; + managed: bool option; + animated: bool option +} diff --git a/lib/models/gen/guild.atd b/lib/models/gen/guild.atd new file mode 100644 index 0000000..c622eea --- /dev/null +++ b/lib/models/gen/guild.atd @@ -0,0 +1,36 @@ +type snowflake = abstract +type user = abstract +type member = abstract +type role = abstract +type channel = abstract +type emoji = abstract + + +type t = { + id: snowflake; + name: string; + ?icon: string option; + ?splash: string option; + owner_id: snowflake; + region: string; + ?afk_channel_id: snowflake option; + afk_timeout: int; + ?embed_enabled: bool option; + ?embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + ?application_id: snowflake option; + ?widget_enabled: bool option; + ?widget_channel: channel option; + ?system_channel: channel option; + ?large: bool option; + ?unavailable: bool option; + ?member_count: int option; + ?members: member list option; + ?channels: channel list option; +} \ No newline at end of file diff --git a/lib/models/gen/guild_j.ml b/lib/models/gen/guild_j.ml new file mode 100644 index 0000000..9f7b069 --- /dev/null +++ b/lib/models/gen/guild_j.ml @@ -0,0 +1,1948 @@ +(* Auto-generated from "guild.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = Guild_t.t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_role = ( + Role_j.write_t +) +let string_of_role ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_role ob x; + Bi_outbuf.contents ob +let read_role = ( + Role_j.read_t +) +let role_of_string s = + read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_member = ( + Member_j.write_t +) +let string_of_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_member ob x; + Bi_outbuf.contents ob +let read_member = ( + Member_j.read_t +) +let member_of_string s = + read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_emoji = ( + Emoji_j.write_t +) +let string_of_emoji ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_emoji ob x; + Bi_outbuf.contents ob +let read_emoji = ( + Emoji_j.read_t +) +let emoji_of_string s = + read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_channel = ( + Channel_j.write_t +) +let string_of_channel ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_channel ob x; + Bi_outbuf.contents ob +let read_channel = ( + Channel_j.read_t +) +let channel_of_string s = + read_channel (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__9 = ( + Atdgen_runtime.Oj_run.write_list ( + write_member + ) +) +let string_of__9 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__9 ob x; + Bi_outbuf.contents ob +let read__9 = ( + Atdgen_runtime.Oj_run.read_list ( + read_member + ) +) +let _9_of_string s = + read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__8 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_int + ) +) +let string_of__8 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__8 ob x; + Bi_outbuf.contents ob +let read__8 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_int + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _8_of_string s = + read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_option ( + write_channel + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_channel + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_channel + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_list ( + Yojson.Safe.write_string + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + Atdgen_runtime.Oj_run.read_list ( + Atdgen_runtime.Oj_run.read_string + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_list ( + write_emoji + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + Atdgen_runtime.Oj_run.read_list ( + read_emoji + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_list ( + write_role + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + Atdgen_runtime.Oj_run.read_list ( + read_role + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_bool + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__11 = ( + Atdgen_runtime.Oj_run.write_list ( + write_channel + ) +) +let string_of__11 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__11 ob x; + Bi_outbuf.contents ob +let read__11 = ( + Atdgen_runtime.Oj_run.read_list ( + read_channel + ) +) +let _11_of_string s = + read__11 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__12 = ( + Atdgen_runtime.Oj_run.write_option ( + write__11 + ) +) +let string_of__12 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__12 ob x; + Bi_outbuf.contents ob +let read__12 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__11 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__11 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _12_of_string s = + read__12 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__10 = ( + Atdgen_runtime.Oj_run.write_option ( + write__9 + ) +) +let string_of__10 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__10 ob x; + Bi_outbuf.contents ob +let read__10 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__9 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__9 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _10_of_string s = + read__10 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + (match x.icon with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"icon\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + (match x.splash with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"splash\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"owner_id\":"; + ( + write_snowflake + ) + ob x.owner_id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"region\":"; + ( + Yojson.Safe.write_string + ) + ob x.region; + (match x.afk_channel_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"afk_channel_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"afk_timeout\":"; + ( + Yojson.Safe.write_int + ) + ob x.afk_timeout; + (match x.embed_enabled with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embed_enabled\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.embed_channel_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embed_channel_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"verification_level\":"; + ( + Yojson.Safe.write_int + ) + ob x.verification_level; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"default_message_notifications\":"; + ( + Yojson.Safe.write_int + ) + ob x.default_message_notifications; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"explicit_content_filter\":"; + ( + Yojson.Safe.write_int + ) + ob x.explicit_content_filter; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__4 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"emojis\":"; + ( + write__5 + ) + ob x.emojis; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"features\":"; + ( + write__6 + ) + ob x.features; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mfa_level\":"; + ( + Yojson.Safe.write_int + ) + ob x.mfa_level; + (match x.application_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"application_id\":"; + ( + write_snowflake + ) + ob x; + ); + (match x.widget_enabled with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"widget_enabled\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.widget_channel with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"widget_channel\":"; + ( + write_channel + ) + ob x; + ); + (match x.system_channel with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"system_channel\":"; + ( + write_channel + ) + ob x; + ); + (match x.large with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"large\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.unavailable with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"unavailable\":"; + ( + Yojson.Safe.write_bool + ) + ob x; + ); + (match x.member_count with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"member_count\":"; + ( + Yojson.Safe.write_int + ) + ob x; + ); + (match x.members with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"members\":"; + ( + write__9 + ) + ob x; + ); + (match x.channels with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"channels\":"; + ( + write__11 + ) + ob x; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_icon = ref (None) in + let field_splash = ref (None) in + let field_owner_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_region = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_afk_channel_id = ref (None) in + let field_afk_timeout = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_embed_enabled = ref (None) in + let field_embed_channel_id = ref (None) in + let field_verification_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_default_message_notifications = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_explicit_content_filter = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_emojis = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_features = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mfa_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_application_id = ref (None) in + let field_widget_enabled = ref (None) in + let field_widget_channel = ref (None) in + let field_system_channel = ref (None) in + let field_large = ref (None) in + let field_unavailable = ref (None) in + let field_member_count = ref (None) in + let field_members = ref (None) in + let field_channels = ref (None) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'l' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 21 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 5 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( + 24 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( + 25 + ) + else ( + -1 + ) + ) + | 'f' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( + 15 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( + 16 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( + 7 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 22 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 12 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( + 23 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( + 8 + ) + else ( + -1 + ) + ) + | 14 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + match String.unsafe_get s (pos+1) with + | 'f' -> ( + if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 20 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( + match String.unsafe_get s (pos+7) with + | 'c' -> ( + if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 19 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( + 18 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 16 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( + 9 + ) + else ( + -1 + ) + ) + | 18 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( + 10 + ) + else ( + -1 + ) + ) + | 23 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( + 12 + ) + else ( + -1 + ) + ) + | 29 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_splash := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + field_owner_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 5 -> + field_region := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_afk_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 7 -> + field_afk_timeout := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 10 -> + field_verification_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 11 -> + field_default_message_notifications := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 12 -> + field_explicit_content_filter := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 13 -> + field_roles := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 14 -> + field_emojis := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 15 -> + field_features := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 16 -> + field_mfa_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 19 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 20 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_system_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 21 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_large := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 22 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_unavailable := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 23 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member_count := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 24 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_members := ( + Some ( + ( + read__9 + ) p lb + ) + ); + ) + | 25 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_channels := ( + Some ( + ( + read__11 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + match String.unsafe_get s pos with + | 'i' -> ( + if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( + 2 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'l' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( + 21 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( + 5 + ) + else ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( + 24 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( + 25 + ) + else ( + -1 + ) + ) + | 'f' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( + 15 + ) + else ( + -1 + ) + ) + | 'o' -> ( + if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( + 16 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( + 7 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 22 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 12 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( + 23 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( + 8 + ) + else ( + -1 + ) + ) + | 14 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + match String.unsafe_get s (pos+1) with + | 'f' -> ( + if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 's' -> ( + if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 20 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( + match String.unsafe_get s (pos+7) with + | 'c' -> ( + if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( + 19 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( + 18 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 16 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( + 9 + ) + else ( + -1 + ) + ) + | 18 -> ( + if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( + 10 + ) + else ( + -1 + ) + ) + | 23 -> ( + if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( + 12 + ) + else ( + -1 + ) + ) + | 29 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_icon := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_splash := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + field_owner_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 5 -> + field_region := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_afk_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 7 -> + field_afk_timeout := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 8 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 9 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_embed_channel_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 10 -> + field_verification_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 11 -> + field_default_message_notifications := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 12 -> + field_explicit_content_filter := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 13 -> + field_roles := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 14 -> + field_emojis := ( + ( + read__5 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 15 -> + field_features := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 16 -> + field_mfa_level := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_application_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_enabled := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 19 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_widget_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 20 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_system_channel := ( + Some ( + ( + read_channel + ) p lb + ) + ); + ) + | 21 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_large := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 22 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_unavailable := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ) + ); + ) + | 23 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member_count := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ) + ); + ) + | 24 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_members := ( + Some ( + ( + read__9 + ) p lb + ) + ); + ) + | 25 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_channels := ( + Some ( + ( + read__11 + ) p lb + ) + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xfff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "owner_id"; "region"; "afk_timeout"; "verification_level"; "default_message_notifications"; "explicit_content_filter"; "roles"; "emojis"; "features"; "mfa_level" |]; + ( + { + id = !field_id; + name = !field_name; + icon = !field_icon; + splash = !field_splash; + owner_id = !field_owner_id; + region = !field_region; + afk_channel_id = !field_afk_channel_id; + afk_timeout = !field_afk_timeout; + embed_enabled = !field_embed_enabled; + embed_channel_id = !field_embed_channel_id; + verification_level = !field_verification_level; + default_message_notifications = !field_default_message_notifications; + explicit_content_filter = !field_explicit_content_filter; + roles = !field_roles; + emojis = !field_emojis; + features = !field_features; + mfa_level = !field_mfa_level; + application_id = !field_application_id; + widget_enabled = !field_widget_enabled; + widget_channel = !field_widget_channel; + system_channel = !field_system_channel; + large = !field_large; + unavailable = !field_unavailable; + member_count = !field_member_count; + members = !field_members; + channels = !field_channels; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/guild_j.mli b/lib/models/gen/guild_j.mli new file mode 100644 index 0000000..d430b2a --- /dev/null +++ b/lib/models/gen/guild_j.mli @@ -0,0 +1,184 @@ +(* Auto-generated from "guild.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = Guild_t.t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_role : + Bi_outbuf.t -> role -> unit + (** Output a JSON value of type {!role}. *) + +val string_of_role : + ?len:int -> role -> string + (** Serialize a value of type {!role} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_role : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> role + (** Input JSON data of type {!role}. *) + +val role_of_string : + string -> role + (** Deserialize JSON data of type {!role}. *) + +val write_member : + Bi_outbuf.t -> member -> unit + (** Output a JSON value of type {!member}. *) + +val string_of_member : + ?len:int -> member -> string + (** Serialize a value of type {!member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> member + (** Input JSON data of type {!member}. *) + +val member_of_string : + string -> member + (** Deserialize JSON data of type {!member}. *) + +val write_emoji : + Bi_outbuf.t -> emoji -> unit + (** Output a JSON value of type {!emoji}. *) + +val string_of_emoji : + ?len:int -> emoji -> string + (** Serialize a value of type {!emoji} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_emoji : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji + (** Input JSON data of type {!emoji}. *) + +val emoji_of_string : + string -> emoji + (** Deserialize JSON data of type {!emoji}. *) + +val write_channel : + Bi_outbuf.t -> channel -> unit + (** Output a JSON value of type {!channel}. *) + +val string_of_channel : + ?len:int -> channel -> string + (** Serialize a value of type {!channel} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_channel : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> channel + (** Input JSON data of type {!channel}. *) + +val channel_of_string : + string -> channel + (** Deserialize JSON data of type {!channel}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/guild_t.ml b/lib/models/gen/guild_t.ml new file mode 100644 index 0000000..9ffe83f --- /dev/null +++ b/lib/models/gen/guild_t.ml @@ -0,0 +1,43 @@ +(* Auto-generated from "guild.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} diff --git a/lib/models/gen/guild_t.mli b/lib/models/gen/guild_t.mli new file mode 100644 index 0000000..9ffe83f --- /dev/null +++ b/lib/models/gen/guild_t.mli @@ -0,0 +1,43 @@ +(* Auto-generated from "guild.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type role = Role_t.t + +type member = Member_t.t + +type emoji = Emoji_t.t + +type channel = Channel_t.t + +type t = { + id: snowflake; + name: string; + icon: string option; + splash: string option; + owner_id: snowflake; + region: string; + afk_channel_id: snowflake option; + afk_timeout: int; + embed_enabled: bool option; + embed_channel_id: snowflake option; + verification_level: int; + default_message_notifications: int; + explicit_content_filter: int; + roles: role list; + emojis: emoji list; + features: string list; + mfa_level: int; + application_id: snowflake option; + widget_enabled: bool option; + widget_channel: channel option; + system_channel: channel option; + large: bool option; + unavailable: bool option; + member_count: int option; + members: member list option; + channels: channel list option +} diff --git a/lib/models/gen/member.atd b/lib/models/gen/member.atd new file mode 100644 index 0000000..11d8b62 --- /dev/null +++ b/lib/models/gen/member.atd @@ -0,0 +1,15 @@ +type snowflake = abstract +type user = abstract + +type partial_member = { + ?nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; +} + +type t = { + inherit partial_member; + user: user; +} \ No newline at end of file diff --git a/lib/models/gen/member_j.ml b/lib/models/gen/member_j.ml new file mode 100644 index 0000000..7fd4aec --- /dev/null +++ b/lib/models/gen/member_j.ml @@ -0,0 +1,750 @@ +(* Auto-generated from "member.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Member_t.t = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = Member_t.partial_member = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.nick with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nick\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"joined_at\":"; + ( + Yojson.Safe.write_string + ) + ob x.joined_at; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"deaf\":"; + ( + Yojson.Safe.write_bool + ) + ob x.deaf; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mute\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mute; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_user + ) + ob x.user; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_nick = ref (None) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_user := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute"; "user" |]; + ( + { + nick = !field_nick; + roles = !field_roles; + joined_at = !field_joined_at; + deaf = !field_deaf; + mute = !field_mute; + user = !field_user; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_member : _ -> partial_member -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + (match x.nick with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nick\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__2 + ) + ob x.roles; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"joined_at\":"; + ( + Yojson.Safe.write_string + ) + ob x.joined_at; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"deaf\":"; + ( + Yojson.Safe.write_bool + ) + ob x.deaf; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mute\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mute; + Bi_outbuf.add_char ob '}'; +) +let string_of_partial_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_member ob x; + Bi_outbuf.contents ob +let read_partial_member = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_nick = ref (None) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'd' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( + 3 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( + 4 + ) + else ( + -1 + ) + ) + | 'n' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 9 -> ( + if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nick := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 1 -> + field_roles := ( + ( + read__2 + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 2 -> + field_joined_at := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 3 -> + field_deaf := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_mute := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xf then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute" |]; + ( + { + nick = !field_nick; + roles = !field_roles; + joined_at = !field_joined_at; + deaf = !field_deaf; + mute = !field_mute; + } + : partial_member) + ) +) +let partial_member_of_string s = + read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/member_j.mli b/lib/models/gen/member_j.mli new file mode 100644 index 0000000..f160b6d --- /dev/null +++ b/lib/models/gen/member_j.mli @@ -0,0 +1,104 @@ +(* Auto-generated from "member.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = Member_t.t = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = Member_t.partial_member = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + +val write_partial_member : + Bi_outbuf.t -> partial_member -> unit + (** Output a JSON value of type {!partial_member}. *) + +val string_of_partial_member : + ?len:int -> partial_member -> string + (** Serialize a value of type {!partial_member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member + (** Input JSON data of type {!partial_member}. *) + +val partial_member_of_string : + string -> partial_member + (** Deserialize JSON data of type {!partial_member}. *) + diff --git a/lib/models/gen/member_t.ml b/lib/models/gen/member_t.ml new file mode 100644 index 0000000..6262e1b --- /dev/null +++ b/lib/models/gen/member_t.ml @@ -0,0 +1,23 @@ +(* Auto-generated from "member.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} diff --git a/lib/models/gen/member_t.mli b/lib/models/gen/member_t.mli new file mode 100644 index 0000000..6262e1b --- /dev/null +++ b/lib/models/gen/member_t.mli @@ -0,0 +1,23 @@ +(* Auto-generated from "member.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type t = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool; + user: user +} + +type partial_member = { + nick: string option; + roles: snowflake list; + joined_at: string; + deaf: bool; + mute: bool +} diff --git a/lib/models/gen/message.atd b/lib/models/gen/message.atd new file mode 100644 index 0000000..8611f6a --- /dev/null +++ b/lib/models/gen/message.atd @@ -0,0 +1,29 @@ +type snowflake = abstract +type user = abstract +type member = abstract +type partial_member = abstract +type attachment = abstract +type embed = abstract +type reaction = abstract + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + ?member: partial_member option; + ?guild_id: snowflake option; + content: string; + timestamp: string; + ?edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: snowflake list; + ?role_mentions: snowflake list option; + attachments: attachment list; + embeds: embed list; + ?reactions: snowflake list option; + ?nonce: snowflake option; + pinned: bool; + ?webhook_id: snowflake option; + kind : int; +} \ No newline at end of file diff --git a/lib/models/gen/message_j.ml b/lib/models/gen/message_j.ml new file mode 100644 index 0000000..faea836 --- /dev/null +++ b/lib/models/gen/message_j.ml @@ -0,0 +1,1363 @@ +(* Auto-generated from "message.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_member = Member_t.partial_member + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = Message_t.t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: partial_member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: snowflake list; + role_mentions: snowflake list option; + attachments: attachment list; + embeds: embed list; + reactions: snowflake list option; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake option; + kind: int +} + +type reaction = Reaction_t.t + +type member = Member_t.t + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_member = ( + Member_j.write_partial_member +) +let string_of_partial_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_member ob x; + Bi_outbuf.contents ob +let read_partial_member = ( + Member_j.read_partial_member +) +let partial_member_of_string s = + read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_embed = ( + Embed_j.write_t +) +let string_of_embed ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_embed ob x; + Bi_outbuf.contents ob +let read_embed = ( + Embed_j.read_t +) +let embed_of_string s = + read_embed (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_attachment = ( + Attachment_j.write_t +) +let string_of_attachment ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_attachment ob x; + Bi_outbuf.contents ob +let read_attachment = ( + Attachment_j.read_t +) +let attachment_of_string s = + read_attachment (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__7 = ( + Atdgen_runtime.Oj_run.write_list ( + write_embed + ) +) +let string_of__7 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__7 ob x; + Bi_outbuf.contents ob +let read__7 = ( + Atdgen_runtime.Oj_run.read_list ( + read_embed + ) +) +let _7_of_string s = + read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__6 = ( + Atdgen_runtime.Oj_run.write_list ( + write_attachment + ) +) +let string_of__6 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__6 ob x; + Bi_outbuf.contents ob +let read__6 = ( + Atdgen_runtime.Oj_run.read_list ( + read_attachment + ) +) +let _6_of_string s = + read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__4 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__4 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__4 ob x; + Bi_outbuf.contents ob +let read__4 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _4_of_string s = + read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__5 = ( + Atdgen_runtime.Oj_run.write_option ( + write__4 + ) +) +let string_of__5 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__5 ob x; + Bi_outbuf.contents ob +let read__5 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read__4 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read__4 + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _5_of_string s = + read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_snowflake + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_snowflake + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + write_partial_member + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_partial_member + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_partial_member + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"author\":"; + ( + write_user + ) + ob x.author; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"channel_id\":"; + ( + write_snowflake + ) + ob x.channel_id; + (match x.member with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"member\":"; + ( + write_partial_member + ) + ob x; + ); + (match x.guild_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"content\":"; + ( + Yojson.Safe.write_string + ) + ob x.content; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x.timestamp; + (match x.edited_timestamp with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"edited_timestamp\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"tts\":"; + ( + Yojson.Safe.write_bool + ) + ob x.tts; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mention_everyone\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mention_everyone; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mentions\":"; + ( + write__4 + ) + ob x.mentions; + (match x.role_mentions with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"role_mentions\":"; + ( + write__4 + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"attachments\":"; + ( + write__6 + ) + ob x.attachments; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"embeds\":"; + ( + write__7 + ) + ob x.embeds; + (match x.reactions with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"reactions\":"; + ( + write__4 + ) + ob x; + ); + (match x.nonce with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"nonce\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"pinned\":"; + ( + Yojson.Safe.write_bool + ) + ob x.pinned; + (match x.webhook_id with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"webhook_id\":"; + ( + write_snowflake + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"type\":"; + ( + Yojson.Safe.write_int + ) + ob x.kind; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_author = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_channel_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_member = ref (None) in + let field_guild_id = ref (None) in + let field_content = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_timestamp = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_edited_timestamp = ref (None) in + let field_tts = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mention_everyone = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mentions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_role_mentions = ref (None) in + let field_attachments = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_embeds = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_reactions = ref (None) in + let field_nonce = ref (None) in + let field_pinned = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_webhook_id = ref (None) in + let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( + 8 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 18 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( + 15 + ) + else ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( + 16 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( + 10 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( + 12 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 16 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( + 7 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_author := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_channel_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member := ( + Some ( + ( + read_partial_member + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 5 -> + field_content := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + field_timestamp := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_edited_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 8 -> + field_tts := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 9 -> + field_mention_everyone := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 10 -> + field_mentions := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_role_mentions := ( + Some ( + ( + read__4 + ) p lb + ) + ); + ) + | 12 -> + field_attachments := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 13 -> + field_embeds := ( + ( + read__7 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 14 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reactions := ( + Some ( + ( + read__4 + ) p lb + ) + ); + ) + | 15 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nonce := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 16 -> + field_pinned := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_webhook_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( + 8 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( + 18 + ) + else ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( + 15 + ) + else ( + -1 + ) + ) + | 6 -> ( + match String.unsafe_get s pos with + | 'a' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( + 1 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( + 13 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( + 16 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( + 5 + ) + else ( + -1 + ) + ) + | 8 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 4 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( + 10 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 9 -> ( + match String.unsafe_get s pos with + | 'r' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( + 14 + ) + else ( + -1 + ) + ) + | 't' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( + 6 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 10 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 2 + ) + else ( + -1 + ) + ) + | 'w' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( + 17 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 11 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( + 12 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( + 11 + ) + else ( + -1 + ) + ) + | 16 -> ( + match String.unsafe_get s pos with + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( + 7 + ) + else ( + -1 + ) + ) + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( + 9 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_author := ( + ( + read_user + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_channel_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_member := ( + Some ( + ( + read_partial_member + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_guild_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 5 -> + field_content := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 6 -> + field_timestamp := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 7 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_edited_timestamp := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 8 -> + field_tts := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 9 -> + field_mention_everyone := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 10 -> + field_mentions := ( + ( + read__4 + ) p lb + ); + bits0 := !bits0 lor 0x80; + | 11 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_role_mentions := ( + Some ( + ( + read__4 + ) p lb + ) + ); + ) + | 12 -> + field_attachments := ( + ( + read__6 + ) p lb + ); + bits0 := !bits0 lor 0x100; + | 13 -> + field_embeds := ( + ( + read__7 + ) p lb + ); + bits0 := !bits0 lor 0x200; + | 14 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_reactions := ( + Some ( + ( + read__4 + ) p lb + ) + ); + ) + | 15 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_nonce := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 16 -> + field_pinned := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x400; + | 17 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_webhook_id := ( + Some ( + ( + read_snowflake + ) p lb + ) + ); + ) + | 18 -> + field_kind := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x800; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xfff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "author"; "channel_id"; "content"; "timestamp"; "tts"; "mention_everyone"; "mentions"; "attachments"; "embeds"; "pinned"; "kind" |]; + ( + { + id = !field_id; + author = !field_author; + channel_id = !field_channel_id; + member = !field_member; + guild_id = !field_guild_id; + content = !field_content; + timestamp = !field_timestamp; + edited_timestamp = !field_edited_timestamp; + tts = !field_tts; + mention_everyone = !field_mention_everyone; + mentions = !field_mentions; + role_mentions = !field_role_mentions; + attachments = !field_attachments; + embeds = !field_embeds; + reactions = !field_reactions; + nonce = !field_nonce; + pinned = !field_pinned; + webhook_id = !field_webhook_id; + kind = !field_kind; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_reaction = ( + Reaction_j.write_t +) +let string_of_reaction ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_reaction ob x; + Bi_outbuf.contents ob +let read_reaction = ( + Reaction_j.read_t +) +let reaction_of_string s = + read_reaction (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_member = ( + Member_j.write_t +) +let string_of_member ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_member ob x; + Bi_outbuf.contents ob +let read_member = ( + Member_j.read_t +) +let member_of_string s = + read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/message_j.mli b/lib/models/gen/message_j.mli new file mode 100644 index 0000000..04aa440 --- /dev/null +++ b/lib/models/gen/message_j.mli @@ -0,0 +1,199 @@ +(* Auto-generated from "message.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_member = Member_t.partial_member + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = Message_t.t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: partial_member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: snowflake list; + role_mentions: snowflake list option; + attachments: attachment list; + embeds: embed list; + reactions: snowflake list option; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake option; + kind: int +} + +type reaction = Reaction_t.t + +type member = Member_t.t + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_partial_member : + Bi_outbuf.t -> partial_member -> unit + (** Output a JSON value of type {!partial_member}. *) + +val string_of_partial_member : + ?len:int -> partial_member -> string + (** Serialize a value of type {!partial_member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member + (** Input JSON data of type {!partial_member}. *) + +val partial_member_of_string : + string -> partial_member + (** Deserialize JSON data of type {!partial_member}. *) + +val write_embed : + Bi_outbuf.t -> embed -> unit + (** Output a JSON value of type {!embed}. *) + +val string_of_embed : + ?len:int -> embed -> string + (** Serialize a value of type {!embed} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_embed : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> embed + (** Input JSON data of type {!embed}. *) + +val embed_of_string : + string -> embed + (** Deserialize JSON data of type {!embed}. *) + +val write_attachment : + Bi_outbuf.t -> attachment -> unit + (** Output a JSON value of type {!attachment}. *) + +val string_of_attachment : + ?len:int -> attachment -> string + (** Serialize a value of type {!attachment} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_attachment : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> attachment + (** Input JSON data of type {!attachment}. *) + +val attachment_of_string : + string -> attachment + (** Deserialize JSON data of type {!attachment}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + +val write_reaction : + Bi_outbuf.t -> reaction -> unit + (** Output a JSON value of type {!reaction}. *) + +val string_of_reaction : + ?len:int -> reaction -> string + (** Serialize a value of type {!reaction} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_reaction : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> reaction + (** Input JSON data of type {!reaction}. *) + +val reaction_of_string : + string -> reaction + (** Deserialize JSON data of type {!reaction}. *) + +val write_member : + Bi_outbuf.t -> member -> unit + (** Output a JSON value of type {!member}. *) + +val string_of_member : + ?len:int -> member -> string + (** Serialize a value of type {!member} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_member : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> member + (** Input JSON data of type {!member}. *) + +val member_of_string : + string -> member + (** Deserialize JSON data of type {!member}. *) + diff --git a/lib/models/gen/message_t.ml b/lib/models/gen/message_t.ml new file mode 100644 index 0000000..ce2d5a4 --- /dev/null +++ b/lib/models/gen/message_t.ml @@ -0,0 +1,38 @@ +(* Auto-generated from "message.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_member = Member_t.partial_member + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: partial_member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: snowflake list; + role_mentions: snowflake list option; + attachments: attachment list; + embeds: embed list; + reactions: snowflake list option; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake option; + kind: int +} + +type reaction = Reaction_t.t + +type member = Member_t.t diff --git a/lib/models/gen/message_t.mli b/lib/models/gen/message_t.mli new file mode 100644 index 0000000..ce2d5a4 --- /dev/null +++ b/lib/models/gen/message_t.mli @@ -0,0 +1,38 @@ +(* Auto-generated from "message.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_member = Member_t.partial_member + +type embed = Embed_t.t + +type attachment = Attachment_t.t + +type t = { + id: snowflake; + author: user; + channel_id: snowflake; + member: partial_member option; + guild_id: snowflake option; + content: string; + timestamp: string; + edited_timestamp: string option; + tts: bool; + mention_everyone: bool; + mentions: snowflake list; + role_mentions: snowflake list option; + attachments: attachment list; + embeds: embed list; + reactions: snowflake list option; + nonce: snowflake option; + pinned: bool; + webhook_id: snowflake option; + kind: int +} + +type reaction = Reaction_t.t + +type member = Member_t.t diff --git a/lib/models/gen/presence.atd b/lib/models/gen/presence.atd new file mode 100644 index 0000000..da9b3fd --- /dev/null +++ b/lib/models/gen/presence.atd @@ -0,0 +1,13 @@ +type snowflake = abstract +type user = abstract +type partial_user = abstract +type activity = abstract + +type t = { + user: partial_user; + roles: snowflake list; + ?game: activity option; + guild_id: snowflake; + status: string; + activities: activity list; +} \ No newline at end of file diff --git a/lib/models/gen/presence_j.ml b/lib/models/gen/presence_j.ml new file mode 100644 index 0000000..b4ea497 --- /dev/null +++ b/lib/models/gen/presence_j.ml @@ -0,0 +1,492 @@ +(* Auto-generated from "presence.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_user = User_t.partial_user + +type activity = Activity_t.t + +type t = Presence_t.t = { + user: partial_user; + roles: snowflake list; + game: activity option; + guild_id: snowflake; + status: string; + activities: activity list +} + +let write_user = ( + User_j.write_t +) +let string_of_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_user ob x; + Bi_outbuf.contents ob +let read_user = ( + User_j.read_t +) +let user_of_string s = + read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_user = ( + User_j.write_partial_user +) +let string_of_partial_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_user ob x; + Bi_outbuf.contents ob +let read_partial_user = ( + User_j.read_partial_user +) +let partial_user_of_string s = + read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_activity = ( + Activity_j.write_t +) +let string_of_activity ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_activity ob x; + Bi_outbuf.contents ob +let read_activity = ( + Activity_j.read_t +) +let activity_of_string s = + read_activity (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__3 = ( + Atdgen_runtime.Oj_run.write_list ( + write_activity + ) +) +let string_of__3 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__3 ob x; + Bi_outbuf.contents ob +let read__3 = ( + Atdgen_runtime.Oj_run.read_list ( + read_activity + ) +) +let _3_of_string s = + read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__2 = ( + Atdgen_runtime.Oj_run.write_option ( + write_activity + ) +) +let string_of__2 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__2 ob x; + Bi_outbuf.contents ob +let read__2 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_activity + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_activity + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _2_of_string s = + read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_list ( + write_snowflake + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + Atdgen_runtime.Oj_run.read_list ( + read_snowflake + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"user\":"; + ( + write_partial_user + ) + ob x.user; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"roles\":"; + ( + write__1 + ) + ob x.roles; + (match x.game with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"game\":"; + ( + write_activity + ) + ob x; + ); + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"guild_id\":"; + ( + write_snowflake + ) + ob x.guild_id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"status\":"; + ( + Yojson.Safe.write_string + ) + ob x.status; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"activities\":"; + ( + write__3 + ) + ob x.activities; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_game = ref (None) in + let field_guild_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_status = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_activities = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) + | 10 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_partial_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_roles := ( + ( + read__1 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_game := ( + Some ( + ( + read_activity + ) p lb + ) + ); + ) + | 3 -> + field_guild_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_status := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_activities := ( + ( + read__3 + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 4 -> ( + match String.unsafe_get s pos with + | 'g' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 2 + ) + else ( + -1 + ) + ) + | 'u' -> ( + if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( + 0 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 5 -> ( + if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( + 1 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( + 4 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( + 3 + ) + else ( + -1 + ) + ) + | 10 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_user := ( + ( + read_partial_user + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_roles := ( + ( + read__1 + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_game := ( + Some ( + ( + read_activity + ) p lb + ) + ); + ) + | 3 -> + field_guild_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 4 -> + field_status := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 5 -> + field_activities := ( + ( + read__3 + ) p lb + ); + bits0 := !bits0 lor 0x10; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "guild_id"; "status"; "activities" |]; + ( + { + user = !field_user; + roles = !field_roles; + game = !field_game; + guild_id = !field_guild_id; + status = !field_status; + activities = !field_activities; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/presence_j.mli b/lib/models/gen/presence_j.mli new file mode 100644 index 0000000..be68b3f --- /dev/null +++ b/lib/models/gen/presence_j.mli @@ -0,0 +1,120 @@ +(* Auto-generated from "presence.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_user = User_t.partial_user + +type activity = Activity_t.t + +type t = Presence_t.t = { + user: partial_user; + roles: snowflake list; + game: activity option; + guild_id: snowflake; + status: string; + activities: activity list +} + +val write_user : + Bi_outbuf.t -> user -> unit + (** Output a JSON value of type {!user}. *) + +val string_of_user : + ?len:int -> user -> string + (** Serialize a value of type {!user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> user + (** Input JSON data of type {!user}. *) + +val user_of_string : + string -> user + (** Deserialize JSON data of type {!user}. *) + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_partial_user : + Bi_outbuf.t -> partial_user -> unit + (** Output a JSON value of type {!partial_user}. *) + +val string_of_partial_user : + ?len:int -> partial_user -> string + (** Serialize a value of type {!partial_user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user + (** Input JSON data of type {!partial_user}. *) + +val partial_user_of_string : + string -> partial_user + (** Deserialize JSON data of type {!partial_user}. *) + +val write_activity : + Bi_outbuf.t -> activity -> unit + (** Output a JSON value of type {!activity}. *) + +val string_of_activity : + ?len:int -> activity -> string + (** Serialize a value of type {!activity} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_activity : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> activity + (** Input JSON data of type {!activity}. *) + +val activity_of_string : + string -> activity + (** Deserialize JSON data of type {!activity}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/presence_t.ml b/lib/models/gen/presence_t.ml new file mode 100644 index 0000000..940d986 --- /dev/null +++ b/lib/models/gen/presence_t.ml @@ -0,0 +1,19 @@ +(* Auto-generated from "presence.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_user = User_t.partial_user + +type activity = Activity_t.t + +type t = { + user: partial_user; + roles: snowflake list; + game: activity option; + guild_id: snowflake; + status: string; + activities: activity list +} diff --git a/lib/models/gen/presence_t.mli b/lib/models/gen/presence_t.mli new file mode 100644 index 0000000..940d986 --- /dev/null +++ b/lib/models/gen/presence_t.mli @@ -0,0 +1,19 @@ +(* Auto-generated from "presence.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type user = User_t.t + +type snowflake = Snowflake_t.t + +type partial_user = User_t.partial_user + +type activity = Activity_t.t + +type t = { + user: partial_user; + roles: snowflake list; + game: activity option; + guild_id: snowflake; + status: string; + activities: activity list +} diff --git a/lib/models/gen/reaction.atd b/lib/models/gen/reaction.atd new file mode 100644 index 0000000..aa41483 --- /dev/null +++ b/lib/models/gen/reaction.atd @@ -0,0 +1,6 @@ +type emoji = abstract + +type t = { + count: int; + emoji: emoji; +} \ No newline at end of file diff --git a/lib/models/gen/reaction_j.ml b/lib/models/gen/reaction_j.ml new file mode 100644 index 0000000..fe91833 --- /dev/null +++ b/lib/models/gen/reaction_j.ml @@ -0,0 +1,180 @@ +(* Auto-generated from "reaction.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = Reaction_t.t = { count: int; emoji: emoji } + +let write_emoji = ( + Emoji_j.write_t +) +let string_of_emoji ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_emoji ob x; + Bi_outbuf.contents ob +let read_emoji = ( + Emoji_j.read_t +) +let emoji_of_string s = + read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"count\":"; + ( + Yojson.Safe.write_int + ) + ob x.count; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"emoji\":"; + ( + write_emoji + ) + ob x.emoji; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_count = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_emoji = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 5 then ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_count := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_emoji := ( + ( + read_emoji + ) p lb + ); + bits0 := !bits0 lor 0x2; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 5 then ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( + 0 + ) + else ( + -1 + ) + ) + | 'e' -> ( + if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_count := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_emoji := ( + ( + read_emoji + ) p lb + ); + bits0 := !bits0 lor 0x2; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "count"; "emoji" |]; + ( + { + count = !field_count; + emoji = !field_emoji; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/reaction_j.mli b/lib/models/gen/reaction_j.mli new file mode 100644 index 0000000..0d6a598 --- /dev/null +++ b/lib/models/gen/reaction_j.mli @@ -0,0 +1,47 @@ +(* Auto-generated from "reaction.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = Reaction_t.t = { count: int; emoji: emoji } + +val write_emoji : + Bi_outbuf.t -> emoji -> unit + (** Output a JSON value of type {!emoji}. *) + +val string_of_emoji : + ?len:int -> emoji -> string + (** Serialize a value of type {!emoji} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_emoji : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji + (** Input JSON data of type {!emoji}. *) + +val emoji_of_string : + string -> emoji + (** Deserialize JSON data of type {!emoji}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/reaction_t.ml b/lib/models/gen/reaction_t.ml new file mode 100644 index 0000000..666030b --- /dev/null +++ b/lib/models/gen/reaction_t.ml @@ -0,0 +1,6 @@ +(* Auto-generated from "reaction.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = { count: int; emoji: emoji } diff --git a/lib/models/gen/reaction_t.mli b/lib/models/gen/reaction_t.mli new file mode 100644 index 0000000..666030b --- /dev/null +++ b/lib/models/gen/reaction_t.mli @@ -0,0 +1,6 @@ +(* Auto-generated from "reaction.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type emoji = Emoji_t.t + +type t = { count: int; emoji: emoji } diff --git a/lib/models/gen/role.atd b/lib/models/gen/role.atd new file mode 100644 index 0000000..a6bdcba --- /dev/null +++ b/lib/models/gen/role.atd @@ -0,0 +1,12 @@ +type snowflake = abstract + +type t = { + id: snowflake; + name: string; + colour : int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool; +} \ No newline at end of file diff --git a/lib/models/gen/role_j.ml b/lib/models/gen/role_j.ml new file mode 100644 index 0000000..a15b6cf --- /dev/null +++ b/lib/models/gen/role_j.ml @@ -0,0 +1,449 @@ +(* Auto-generated from "role.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Role_t.t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"name\":"; + ( + Yojson.Safe.write_string + ) + ob x.name; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"color\":"; + ( + Yojson.Safe.write_int + ) + ob x.colour; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"hoist\":"; + ( + Yojson.Safe.write_bool + ) + ob x.hoist; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"position\":"; + ( + Yojson.Safe.write_int + ) + ob x.position; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"permissions\":"; + ( + Yojson.Safe.write_int + ) + ob x.permissions; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"managed\":"; + ( + Yojson.Safe.write_bool + ) + ob x.managed; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"mentionable\":"; + ( + Yojson.Safe.write_bool + ) + ob x.mentionable; + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_colour = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_hoist = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_position = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_permissions = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_managed = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_mentionable = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | 'h' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 4 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_colour := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_hoist := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_position := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + field_permissions := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 6 -> + field_managed := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 7 -> + field_mentionable := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x80; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 4 -> ( + if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 5 -> ( + match String.unsafe_get s pos with + | 'c' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | 'h' -> ( + if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( + 3 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | 7 -> ( + if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( + 6 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( + 4 + ) + else ( + -1 + ) + ) + | 11 -> ( + match String.unsafe_get s pos with + | 'm' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( + 7 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( + 5 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_name := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_colour := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + field_hoist := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x8; + | 4 -> + field_position := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x10; + | 5 -> + field_permissions := ( + ( + Atdgen_runtime.Oj_run.read_int + ) p lb + ); + bits0 := !bits0 lor 0x20; + | 6 -> + field_managed := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x40; + | 7 -> + field_mentionable := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + bits0 := !bits0 lor 0x80; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0xff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "colour"; "hoist"; "position"; "permissions"; "managed"; "mentionable" |]; + ( + { + id = !field_id; + name = !field_name; + colour = !field_colour; + hoist = !field_hoist; + position = !field_position; + permissions = !field_permissions; + managed = !field_managed; + mentionable = !field_mentionable; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/role_j.mli b/lib/models/gen/role_j.mli new file mode 100644 index 0000000..b4ea78c --- /dev/null +++ b/lib/models/gen/role_j.mli @@ -0,0 +1,56 @@ +(* Auto-generated from "role.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = Role_t.t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/role_t.ml b/lib/models/gen/role_t.ml new file mode 100644 index 0000000..a4e83c5 --- /dev/null +++ b/lib/models/gen/role_t.ml @@ -0,0 +1,15 @@ +(* Auto-generated from "role.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} diff --git a/lib/models/gen/role_t.mli b/lib/models/gen/role_t.mli new file mode 100644 index 0000000..a4e83c5 --- /dev/null +++ b/lib/models/gen/role_t.mli @@ -0,0 +1,15 @@ +(* Auto-generated from "role.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + name: string; + colour: int; + hoist: bool; + position: int; + permissions: int; + managed: bool; + mentionable: bool +} diff --git a/lib/models/gen/snowflake.atd b/lib/models/gen/snowflake.atd new file mode 100644 index 0000000..98dc032 --- /dev/null +++ b/lib/models/gen/snowflake.atd @@ -0,0 +1 @@ +type t = int \ No newline at end of file diff --git a/lib/models/gen/snowflake_j.ml b/lib/models/gen/snowflake_j.ml new file mode 100644 index 0000000..80f6f63 --- /dev/null +++ b/lib/models/gen/snowflake_j.ml @@ -0,0 +1,17 @@ +(* Auto-generated from "snowflake.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Snowflake_t.t + +let write_t = ( + Yojson.Safe.write_int +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + Atdgen_runtime.Oj_run.read_int +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/snowflake_j.mli b/lib/models/gen/snowflake_j.mli new file mode 100644 index 0000000..fed97a4 --- /dev/null +++ b/lib/models/gen/snowflake_j.mli @@ -0,0 +1,25 @@ +(* Auto-generated from "snowflake.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type t = Snowflake_t.t + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + diff --git a/lib/models/gen/snowflake_t.ml b/lib/models/gen/snowflake_t.ml new file mode 100644 index 0000000..a7bdb08 --- /dev/null +++ b/lib/models/gen/snowflake_t.ml @@ -0,0 +1,4 @@ +(* Auto-generated from "snowflake.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = int diff --git a/lib/models/gen/snowflake_t.mli b/lib/models/gen/snowflake_t.mli new file mode 100644 index 0000000..a7bdb08 --- /dev/null +++ b/lib/models/gen/snowflake_t.mli @@ -0,0 +1,4 @@ +(* Auto-generated from "snowflake.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type t = int diff --git a/lib/models/gen/user.atd b/lib/models/gen/user.atd new file mode 100644 index 0000000..106b3b0 --- /dev/null +++ b/lib/models/gen/user.atd @@ -0,0 +1,13 @@ +type snowflake = abstract + +type t = { + id: snowflake; + username: string; + discriminator: string; + ?avatar: string option; + ~bot : bool; +} + +type partial_user = { + id: snowflake; +} \ No newline at end of file diff --git a/lib/models/gen/user_j.ml b/lib/models/gen/user_j.ml new file mode 100644 index 0000000..552a20d --- /dev/null +++ b/lib/models/gen/user_j.ml @@ -0,0 +1,468 @@ +(* Auto-generated from "user.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = User_t.t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +type partial_user = User_t.partial_user = { id: snowflake } + +let write_snowflake = ( + Snowflake_j.write_t +) +let string_of_snowflake ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_snowflake ob x; + Bi_outbuf.contents ob +let read_snowflake = ( + Snowflake_j.read_t +) +let snowflake_of_string s = + read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__1 = ( + Atdgen_runtime.Oj_run.write_option ( + Yojson.Safe.write_string + ) +) +let string_of__1 ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write__1 ob x; + Bi_outbuf.contents ob +let read__1 = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "None" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (None : _ option) + | "Some" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "None" -> + (None : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "Some" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + Atdgen_runtime.Oj_run.read_string + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (Some x : _ option) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let _1_of_string s = + read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_t : _ -> t -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"username\":"; + ( + Yojson.Safe.write_string + ) + ob x.username; + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"discriminator\":"; + ( + Yojson.Safe.write_string + ) + ob x.discriminator; + (match x.avatar with None -> () | Some x -> + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"avatar\":"; + ( + Yojson.Safe.write_string + ) + ob x; + ); + if x.bot <> false then ( + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"bot\":"; + ( + Yojson.Safe.write_bool + ) + ob x.bot; + ); + Bi_outbuf.add_char ob '}'; +) +let string_of_t ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_t ob x; + Bi_outbuf.contents ob +let read_t = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_username = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_discriminator = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let field_avatar = ref (None) in + let field_bot = ref (false) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( + 4 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_username := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_discriminator := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_avatar := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bot := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + match len with + | 2 -> ( + if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 3 -> ( + if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( + 4 + ) + else ( + -1 + ) + ) + | 6 -> ( + if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( + 3 + ) + else ( + -1 + ) + ) + | 8 -> ( + if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( + 1 + ) + else ( + -1 + ) + ) + | 13 -> ( + if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( + 2 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | 1 -> + field_username := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x2; + | 2 -> + field_discriminator := ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ); + bits0 := !bits0 lor 0x4; + | 3 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_avatar := ( + Some ( + ( + Atdgen_runtime.Oj_run.read_string + ) p lb + ) + ); + ) + | 4 -> + if not (Yojson.Safe.read_null_if_possible p lb) then ( + field_bot := ( + ( + Atdgen_runtime.Oj_run.read_bool + ) p lb + ); + ) + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x7 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "username"; "discriminator" |]; + ( + { + id = !field_id; + username = !field_username; + discriminator = !field_discriminator; + avatar = !field_avatar; + bot = !field_bot; + } + : t) + ) +) +let t_of_string s = + read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_partial_user : _ -> partial_user -> _ = ( + fun ob x -> + Bi_outbuf.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Bi_outbuf.add_char ob ','; + Bi_outbuf.add_string ob "\"id\":"; + ( + write_snowflake + ) + ob x.id; + Bi_outbuf.add_char ob '}'; +) +let string_of_partial_user ?(len = 1024) x = + let ob = Bi_outbuf.create len in + write_partial_user ob x; + Bi_outbuf.contents ob +let read_partial_user = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in + let bits0 = ref 0 in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg "out-of-bounds substring position or length"; + if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( + 0 + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_id := ( + ( + read_snowflake + ) p lb + ); + bits0 := !bits0 lor 0x1; + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; + ( + { + id = !field_id; + } + : partial_user) + ) +) +let partial_user_of_string s = + read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/gen/user_j.mli b/lib/models/gen/user_j.mli new file mode 100644 index 0000000..576768e --- /dev/null +++ b/lib/models/gen/user_j.mli @@ -0,0 +1,75 @@ +(* Auto-generated from "user.atd" *) +[@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = User_t.t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +type partial_user = User_t.partial_user = { id: snowflake } + +val write_snowflake : + Bi_outbuf.t -> snowflake -> unit + (** Output a JSON value of type {!snowflake}. *) + +val string_of_snowflake : + ?len:int -> snowflake -> string + (** Serialize a value of type {!snowflake} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_snowflake : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake + (** Input JSON data of type {!snowflake}. *) + +val snowflake_of_string : + string -> snowflake + (** Deserialize JSON data of type {!snowflake}. *) + +val write_t : + Bi_outbuf.t -> t -> unit + (** Output a JSON value of type {!t}. *) + +val string_of_t : + ?len:int -> t -> string + (** Serialize a value of type {!t} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_t : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> t + (** Input JSON data of type {!t}. *) + +val t_of_string : + string -> t + (** Deserialize JSON data of type {!t}. *) + +val write_partial_user : + Bi_outbuf.t -> partial_user -> unit + (** Output a JSON value of type {!partial_user}. *) + +val string_of_partial_user : + ?len:int -> partial_user -> string + (** Serialize a value of type {!partial_user} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_partial_user : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user + (** Input JSON data of type {!partial_user}. *) + +val partial_user_of_string : + string -> partial_user + (** Deserialize JSON data of type {!partial_user}. *) + diff --git a/lib/models/gen/user_t.ml b/lib/models/gen/user_t.ml new file mode 100644 index 0000000..294cf0a --- /dev/null +++ b/lib/models/gen/user_t.ml @@ -0,0 +1,14 @@ +(* Auto-generated from "user.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +type partial_user = { id: snowflake } diff --git a/lib/models/gen/user_t.mli b/lib/models/gen/user_t.mli new file mode 100644 index 0000000..294cf0a --- /dev/null +++ b/lib/models/gen/user_t.mli @@ -0,0 +1,14 @@ +(* Auto-generated from "user.atd" *) + [@@@ocaml.warning "-27-32-35-39"] + +type snowflake = Snowflake_t.t + +type t = { + id: snowflake; + username: string; + discriminator: string; + avatar: string option; + bot: bool +} + +type partial_user = { id: snowflake } diff --git a/lib/models/guild.atd b/lib/models/guild.atd deleted file mode 100644 index c622eea..0000000 --- a/lib/models/guild.atd +++ /dev/null @@ -1,36 +0,0 @@ -type snowflake = abstract -type user = abstract -type member = abstract -type role = abstract -type channel = abstract -type emoji = abstract - - -type t = { - id: snowflake; - name: string; - ?icon: string option; - ?splash: string option; - owner_id: snowflake; - region: string; - ?afk_channel_id: snowflake option; - afk_timeout: int; - ?embed_enabled: bool option; - ?embed_channel_id: snowflake option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: role list; - emojis: emoji list; - features: string list; - mfa_level: int; - ?application_id: snowflake option; - ?widget_enabled: bool option; - ?widget_channel: channel option; - ?system_channel: channel option; - ?large: bool option; - ?unavailable: bool option; - ?member_count: int option; - ?members: member list option; - ?channels: channel list option; -} \ No newline at end of file diff --git a/lib/models/guild.ml b/lib/models/guild.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/guild.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/guild_j.ml b/lib/models/guild_j.ml deleted file mode 100644 index 9f7b069..0000000 --- a/lib/models/guild_j.ml +++ /dev/null @@ -1,1948 +0,0 @@ -(* Auto-generated from "guild.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type member = Member_t.t - -type emoji = Emoji_t.t - -type channel = Channel_t.t - -type t = Guild_t.t = { - id: snowflake; - name: string; - icon: string option; - splash: string option; - owner_id: snowflake; - region: string; - afk_channel_id: snowflake option; - afk_timeout: int; - embed_enabled: bool option; - embed_channel_id: snowflake option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: role list; - emojis: emoji list; - features: string list; - mfa_level: int; - application_id: snowflake option; - widget_enabled: bool option; - widget_channel: channel option; - system_channel: channel option; - large: bool option; - unavailable: bool option; - member_count: int option; - members: member list option; - channels: channel list option -} - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_role = ( - Role_j.write_t -) -let string_of_role ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_role ob x; - Bi_outbuf.contents ob -let read_role = ( - Role_j.read_t -) -let role_of_string s = - read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_member = ( - Member_j.write_t -) -let string_of_member ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_member ob x; - Bi_outbuf.contents ob -let read_member = ( - Member_j.read_t -) -let member_of_string s = - read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_emoji = ( - Emoji_j.write_t -) -let string_of_emoji ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_emoji ob x; - Bi_outbuf.contents ob -let read_emoji = ( - Emoji_j.read_t -) -let emoji_of_string s = - read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_channel = ( - Channel_j.write_t -) -let string_of_channel ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_channel ob x; - Bi_outbuf.contents ob -let read_channel = ( - Channel_j.read_t -) -let channel_of_string s = - read_channel (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__9 = ( - Atdgen_runtime.Oj_run.write_list ( - write_member - ) -) -let string_of__9 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__9 ob x; - Bi_outbuf.contents ob -let read__9 = ( - Atdgen_runtime.Oj_run.read_list ( - read_member - ) -) -let _9_of_string s = - read__9 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__8 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_int - ) -) -let string_of__8 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__8 ob x; - Bi_outbuf.contents ob -let read__8 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_int - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _8_of_string s = - read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__7 = ( - Atdgen_runtime.Oj_run.write_option ( - write_channel - ) -) -let string_of__7 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__7 ob x; - Bi_outbuf.contents ob -let read__7 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_channel - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_channel - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _7_of_string s = - read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__6 = ( - Atdgen_runtime.Oj_run.write_list ( - Yojson.Safe.write_string - ) -) -let string_of__6 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__6 ob x; - Bi_outbuf.contents ob -let read__6 = ( - Atdgen_runtime.Oj_run.read_list ( - Atdgen_runtime.Oj_run.read_string - ) -) -let _6_of_string s = - read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__5 = ( - Atdgen_runtime.Oj_run.write_list ( - write_emoji - ) -) -let string_of__5 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__5 ob x; - Bi_outbuf.contents ob -let read__5 = ( - Atdgen_runtime.Oj_run.read_list ( - read_emoji - ) -) -let _5_of_string s = - read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__4 = ( - Atdgen_runtime.Oj_run.write_list ( - write_role - ) -) -let string_of__4 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__4 ob x; - Bi_outbuf.contents ob -let read__4 = ( - Atdgen_runtime.Oj_run.read_list ( - read_role - ) -) -let _4_of_string s = - read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_bool - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_option ( - write_snowflake - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__11 = ( - Atdgen_runtime.Oj_run.write_list ( - write_channel - ) -) -let string_of__11 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__11 ob x; - Bi_outbuf.contents ob -let read__11 = ( - Atdgen_runtime.Oj_run.read_list ( - read_channel - ) -) -let _11_of_string s = - read__11 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__12 = ( - Atdgen_runtime.Oj_run.write_option ( - write__11 - ) -) -let string_of__12 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__12 ob x; - Bi_outbuf.contents ob -let read__12 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read__11 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read__11 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _12_of_string s = - read__12 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__10 = ( - Atdgen_runtime.Oj_run.write_option ( - write__9 - ) -) -let string_of__10 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__10 ob x; - Bi_outbuf.contents ob -let read__10 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read__9 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read__9 - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _10_of_string s = - read__10 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x.name; - (match x.icon with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"icon\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - (match x.splash with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"splash\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"owner_id\":"; - ( - write_snowflake - ) - ob x.owner_id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"region\":"; - ( - Yojson.Safe.write_string - ) - ob x.region; - (match x.afk_channel_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"afk_channel_id\":"; - ( - write_snowflake - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"afk_timeout\":"; - ( - Yojson.Safe.write_int - ) - ob x.afk_timeout; - (match x.embed_enabled with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"embed_enabled\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.embed_channel_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"embed_channel_id\":"; - ( - write_snowflake - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"verification_level\":"; - ( - Yojson.Safe.write_int - ) - ob x.verification_level; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"default_message_notifications\":"; - ( - Yojson.Safe.write_int - ) - ob x.default_message_notifications; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"explicit_content_filter\":"; - ( - Yojson.Safe.write_int - ) - ob x.explicit_content_filter; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"roles\":"; - ( - write__4 - ) - ob x.roles; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"emojis\":"; - ( - write__5 - ) - ob x.emojis; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"features\":"; - ( - write__6 - ) - ob x.features; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mfa_level\":"; - ( - Yojson.Safe.write_int - ) - ob x.mfa_level; - (match x.application_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"application_id\":"; - ( - write_snowflake - ) - ob x; - ); - (match x.widget_enabled with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"widget_enabled\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.widget_channel with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"widget_channel\":"; - ( - write_channel - ) - ob x; - ); - (match x.system_channel with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"system_channel\":"; - ( - write_channel - ) - ob x; - ); - (match x.large with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"large\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.unavailable with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"unavailable\":"; - ( - Yojson.Safe.write_bool - ) - ob x; - ); - (match x.member_count with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"member_count\":"; - ( - Yojson.Safe.write_int - ) - ob x; - ); - (match x.members with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"members\":"; - ( - write__9 - ) - ob x; - ); - (match x.channels with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"channels\":"; - ( - write__11 - ) - ob x; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_icon = ref (None) in - let field_splash = ref (None) in - let field_owner_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_region = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_afk_channel_id = ref (None) in - let field_afk_timeout = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_embed_enabled = ref (None) in - let field_embed_channel_id = ref (None) in - let field_verification_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_default_message_notifications = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_explicit_content_filter = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_emojis = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_features = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mfa_level = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_application_id = ref (None) in - let field_widget_enabled = ref (None) in - let field_widget_channel = ref (None) in - let field_system_channel = ref (None) in - let field_large = ref (None) in - let field_unavailable = ref (None) in - let field_member_count = ref (None) in - let field_members = ref (None) in - let field_channels = ref (None) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( - 2 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'l' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( - 21 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 13 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( - 14 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( - 5 - ) - else ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( - 24 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( - 25 - ) - else ( - -1 - ) - ) - | 'f' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( - 15 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( - 16 - ) - else ( - -1 - ) - ) - | 11 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( - 7 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( - 22 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 12 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( - 23 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( - 8 - ) - else ( - -1 - ) - ) - | 14 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - match String.unsafe_get s (pos+1) with - | 'f' -> ( - if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 17 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( - 20 - ) - else ( - -1 - ) - ) - | 'w' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( - match String.unsafe_get s (pos+7) with - | 'c' -> ( - if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( - 19 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( - 18 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 16 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( - 9 - ) - else ( - -1 - ) - ) - | 18 -> ( - if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( - 10 - ) - else ( - -1 - ) - ) - | 23 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( - 12 - ) - else ( - -1 - ) - ) - | 29 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_splash := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - field_owner_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 5 -> - field_region := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_afk_channel_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 7 -> - field_afk_timeout := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_embed_enabled := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_embed_channel_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 10 -> - field_verification_level := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 11 -> - field_default_message_notifications := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 12 -> - field_explicit_content_filter := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x80; - | 13 -> - field_roles := ( - ( - read__4 - ) p lb - ); - bits0 := !bits0 lor 0x100; - | 14 -> - field_emojis := ( - ( - read__5 - ) p lb - ); - bits0 := !bits0 lor 0x200; - | 15 -> - field_features := ( - ( - read__6 - ) p lb - ); - bits0 := !bits0 lor 0x400; - | 16 -> - field_mfa_level := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x800; - | 17 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_application_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 18 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_widget_enabled := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 19 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_widget_channel := ( - Some ( - ( - read_channel - ) p lb - ) - ); - ) - | 20 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_system_channel := ( - Some ( - ( - read_channel - ) p lb - ) - ); - ) - | 21 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_large := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 22 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_unavailable := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 23 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_member_count := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 24 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_members := ( - Some ( - ( - read__9 - ) p lb - ) - ); - ) - | 25 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_channels := ( - Some ( - ( - read__11 - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - match String.unsafe_get s pos with - | 'i' -> ( - if String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'n' then ( - 2 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'l' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' then ( - 21 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 13 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' then ( - 14 - ) - else ( - -1 - ) - ) - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'g' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'n' then ( - 5 - ) - else ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+1) = 'p' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 'h' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 's' then ( - 24 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 's' then ( - 25 - ) - else ( - -1 - ) - ) - | 'f' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 's' then ( - 15 - ) - else ( - -1 - ) - ) - | 'o' -> ( - if String.unsafe_get s (pos+1) = 'w' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 4 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'l' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'v' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'l' then ( - 16 - ) - else ( - -1 - ) - ) - | 11 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - if String.unsafe_get s (pos+1) = 'f' && String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 't' then ( - 7 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 'n' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'v' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( - 22 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 12 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'u' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 't' then ( - 23 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'b' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'd' then ( - 8 - ) - else ( - -1 - ) - ) - | 14 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - match String.unsafe_get s (pos+1) with - | 'f' -> ( - if String.unsafe_get s (pos+2) = 'k' && String.unsafe_get s (pos+3) = '_' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 'l' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'o' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = '_' && String.unsafe_get s (pos+12) = 'i' && String.unsafe_get s (pos+13) = 'd' then ( - 17 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 's' -> ( - if String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'c' && String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( - 20 - ) - else ( - -1 - ) - ) - | 'w' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'd' && String.unsafe_get s (pos+3) = 'g' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = '_' then ( - match String.unsafe_get s (pos+7) with - | 'c' -> ( - if String.unsafe_get s (pos+8) = 'h' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'l' then ( - 19 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 'b' && String.unsafe_get s (pos+11) = 'l' && String.unsafe_get s (pos+12) = 'e' && String.unsafe_get s (pos+13) = 'd' then ( - 18 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 16 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'h' && String.unsafe_get s (pos+8) = 'a' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 'n' && String.unsafe_get s (pos+11) = 'e' && String.unsafe_get s (pos+12) = 'l' && String.unsafe_get s (pos+13) = '_' && String.unsafe_get s (pos+14) = 'i' && String.unsafe_get s (pos+15) = 'd' then ( - 9 - ) - else ( - -1 - ) - ) - | 18 -> ( - if String.unsafe_get s pos = 'v' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'f' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'c' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = '_' && String.unsafe_get s (pos+13) = 'l' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = 'v' && String.unsafe_get s (pos+16) = 'e' && String.unsafe_get s (pos+17) = 'l' then ( - 10 - ) - else ( - -1 - ) - ) - | 23 -> ( - if String.unsafe_get s pos = 'e' && String.unsafe_get s (pos+1) = 'x' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'c' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = '_' && String.unsafe_get s (pos+9) = 'c' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'e' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 't' && String.unsafe_get s (pos+16) = '_' && String.unsafe_get s (pos+17) = 'f' && String.unsafe_get s (pos+18) = 'i' && String.unsafe_get s (pos+19) = 'l' && String.unsafe_get s (pos+20) = 't' && String.unsafe_get s (pos+21) = 'e' && String.unsafe_get s (pos+22) = 'r' then ( - 12 - ) - else ( - -1 - ) - ) - | 29 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'f' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 'l' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'm' && String.unsafe_get s (pos+9) = 'e' && String.unsafe_get s (pos+10) = 's' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 'a' && String.unsafe_get s (pos+13) = 'g' && String.unsafe_get s (pos+14) = 'e' && String.unsafe_get s (pos+15) = '_' && String.unsafe_get s (pos+16) = 'n' && String.unsafe_get s (pos+17) = 'o' && String.unsafe_get s (pos+18) = 't' && String.unsafe_get s (pos+19) = 'i' && String.unsafe_get s (pos+20) = 'f' && String.unsafe_get s (pos+21) = 'i' && String.unsafe_get s (pos+22) = 'c' && String.unsafe_get s (pos+23) = 'a' && String.unsafe_get s (pos+24) = 't' && String.unsafe_get s (pos+25) = 'i' && String.unsafe_get s (pos+26) = 'o' && String.unsafe_get s (pos+27) = 'n' && String.unsafe_get s (pos+28) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_icon := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_splash := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - field_owner_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 5 -> - field_region := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 6 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_afk_channel_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 7 -> - field_afk_timeout := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 8 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_embed_enabled := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 9 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_embed_channel_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 10 -> - field_verification_level := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 11 -> - field_default_message_notifications := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 12 -> - field_explicit_content_filter := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x80; - | 13 -> - field_roles := ( - ( - read__4 - ) p lb - ); - bits0 := !bits0 lor 0x100; - | 14 -> - field_emojis := ( - ( - read__5 - ) p lb - ); - bits0 := !bits0 lor 0x200; - | 15 -> - field_features := ( - ( - read__6 - ) p lb - ); - bits0 := !bits0 lor 0x400; - | 16 -> - field_mfa_level := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x800; - | 17 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_application_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 18 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_widget_enabled := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 19 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_widget_channel := ( - Some ( - ( - read_channel - ) p lb - ) - ); - ) - | 20 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_system_channel := ( - Some ( - ( - read_channel - ) p lb - ) - ); - ) - | 21 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_large := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 22 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_unavailable := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ) - ); - ) - | 23 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_member_count := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ) - ); - ) - | 24 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_members := ( - Some ( - ( - read__9 - ) p lb - ) - ); - ) - | 25 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_channels := ( - Some ( - ( - read__11 - ) p lb - ) - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0xfff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "owner_id"; "region"; "afk_timeout"; "verification_level"; "default_message_notifications"; "explicit_content_filter"; "roles"; "emojis"; "features"; "mfa_level" |]; - ( - { - id = !field_id; - name = !field_name; - icon = !field_icon; - splash = !field_splash; - owner_id = !field_owner_id; - region = !field_region; - afk_channel_id = !field_afk_channel_id; - afk_timeout = !field_afk_timeout; - embed_enabled = !field_embed_enabled; - embed_channel_id = !field_embed_channel_id; - verification_level = !field_verification_level; - default_message_notifications = !field_default_message_notifications; - explicit_content_filter = !field_explicit_content_filter; - roles = !field_roles; - emojis = !field_emojis; - features = !field_features; - mfa_level = !field_mfa_level; - application_id = !field_application_id; - widget_enabled = !field_widget_enabled; - widget_channel = !field_widget_channel; - system_channel = !field_system_channel; - large = !field_large; - unavailable = !field_unavailable; - member_count = !field_member_count; - members = !field_members; - channels = !field_channels; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/guild_j.mli b/lib/models/guild_j.mli deleted file mode 100644 index d430b2a..0000000 --- a/lib/models/guild_j.mli +++ /dev/null @@ -1,184 +0,0 @@ -(* Auto-generated from "guild.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type member = Member_t.t - -type emoji = Emoji_t.t - -type channel = Channel_t.t - -type t = Guild_t.t = { - id: snowflake; - name: string; - icon: string option; - splash: string option; - owner_id: snowflake; - region: string; - afk_channel_id: snowflake option; - afk_timeout: int; - embed_enabled: bool option; - embed_channel_id: snowflake option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: role list; - emojis: emoji list; - features: string list; - mfa_level: int; - application_id: snowflake option; - widget_enabled: bool option; - widget_channel: channel option; - system_channel: channel option; - large: bool option; - unavailable: bool option; - member_count: int option; - members: member list option; - channels: channel list option -} - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_role : - Bi_outbuf.t -> role -> unit - (** Output a JSON value of type {!role}. *) - -val string_of_role : - ?len:int -> role -> string - (** Serialize a value of type {!role} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_role : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> role - (** Input JSON data of type {!role}. *) - -val role_of_string : - string -> role - (** Deserialize JSON data of type {!role}. *) - -val write_member : - Bi_outbuf.t -> member -> unit - (** Output a JSON value of type {!member}. *) - -val string_of_member : - ?len:int -> member -> string - (** Serialize a value of type {!member} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_member : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> member - (** Input JSON data of type {!member}. *) - -val member_of_string : - string -> member - (** Deserialize JSON data of type {!member}. *) - -val write_emoji : - Bi_outbuf.t -> emoji -> unit - (** Output a JSON value of type {!emoji}. *) - -val string_of_emoji : - ?len:int -> emoji -> string - (** Serialize a value of type {!emoji} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_emoji : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji - (** Input JSON data of type {!emoji}. *) - -val emoji_of_string : - string -> emoji - (** Deserialize JSON data of type {!emoji}. *) - -val write_channel : - Bi_outbuf.t -> channel -> unit - (** Output a JSON value of type {!channel}. *) - -val string_of_channel : - ?len:int -> channel -> string - (** Serialize a value of type {!channel} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_channel : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> channel - (** Input JSON data of type {!channel}. *) - -val channel_of_string : - string -> channel - (** Deserialize JSON data of type {!channel}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/guild_t.ml b/lib/models/guild_t.ml deleted file mode 100644 index 9ffe83f..0000000 --- a/lib/models/guild_t.ml +++ /dev/null @@ -1,43 +0,0 @@ -(* Auto-generated from "guild.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type member = Member_t.t - -type emoji = Emoji_t.t - -type channel = Channel_t.t - -type t = { - id: snowflake; - name: string; - icon: string option; - splash: string option; - owner_id: snowflake; - region: string; - afk_channel_id: snowflake option; - afk_timeout: int; - embed_enabled: bool option; - embed_channel_id: snowflake option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: role list; - emojis: emoji list; - features: string list; - mfa_level: int; - application_id: snowflake option; - widget_enabled: bool option; - widget_channel: channel option; - system_channel: channel option; - large: bool option; - unavailable: bool option; - member_count: int option; - members: member list option; - channels: channel list option -} diff --git a/lib/models/guild_t.mli b/lib/models/guild_t.mli deleted file mode 100644 index 9ffe83f..0000000 --- a/lib/models/guild_t.mli +++ /dev/null @@ -1,43 +0,0 @@ -(* Auto-generated from "guild.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type member = Member_t.t - -type emoji = Emoji_t.t - -type channel = Channel_t.t - -type t = { - id: snowflake; - name: string; - icon: string option; - splash: string option; - owner_id: snowflake; - region: string; - afk_channel_id: snowflake option; - afk_timeout: int; - embed_enabled: bool option; - embed_channel_id: snowflake option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: role list; - emojis: emoji list; - features: string list; - mfa_level: int; - application_id: snowflake option; - widget_enabled: bool option; - widget_channel: channel option; - system_channel: channel option; - large: bool option; - unavailable: bool option; - member_count: int option; - members: member list option; - channels: channel list option -} diff --git a/lib/models/member.atd b/lib/models/member.atd deleted file mode 100644 index 11d8b62..0000000 --- a/lib/models/member.atd +++ /dev/null @@ -1,15 +0,0 @@ -type snowflake = abstract -type user = abstract - -type partial_member = { - ?nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool; -} - -type t = { - inherit partial_member; - user: user; -} \ No newline at end of file diff --git a/lib/models/member.ml b/lib/models/member.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/member.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/member_j.ml b/lib/models/member_j.ml deleted file mode 100644 index 7fd4aec..0000000 --- a/lib/models/member_j.ml +++ /dev/null @@ -1,750 +0,0 @@ -(* Auto-generated from "member.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Member_t.t = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool; - user: user -} - -type partial_member = Member_t.partial_member = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool -} - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_list ( - write_snowflake - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - Atdgen_runtime.Oj_run.read_list ( - read_snowflake - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.nick with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"nick\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"roles\":"; - ( - write__2 - ) - ob x.roles; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"joined_at\":"; - ( - Yojson.Safe.write_string - ) - ob x.joined_at; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"deaf\":"; - ( - Yojson.Safe.write_bool - ) - ob x.deaf; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mute\":"; - ( - Yojson.Safe.write_bool - ) - ob x.mute; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user\":"; - ( - write_user - ) - ob x.user; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_nick = ref (None) in - let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'd' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 3 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 0 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nick := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_roles := ( - ( - read__2 - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - field_joined_at := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 3 -> - field_deaf := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_mute := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 5 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x10; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'd' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 3 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 0 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nick := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_roles := ( - ( - read__2 - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - field_joined_at := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 3 -> - field_deaf := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_mute := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 5 -> - field_user := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x10; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute"; "user" |]; - ( - { - nick = !field_nick; - roles = !field_roles; - joined_at = !field_joined_at; - deaf = !field_deaf; - mute = !field_mute; - user = !field_user; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_partial_member : _ -> partial_member -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - (match x.nick with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"nick\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"roles\":"; - ( - write__2 - ) - ob x.roles; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"joined_at\":"; - ( - Yojson.Safe.write_string - ) - ob x.joined_at; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"deaf\":"; - ( - Yojson.Safe.write_bool - ) - ob x.deaf; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mute\":"; - ( - Yojson.Safe.write_bool - ) - ob x.mute; - Bi_outbuf.add_char ob '}'; -) -let string_of_partial_member ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_partial_member ob x; - Bi_outbuf.contents ob -let read_partial_member = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_nick = ref (None) in - let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_joined_at = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_deaf = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mute = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'd' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 3 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nick := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_roles := ( - ( - read__2 - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - field_joined_at := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 3 -> - field_deaf := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_mute := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'd' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'f' then ( - 3 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'e' then ( - 4 - ) - else ( - -1 - ) - ) - | 'n' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'c' && String.unsafe_get s (pos+3) = 'k' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 9 -> ( - if String.unsafe_get s pos = 'j' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 't' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nick := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 1 -> - field_roles := ( - ( - read__2 - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 2 -> - field_joined_at := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 3 -> - field_deaf := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_mute := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0xf then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "roles"; "joined_at"; "deaf"; "mute" |]; - ( - { - nick = !field_nick; - roles = !field_roles; - joined_at = !field_joined_at; - deaf = !field_deaf; - mute = !field_mute; - } - : partial_member) - ) -) -let partial_member_of_string s = - read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/member_j.mli b/lib/models/member_j.mli deleted file mode 100644 index f160b6d..0000000 --- a/lib/models/member_j.mli +++ /dev/null @@ -1,104 +0,0 @@ -(* Auto-generated from "member.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = Member_t.t = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool; - user: user -} - -type partial_member = Member_t.partial_member = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool -} - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - -val write_partial_member : - Bi_outbuf.t -> partial_member -> unit - (** Output a JSON value of type {!partial_member}. *) - -val string_of_partial_member : - ?len:int -> partial_member -> string - (** Serialize a value of type {!partial_member} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_partial_member : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member - (** Input JSON data of type {!partial_member}. *) - -val partial_member_of_string : - string -> partial_member - (** Deserialize JSON data of type {!partial_member}. *) - diff --git a/lib/models/member_t.ml b/lib/models/member_t.ml deleted file mode 100644 index 6262e1b..0000000 --- a/lib/models/member_t.ml +++ /dev/null @@ -1,23 +0,0 @@ -(* Auto-generated from "member.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool; - user: user -} - -type partial_member = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool -} diff --git a/lib/models/member_t.mli b/lib/models/member_t.mli deleted file mode 100644 index 6262e1b..0000000 --- a/lib/models/member_t.mli +++ /dev/null @@ -1,23 +0,0 @@ -(* Auto-generated from "member.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type t = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool; - user: user -} - -type partial_member = { - nick: string option; - roles: snowflake list; - joined_at: string; - deaf: bool; - mute: bool -} diff --git a/lib/models/message.atd b/lib/models/message.atd deleted file mode 100644 index 1c90be9..0000000 --- a/lib/models/message.atd +++ /dev/null @@ -1,30 +0,0 @@ -type snowflake = abstract -type user = abstract -type member = abstract -type partial_member = abstract -type role = abstract -type attachment = abstract -type embed = abstract -type reaction = abstract - -type t = { - id: snowflake; - author: user; - channel_id: snowflake; - ?member: partial_member option; - ?guild_id: snowflake option; - content: string; - timestamp: string; - ?edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: user list; - role_mentions: role list; - attachments: attachment list; - embeds: embed list; - reactions: reaction list; - ?nonce: snowflake option; - pinned: bool; - webhook_id: snowflake; - kind : int; -} \ No newline at end of file diff --git a/lib/models/message.ml b/lib/models/message.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/message.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/message_j.ml b/lib/models/message_j.ml deleted file mode 100644 index 206d69c..0000000 --- a/lib/models/message_j.ml +++ /dev/null @@ -1,1328 +0,0 @@ -(* Auto-generated from "message.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type reaction = Reaction_t.t - -type partial_member = Member_t.partial_member - -type embed = Embed_t.t - -type attachment = Attachment_t.t - -type t = Message_t.t = { - id: snowflake; - author: user; - channel_id: snowflake; - member: partial_member option; - guild_id: snowflake option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: user list; - role_mentions: role list; - attachments: attachment list; - embeds: embed list; - reactions: reaction list; - nonce: snowflake option; - pinned: bool; - webhook_id: snowflake; - kind: int -} - -type member = Member_t.t - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_role = ( - Role_j.write_t -) -let string_of_role ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_role ob x; - Bi_outbuf.contents ob -let read_role = ( - Role_j.read_t -) -let role_of_string s = - read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_reaction = ( - Reaction_j.write_t -) -let string_of_reaction ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_reaction ob x; - Bi_outbuf.contents ob -let read_reaction = ( - Reaction_j.read_t -) -let reaction_of_string s = - read_reaction (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_partial_member = ( - Member_j.write_partial_member -) -let string_of_partial_member ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_partial_member ob x; - Bi_outbuf.contents ob -let read_partial_member = ( - Member_j.read_partial_member -) -let partial_member_of_string s = - read_partial_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_embed = ( - Embed_j.write_t -) -let string_of_embed ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_embed ob x; - Bi_outbuf.contents ob -let read_embed = ( - Embed_j.read_t -) -let embed_of_string s = - read_embed (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_attachment = ( - Attachment_j.write_t -) -let string_of_attachment ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_attachment ob x; - Bi_outbuf.contents ob -let read_attachment = ( - Attachment_j.read_t -) -let attachment_of_string s = - read_attachment (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__8 = ( - Atdgen_runtime.Oj_run.write_list ( - write_reaction - ) -) -let string_of__8 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__8 ob x; - Bi_outbuf.contents ob -let read__8 = ( - Atdgen_runtime.Oj_run.read_list ( - read_reaction - ) -) -let _8_of_string s = - read__8 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__7 = ( - Atdgen_runtime.Oj_run.write_list ( - write_embed - ) -) -let string_of__7 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__7 ob x; - Bi_outbuf.contents ob -let read__7 = ( - Atdgen_runtime.Oj_run.read_list ( - read_embed - ) -) -let _7_of_string s = - read__7 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__6 = ( - Atdgen_runtime.Oj_run.write_list ( - write_attachment - ) -) -let string_of__6 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__6 ob x; - Bi_outbuf.contents ob -let read__6 = ( - Atdgen_runtime.Oj_run.read_list ( - read_attachment - ) -) -let _6_of_string s = - read__6 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__5 = ( - Atdgen_runtime.Oj_run.write_list ( - write_role - ) -) -let string_of__5 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__5 ob x; - Bi_outbuf.contents ob -let read__5 = ( - Atdgen_runtime.Oj_run.read_list ( - read_role - ) -) -let _5_of_string s = - read__5 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__4 = ( - Atdgen_runtime.Oj_run.write_list ( - write_user - ) -) -let string_of__4 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__4 ob x; - Bi_outbuf.contents ob -let read__4 = ( - Atdgen_runtime.Oj_run.read_list ( - read_user - ) -) -let _4_of_string s = - read__4 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_option ( - write_snowflake - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_snowflake - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - write_partial_member - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_partial_member - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_partial_member - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"author\":"; - ( - write_user - ) - ob x.author; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"channel_id\":"; - ( - write_snowflake - ) - ob x.channel_id; - (match x.member with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"member\":"; - ( - write_partial_member - ) - ob x; - ); - (match x.guild_id with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"guild_id\":"; - ( - write_snowflake - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"content\":"; - ( - Yojson.Safe.write_string - ) - ob x.content; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"timestamp\":"; - ( - Yojson.Safe.write_string - ) - ob x.timestamp; - (match x.edited_timestamp with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"edited_timestamp\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"tts\":"; - ( - Yojson.Safe.write_bool - ) - ob x.tts; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mention_everyone\":"; - ( - Yojson.Safe.write_bool - ) - ob x.mention_everyone; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mentions\":"; - ( - write__4 - ) - ob x.mentions; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"role_mentions\":"; - ( - write__5 - ) - ob x.role_mentions; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"attachments\":"; - ( - write__6 - ) - ob x.attachments; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"embeds\":"; - ( - write__7 - ) - ob x.embeds; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"reactions\":"; - ( - write__8 - ) - ob x.reactions; - (match x.nonce with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"nonce\":"; - ( - write_snowflake - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"pinned\":"; - ( - Yojson.Safe.write_bool - ) - ob x.pinned; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"webhook_id\":"; - ( - write_snowflake - ) - ob x.webhook_id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"type\":"; - ( - Yojson.Safe.write_int - ) - ob x.kind; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_author = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_channel_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_member = ref (None) in - let field_guild_id = ref (None) in - let field_content = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_timestamp = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_edited_timestamp = ref (None) in - let field_tts = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mention_everyone = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mentions = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_role_mentions = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_attachments = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_embeds = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_reactions = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_nonce = ref (None) in - let field_pinned = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_webhook_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_kind = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( - 8 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 18 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( - 15 - ) - else ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( - 1 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( - 13 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( - 16 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 4 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( - 10 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - match String.unsafe_get s pos with - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( - 14 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 10 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( - 2 - ) - else ( - -1 - ) - ) - | 'w' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( - 17 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 11 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( - 12 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | 16 -> ( - match String.unsafe_get s pos with - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( - 7 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( - 9 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_author := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_channel_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_member := ( - Some ( - ( - read_partial_member - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_guild_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 5 -> - field_content := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 6 -> - field_timestamp := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_edited_timestamp := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 8 -> - field_tts := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 9 -> - field_mention_everyone := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 10 -> - field_mentions := ( - ( - read__4 - ) p lb - ); - bits0 := !bits0 lor 0x80; - | 11 -> - field_role_mentions := ( - ( - read__5 - ) p lb - ); - bits0 := !bits0 lor 0x100; - | 12 -> - field_attachments := ( - ( - read__6 - ) p lb - ); - bits0 := !bits0 lor 0x200; - | 13 -> - field_embeds := ( - ( - read__7 - ) p lb - ); - bits0 := !bits0 lor 0x400; - | 14 -> - field_reactions := ( - ( - read__8 - ) p lb - ); - bits0 := !bits0 lor 0x800; - | 15 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nonce := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 16 -> - field_pinned := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x1000; - | 17 -> - field_webhook_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x2000; - | 18 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4000; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 's' then ( - 8 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 't' && String.unsafe_get s (pos+1) = 'y' && String.unsafe_get s (pos+2) = 'p' && String.unsafe_get s (pos+3) = 'e' then ( - 18 - ) - else ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'e' then ( - 15 - ) - else ( - -1 - ) - ) - | 6 -> ( - match String.unsafe_get s pos with - | 'a' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'r' then ( - 1 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = 's' then ( - 13 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'b' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' then ( - 16 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'c' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'n' && String.unsafe_get s (pos+6) = 't' then ( - 5 - ) - else ( - -1 - ) - ) - | 8 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 4 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 's' then ( - 10 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 9 -> ( - match String.unsafe_get s pos with - | 'r' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 's' then ( - 14 - ) - else ( - -1 - ) - ) - | 't' -> ( - if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' && String.unsafe_get s (pos+5) = 't' && String.unsafe_get s (pos+6) = 'a' && String.unsafe_get s (pos+7) = 'm' && String.unsafe_get s (pos+8) = 'p' then ( - 6 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 10 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'h' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'l' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( - 2 - ) - else ( - -1 - ) - ) - | 'w' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'b' && String.unsafe_get s (pos+3) = 'h' && String.unsafe_get s (pos+4) = 'o' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'k' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'd' then ( - 17 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 11 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'c' && String.unsafe_get s (pos+5) = 'h' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 't' && String.unsafe_get s (pos+10) = 's' then ( - 12 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = '_' && String.unsafe_get s (pos+5) = 'm' && String.unsafe_get s (pos+6) = 'e' && String.unsafe_get s (pos+7) = 'n' && String.unsafe_get s (pos+8) = 't' && String.unsafe_get s (pos+9) = 'i' && String.unsafe_get s (pos+10) = 'o' && String.unsafe_get s (pos+11) = 'n' && String.unsafe_get s (pos+12) = 's' then ( - 11 - ) - else ( - -1 - ) - ) - | 16 -> ( - match String.unsafe_get s pos with - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'd' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'e' && String.unsafe_get s (pos+5) = 'd' && String.unsafe_get s (pos+6) = '_' && String.unsafe_get s (pos+7) = 't' && String.unsafe_get s (pos+8) = 'i' && String.unsafe_get s (pos+9) = 'm' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 's' && String.unsafe_get s (pos+12) = 't' && String.unsafe_get s (pos+13) = 'a' && String.unsafe_get s (pos+14) = 'm' && String.unsafe_get s (pos+15) = 'p' then ( - 7 - ) - else ( - -1 - ) - ) - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = '_' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 'v' && String.unsafe_get s (pos+10) = 'e' && String.unsafe_get s (pos+11) = 'r' && String.unsafe_get s (pos+12) = 'y' && String.unsafe_get s (pos+13) = 'o' && String.unsafe_get s (pos+14) = 'n' && String.unsafe_get s (pos+15) = 'e' then ( - 9 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_author := ( - ( - read_user - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_channel_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_member := ( - Some ( - ( - read_partial_member - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_guild_id := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 5 -> - field_content := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 6 -> - field_timestamp := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 7 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_edited_timestamp := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 8 -> - field_tts := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 9 -> - field_mention_everyone := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 10 -> - field_mentions := ( - ( - read__4 - ) p lb - ); - bits0 := !bits0 lor 0x80; - | 11 -> - field_role_mentions := ( - ( - read__5 - ) p lb - ); - bits0 := !bits0 lor 0x100; - | 12 -> - field_attachments := ( - ( - read__6 - ) p lb - ); - bits0 := !bits0 lor 0x200; - | 13 -> - field_embeds := ( - ( - read__7 - ) p lb - ); - bits0 := !bits0 lor 0x400; - | 14 -> - field_reactions := ( - ( - read__8 - ) p lb - ); - bits0 := !bits0 lor 0x800; - | 15 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_nonce := ( - Some ( - ( - read_snowflake - ) p lb - ) - ); - ) - | 16 -> - field_pinned := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x1000; - | 17 -> - field_webhook_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x2000; - | 18 -> - field_kind := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4000; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x7fff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "author"; "channel_id"; "content"; "timestamp"; "tts"; "mention_everyone"; "mentions"; "role_mentions"; "attachments"; "embeds"; "reactions"; "pinned"; "webhook_id"; "kind" |]; - ( - { - id = !field_id; - author = !field_author; - channel_id = !field_channel_id; - member = !field_member; - guild_id = !field_guild_id; - content = !field_content; - timestamp = !field_timestamp; - edited_timestamp = !field_edited_timestamp; - tts = !field_tts; - mention_everyone = !field_mention_everyone; - mentions = !field_mentions; - role_mentions = !field_role_mentions; - attachments = !field_attachments; - embeds = !field_embeds; - reactions = !field_reactions; - nonce = !field_nonce; - pinned = !field_pinned; - webhook_id = !field_webhook_id; - kind = !field_kind; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_member = ( - Member_j.write_t -) -let string_of_member ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_member ob x; - Bi_outbuf.contents ob -let read_member = ( - Member_j.read_t -) -let member_of_string s = - read_member (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/message_j.mli b/lib/models/message_j.mli deleted file mode 100644 index e3a3e5b..0000000 --- a/lib/models/message_j.mli +++ /dev/null @@ -1,221 +0,0 @@ -(* Auto-generated from "message.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type reaction = Reaction_t.t - -type partial_member = Member_t.partial_member - -type embed = Embed_t.t - -type attachment = Attachment_t.t - -type t = Message_t.t = { - id: snowflake; - author: user; - channel_id: snowflake; - member: partial_member option; - guild_id: snowflake option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: user list; - role_mentions: role list; - attachments: attachment list; - embeds: embed list; - reactions: reaction list; - nonce: snowflake option; - pinned: bool; - webhook_id: snowflake; - kind: int -} - -type member = Member_t.t - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_role : - Bi_outbuf.t -> role -> unit - (** Output a JSON value of type {!role}. *) - -val string_of_role : - ?len:int -> role -> string - (** Serialize a value of type {!role} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_role : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> role - (** Input JSON data of type {!role}. *) - -val role_of_string : - string -> role - (** Deserialize JSON data of type {!role}. *) - -val write_reaction : - Bi_outbuf.t -> reaction -> unit - (** Output a JSON value of type {!reaction}. *) - -val string_of_reaction : - ?len:int -> reaction -> string - (** Serialize a value of type {!reaction} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_reaction : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> reaction - (** Input JSON data of type {!reaction}. *) - -val reaction_of_string : - string -> reaction - (** Deserialize JSON data of type {!reaction}. *) - -val write_partial_member : - Bi_outbuf.t -> partial_member -> unit - (** Output a JSON value of type {!partial_member}. *) - -val string_of_partial_member : - ?len:int -> partial_member -> string - (** Serialize a value of type {!partial_member} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_partial_member : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_member - (** Input JSON data of type {!partial_member}. *) - -val partial_member_of_string : - string -> partial_member - (** Deserialize JSON data of type {!partial_member}. *) - -val write_embed : - Bi_outbuf.t -> embed -> unit - (** Output a JSON value of type {!embed}. *) - -val string_of_embed : - ?len:int -> embed -> string - (** Serialize a value of type {!embed} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_embed : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> embed - (** Input JSON data of type {!embed}. *) - -val embed_of_string : - string -> embed - (** Deserialize JSON data of type {!embed}. *) - -val write_attachment : - Bi_outbuf.t -> attachment -> unit - (** Output a JSON value of type {!attachment}. *) - -val string_of_attachment : - ?len:int -> attachment -> string - (** Serialize a value of type {!attachment} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_attachment : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> attachment - (** Input JSON data of type {!attachment}. *) - -val attachment_of_string : - string -> attachment - (** Deserialize JSON data of type {!attachment}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - -val write_member : - Bi_outbuf.t -> member -> unit - (** Output a JSON value of type {!member}. *) - -val string_of_member : - ?len:int -> member -> string - (** Serialize a value of type {!member} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_member : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> member - (** Input JSON data of type {!member}. *) - -val member_of_string : - string -> member - (** Deserialize JSON data of type {!member}. *) - diff --git a/lib/models/message_t.ml b/lib/models/message_t.ml deleted file mode 100644 index 2442d76..0000000 --- a/lib/models/message_t.ml +++ /dev/null @@ -1,40 +0,0 @@ -(* Auto-generated from "message.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type reaction = Reaction_t.t - -type partial_member = Member_t.partial_member - -type embed = Embed_t.t - -type attachment = Attachment_t.t - -type t = { - id: snowflake; - author: user; - channel_id: snowflake; - member: partial_member option; - guild_id: snowflake option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: user list; - role_mentions: role list; - attachments: attachment list; - embeds: embed list; - reactions: reaction list; - nonce: snowflake option; - pinned: bool; - webhook_id: snowflake; - kind: int -} - -type member = Member_t.t diff --git a/lib/models/message_t.mli b/lib/models/message_t.mli deleted file mode 100644 index 2442d76..0000000 --- a/lib/models/message_t.mli +++ /dev/null @@ -1,40 +0,0 @@ -(* Auto-generated from "message.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type role = Role_t.t - -type reaction = Reaction_t.t - -type partial_member = Member_t.partial_member - -type embed = Embed_t.t - -type attachment = Attachment_t.t - -type t = { - id: snowflake; - author: user; - channel_id: snowflake; - member: partial_member option; - guild_id: snowflake option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: user list; - role_mentions: role list; - attachments: attachment list; - embeds: embed list; - reactions: reaction list; - nonce: snowflake option; - pinned: bool; - webhook_id: snowflake; - kind: int -} - -type member = Member_t.t diff --git a/lib/models/presence.atd b/lib/models/presence.atd deleted file mode 100644 index da9b3fd..0000000 --- a/lib/models/presence.atd +++ /dev/null @@ -1,13 +0,0 @@ -type snowflake = abstract -type user = abstract -type partial_user = abstract -type activity = abstract - -type t = { - user: partial_user; - roles: snowflake list; - ?game: activity option; - guild_id: snowflake; - status: string; - activities: activity list; -} \ No newline at end of file diff --git a/lib/models/presence.ml b/lib/models/presence.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/presence.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/presence_j.ml b/lib/models/presence_j.ml deleted file mode 100644 index b4ea497..0000000 --- a/lib/models/presence_j.ml +++ /dev/null @@ -1,492 +0,0 @@ -(* Auto-generated from "presence.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type partial_user = User_t.partial_user - -type activity = Activity_t.t - -type t = Presence_t.t = { - user: partial_user; - roles: snowflake list; - game: activity option; - guild_id: snowflake; - status: string; - activities: activity list -} - -let write_user = ( - User_j.write_t -) -let string_of_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_user ob x; - Bi_outbuf.contents ob -let read_user = ( - User_j.read_t -) -let user_of_string s = - read_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_partial_user = ( - User_j.write_partial_user -) -let string_of_partial_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_partial_user ob x; - Bi_outbuf.contents ob -let read_partial_user = ( - User_j.read_partial_user -) -let partial_user_of_string s = - read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_activity = ( - Activity_j.write_t -) -let string_of_activity ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_activity ob x; - Bi_outbuf.contents ob -let read_activity = ( - Activity_j.read_t -) -let activity_of_string s = - read_activity (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__3 = ( - Atdgen_runtime.Oj_run.write_list ( - write_activity - ) -) -let string_of__3 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__3 ob x; - Bi_outbuf.contents ob -let read__3 = ( - Atdgen_runtime.Oj_run.read_list ( - read_activity - ) -) -let _3_of_string s = - read__3 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__2 = ( - Atdgen_runtime.Oj_run.write_option ( - write_activity - ) -) -let string_of__2 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__2 ob x; - Bi_outbuf.contents ob -let read__2 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - read_activity - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - read_activity - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _2_of_string s = - read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_list ( - write_snowflake - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - Atdgen_runtime.Oj_run.read_list ( - read_snowflake - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"user\":"; - ( - write_partial_user - ) - ob x.user; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"roles\":"; - ( - write__1 - ) - ob x.roles; - (match x.game with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"game\":"; - ( - write_activity - ) - ob x; - ); - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"guild_id\":"; - ( - write_snowflake - ) - ob x.guild_id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"status\":"; - ( - Yojson.Safe.write_string - ) - ob x.status; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"activities\":"; - ( - write__3 - ) - ob x.activities; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_user = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_roles = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_game = ref (None) in - let field_guild_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_status = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_activities = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( - 4 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 3 - ) - else ( - -1 - ) - ) - | 10 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_user := ( - ( - read_partial_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_roles := ( - ( - read__1 - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_game := ( - Some ( - ( - read_activity - ) p lb - ) - ); - ) - | 3 -> - field_guild_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_status := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 5 -> - field_activities := ( - ( - read__3 - ) p lb - ); - bits0 := !bits0 lor 0x10; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 4 -> ( - match String.unsafe_get s pos with - | 'g' -> ( - if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 2 - ) - else ( - -1 - ) - ) - | 'u' -> ( - if String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' then ( - 0 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 5 -> ( - if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' && String.unsafe_get s (pos+4) = 's' then ( - 1 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 's' && String.unsafe_get s (pos+1) = 't' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'u' && String.unsafe_get s (pos+5) = 's' then ( - 4 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'g' && String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then ( - 3 - ) - else ( - -1 - ) - ) - | 10 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'c' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 'v' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 't' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'e' && String.unsafe_get s (pos+9) = 's' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_user := ( - ( - read_partial_user - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_roles := ( - ( - read__1 - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_game := ( - Some ( - ( - read_activity - ) p lb - ) - ); - ) - | 3 -> - field_guild_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 4 -> - field_status := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 5 -> - field_activities := ( - ( - read__3 - ) p lb - ); - bits0 := !bits0 lor 0x10; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1f then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "user"; "roles"; "guild_id"; "status"; "activities" |]; - ( - { - user = !field_user; - roles = !field_roles; - game = !field_game; - guild_id = !field_guild_id; - status = !field_status; - activities = !field_activities; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/presence_j.mli b/lib/models/presence_j.mli deleted file mode 100644 index be68b3f..0000000 --- a/lib/models/presence_j.mli +++ /dev/null @@ -1,120 +0,0 @@ -(* Auto-generated from "presence.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type partial_user = User_t.partial_user - -type activity = Activity_t.t - -type t = Presence_t.t = { - user: partial_user; - roles: snowflake list; - game: activity option; - guild_id: snowflake; - status: string; - activities: activity list -} - -val write_user : - Bi_outbuf.t -> user -> unit - (** Output a JSON value of type {!user}. *) - -val string_of_user : - ?len:int -> user -> string - (** Serialize a value of type {!user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> user - (** Input JSON data of type {!user}. *) - -val user_of_string : - string -> user - (** Deserialize JSON data of type {!user}. *) - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_partial_user : - Bi_outbuf.t -> partial_user -> unit - (** Output a JSON value of type {!partial_user}. *) - -val string_of_partial_user : - ?len:int -> partial_user -> string - (** Serialize a value of type {!partial_user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_partial_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user - (** Input JSON data of type {!partial_user}. *) - -val partial_user_of_string : - string -> partial_user - (** Deserialize JSON data of type {!partial_user}. *) - -val write_activity : - Bi_outbuf.t -> activity -> unit - (** Output a JSON value of type {!activity}. *) - -val string_of_activity : - ?len:int -> activity -> string - (** Serialize a value of type {!activity} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_activity : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> activity - (** Input JSON data of type {!activity}. *) - -val activity_of_string : - string -> activity - (** Deserialize JSON data of type {!activity}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/presence_t.ml b/lib/models/presence_t.ml deleted file mode 100644 index 940d986..0000000 --- a/lib/models/presence_t.ml +++ /dev/null @@ -1,19 +0,0 @@ -(* Auto-generated from "presence.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type partial_user = User_t.partial_user - -type activity = Activity_t.t - -type t = { - user: partial_user; - roles: snowflake list; - game: activity option; - guild_id: snowflake; - status: string; - activities: activity list -} diff --git a/lib/models/presence_t.mli b/lib/models/presence_t.mli deleted file mode 100644 index 940d986..0000000 --- a/lib/models/presence_t.mli +++ /dev/null @@ -1,19 +0,0 @@ -(* Auto-generated from "presence.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type user = User_t.t - -type snowflake = Snowflake_t.t - -type partial_user = User_t.partial_user - -type activity = Activity_t.t - -type t = { - user: partial_user; - roles: snowflake list; - game: activity option; - guild_id: snowflake; - status: string; - activities: activity list -} diff --git a/lib/models/reaction.atd b/lib/models/reaction.atd deleted file mode 100644 index aa41483..0000000 --- a/lib/models/reaction.atd +++ /dev/null @@ -1,6 +0,0 @@ -type emoji = abstract - -type t = { - count: int; - emoji: emoji; -} \ No newline at end of file diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/reaction.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/reaction_j.ml b/lib/models/reaction_j.ml deleted file mode 100644 index fe91833..0000000 --- a/lib/models/reaction_j.ml +++ /dev/null @@ -1,180 +0,0 @@ -(* Auto-generated from "reaction.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type emoji = Emoji_t.t - -type t = Reaction_t.t = { count: int; emoji: emoji } - -let write_emoji = ( - Emoji_j.write_t -) -let string_of_emoji ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_emoji ob x; - Bi_outbuf.contents ob -let read_emoji = ( - Emoji_j.read_t -) -let emoji_of_string s = - read_emoji (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"count\":"; - ( - Yojson.Safe.write_int - ) - ob x.count; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"emoji\":"; - ( - write_emoji - ) - ob x.emoji; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_count = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_emoji = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - if len = 5 then ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( - 0 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_count := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_emoji := ( - ( - read_emoji - ) p lb - ); - bits0 := !bits0 lor 0x2; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - if len = 5 then ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'u' && String.unsafe_get s (pos+3) = 'n' && String.unsafe_get s (pos+4) = 't' then ( - 0 - ) - else ( - -1 - ) - ) - | 'e' -> ( - if String.unsafe_get s (pos+1) = 'm' && String.unsafe_get s (pos+2) = 'o' && String.unsafe_get s (pos+3) = 'j' && String.unsafe_get s (pos+4) = 'i' then ( - 1 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - else ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_count := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_emoji := ( - ( - read_emoji - ) p lb - ); - bits0 := !bits0 lor 0x2; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "count"; "emoji" |]; - ( - { - count = !field_count; - emoji = !field_emoji; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/reaction_j.mli b/lib/models/reaction_j.mli deleted file mode 100644 index 0d6a598..0000000 --- a/lib/models/reaction_j.mli +++ /dev/null @@ -1,47 +0,0 @@ -(* Auto-generated from "reaction.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type emoji = Emoji_t.t - -type t = Reaction_t.t = { count: int; emoji: emoji } - -val write_emoji : - Bi_outbuf.t -> emoji -> unit - (** Output a JSON value of type {!emoji}. *) - -val string_of_emoji : - ?len:int -> emoji -> string - (** Serialize a value of type {!emoji} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_emoji : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> emoji - (** Input JSON data of type {!emoji}. *) - -val emoji_of_string : - string -> emoji - (** Deserialize JSON data of type {!emoji}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/reaction_t.ml b/lib/models/reaction_t.ml deleted file mode 100644 index 666030b..0000000 --- a/lib/models/reaction_t.ml +++ /dev/null @@ -1,6 +0,0 @@ -(* Auto-generated from "reaction.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type emoji = Emoji_t.t - -type t = { count: int; emoji: emoji } diff --git a/lib/models/reaction_t.mli b/lib/models/reaction_t.mli deleted file mode 100644 index 666030b..0000000 --- a/lib/models/reaction_t.mli +++ /dev/null @@ -1,6 +0,0 @@ -(* Auto-generated from "reaction.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type emoji = Emoji_t.t - -type t = { count: int; emoji: emoji } diff --git a/lib/models/role.atd b/lib/models/role.atd deleted file mode 100644 index a6bdcba..0000000 --- a/lib/models/role.atd +++ /dev/null @@ -1,12 +0,0 @@ -type snowflake = abstract - -type t = { - id: snowflake; - name: string; - colour : int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool; -} \ No newline at end of file diff --git a/lib/models/role.ml b/lib/models/role.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/role.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/role_j.ml b/lib/models/role_j.ml deleted file mode 100644 index a15b6cf..0000000 --- a/lib/models/role_j.ml +++ /dev/null @@ -1,449 +0,0 @@ -(* Auto-generated from "role.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = Role_t.t = { - id: snowflake; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool -} - -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"name\":"; - ( - Yojson.Safe.write_string - ) - ob x.name; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"color\":"; - ( - Yojson.Safe.write_int - ) - ob x.colour; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"hoist\":"; - ( - Yojson.Safe.write_bool - ) - ob x.hoist; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"position\":"; - ( - Yojson.Safe.write_int - ) - ob x.position; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"permissions\":"; - ( - Yojson.Safe.write_int - ) - ob x.permissions; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"managed\":"; - ( - Yojson.Safe.write_bool - ) - ob x.managed; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"mentionable\":"; - ( - Yojson.Safe.write_bool - ) - ob x.mentionable; - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_colour = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_hoist = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_position = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_permissions = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_managed = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_mentionable = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( - 2 - ) - else ( - -1 - ) - ) - | 'h' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( - 4 - ) - else ( - -1 - ) - ) - | 11 -> ( - match String.unsafe_get s pos with - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_colour := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - field_hoist := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 4 -> - field_position := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 5 -> - field_permissions := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 6 -> - field_managed := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 7 -> - field_mentionable := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x80; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 4 -> ( - if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 5 -> ( - match String.unsafe_get s pos with - | 'c' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then ( - 2 - ) - else ( - -1 - ) - ) - | 'h' -> ( - if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then ( - 3 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | 7 -> ( - if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then ( - 6 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'p' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then ( - 4 - ) - else ( - -1 - ) - ) - | 11 -> ( - match String.unsafe_get s pos with - | 'm' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then ( - 7 - ) - else ( - -1 - ) - ) - | 'p' -> ( - if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then ( - 5 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_name := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_colour := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - field_hoist := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x8; - | 4 -> - field_position := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x10; - | 5 -> - field_permissions := ( - ( - Atdgen_runtime.Oj_run.read_int - ) p lb - ); - bits0 := !bits0 lor 0x20; - | 6 -> - field_managed := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x40; - | 7 -> - field_mentionable := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - bits0 := !bits0 lor 0x80; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0xff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "colour"; "hoist"; "position"; "permissions"; "managed"; "mentionable" |]; - ( - { - id = !field_id; - name = !field_name; - colour = !field_colour; - hoist = !field_hoist; - position = !field_position; - permissions = !field_permissions; - managed = !field_managed; - mentionable = !field_mentionable; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/role_j.mli b/lib/models/role_j.mli deleted file mode 100644 index b4ea78c..0000000 --- a/lib/models/role_j.mli +++ /dev/null @@ -1,56 +0,0 @@ -(* Auto-generated from "role.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = Role_t.t = { - id: snowflake; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool -} - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/role_t.ml b/lib/models/role_t.ml deleted file mode 100644 index a4e83c5..0000000 --- a/lib/models/role_t.ml +++ /dev/null @@ -1,15 +0,0 @@ -(* Auto-generated from "role.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool -} diff --git a/lib/models/role_t.mli b/lib/models/role_t.mli deleted file mode 100644 index a4e83c5..0000000 --- a/lib/models/role_t.mli +++ /dev/null @@ -1,15 +0,0 @@ -(* Auto-generated from "role.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool -} diff --git a/lib/models/snowflake.atd b/lib/models/snowflake.atd deleted file mode 100644 index 98dc032..0000000 --- a/lib/models/snowflake.atd +++ /dev/null @@ -1 +0,0 @@ -type t = int \ No newline at end of file diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/snowflake.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/snowflake_j.ml b/lib/models/snowflake_j.ml deleted file mode 100644 index 80f6f63..0000000 --- a/lib/models/snowflake_j.ml +++ /dev/null @@ -1,17 +0,0 @@ -(* Auto-generated from "snowflake.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type t = Snowflake_t.t - -let write_t = ( - Yojson.Safe.write_int -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - Atdgen_runtime.Oj_run.read_int -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/snowflake_j.mli b/lib/models/snowflake_j.mli deleted file mode 100644 index fed97a4..0000000 --- a/lib/models/snowflake_j.mli +++ /dev/null @@ -1,25 +0,0 @@ -(* Auto-generated from "snowflake.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type t = Snowflake_t.t - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - diff --git a/lib/models/snowflake_t.ml b/lib/models/snowflake_t.ml deleted file mode 100644 index a7bdb08..0000000 --- a/lib/models/snowflake_t.ml +++ /dev/null @@ -1,4 +0,0 @@ -(* Auto-generated from "snowflake.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type t = int diff --git a/lib/models/snowflake_t.mli b/lib/models/snowflake_t.mli deleted file mode 100644 index a7bdb08..0000000 --- a/lib/models/snowflake_t.mli +++ /dev/null @@ -1,4 +0,0 @@ -(* Auto-generated from "snowflake.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type t = int diff --git a/lib/models/user.atd b/lib/models/user.atd deleted file mode 100644 index 106b3b0..0000000 --- a/lib/models/user.atd +++ /dev/null @@ -1,13 +0,0 @@ -type snowflake = abstract - -type t = { - id: snowflake; - username: string; - discriminator: string; - ?avatar: string option; - ~bot : bool; -} - -type partial_user = { - id: snowflake; -} \ No newline at end of file diff --git a/lib/models/user.ml b/lib/models/user.ml new file mode 100644 index 0000000..36b7d4b --- /dev/null +++ b/lib/models/user.ml @@ -0,0 +1,2 @@ +module Make(Http : S.Http) = struct +end \ No newline at end of file diff --git a/lib/models/user_j.ml b/lib/models/user_j.ml deleted file mode 100644 index 552a20d..0000000 --- a/lib/models/user_j.ml +++ /dev/null @@ -1,468 +0,0 @@ -(* Auto-generated from "user.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = User_t.t = { - id: snowflake; - username: string; - discriminator: string; - avatar: string option; - bot: bool -} - -type partial_user = User_t.partial_user = { id: snowflake } - -let write_snowflake = ( - Snowflake_j.write_t -) -let string_of_snowflake ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_snowflake ob x; - Bi_outbuf.contents ob -let read_snowflake = ( - Snowflake_j.read_t -) -let snowflake_of_string s = - read_snowflake (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__1 = ( - Atdgen_runtime.Oj_run.write_option ( - Yojson.Safe.write_string - ) -) -let string_of__1 ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write__1 ob x; - Bi_outbuf.contents ob -let read__1 = ( - fun p lb -> - Yojson.Safe.read_space p lb; - match Yojson.Safe.start_any_variant p lb with - | `Edgy_bracket -> ( - match Yojson.Safe.read_ident p lb with - | "None" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (None : _ option) - | "Some" -> - Atdgen_runtime.Oj_run.read_until_field_value p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_gt p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Double_quote -> ( - match Yojson.Safe.finish_string p lb with - | "None" -> - (None : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) - | `Square_bracket -> ( - match Atdgen_runtime.Oj_run.read_string p lb with - | "Some" -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_comma p lb; - Yojson.Safe.read_space p lb; - let x = ( - Atdgen_runtime.Oj_run.read_string - ) p lb - in - Yojson.Safe.read_space p lb; - Yojson.Safe.read_rbr p lb; - (Some x : _ option) - | x -> - Atdgen_runtime.Oj_run.invalid_variant_tag p x - ) -) -let _1_of_string s = - read__1 (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_t : _ -> t -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"username\":"; - ( - Yojson.Safe.write_string - ) - ob x.username; - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"discriminator\":"; - ( - Yojson.Safe.write_string - ) - ob x.discriminator; - (match x.avatar with None -> () | Some x -> - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"avatar\":"; - ( - Yojson.Safe.write_string - ) - ob x; - ); - if x.bot <> false then ( - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"bot\":"; - ( - Yojson.Safe.write_bool - ) - ob x.bot; - ); - Bi_outbuf.add_char ob '}'; -) -let string_of_t ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_t ob x; - Bi_outbuf.contents ob -let read_t = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_username = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_discriminator = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let field_avatar = ref (None) in - let field_bot = ref (false) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( - 4 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_username := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_discriminator := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_avatar := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_bot := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - match len with - | 2 -> ( - if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - ) - | 3 -> ( - if String.unsafe_get s pos = 'b' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 't' then ( - 4 - ) - else ( - -1 - ) - ) - | 6 -> ( - if String.unsafe_get s pos = 'a' && String.unsafe_get s (pos+1) = 'v' && String.unsafe_get s (pos+2) = 'a' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'a' && String.unsafe_get s (pos+5) = 'r' then ( - 3 - ) - else ( - -1 - ) - ) - | 8 -> ( - if String.unsafe_get s pos = 'u' && String.unsafe_get s (pos+1) = 's' && String.unsafe_get s (pos+2) = 'e' && String.unsafe_get s (pos+3) = 'r' && String.unsafe_get s (pos+4) = 'n' && String.unsafe_get s (pos+5) = 'a' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'e' then ( - 1 - ) - else ( - -1 - ) - ) - | 13 -> ( - if String.unsafe_get s pos = 'd' && String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'c' && String.unsafe_get s (pos+4) = 'r' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'm' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'n' && String.unsafe_get s (pos+9) = 'a' && String.unsafe_get s (pos+10) = 't' && String.unsafe_get s (pos+11) = 'o' && String.unsafe_get s (pos+12) = 'r' then ( - 2 - ) - else ( - -1 - ) - ) - | _ -> ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | 1 -> - field_username := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x2; - | 2 -> - field_discriminator := ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ); - bits0 := !bits0 lor 0x4; - | 3 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_avatar := ( - Some ( - ( - Atdgen_runtime.Oj_run.read_string - ) p lb - ) - ); - ) - | 4 -> - if not (Yojson.Safe.read_null_if_possible p lb) then ( - field_bot := ( - ( - Atdgen_runtime.Oj_run.read_bool - ) p lb - ); - ) - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x7 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "username"; "discriminator" |]; - ( - { - id = !field_id; - username = !field_username; - discriminator = !field_discriminator; - avatar = !field_avatar; - bot = !field_bot; - } - : t) - ) -) -let t_of_string s = - read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write_partial_user : _ -> partial_user -> _ = ( - fun ob x -> - Bi_outbuf.add_char ob '{'; - let is_first = ref true in - if !is_first then - is_first := false - else - Bi_outbuf.add_char ob ','; - Bi_outbuf.add_string ob "\"id\":"; - ( - write_snowflake - ) - ob x.id; - Bi_outbuf.add_char ob '}'; -) -let string_of_partial_user ?(len = 1024) x = - let ob = Bi_outbuf.create len in - write_partial_user ob x; - Bi_outbuf.contents ob -let read_partial_user = ( - fun p lb -> - Yojson.Safe.read_space p lb; - Yojson.Safe.read_lcurl p lb; - let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in - let bits0 = ref 0 in - try - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_end lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - while true do - Yojson.Safe.read_space p lb; - Yojson.Safe.read_object_sep p lb; - Yojson.Safe.read_space p lb; - let f = - fun s pos len -> - if pos < 0 || len < 0 || pos + len > String.length s then - invalid_arg "out-of-bounds substring position or length"; - if len = 2 && String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then ( - 0 - ) - else ( - -1 - ) - in - let i = Yojson.Safe.map_ident p f lb in - Atdgen_runtime.Oj_run.read_until_field_value p lb; - ( - match i with - | 0 -> - field_id := ( - ( - read_snowflake - ) p lb - ); - bits0 := !bits0 lor 0x1; - | _ -> ( - Yojson.Safe.skip_json p lb - ) - ); - done; - assert false; - with Yojson.End_of_object -> ( - if !bits0 <> 0x1 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id" |]; - ( - { - id = !field_id; - } - : partial_user) - ) -) -let partial_user_of_string s = - read_partial_user (Yojson.Safe.init_lexer ()) (Lexing.from_string s) diff --git a/lib/models/user_j.mli b/lib/models/user_j.mli deleted file mode 100644 index 576768e..0000000 --- a/lib/models/user_j.mli +++ /dev/null @@ -1,75 +0,0 @@ -(* Auto-generated from "user.atd" *) -[@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = User_t.t = { - id: snowflake; - username: string; - discriminator: string; - avatar: string option; - bot: bool -} - -type partial_user = User_t.partial_user = { id: snowflake } - -val write_snowflake : - Bi_outbuf.t -> snowflake -> unit - (** Output a JSON value of type {!snowflake}. *) - -val string_of_snowflake : - ?len:int -> snowflake -> string - (** Serialize a value of type {!snowflake} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_snowflake : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> snowflake - (** Input JSON data of type {!snowflake}. *) - -val snowflake_of_string : - string -> snowflake - (** Deserialize JSON data of type {!snowflake}. *) - -val write_t : - Bi_outbuf.t -> t -> unit - (** Output a JSON value of type {!t}. *) - -val string_of_t : - ?len:int -> t -> string - (** Serialize a value of type {!t} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_t : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> t - (** Input JSON data of type {!t}. *) - -val t_of_string : - string -> t - (** Deserialize JSON data of type {!t}. *) - -val write_partial_user : - Bi_outbuf.t -> partial_user -> unit - (** Output a JSON value of type {!partial_user}. *) - -val string_of_partial_user : - ?len:int -> partial_user -> string - (** Serialize a value of type {!partial_user} - into a JSON string. - @param len specifies the initial length - of the buffer used internally. - Default: 1024. *) - -val read_partial_user : - Yojson.Safe.lexer_state -> Lexing.lexbuf -> partial_user - (** Input JSON data of type {!partial_user}. *) - -val partial_user_of_string : - string -> partial_user - (** Deserialize JSON data of type {!partial_user}. *) - diff --git a/lib/models/user_t.ml b/lib/models/user_t.ml deleted file mode 100644 index 294cf0a..0000000 --- a/lib/models/user_t.ml +++ /dev/null @@ -1,14 +0,0 @@ -(* Auto-generated from "user.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - username: string; - discriminator: string; - avatar: string option; - bot: bool -} - -type partial_user = { id: snowflake } diff --git a/lib/models/user_t.mli b/lib/models/user_t.mli deleted file mode 100644 index 294cf0a..0000000 --- a/lib/models/user_t.mli +++ /dev/null @@ -1,14 +0,0 @@ -(* Auto-generated from "user.atd" *) - [@@@ocaml.warning "-27-32-35-39"] - -type snowflake = Snowflake_t.t - -type t = { - id: snowflake; - username: string; - discriminator: string; - avatar: string option; - bot: bool -} - -type partial_user = { id: snowflake } diff --git a/lib/s.ml b/lib/s.ml index 32347cb..1fb8fdf 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -4,55 +4,21 @@ module type Token = sig val token : string end +module type Models = sig +end + module type Handler = sig val handle_event : - 'a -> - 'b -> + Event.t -> unit end -module type Dispatch = sig - type dispatch_event = - | HELLO of Yojson.Safe.json - | READY of Yojson.Safe.json - | RESUMED of Yojson.Safe.json - | INVALID_SESSION of Yojson.Safe.json - | CHANNEL_CREATE of Channel_t.t - | CHANNEL_UPDATE of Channel_t.t - | CHANNEL_DELETE of Channel_t.t - | CHANNEL_PINS_UPDATE of Yojson.Safe.json - | GUILD_CREATE of Guild_t.t - | GUILD_UPDATE of Guild_t.t - | GUILD_DELETE of Guild_t.t - | GUILD_BAN_ADD of Ban_t.t - | GUILD_BAN_REMOVE of Ban_t.t - | GUILD_EMOJIS_UPDATE of Yojson.Safe.json - | GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json - | GUILD_MEMBER_ADD of Member_t.t - | GUILD_MEMBER_REMOVE of Member_t.t - | GUILD_MEMBER_UPDATE of Member_t.t - | GUILD_MEMBERS_CHUNK of Member_t.t list - | GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *) - | GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *) - | GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *) - | MESSAGE_CREATE of Message_t.t - | MESSAGE_UPDATE of Message_t.t - | MESSAGE_DELETE of Message_t.t - | MESSAGE_BULK_DELETE of Message_t.t list - | MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t - | MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t - | MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list - | PRESENCE_UPDATE of Presence_t.t - | TYPING_START of Yojson.Safe.json - | USER_UPDATE of Yojson.Safe.json - | VOICE_STATE_UPDATE of Yojson.Safe.json - | VOICE_SERVER_UPDATE of Yojson.Safe.json - | WEBHOOKS_UPDATE of Yojson.Safe.json - - exception Invalid_event of string +module type Handler_f = sig + module Make(Models : Models) : Handler +end - val event_of_string : contents:string -> string -> dispatch_event - val dispatch : ev: -> string -> unit +module type Dispatch = sig + val dispatch : ev:string -> string -> unit end module type Http = sig diff --git a/lib/sharder.ml b/lib/sharder.ml index 7366fd9..98df132 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -70,7 +70,6 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct if t = "READY" then begin Ivar.fill_if_empty shard.ready () end; - print_endline @@ Yojson.Safe.pretty_to_string data; D.dispatch ~ev:t (Yojson.Safe.to_string data); return { shard with seq = seq; -- cgit v1.2.3 From 4df67b173aa7d51f5bd2ce95e476d130a6f93fd6 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Fri, 14 Dec 2018 11:53:25 -0700 Subject: Working and pretty message replying! --- lib/models/message.ml | 5 +++++ lib/s.ml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'lib') diff --git a/lib/models/message.ml b/lib/models/message.ml index 36b7d4b..7849afe 100644 --- a/lib/models/message.ml +++ b/lib/models/message.ml @@ -1,2 +1,7 @@ module Make(Http : S.Http) = struct + let reply (message:Message_t.t) str = + let msg = `Assoc [ + ("content", `String str) + ] in + Http.create_message (string_of_int (message.channel_id)) (msg) end \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index 1fb8fdf..40af880 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -4,7 +4,51 @@ module type Token = sig val token : string end +module type Activity = sig end + +module type Attachment = sig end + +module type Ban = sig end + +module type Channel = sig end + +module type Embed = sig end + +module type Emoji = sig end + +module type Guild = sig end + +module type Member = sig end + +module type Message = sig + val reply : Message_t.t -> string -> Yojson.Safe.json Deferred.t +end + +module type Presence = sig end + +module type Reaction = sig end + +module type Role = sig end + +module type Snowflake = sig end + +module type User = sig end + module type Models = sig + module Activity : Activity + module Attachment : Attachment + module Ban : Ban + module Channel : Channel + module Embed : Embed + module Emoji : Emoji + module Guild : Guild + module Member : Member + module Message : Message + module Presence : Presence + module Reaction : Reaction + module Role : Role + module Snowflake : Snowflake + module User : User end module type Handler = sig -- cgit v1.2.3 From 043d6adcaf557981f764ec1eb8c6400cc10f3eb8 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Fri, 14 Dec 2018 15:09:23 -0700 Subject: Improve endpoint module and add Message abstraction --- lib/endpoints.ml | 138 ++++++++++++------------------- lib/models/message.ml | 46 +++++++++-- lib/models/message.mli | 1 + lib/s.ml | 218 +++++++++++++++++++++++-------------------------- 4 files changed, 195 insertions(+), 208 deletions(-) create mode 100644 lib/models/message.mli (limited to 'lib') diff --git a/lib/endpoints.ml b/lib/endpoints.ml index 4fc2d1a..12563b0 100644 --- a/lib/endpoints.ml +++ b/lib/endpoints.ml @@ -1,96 +1,62 @@ +open Printf + let gateway = "/gateway" let gateway_bot = "/gateway/bot" - -let channel channel_id = "/channels/"^channel_id -let channel_messages channel_id = "/channels/"^channel_id^"/messages" - -let channel_message channel_id msg_id = - "/channels/"^channel_id^"/messages/"^msg_id - -let channel_reaction_me channel_id msg_id emoji = - "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji^"/@me" - -let channel_reaction channel_id msg_id emoji user_id = - "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji^"/"^user_id - -let channel_reactions_get channel_id msg_id emoji = - "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji - -let channel_reactions_delete channel_id msg_id = - "/channels/"^channel_id^"/messages/"^msg_id^"/reactions" - -let channel_bulk_delete channel_id = "/channels/"^channel_id - -let channel_permission channel_id overwrite_id = - "/channels/"^channel_id^"/permissions/"^overwrite_id - -let channel_permissions channel_id = "/channels"^channel_id^"/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 channel_id = "/channels/"^channel_id^"/call/ring" -let channel_invites channel_id = "/channels/"^channel_id^"/invites" -let channel_typing channel_id = "/channels/"^channel_id^"/typing" -let channel_pins channel_id = "/channels/"^channel_id^"/pins" -let channel_pin channel_id msg_id = "/channels/"^channel_id^"/pins/"^msg_id - +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 guild_id = "/guilds/"^guild_id -let guild_channels guild_id = "/guilds/"^guild_id^"/channels" -let guild_members guild_id = "/guilds/"^guild_id^"/members" -let guild_member guild_id user_id = "/guilds/"^guild_id^"/members/"^user_id - -let guild_member_role guild_id user_id role_id = - "/guilds/"^guild_id^"/members/"^user_id^"/roles/"^role_id - -let guild_bans guild_id = "/guilds/"^guild_id^"/bans" -let guild_ban guild_id user_id = "/guilds/"^guild_id^"/bans"^user_id -let guild_roles guild_id = "/guilds/"^guild_id^"/roles" -let guild_role guild_id role_id = "/guilds/"^guild_id^"/roles"^role_id -let guild_prune guild_id = "/guilds/"^guild_id^"/prune" -let guild_voice_regions guild_id = "/guilds/"^guild_id^"/regions" -let guild_invites guild_id = "/guilds/"^guild_id^"/invites" -let guild_integrations guild_id = "/guilds/"^guild_id^"/integrations" - -let guild_integration guild_id integration_id = - "/guilds/"^guild_id^"/integrations/"^integration_id - -let guild_integration_sync guild_id integration_id = - "/guilds/"^guild_id^"/integrations/"^integration_id^"/sync" - -let guild_embed guild_id = "/guilds/"^guild_id^"/embed" -let guild_emojis guild_id = "/guilds/"^guild_id^"/emojis" -let guild_emoji guild_id emoji_id = "/guilds/"^guild_id^"/emojis/"^emoji_id - -let webhooks_guild guild_id = "/guilds/"^guild_id^"/webhooks" -let webhooks_channel channel_id = "/channels/"^channel_id^"/webhooks" -let webhook webhook_id = "/webhooks/"^webhook_id -let webhook_token webhook_id token = "/webhooks/"^webhook_id^"/"^token - -let webhook_git webhook_id token = - "/webhooks/"^webhook_id^"/"^token^"/github" - -let webhook_slack webhook_id token = - "/webhooks/"^webhook_id^"/"^token^"/slack" - -let user user_id = "/users/"^user_id - +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 guild_id = "/users/@me/guilds/"^guild_id +let me_guild = sprintf "/users/@me/guilds/%d" let me_channels = "/users/@me/channels" let me_connections = "/users/@me/connections" - -let invite code = "/invites/"^code +let invite = sprintf "/invites/%s" let regions = "/voice/regions" - let application_information = "/oauth2/applications/@me" - -let group_recipient group_id user_id = "/channels/"^group_id^"/recipients/"^user_id -let guild_me_nick guild_id = "/guilds/"^guild_id^"/members/@me/nick" -let guild_vanity_url guild_id = "/guilds/"^guild_id^"/vanity-url" -let guild_audit_logs guild_id = "/guilds/"^guild_id^"/audit-logs" - -(* let cdn_avatar id avatar image_format = "/avatars/"^id^"/"^avatar^"."^image_format *) -let cdn_embed_avatar image_name = "/embed/avatars/"^image_name^".png" -let cdn_emoji id image_format = "/emojis/"^id^"."^image_format -let cdn_icon id icon image_format = "/icons/"^id^"/"^icon^"."^image_format -let cdn_avatar id splash image_format = "/splashes/"^id^"/"^splash^"."^image_format \ No newline at end of file +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/%d/%s.%s" +let cdn_avatar = sprintf "/splashes/%d/%s.%s" \ No newline at end of file diff --git a/lib/models/message.ml b/lib/models/message.ml index 7849afe..29148ee 100644 --- a/lib/models/message.ml +++ b/lib/models/message.ml @@ -1,7 +1,43 @@ module Make(Http : S.Http) = struct - let reply (message:Message_t.t) str = - let msg = `Assoc [ - ("content", `String str) - ] in - Http.create_message (string_of_int (message.channel_id)) (msg) + open Message_t + + let add_reaction msg (emoji:Emoji_t.t) = + let e = match emoji.id with + | Some i -> Printf.sprintf "%s:%d" emoji.name i + | None -> emoji.name + in + Http.create_reaction msg.channel_id msg.id e + + let remove_reaction msg (emoji:Emoji_t.t) (user:User_t.t) = + let e = match emoji.id with + | Some i -> Printf.sprintf "%s:%d" emoji.name i + | None -> emoji.name + in + Http.delete_reaction msg.channel_id msg.id e user.id + + let clear_reactions msg = + Http.delete_reactions msg.channel_id msg.id + + let delete msg = + Http.delete_message msg.channel_id msg.id + + let pin msg = + Http.pin_message msg.channel_id msg.id + + let unpin msg = + Http.unpin_message msg.channel_id msg.id + + let reply msg cont = + let rep = `Assoc [("content", `String cont)] in + Http.create_message msg.channel_id rep + + let set_content msg cont = + Message_j.string_of_t { msg with content = cont; } + |> Yojson.Safe.from_string + |> Http.edit_message msg.channel_id msg.id + + let set_embed msg embed = + Message_j.string_of_t { msg with embeds = [embed]; } + |> Yojson.Safe.from_string + |> Http.edit_message msg.channel_id msg.id end \ No newline at end of file diff --git a/lib/models/message.mli b/lib/models/message.mli new file mode 100644 index 0000000..6f6242f --- /dev/null +++ b/lib/models/message.mli @@ -0,0 +1 @@ +module Make(Http : S.Http) : S.Message \ No newline at end of file diff --git a/lib/s.ml b/lib/s.ml index 40af880..f4f0e77 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -21,7 +21,15 @@ module type Guild = sig end module type Member = sig end module type Message = sig - val reply : Message_t.t -> string -> Yojson.Safe.json Deferred.t + val add_reaction : Message_t.t -> Emoji_t.t -> Yojson.Safe.json Deferred.t + val remove_reaction : Message_t.t -> Emoji_t.t -> User_t.t -> Yojson.Safe.json Deferred.t + val clear_reactions : Message_t.t -> Yojson.Safe.json Deferred.t + val delete : Message_t.t -> Yojson.Safe.json Deferred.t + val pin : Message_t.t -> Yojson.Safe.json Deferred.t + val unpin : Message_t.t -> Yojson.Safe.json Deferred.t + val reply : Message_t.t -> string -> Yojson.Safe.json Deferred.t + val set_content : Message_t.t -> string -> Yojson.Safe.json Deferred.t + val set_embed : Message_t.t -> Embed_t.t -> Yojson.Safe.json Deferred.t end module type Presence = sig end @@ -90,163 +98,139 @@ module type Http = sig end (* Auto-generated signatures *) - val get_gateway : unit -> Yojson.Safe.json Async.Deferred.t - val get_gateway_bot : unit -> Yojson.Safe.json Async.Deferred.t - val get_channel : string -> Yojson.Safe.json Async.Deferred.t + val get_gateway : unit -> Yojson.Safe.json Conduit_async.io + val get_gateway_bot : unit -> Yojson.Safe.json Conduit_async.io + val get_channel : int -> Yojson.Safe.json Conduit_async.io val modify_channel : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_channel : string -> Yojson.Safe.json Async.Deferred.t - val get_messages : string -> Yojson.Safe.json Async.Deferred.t - val get_message : string -> string -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_channel : int -> Yojson.Safe.json Conduit_async.io + val get_messages : int -> Yojson.Safe.json Conduit_async.io + val get_message : int -> int -> Yojson.Safe.json Conduit_async.io val create_message : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val create_reaction : - string -> string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> string -> Yojson.Safe.json Conduit_async.io val delete_own_reaction : - string -> string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> string -> Yojson.Safe.json Conduit_async.io val delete_reaction : - string -> - string -> string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> string -> int -> Yojson.Safe.json Conduit_async.io val get_reactions : - string -> string -> string -> Yojson.Safe.json Async.Deferred.t - val delete_reactions : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> string -> Yojson.Safe.json Conduit_async.io + val delete_reactions : int -> int -> Yojson.Safe.json Conduit_async.io val edit_message : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_message : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_message : int -> int -> Yojson.Safe.json Conduit_async.io val bulk_delete : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val edit_channel_permissions : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_channel_invites : string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_channel_invites : int -> Yojson.Safe.json Conduit_async.io val create_channel_invite : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val delete_channel_permission : - string -> string -> Yojson.Safe.json Async.Deferred.t - val broadcast_typing : string -> Yojson.Safe.json Async.Deferred.t - val get_pinned_messages : string -> Yojson.Safe.json Async.Deferred.t - val pin_message : string -> string -> Yojson.Safe.json Async.Deferred.t - val unpin_message : - string -> string -> Yojson.Safe.json Async.Deferred.t - val group_recipient_add : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json Conduit_async.io + val broadcast_typing : int -> Yojson.Safe.json Conduit_async.io + val get_pinned_messages : int -> Yojson.Safe.json Conduit_async.io + val pin_message : int -> int -> Yojson.Safe.json Conduit_async.io + val unpin_message : int -> int -> Yojson.Safe.json Conduit_async.io + val group_recipient_add : int -> int -> Yojson.Safe.json Conduit_async.io val group_recipient_remove : - string -> string -> Yojson.Safe.json Async.Deferred.t - val get_emojis : string -> Yojson.Safe.json Async.Deferred.t - val get_emoji : string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json Conduit_async.io + val get_emojis : int -> Yojson.Safe.json Conduit_async.io + val get_emoji : int -> int -> Yojson.Safe.json Conduit_async.io val create_emoji : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val edit_emoji : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_emoji : string -> string -> Yojson.Safe.json Async.Deferred.t - val create_guild : - Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_guild : string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_emoji : int -> int -> Yojson.Safe.json Conduit_async.io + val create_guild : Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_guild : int -> Yojson.Safe.json Conduit_async.io val edit_guild : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_guild : string -> Yojson.Safe.json Async.Deferred.t - val get_guild_channels : string -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_guild : int -> Yojson.Safe.json Conduit_async.io + val get_guild_channels : int -> Yojson.Safe.json Conduit_async.io val create_guild_channel : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val modify_guild_channel_positions : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_member : string -> string -> Yojson.Safe.json Async.Deferred.t - val get_members : string -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_member : int -> int -> Yojson.Safe.json Conduit_async.io + val get_members : int -> Yojson.Safe.json Conduit_async.io val add_member : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val edit_member : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val remove_member : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val remove_member : int -> int -> Yojson.Safe.json Conduit_async.io val change_nickname : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val add_member_role : - string -> string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> int -> Yojson.Safe.json Conduit_async.io val remove_member_role : - string -> string -> string -> Yojson.Safe.json Async.Deferred.t - val get_bans : string -> Yojson.Safe.json Async.Deferred.t - val get_ban : string -> string -> Yojson.Safe.json Async.Deferred.t + int -> int -> int -> Yojson.Safe.json Conduit_async.io + val get_bans : int -> Yojson.Safe.json Conduit_async.io + val get_ban : int -> int -> Yojson.Safe.json Conduit_async.io val guild_ban_add : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val guild_ban_remove : - string -> string -> Yojson.Safe.json Async.Deferred.t - val get_roles : string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val guild_ban_remove : int -> int -> Yojson.Safe.json Conduit_async.io + val get_roles : int -> Yojson.Safe.json Conduit_async.io val guild_role_add : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val guild_roles_edit : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val guild_role_edit : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val guild_role_remove : - string -> string -> Yojson.Safe.json Async.Deferred.t - val guild_prune_count : string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val guild_role_remove : int -> int -> Yojson.Safe.json Conduit_async.io + val guild_prune_count : int -> Yojson.Safe.json Conduit_async.io val guild_prune_start : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_guild_voice_regions : - string -> Yojson.Safe.json Async.Deferred.t - val get_guild_invites : string -> Yojson.Safe.json Async.Deferred.t - val get_integrations : string -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_guild_voice_regions : int -> Yojson.Safe.json Conduit_async.io + val get_guild_invites : int -> Yojson.Safe.json Conduit_async.io + val get_integrations : int -> Yojson.Safe.json Conduit_async.io val add_integration : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val edit_integration : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_integration : - string -> string -> Yojson.Safe.json Async.Deferred.t - val sync_integration : - string -> string -> Yojson.Safe.json Async.Deferred.t - val get_guild_embed : string -> Yojson.Safe.json Async.Deferred.t + int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_integration : int -> int -> Yojson.Safe.json Conduit_async.io + val sync_integration : int -> int -> Yojson.Safe.json Conduit_async.io + val get_guild_embed : int -> Yojson.Safe.json Conduit_async.io val edit_guild_embed : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_vanity_url : string -> Yojson.Safe.json Async.Deferred.t - val get_invite : string -> Yojson.Safe.json Async.Deferred.t - val delete_invite : string -> Yojson.Safe.json Async.Deferred.t - val get_current_user : unit -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_vanity_url : int -> Yojson.Safe.json Conduit_async.io + val get_invite : string -> Yojson.Safe.json Conduit_async.io + val delete_invite : string -> Yojson.Safe.json Conduit_async.io + val get_current_user : unit -> Yojson.Safe.json Conduit_async.io val edit_current_user : - Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_guilds : unit -> Yojson.Safe.json Async.Deferred.t - val leave_guild : string -> Yojson.Safe.json Async.Deferred.t - val get_private_channels : unit -> Yojson.Safe.json Async.Deferred.t - val create_dm : Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_guilds : unit -> Yojson.Safe.json Conduit_async.io + val leave_guild : int -> Yojson.Safe.json Conduit_async.io + val get_private_channels : unit -> Yojson.Safe.json Conduit_async.io + val create_dm : Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val create_group_dm : - Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_connections : unit -> Yojson.Safe.json Async.Deferred.t - val get_user : string -> Yojson.Safe.json Async.Deferred.t - val get_voice_regions : unit -> Yojson.Safe.json Async.Deferred.t + Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_connections : unit -> Yojson.Safe.json Conduit_async.io + val get_user : int -> Yojson.Safe.json Conduit_async.io + val get_voice_regions : unit -> Yojson.Safe.json Conduit_async.io val create_webhook : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val get_channel_webhooks : string -> Yojson.Safe.json Async.Deferred.t - val get_guild_webhooks : string -> Yojson.Safe.json Async.Deferred.t - val get_webhook : string -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val get_channel_webhooks : int -> Yojson.Safe.json Conduit_async.io + val get_guild_webhooks : int -> Yojson.Safe.json Conduit_async.io + val get_webhook : int -> Yojson.Safe.json Conduit_async.io val get_webhook_with_token : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json Conduit_async.io val edit_webhook : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val edit_webhook_with_token : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t - val delete_webhook : string -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io + val delete_webhook : int -> Yojson.Safe.json Conduit_async.io val delete_webhook_with_token : - string -> string -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json Conduit_async.io val execute_webhook : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val execute_slack_webhook : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val execute_git_webhook : - string -> - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> string -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io val get_audit_logs : - string -> Yojson.Safe.json -> Yojson.Safe.json Async.Deferred.t + int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io end module type Sharder = sig -- cgit v1.2.3 From a96b6386c0eeaa7ce3b65c39413cd89b7117ae0f Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Fri, 14 Dec 2018 15:45:27 -0700 Subject: A few odds and ends --- lib/models.ml | 1 + lib/s.ml | 75 ++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 44 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/models.ml b/lib/models.ml index 1b23a21..250de34 100644 --- a/lib/models.ml +++ b/lib/models.ml @@ -1,4 +1,5 @@ module Make(H : S.Http) = struct + module Http = H module Activity = Activity.Make(H) module Attachment = Attachment.Make(H) module Ban = Ban.Make(H) diff --git a/lib/s.ml b/lib/s.ml index f4f0e77..afe4209 100644 --- a/lib/s.ml +++ b/lib/s.ml @@ -18,7 +18,17 @@ module type Emoji = sig end module type Guild = sig end -module type Member = sig end +module type Member = sig + (* val add_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.t + val remove_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.t + val ban : ?reason:string -> ?days:int -> Member_t.t -> Yojson.Safe.json Deferred.t + val ban : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t + val kick : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t + val mute : Member_t.t -> Yojson.Safe.json Deferred.t + val deafen : Member_t.t -> Yojson.Safe.json Deferred.t + val unmute : Member_t.t -> Yojson.Safe.json Deferred.t + val undeafen : Member_t.t -> Yojson.Safe.json Deferred.t *) +end module type Message = sig val add_reaction : Message_t.t -> Emoji_t.t -> Yojson.Safe.json Deferred.t @@ -42,37 +52,6 @@ module type Snowflake = sig end module type User = sig end -module type Models = sig - module Activity : Activity - module Attachment : Attachment - module Ban : Ban - module Channel : Channel - module Embed : Embed - module Emoji : Emoji - module Guild : Guild - module Member : Member - module Message : Message - module Presence : Presence - module Reaction : Reaction - module Role : Role - module Snowflake : Snowflake - module User : User -end - -module type Handler = sig - val handle_event : - Event.t -> - unit -end - -module type Handler_f = sig - module Make(Models : Models) : Handler -end - -module type Dispatch = sig - val dispatch : ev:string -> string -> unit -end - module type Http = sig val token : string @@ -233,6 +212,38 @@ module type Http = sig int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io end +module type Models = sig + module Http : Http + module Activity : Activity + module Attachment : Attachment + module Ban : Ban + module Channel : Channel + module Embed : Embed + module Emoji : Emoji + module Guild : Guild + module Member : Member + module Message : Message + module Presence : Presence + module Reaction : Reaction + module Role : Role + module Snowflake : Snowflake + module User : User +end + +module type Handler = sig + val handle_event : + Event.t -> + unit +end + +module type Handler_f = sig + module Make(Models : Models) : Handler +end + +module type Dispatch = sig + val dispatch : ev:string -> string -> unit +end + module type Sharder = sig exception Invalid_Payload exception Failure_to_Establish_Heartbeat -- cgit v1.2.3