blob: 6249d4d05f3d3677b724b0ae284bd5dcb6cf9022 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
(** Internal sharding manager. Most of this is accessed through {!Client}. *)
open Core
open Async
open Websocket_async
exception Invalid_Payload
exception Failure_to_Establish_Heartbeat
type t
(** Start the Sharder. This is called by {!Client.start}. *)
val start :
?count:int ->
?compress:bool ->
?large_threshold:int ->
unit ->
t Deferred.t
(** Module representing a single shard. *)
module Shard : sig
(** Representation of the state of a shard. *)
type shard = {
compress: bool; (** Whether to compress payloads. *)
id: int * int; (** A tuple as expected by Discord. First element is the current shard index, second element is the total shard count. *)
hb_interval: Time.Span.t Ivar.t; (** Time span between heartbeats, wrapped in an Ivar. *)
hb_stopper: unit Ivar.t; (** Stops the heartbeat sequencer when filled. *)
large_threshold: int; (** Minimum number of members needed for a guild to be considered large. *)
pipe: Frame.t Pipe.Reader.t * Frame.t Pipe.Writer.t; (** Raw frame IO pipe used for websocket communications. *)
ready: unit Ivar.t; (** A simple Ivar indicating if the shard has received READY. *)
seq: int; (** Current sequence number *)
session: string option; (** Session id, if one exists. *)
url: string; (** The websocket URL in use. *)
_internal: Reader.t * Writer.t;
}
(** Wrapper around an internal state, used to wrap {!shard}. *)
type 'a t = {
mutable state: 'a;
mutable stopped: bool;
mutable can_resume: bool;
}
(** Send a heartbeat to Discord. This is handled automatically. *)
val heartbeat :
shard ->
shard Deferred.t
(** Set the status of the shard. *)
val set_status :
?status:string ->
?kind:int ->
?name:string ->
?since:int ->
?url:string ->
shard ->
shard Deferred.t
(** Request guild members for the shard's guild. Causes dispatch of multiple {{!Dispatch.members_chunk}member chunk} events. *)
val request_guild_members :
?query:string ->
?limit:int ->
guild:Snowflake.t ->
shard ->
shard Deferred.t
(** Create a new shard *)
val create :
url:string ->
shards:int * int ->
?compress:bool ->
?large_threshold:int ->
unit ->
shard Deferred.t
val shutdown :
?clean:bool ->
?restart:bool ->
shard t ->
unit Deferred.t
end
(** Calls {!Shard.set_status} for each shard registered with the sharder. *)
val set_status :
?status:string ->
?kind:int ->
?name:string ->
?since:int ->
?url:string ->
t ->
Shard.shard list Deferred.t
(** Calls {!Shard.request_guild_members} for each shard registered with the sharder. *)
val request_guild_members :
?query:string ->
?limit:int ->
guild:Snowflake.t ->
t ->
Shard.shard list Deferred.t
val shutdown_all :
?restart:bool ->
t ->
unit list Deferred.t
|