aboutsummaryrefslogtreecommitdiff
path: root/lib/sharder.ml
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2018-12-12 17:01:04 -0700
committerAdelyn Breedlove <[email protected]>2018-12-12 17:01:04 -0700
commita1e99ad1691a67d5aecc73109d2e1c16bdbe4050 (patch)
tree0c29235bf41df0705e854c73b2b32ce60b3a357d /lib/sharder.ml
parentMerge branch 'dev' of https://gitlab.com/Mishio595/disml into dev (diff)
parentUpdate my name in disml.opam (diff)
downloaddisml-a1e99ad1691a67d5aecc73109d2e1c16bdbe4050.tar.xz
disml-a1e99ad1691a67d5aecc73109d2e1c16bdbe4050.zip
Merge branch 'dev' of https://gitlab.com/Mishio595/disml into dev
Diffstat (limited to 'lib/sharder.ml')
-rw-r--r--lib/sharder.ml19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sharder.ml b/lib/sharder.ml
index 1c26d8c..6ac8584 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) : S.Sharder = struct
open Async
open Core
open Websocket_async
@@ -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,20 +62,21 @@ 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
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;
}
- 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 +113,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 +169,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 +286,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