From d4abffca092879e959ab291ca369671c047b4125 Mon Sep 17 00:00:00 2001 From: Adelyn Breelove Date: Tue, 29 Jan 2019 14:18:16 -0700 Subject: Make a few things more legible, update build and readme --- README.md | 6 ++--- disml.opam | 2 +- lib/dune | 2 +- lib/models/snowflake.ml | 2 +- lib/sharder.ml | 65 +++++++++++++++++++++++++------------------------ 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index b304e7a..a7635c7 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ Latest changes are on master #### What is implemented? * The full Discord REST API * Complete gateway support (sans voice) -* Automatic sharding -* Event dispatch to a user-defined consumer +* Automatic and manual sharding +* Event dispatch to a user-defined consumer that can be changed at runtime * Automatic reconnection of dropped gateway connections * Automatic rate limit handling #### What is not implemented? -* Abstractions for Discord Objects (Message, Guild, Channel, etc) (**Mostly Completed**) +* Abstractions for Discord Objects (**Mostly Completed**) * Voice * Cache diff --git a/disml.opam b/disml.opam index 5693984..5c09638 100644 --- a/disml.opam +++ b/disml.opam @@ -25,7 +25,7 @@ depends: [ "async_ssl" {>= "v0.11.0"} "core" {>= "v0.11.3"} "cohttp-async" {>= "1.2.0"} - "ppx_jane" {>= "v0.11.0"} + "ppx_sexp" {>= "v0.11.2"} "ppx_deriving_yojson" {>= "3.1"} "websocket-async" {>= "2.12"} "decompress" diff --git a/lib/dune b/lib/dune index e190d0c..7fa316e 100644 --- a/lib/dune +++ b/lib/dune @@ -21,7 +21,7 @@ client client_options disml dispatch endpoints event http impl opcode rl s sharder ) (libraries checkseum.c core async_ssl cohttp-async decompress logs yojson websocket-async ppx_deriving_yojson.runtime) - (preprocess (pps ppx_jane ppx_deriving_yojson)) + (preprocess (pps ppx_sexp_conv ppx_deriving_yojson)) ) (include_subdirs unqualified) diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 44b0a48..92c692c 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -5,7 +5,7 @@ type t = Int.t [@@deriving sexp] let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string let of_yojson d = - try of_yojson_exn d |> Ok + try Ok (of_yojson_exn d) with Yojson.Safe.Util.Type_error (why,_) -> Error why let to_yojson s : Yojson.Safe.json = `String (Int.to_string s) diff --git a/lib/sharder.ml b/lib/sharder.ml index cae5356..ddd419d 100644 --- a/lib/sharder.ml +++ b/lib/sharder.ml @@ -70,8 +70,8 @@ module Shard = struct | None -> "" | Some p -> Yojson.Safe.to_string @@ `Assoc [ - ("op", `Int (Opcode.to_int ev)); - ("d", p); + "op", `Int (Opcode.to_int ev); + "d", p; ] in let (_, write) = shard.pipe in @@ -105,25 +105,26 @@ module Shard = struct let set_status ~(status:Yojson.Safe.json) shard = let payload = match status with - | `Assoc [("name", `String name); ("type", `Int t)] -> + | `Assoc ["name", `String name; "type", `Int t] + | `Assoc ["type", `Int t; "name", `String name] -> `Assoc [ - ("status", `String "online"); - ("afk", `Bool false); - ("since", `Null); - ("game", `Assoc [ - ("name", `String name); - ("type", `Int t) - ]) + "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) - ]) + "status", `String "online"; + "afk", `Bool false; + "since", `Null; + "game", `Assoc [ + "name", `String name; + "type", `Int 0 + ] ] | _ -> raise Invalid_Payload in @@ -132,9 +133,9 @@ module Shard = struct let request_guild_members ?(query="") ?(limit=0) ~guild shard = let payload = `Assoc [ - ("guild_id", `String (Int.to_string guild)); - ("query", `String query); - ("limit", `Int limit); + "guild_id", `String (Int.to_string guild); + "query", `String query; + "limit", `Int limit; ] in Ivar.read shard.ready >>= fun _ -> push_frame ~payload ~ev:REQUEST_GUILD_MEMBERS shard @@ -151,24 +152,24 @@ module Shard = struct Mvar.take identify_lock >>= fun () -> Logs.debug (fun m -> m "Identifying shard [%d, %d]" (fst shard.id) (snd shard.id)); let payload = `Assoc [ - ("token", `String !Client_options.token); - ("properties", `Assoc [ - ("$os", `String Sys.os_type); - ("$device", `String "dis.ml"); - ("$browser", `String "dis.ml") - ]); - ("compress", `Bool shard.compress); - ("large_threshold", `Int !Client_options.large_threshold); - ("shard", `List shards); + "token", `String !Client_options.token; + "properties", `Assoc [ + "$os", `String Sys.os_type; + "$device", `String "dis.ml"; + "$browser", `String "dis.ml"; + ]; + "compress", `Bool shard.compress; + "large_threshold", `Int !Client_options.large_threshold; + "shard", `List shards; ] in push_frame ~payload ~ev:IDENTIFY shard >>| fun s -> s end | Some s -> let payload = `Assoc [ - ("token", `String !Client_options.token); - ("session_id", `String s); - ("seq", `Int shard.seq) + "token", `String !Client_options.token; + "session_id", `String s; + "seq", `Int shard.seq; ] in push_frame ~payload ~ev:RESUME shard -- cgit v1.2.3