aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-19 13:06:40 -0700
committerAdelyn Breedlove <[email protected]>2019-01-19 13:06:40 -0700
commit721bbc88c75eea240607054f2ec5a371f4d60e08 (patch)
tree40af2abb5f6179194c0580defee32215245d04ef /lib
parentAdd docs to event dispatch (diff)
downloaddisml-721bbc88c75eea240607054f2ec5a371f4d60e08.tar.xz
disml-721bbc88c75eea240607054f2ec5a371f4d60e08.zip
Some changes for doc readability
Diffstat (limited to 'lib')
-rw-r--r--lib/client.ml7
-rw-r--r--lib/client_options.ml1
-rw-r--r--lib/client_options.mli1
-rw-r--r--lib/config.mli104
-rw-r--r--lib/dispatch.ml (renamed from lib/config.ml)2
-rw-r--r--lib/dispatch.mli100
-rw-r--r--lib/dune2
-rw-r--r--lib/event.ml70
-rw-r--r--lib/http.ml2
-rw-r--r--lib/sharder.ml4
10 files changed, 145 insertions, 148 deletions
diff --git a/lib/client.ml b/lib/client.ml
index 49d01dc..3b0024d 100644
--- a/lib/client.ml
+++ b/lib/client.ml
@@ -1,5 +1,6 @@
open Async
-include Config
+include Client_options
+include Dispatch
type t = {
sharder: Sharder.t;
@@ -7,10 +8,10 @@ type t = {
}
let start ?count token =
- Config.token := token;
+ Client_options.token := token;
Sharder.start ?count ()
>>| fun sharder ->
- { sharder; token = !Config.token; }
+ { sharder; token; }
let set_status ~status client =
Sharder.set_status ~status client.sharder
diff --git a/lib/client_options.ml b/lib/client_options.ml
new file mode 100644
index 0000000..0571fea
--- /dev/null
+++ b/lib/client_options.ml
@@ -0,0 +1 @@
+let token = ref "" \ No newline at end of file
diff --git a/lib/client_options.mli b/lib/client_options.mli
new file mode 100644
index 0000000..ef94691
--- /dev/null
+++ b/lib/client_options.mli
@@ -0,0 +1 @@
+val token : string ref \ No newline at end of file
diff --git a/lib/config.mli b/lib/config.mli
deleted file mode 100644
index 6f4dcef..0000000
--- a/lib/config.mli
+++ /dev/null
@@ -1,104 +0,0 @@
-(** Fired when connecting to the gateway, most users will have no use for this. *)
-val hello : (Yojson.Safe.json -> unit) ref
-
-(** Fired when each shard receives READY from discord after identifying on the gateway. Other event dispatch is received after this. *)
-val ready : (Yojson.Safe.json -> unit) ref
-
-(** Fired after successfully reconnecting to the gateway. *)
-val resumed : (Yojson.Safe.json -> unit) ref
-
-(** Fired when Discord decides a session is invalid, much like {!Client.hello} this is not very useful for most people. *)
-val invalid_session : (Yojson.Safe.json -> unit) ref
-
-(** Fired anytime a channel is created which is visible to the bot. *)
-val channel_create : (Channel_t.t -> unit) ref
-
-(** Fired anytime a channel visible to the bot is changed. *)
-val channel_update : (Channel_t.t -> unit) ref
-
-(** Fired anytime a channel visible to the bot is deleted. *)
-val channel_delete : (Channel_t.t -> unit) ref
-
-(** Fired when messages are pinned or unpinned from a a channel. *)
-val channel_pins_update : (Yojson.Safe.json -> unit) ref
-
-(** Fired when the bot joins a guild, and during startup. *)
-val guild_create : (Guild_t.t -> unit) ref
-
-(** Fired when a guild the bot is in is edited. *)
-val guild_update : (Guild_t.t -> unit) ref
-
-(** Fired when the bot is removed from a guild. *)
-val guild_delete : (Guild_t.t -> unit) ref
-
-(** Fired when a member is banned. *)
-val member_ban : (Ban_t.t -> unit) ref
-
-(** Fired when a member is unbanned. *)
-val member_unban : (Ban_t.t -> unit) ref
-
-(** Fired when emojis are added or removed from a guild. *)
-val guild_emojis_update : (Yojson.Safe.json -> unit) ref
-
-(** Fired when a guild's integrations are updated. *)
-val integrations_update : (Yojson.Safe.json -> unit) ref
-
-(** Fired when a member joins a guild. *)
-val member_join : (Member_t.t -> unit) ref
-
-(** Fired when a member leaves a guild. Is fired alongside {!Client.member_ban} when a user is banned. *)
-val member_leave : (Member_t.member_wrapper -> unit) ref
-
-(** Fired when a member object is updated. *)
-val member_update : (Member_t.member_update -> unit) ref
-
-(** Fired when requesting guild members through {!Client.request_guild_members} *)
-val members_chunk : (Member_t.t list -> unit) ref
-
-(** Fired when a role is created. *)
-val role_create : (Role_t.t -> unit) ref
-
-(** Fired when a role is edited. *)
-val role_update : (Role_t.t -> unit) ref
-
-(** Fired when a role is deleted. *)
-val role_delete : (Role_t.t -> unit) ref
-
-(** Fired when a message is sent. *)
-val message_create : (Message_t.t -> unit) ref
-
-(** Fired when a message is edited. This does not necessarily mean the content changed. *)
-val message_update : (Message_t.message_update -> unit) ref
-
-(** Fired when a message is deleted. *)
-val message_delete : (Snowflake.t -> Snowflake.t -> unit) ref
-
-(** Fired when messages are bulk deleted. *)
-val message_bulk_delete : (Snowflake.t list -> unit) ref
-
-(** Fired when a rection is added to a message. *)
-val reaction_add : (Reaction_t.reaction_event -> unit) ref
-
-(** Fired when a reaction is removed from a message. *)
-val reaction_remove : (Reaction_t.reaction_event -> unit) ref
-
-(** Fired when all reactions are cleared from a message. *)
-val reaction_bulk_remove : (Reaction_t.t list -> unit) ref
-
-(** Fired when a user updates their presence. *)
-val presence_update : (Presence.t -> unit) ref
-
-(** Fired when a typing indicator is displayed. *)
-val typing_start : (Yojson.Safe.json -> unit) ref
-
-(** Fired when the current user is updated. You most likely want {!Client.member_update} or {!Client.presence_update} instead. *)
-val user_update : (Yojson.Safe.json -> unit) ref
-
-(**/**)
-val voice_state_update : (Yojson.Safe.json -> unit) ref
-val voice_server_update : (Yojson.Safe.json -> unit) ref
-val webhooks_update : (Yojson.Safe.json -> unit) ref
-(**/**)
-
-(**/**)
-val token : string ref \ No newline at end of file
diff --git a/lib/config.ml b/lib/dispatch.ml
index de01dc2..8ef50b2 100644
--- a/lib/config.ml
+++ b/lib/dispatch.ml
@@ -1,5 +1,3 @@
-let token = ref ""
-
let hello = ref (fun (_:Yojson.Safe.json) -> ())
let ready = ref (fun (_:Yojson.Safe.json) -> ())
let resumed = ref (fun (_:Yojson.Safe.json) -> ())
diff --git a/lib/dispatch.mli b/lib/dispatch.mli
new file mode 100644
index 0000000..51d94b4
--- /dev/null
+++ b/lib/dispatch.mli
@@ -0,0 +1,100 @@
+(** Dispatched when connecting to the gateway, most users will have no use for this. *)
+val hello : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when each shard receives READY from discord after identifying on the gateway. Other event dispatch is received after this. *)
+val ready : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when successfully reconnecting to the gateway. *)
+val resumed : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when Discord decides a session is invalid, much like {!Client.hello} this is not very useful for most people. *)
+val invalid_session : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when a channel is created which is visible to the bot. *)
+val channel_create : (Channel_t.t -> unit) ref
+
+(** Dispatched when a channel visible to the bot is changed. *)
+val channel_update : (Channel_t.t -> unit) ref
+
+(** Dispatched when a channel visible to the bot is deleted. *)
+val channel_delete : (Channel_t.t -> unit) ref
+
+(** Dispatched when messages are pinned or unpinned from a a channel. *)
+val channel_pins_update : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when the bot joins a guild, and during startup. *)
+val guild_create : (Guild_t.t -> unit) ref
+
+(** Dispatched when a guild the bot is in is edited. *)
+val guild_update : (Guild_t.t -> unit) ref
+
+(** Dispatched when the bot is removed from a guild. *)
+val guild_delete : (Guild_t.t -> unit) ref
+
+(** Dispatched when a member is banned. *)
+val member_ban : (Ban_t.t -> unit) ref
+
+(** Dispatched when a member is unbanned. *)
+val member_unban : (Ban_t.t -> unit) ref
+
+(** Dispatched when emojis are added or removed from a guild. *)
+val guild_emojis_update : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when a guild's integrations are updated. *)
+val integrations_update : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when a member joins a guild. *)
+val member_join : (Member_t.t -> unit) ref
+
+(** Dispatched when a member leaves a guild. Is Dispatched alongside {!Client.member_ban} when a user is banned. *)
+val member_leave : (Member_t.member_wrapper -> unit) ref
+
+(** Dispatched when a member object is updated. *)
+val member_update : (Member_t.member_update -> unit) ref
+
+(** Dispatched when requesting guild members through {!Client.request_guild_members} *)
+val members_chunk : (Member_t.t list -> unit) ref
+
+(** Dispatched when a role is created. *)
+val role_create : (Role_t.t -> unit) ref
+
+(** Dispatched when a role is edited. *)
+val role_update : (Role_t.t -> unit) ref
+
+(** Dispatched when a role is deleted. *)
+val role_delete : (Role_t.t -> unit) ref
+
+(** Dispatched when a message is sent. *)
+val message_create : (Message_t.t -> unit) ref
+
+(** Dispatched when a message is edited. This does not necessarily mean the content changed. *)
+val message_update : (Message_t.message_update -> unit) ref
+
+(** Dispatched when a message is deleted. *)
+val message_delete : (Snowflake.t -> Snowflake.t -> unit) ref
+
+(** Dispatched when messages are bulk deleted. *)
+val message_bulk_delete : (Snowflake.t list -> unit) ref
+
+(** Dispatched when a rection is added to a message. *)
+val reaction_add : (Reaction_t.reaction_event -> unit) ref
+
+(** Dispatched when a reaction is removed from a message. *)
+val reaction_remove : (Reaction_t.reaction_event -> unit) ref
+
+(** Dispatched when all reactions are cleared from a message. *)
+val reaction_bulk_remove : (Reaction_t.t list -> unit) ref
+
+(** Dispatched when a user updates their presence. *)
+val presence_update : (Presence.t -> unit) ref
+
+(** Dispatched when a typing indicator is displayed. *)
+val typing_start : (Yojson.Safe.json -> unit) ref
+
+(** Dispatched when the current user is updated. You most likely want {!Client.member_update} or {!Client.presence_update} instead. *)
+val user_update : (Yojson.Safe.json -> unit) ref
+
+(**/**)
+val voice_state_update : (Yojson.Safe.json -> unit) ref
+val voice_server_update : (Yojson.Safe.json -> unit) ref
+val webhooks_update : (Yojson.Safe.json -> unit) ref \ No newline at end of file
diff --git a/lib/dune b/lib/dune
index 275cdae..f3888e0 100644
--- a/lib/dune
+++ b/lib/dune
@@ -17,7 +17,7 @@
role role_t
snowflake
user user_t
- client config endpoints event http opcode rl sharder
+ client client_options dispatch endpoints event http opcode rl sharder
)
(libraries core async_ssl cohttp-async yojson websocket-async zlib ppx_deriving_yojson.runtime)
(preprocess (pps ppx_jane ppx_deriving_yojson))
diff --git a/lib/event.ml b/lib/event.ml
index 1c0bcc2..614c485 100644
--- a/lib/event.ml
+++ b/lib/event.ml
@@ -78,41 +78,41 @@ let event_of_yojson ~contents t = match t with
| s -> raise @@ Invalid_event s
let dispatch ev = match ev with
-| HELLO d -> !Config.hello d
-| READY d -> !Config.ready d
-| RESUMED d -> !Config.resumed d
-| INVALID_SESSION d -> !Config.invalid_session d
-| CHANNEL_CREATE d -> !Config.channel_create d
-| CHANNEL_UPDATE d -> !Config.channel_update d
-| CHANNEL_DELETE d -> !Config.channel_delete d
-| CHANNEL_PINS_UPDATE d -> !Config.channel_pins_update d
-| GUILD_CREATE d -> !Config.guild_create d
-| GUILD_UPDATE d -> !Config.guild_update d
-| GUILD_DELETE d -> !Config.guild_delete d
-| GUILD_BAN_ADD d -> !Config.member_ban d
-| GUILD_BAN_REMOVE d -> !Config.member_unban d
-| GUILD_EMOJIS_UPDATE d -> !Config.guild_emojis_update d
-| GUILD_INTEGRATIONS_UPDATE d -> !Config.integrations_update d
-| GUILD_MEMBER_ADD d -> !Config.member_join d
-| GUILD_MEMBER_REMOVE d -> !Config.member_leave d
-| GUILD_MEMBER_UPDATE d -> !Config.member_update d
-| GUILD_MEMBERS_CHUNK d -> !Config.members_chunk d
-| GUILD_ROLE_CREATE d -> !Config.role_create d
-| GUILD_ROLE_UPDATE d -> !Config.role_update d
-| GUILD_ROLE_DELETE d -> !Config.role_delete d
-| MESSAGE_CREATE d -> !Config.message_create d
-| MESSAGE_UPDATE d -> !Config.message_update d
-| MESSAGE_DELETE (d,e) -> !Config.message_delete d e
-| MESSAGE_BULK_DELETE d -> !Config.message_bulk_delete d
-| MESSAGE_REACTION_ADD d -> !Config.reaction_add d
-| MESSAGE_REACTION_REMOVE d -> !Config.reaction_remove d
-| MESSAGE_REACTION_REMOVE_ALL d -> !Config.reaction_bulk_remove d
-| PRESENCE_UPDATE d -> !Config.presence_update d
-| TYPING_START d -> !Config.typing_start d
-| USER_UPDATE d -> !Config.user_update d
-| VOICE_STATE_UPDATE d -> !Config.voice_state_update d
-| VOICE_SERVER_UPDATE d -> !Config.voice_server_update d
-| WEBHOOKS_UPDATE d -> !Config.webhooks_update d
+| HELLO d -> !Dispatch.hello d
+| READY d -> !Dispatch.ready d
+| RESUMED d -> !Dispatch.resumed d
+| INVALID_SESSION d -> !Dispatch.invalid_session d
+| CHANNEL_CREATE d -> !Dispatch.channel_create d
+| CHANNEL_UPDATE d -> !Dispatch.channel_update d
+| CHANNEL_DELETE d -> !Dispatch.channel_delete d
+| CHANNEL_PINS_UPDATE d -> !Dispatch.channel_pins_update d
+| GUILD_CREATE d -> !Dispatch.guild_create d
+| GUILD_UPDATE d -> !Dispatch.guild_update d
+| GUILD_DELETE d -> !Dispatch.guild_delete d
+| GUILD_BAN_ADD d -> !Dispatch.member_ban d
+| GUILD_BAN_REMOVE d -> !Dispatch.member_unban d
+| GUILD_EMOJIS_UPDATE d -> !Dispatch.guild_emojis_update d
+| GUILD_INTEGRATIONS_UPDATE d -> !Dispatch.integrations_update d
+| GUILD_MEMBER_ADD d -> !Dispatch.member_join d
+| GUILD_MEMBER_REMOVE d -> !Dispatch.member_leave d
+| GUILD_MEMBER_UPDATE d -> !Dispatch.member_update d
+| GUILD_MEMBERS_CHUNK d -> !Dispatch.members_chunk d
+| GUILD_ROLE_CREATE d -> !Dispatch.role_create d
+| GUILD_ROLE_UPDATE d -> !Dispatch.role_update d
+| GUILD_ROLE_DELETE d -> !Dispatch.role_delete d
+| MESSAGE_CREATE d -> !Dispatch.message_create d
+| MESSAGE_UPDATE d -> !Dispatch.message_update d
+| MESSAGE_DELETE (d,e) -> !Dispatch.message_delete d e
+| MESSAGE_BULK_DELETE d -> !Dispatch.message_bulk_delete d
+| MESSAGE_REACTION_ADD d -> !Dispatch.reaction_add d
+| MESSAGE_REACTION_REMOVE d -> !Dispatch.reaction_remove d
+| MESSAGE_REACTION_REMOVE_ALL d -> !Dispatch.reaction_bulk_remove d
+| PRESENCE_UPDATE d -> !Dispatch.presence_update d
+| TYPING_START d -> !Dispatch.typing_start d
+| USER_UPDATE d -> !Dispatch.user_update d
+| VOICE_STATE_UPDATE d -> !Dispatch.voice_state_update d
+| VOICE_SERVER_UPDATE d -> !Dispatch.voice_server_update d
+| WEBHOOKS_UPDATE d -> !Dispatch.webhooks_update d
let handle_event ~ev contents =
(* Printf.printf "Dispatching %s\n%!" ev; *)
diff --git a/lib/http.ml b/lib/http.ml
index 5f8e4e6..77fc9a8 100644
--- a/lib/http.ml
+++ b/lib/http.ml
@@ -22,7 +22,7 @@ module Base = struct
let h = Header.init () in
Header.add_list h [
"User-Agent", "Dis.ml v0.1.0";
- "Authorization", ("Bot " ^ !Config.token);
+ "Authorization", ("Bot " ^ !Client_options.token);
"Content-Type", "application/json";
]
diff --git a/lib/sharder.ml b/lib/sharder.ml
index 823fe28..9ad0022 100644
--- a/lib/sharder.ml
+++ b/lib/sharder.ml
@@ -136,7 +136,7 @@ module Shard = struct
| None -> begin
Mutex.lock identify_lock;
let payload = `Assoc [
- ("token", `String !Config.token);
+ ("token", `String !Client_options.token);
("properties", `Assoc [
("$os", `String Sys.os_type);
("$device", `String "dis.ml");
@@ -155,7 +155,7 @@ module Shard = struct
end
| Some s ->
let payload = `Assoc [
- ("token", `String !Config.token);
+ ("token", `String !Client_options.token);
("session_id", `String s);
("seq", `Int shard.seq)
] in