diff options
| author | Adelyn Breelove <[email protected]> | 2018-12-12 15:23:14 -0700 |
|---|---|---|
| committer | Adelyn Breelove <[email protected]> | 2018-12-12 15:23:14 -0700 |
| commit | c046760eb599e42226c683aecbe33753dfc4d500 (patch) | |
| tree | 69b2be155e7dfc52710cb5b7700c31fab633896c /lib | |
| parent | Work on event dispatch and add model derives (diff) | |
| download | disml-c046760eb599e42226c683aecbe33753dfc4d500.tar.xz disml-c046760eb599e42226c683aecbe33753dfc4d500.zip | |
Complete event dispatch
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/client.ml | 9 | ||||
| -rw-r--r-- | lib/dispatch.ml | 2 | ||||
| -rw-r--r-- | lib/s.ml | 44 | ||||
| -rw-r--r-- | lib/sharder.ml | 5 | ||||
| -rw-r--r-- | lib/sharder.mli | 2 |
5 files changed, 53 insertions, 9 deletions
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 @@ -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 |