aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2019-01-29 14:18:16 -0700
committerAdelyn Breelove <[email protected]>2019-01-29 14:18:16 -0700
commitd4abffca092879e959ab291ca369671c047b4125 (patch)
treeddcbb3a56dd406c8fca11c43130e494815ba4254 /lib
parentRemove some debug code (diff)
downloaddisml-d4abffca092879e959ab291ca369671c047b4125.tar.xz
disml-d4abffca092879e959ab291ca369671c047b4125.zip
Make a few things more legible, update build and readme
Diffstat (limited to 'lib')
-rw-r--r--lib/dune2
-rw-r--r--lib/models/snowflake.ml2
-rw-r--r--lib/sharder.ml65
3 files changed, 35 insertions, 34 deletions
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