aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-13 23:52:45 +0000
committerAdelyn Breedlove <[email protected]>2019-01-13 23:52:45 +0000
commitd95f0342f9cf2280b5d9794ab638c16a59c02a69 (patch)
tree191164d198c07cf388d9aae8a54013e5613c272c
parentMerge branch 'dev' into 'master' (diff)
parentAdd deriving sexp to models (diff)
downloaddisml-d95f0342f9cf2280b5d9794ab638c16a59c02a69.tar.xz
disml-d95f0342f9cf2280b5d9794ab638c16a59c02a69.zip
Merge branch 'switch-to-deriving_yojson' into 'master'
Switch to deriving yojson See merge request Mishio595/disml!12
-rw-r--r--bin/handler.ml75
-rw-r--r--lib/activity.atd5
-rw-r--r--lib/attachment.atd11
-rw-r--r--lib/ban.atd6
-rw-r--r--lib/channel.atd79
-rw-r--r--lib/client.ml6
-rw-r--r--lib/dispatch.ml10
-rw-r--r--lib/dispatch.mli1
-rw-r--r--lib/dune147
-rw-r--r--lib/embed.atd44
-rw-r--r--lib/emoji.atd12
-rw-r--r--lib/event.ml122
-rw-r--r--lib/guild.atd36
-rw-r--r--lib/http.ml6
-rw-r--r--lib/http.mli1
-rw-r--r--lib/member.atd25
-rw-r--r--lib/message.atd29
-rw-r--r--lib/models.ml7
-rw-r--r--lib/models.mli1
-rw-r--r--lib/models/activity.ml10
-rw-r--r--lib/models/attachment.ml14
-rw-r--r--lib/models/ban_t.ml6
-rw-r--r--lib/models/channel.ml38
-rw-r--r--lib/models/channel_t.ml118
-rw-r--r--lib/models/embed.ml62
-rw-r--r--lib/models/emoji.ml19
-rw-r--r--lib/models/guild.ml69
-rw-r--r--lib/models/guild_t.ml67
-rw-r--r--lib/models/member.ml3
-rw-r--r--lib/models/member_t.ml43
-rw-r--r--lib/models/message.ml24
-rw-r--r--lib/models/message_t.ml45
-rw-r--r--lib/models/presence.ml13
-rw-r--r--lib/models/reaction.ml2
-rw-r--r--lib/models/reaction_t.ml14
-rw-r--r--lib/models/role.ml6
-rw-r--r--lib/models/role_t.ml32
-rw-r--r--lib/models/snowflake.ml32
-rw-r--r--lib/models/user.ml10
-rw-r--r--lib/models/user_t.ml13
-rw-r--r--lib/presence.atd13
-rw-r--r--lib/reaction.atd6
-rw-r--r--lib/role.atd22
-rw-r--r--lib/s.ml394
-rw-r--r--lib/sharder.ml13
-rw-r--r--lib/sharder.mli1
-rw-r--r--lib/snowflake.atd1
-rw-r--r--lib/user.atd13
48 files changed, 814 insertions, 912 deletions
diff --git a/bin/handler.ml b/bin/handler.ml
index 5b22527..5afbbee 100644
--- a/bin/handler.ml
+++ b/bin/handler.ml
@@ -4,11 +4,12 @@ module Make(Models : Disml.S.Models) = struct
open Models
open Disml.Event
- let check_command (msg:Disml.Message_t.t) =
+ let check_command (msg:Message.t) =
if String.is_prefix ~prefix:"!ping" msg.content then
Message.reply msg "Pong!" >>> ignore
else if String.is_prefix ~prefix:"!spam" msg.content then
- List.range 0 20
+ let count = String.chop_prefix_exn ~prefix:"!spam" msg.content |> String.strip |> Int.of_string in
+ List.range 0 count
|> List.iter ~f:(fun i -> Message.reply msg (string_of_int i) >>> ignore)
else if String.is_prefix ~prefix:"!list" msg.content then
let count = String.chop_prefix_exn ~prefix:"!list" msg.content |> String.strip |> Int.of_string in
@@ -24,39 +25,39 @@ module Make(Models : Disml.S.Models) = struct
Message.reply msg list >>> ignore
let handle_event = function
- | HELLO _ -> print_endline "Received HELLO"
- | READY _ -> print_endline "Received READY"
- | RESUMED _ -> print_endline "Received RESUMED"
- | INVALID_SESSION _ -> print_endline "Received INVALID_SESSION"
- | CHANNEL_CREATE _ -> print_endline "Received CHANNEL_CREATE"
- | CHANNEL_UPDATE _ -> print_endline "Received CHANNEL_UPDATE"
- | CHANNEL_DELETE _ -> print_endline "Received CHANNEL_DELETE"
- | CHANNEL_PINS_UPDATE _ -> print_endline "Received CHANNEL_PINS_UPDATE"
- | GUILD_CREATE _ -> print_endline "Received GUILD_CREATE"
- | GUILD_UPDATE _ -> print_endline "Received GUILD_UPDATE"
- | GUILD_DELETE _ -> print_endline "Received GUILD_DELETE"
- | GUILD_BAN_ADD _ -> print_endline "Received GUILD_BAN_ADD"
- | GUILD_BAN_REMOVE _ -> print_endline "Received GUILD_BAN_REMOVE"
- | GUILD_EMOJIS_UPDATE _ -> print_endline "Received GUILD_EMOJIS_UPDATE"
- | GUILD_INTEGRATIONS_UPDATE _ -> print_endline "Received GUILD_INTEGRATIONS_UPDATE"
- | GUILD_MEMBER_ADD _ -> print_endline "Received GUILD_MEMBER_ADD"
- | GUILD_MEMBER_REMOVE _ -> print_endline "Received GUILD_MEMBER_REMOVE"
- | GUILD_MEMBER_UPDATE _ -> print_endline "Received GUILD_MEMBER_UPDATE"
- | GUILD_MEMBERS_CHUNK _ -> print_endline "Received GUILD_MEMBERS_CHUNK"
- | GUILD_ROLE_CREATE _ -> print_endline "Received GUILD_ROLE_CREATE"
- | GUILD_ROLE_UPDATE _ -> print_endline "Received GUILD_ROLE_UPDATE"
- | GUILD_ROLE_DELETE _ -> print_endline "Received GUILD_ROLE_DELETE"
- | MESSAGE_CREATE msg -> check_command msg; print_endline "Received MESSAGE_CREATE"
- | MESSAGE_UPDATE _ -> print_endline "Received MESSAGE_UPDATE"
- | MESSAGE_DELETE _ -> print_endline "Received MESSAGE_DELETE"
- | MESSAGE_BULK_DELETE _ -> print_endline "Received MESSAGE_BULK_DELETE"
- | MESSAGE_REACTION_ADD _ -> print_endline "Received MESSAGE_REACTION_ADD"
- | MESSAGE_REACTION_REMOVE _ -> print_endline "Received MESSAGE_REACTION_REMOVE"
- | MESSAGE_REACTION_REMOVE_ALL _ -> print_endline "Received MESSAGE_REACTION_REMOVE_ALL"
- | PRESENCE_UPDATE _ -> print_endline "Received PRESENCE_UPDATE"
- | TYPING_START _ -> print_endline "Received TYPING_START"
- | USER_UPDATE _ -> print_endline "Received USER_UPDATE"
- | VOICE_STATE_UPDATE _ -> print_endline "Received VOICE_STATE_UPDATE"
- | VOICE_SERVER_UPDATE _ -> print_endline "Received VOICE_SERVER_UPDATE"
+ | HELLO _ -> print_endline "Received HELLO"
+ | READY _ -> print_endline "Received READY"
+ | RESUMED _ -> print_endline "Received RESUMED"
+ | INVALID_SESSION _ -> print_endline "Received INVALID_SESSION"
+ | CHANNEL_CREATE _ -> print_endline "Received CHANNEL_CREATE"
+ | CHANNEL_UPDATE _ -> print_endline "Received CHANNEL_UPDATE"
+ | CHANNEL_DELETE _ -> print_endline "Received CHANNEL_DELETE"
+ | CHANNEL_PINS_UPDATE _ -> print_endline "Received CHANNEL_PINS_UPDATE"
+ | GUILD_CREATE _ -> print_endline "Received GUILD_CREATE"
+ | GUILD_UPDATE _ -> print_endline "Received GUILD_UPDATE"
+ | GUILD_DELETE _ -> print_endline "Received GUILD_DELETE"
+ | GUILD_BAN_ADD _ -> print_endline "Received GUILD_BAN_ADD"
+ | GUILD_BAN_REMOVE _ -> print_endline "Received GUILD_BAN_REMOVE"
+ | GUILD_EMOJIS_UPDATE _ -> print_endline "Received GUILD_EMOJIS_UPDATE"
+ | GUILD_INTEGRATIONS_UPDATE _ -> print_endline "Received GUILD_INTEGRATIONS_UPDATE"
+ | GUILD_MEMBER_ADD _ -> print_endline "Received GUILD_MEMBER_ADD"
+ | GUILD_MEMBER_REMOVE _ -> print_endline "Received GUILD_MEMBER_REMOVE"
+ | GUILD_MEMBER_UPDATE _ -> print_endline "Received GUILD_MEMBER_UPDATE"
+ | GUILD_MEMBERS_CHUNK _ -> print_endline "Received GUILD_MEMBERS_CHUNK"
+ | GUILD_ROLE_CREATE _ -> print_endline "Received GUILD_ROLE_CREATE"
+ | GUILD_ROLE_UPDATE _ -> print_endline "Received GUILD_ROLE_UPDATE"
+ | GUILD_ROLE_DELETE _ -> print_endline "Received GUILD_ROLE_DELETE"
+ | MESSAGE_CREATE msg -> check_command msg; print_endline "Received MESSAGE_CREATE"
+ | MESSAGE_UPDATE _ -> print_endline "Received MESSAGE_UPDATE"
+ | MESSAGE_DELETE _ -> print_endline "Received MESSAGE_DELETE"
+ | MESSAGE_BULK_DELETE _ -> print_endline "Received MESSAGE_BULK_DELETE"
+ | MESSAGE_REACTION_ADD _ -> print_endline "Received MESSAGE_REACTION_ADD"
+ | MESSAGE_REACTION_REMOVE _ -> print_endline "Received MESSAGE_REACTION_REMOVE"
+ | MESSAGE_REACTION_REMOVE_ALL _ -> print_endline "Received MESSAGE_REACTION_REMOVE_ALL"
+ | PRESENCE_UPDATE _ -> print_endline "Received PRESENCE_UPDATE"
+ | TYPING_START _ -> print_endline "Received TYPING_START"
+ | USER_UPDATE _ -> print_endline "Received USER_UPDATE"
+ | VOICE_STATE_UPDATE _ -> print_endline "Received VOICE_STATE_UPDATE"
+ | VOICE_SERVER_UPDATE _ -> print_endline "Received VOICE_SERVER_UPDATE"
| WEBHOOKS_UPDATE _ -> print_endline "Received WEBHOOKS_UPDATE"
-end \ No newline at end of file
+end
diff --git a/lib/activity.atd b/lib/activity.atd
deleted file mode 100644
index 8e02191..0000000
--- a/lib/activity.atd
+++ /dev/null
@@ -1,5 +0,0 @@
-type t = {
- name: string;
- kind <json name="type">: int;
- ?url: string option;
-} \ No newline at end of file
diff --git a/lib/attachment.atd b/lib/attachment.atd
deleted file mode 100644
index 9757b49..0000000
--- a/lib/attachment.atd
+++ /dev/null
@@ -1,11 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-
-type t = {
- id: snowflake;
- filename: string;
- size: int;
- url: string;
- proxy_url: string;
- ?height: int option;
- ?width: int option;
-} \ No newline at end of file
diff --git a/lib/ban.atd b/lib/ban.atd
deleted file mode 100644
index 0a87338..0000000
--- a/lib/ban.atd
+++ /dev/null
@@ -1,6 +0,0 @@
-type user <ocaml from="User" t="t"> = abstract
-
-type t = {
- ?reason: string option;
- user: user;
-} \ No newline at end of file
diff --git a/lib/channel.atd b/lib/channel.atd
deleted file mode 100644
index 4094ff1..0000000
--- a/lib/channel.atd
+++ /dev/null
@@ -1,79 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-
-type group = {
- id: snowflake;
- ?last_message_id: snowflake option;
- ?last_pin_timestamp: string option;
- ?icon: string option;
- ?name: string option;
- owner_id: snowflake;
- recipients: user list;
-}
-
-type dm = {
- id: snowflake;
- ?last_message_id: snowflake option;
- ?last_pin_timestamp: string option;
-}
-
-type guild_text = {
- id: snowflake;
- ?last_message_id: snowflake option;
- ?last_pin_timestamp: string option;
- ?category_id <json name="parent_id">: snowflake option;
- guild_id: snowflake;
- name: string;
- position: int;
- ?topic: string option;
- nsfw: bool;
- ?slow_mode_timeout <json name="rate_limit_per_user">: int option;
-}
-
-type guild_voice = {
- id: snowflake;
- ?category_id <json name="parent_id">: snowflake option;
- guild_id: snowflake;
- name: string;
- position: int;
- ?topic: string option;
- nsfw: bool;
- ?user_limit: int option;
- ?bitrate: int option;
-}
-
-type category = {
- id: snowflake;
- ?category_id <json name="parent_id">: snowflake option;
- position: int;
- name: string;
- nsfw: bool;
-}
-
-type t = [
- Group of group
- | Private of dm
- | GuildText of guild_text
- | GuildVoice of guild_voice
- | Category of category
-]
-
-type channel_wrapper = {
- id: snowflake;
- kind <json name="type">: int;
- ?guild_id: snowflake option;
- ?position: int option;
- ?name: string option;
- ?topic: string option;
- ?nsfw: bool option;
- ?last_message_id: snowflake option;
- ?bitrate: int option;
- ?user_limit: int option;
- ?rate_limit_per_user: int option;
- ?recipients: user list option;
- ?icon: string option;
- ?owner_id: snowflake option;
- ?application_id: snowflake option;
- ?category_id <json name="parent_id">: snowflake option;
- ?last_pin_timestamp: string option;
-} \ No newline at end of file
diff --git a/lib/client.ml b/lib/client.ml
index 229c9cc..6ee4a3a 100644
--- a/lib/client.ml
+++ b/lib/client.ml
@@ -1,7 +1,5 @@
-open Async
-
module Make(T : S.Token)(H : S.Handler_f) = struct
- include T
+ open Async
module Http = Http.Make(T)
module Models = Models.Make(Http)
@@ -14,6 +12,8 @@ module Make(T : S.Token)(H : S.Handler_f) = struct
token: string;
}
+ let token = T.token
+
let start ?count () =
Sharder.start ?count ()
>>| fun sharder ->
diff --git a/lib/dispatch.ml b/lib/dispatch.ml
index 66c6fee..4a9b791 100644
--- a/lib/dispatch.ml
+++ b/lib/dispatch.ml
@@ -1,7 +1,9 @@
-module Make(H : S.Handler) : S.Dispatch = struct
+module Make(H : sig val handle_event : Event.t -> unit end) : S.Dispatch = struct
let dispatch ~ev contents =
- Printf.printf "Dispatching %s\n%!" ev;
+ (* Printf.printf "Dispatching %s\n%!" ev; *)
(* print_endline (Yojson.Safe.prettify contents); *)
- Event.event_of_string ~contents ev
- |> H.handle_event
+ try
+ Event.event_of_yojson ~contents ev
+ |> H.handle_event
+ with Event.Invalid_event ev -> Printf.printf "Unknown event: %s%!" ev
end \ No newline at end of file
diff --git a/lib/dispatch.mli b/lib/dispatch.mli
deleted file mode 100644
index 100a34b..0000000
--- a/lib/dispatch.mli
+++ /dev/null
@@ -1 +0,0 @@
-module Make(H : S.Handler) : S.Dispatch \ No newline at end of file
diff --git a/lib/dune b/lib/dune
index 667d021..0e28b0b 100644
--- a/lib/dune
+++ b/lib/dune
@@ -1,139 +1,26 @@
-(rule
- (targets activity_t.ml activity_t.mli)
- (deps activity.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets activity_j.ml activity_j.mli)
- (deps activity.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets attachment_t.ml attachment_t.mli)
- (deps attachment.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets attachment_j.ml attachment_j.mli)
- (deps attachment.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets ban_t.ml ban_t.mli)
- (deps ban.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets ban_j.ml ban_j.mli)
- (deps ban.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets channel_t.ml channel_t.mli)
- (deps channel.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets channel_j.ml channel_j.mli)
- (deps channel.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets embed_t.ml embed_t.mli)
- (deps embed.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets embed_j.ml embed_j.mli)
- (deps embed.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets emoji_t.ml emoji_t.mli)
- (deps emoji.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets emoji_j.ml emoji_j.mli)
- (deps emoji.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets guild_t.ml guild_t.mli)
- (deps guild.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets guild_j.ml guild_j.mli)
- (deps guild.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets member_t.ml member_t.mli)
- (deps member.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets member_j.ml member_j.mli)
- (deps member.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets message_t.ml message_t.mli)
- (deps message.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets message_j.ml message_j.mli)
- (deps message.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets presence_t.ml presence_t.mli)
- (deps presence.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets presence_j.ml presence_j.mli)
- (deps presence.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets reaction_t.ml reaction_t.mli)
- (deps reaction.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets reaction_j.ml reaction_j.mli)
- (deps reaction.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets role_t.ml role_t.mli)
- (deps role.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets role_j.ml role_j.mli)
- (deps role.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets snowflake_t.ml snowflake_t.mli)
- (deps snowflake.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets snowflake_j.ml snowflake_j.mli)
- (deps snowflake.atd)
- (action (run atdgen -j %{deps})))
-(rule
- (targets user_t.ml user_t.mli)
- (deps user.atd)
- (action (run atdgen -t %{deps})))
-(rule
- (targets user_j.ml user_j.mli)
- (deps user.atd)
- (action (run atdgen -j %{deps})))
-
(library
(name disml)
(public_name disml)
(synopsis "An OCaml library for interfacing with the Discord API")
(modules
- activity_t activity_j
- attachment_t attachment_j
- ban_t ban_j
- channel_t channel_j
- embed_t embed_j
- emoji_t emoji_j
- guild_t guild_j
- member_t member_j
- message_t message_j
- presence_t presence_j
- reaction_t reaction_j
- role_t role_j
- snowflake_t snowflake_j
- user_t user_j
- activity attachment ban channel embed emoji guild member message presence reaction role snowflake user client dispatch endpoints event http models opcode rl s sharder
+ activity
+ attachment
+ ban ban_t
+ channel channel_t
+ embed
+ emoji
+ guild guild_t
+ member member_t
+ message message_t
+ presence
+ reaction reaction_t
+ role role_t
+ snowflake
+ user user_t
+ client dispatch endpoints event http models opcode rl s sharder
)
- (libraries core async_ssl cohttp-async yojson websocket-async zlib atdgen)
- (preprocess (pps ppx_jane))
+ (libraries core async_ssl cohttp-async yojson websocket-async zlib ppx_deriving_yojson.runtime)
+ (preprocess (pps ppx_jane ppx_deriving_yojson))
)
(include_subdirs unqualified)
diff --git a/lib/embed.atd b/lib/embed.atd
deleted file mode 100644
index 0d3aed4..0000000
--- a/lib/embed.atd
+++ /dev/null
@@ -1,44 +0,0 @@
-type footer = {
- text: string;
- ?icon_url: string option;
- ?proxy_icon_url: string option;
-}
-
-type image = {
- ?url: string option;
- ?proxy_url: string option;
- ?height: int option;
- ?width: int option;
-}
-
-type video = {
- ?url: string option;
- ?height: int option;
- ?width: int option;
-}
-
-type provider = {
- ?name: string option;
- ?url: string option;
-}
-
-type field = {
- name: string;
- value: string;
- ?inline: bool option;
-}
-
-type t = {
- ?title: string option;
- ?kind: string option;
- ?description: string option;
- ?url: string option;
- ?timestamp: string option;
- ?colour: int option;
- ?footer: footer option;
- ?image: image option;
- ?thumbnail: image option;
- ?video: video option;
- ?provider: provider option;
- ?fields: field list option;
-} \ No newline at end of file
diff --git a/lib/emoji.atd b/lib/emoji.atd
deleted file mode 100644
index 877323b..0000000
--- a/lib/emoji.atd
+++ /dev/null
@@ -1,12 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-
-type t = {
- ?id: snowflake option;
- name: string;
- ?roles: snowflake list option;
- ?user: user option;
- ?require_colons: bool option;
- ?managed: bool option;
- ?animated: bool option;
-} \ No newline at end of file
diff --git a/lib/event.ml b/lib/event.ml
index 8e04fee..d6a6372 100644
--- a/lib/event.ml
+++ b/lib/event.ml
@@ -1,5 +1,7 @@
open Core
+exception Invalid_event of string
+
type t =
| HELLO of Yojson.Safe.json
| READY of Yojson.Safe.json
@@ -17,82 +19,60 @@ type t =
| GUILD_EMOJIS_UPDATE of Yojson.Safe.json
| GUILD_INTEGRATIONS_UPDATE of Yojson.Safe.json
| GUILD_MEMBER_ADD of Member_t.t
-| GUILD_MEMBER_REMOVE of Member_t.t
-| GUILD_MEMBER_UPDATE of Member_t.t
+| GUILD_MEMBER_REMOVE of Member_t.member_wrapper
+| GUILD_MEMBER_UPDATE of Member_t.member_update
| GUILD_MEMBERS_CHUNK of Member_t.t list
-| GUILD_ROLE_CREATE of Role_t.t (* * Guild.t *)
-| GUILD_ROLE_UPDATE of Role_t.t (* * Guild.t *)
-| GUILD_ROLE_DELETE of Role_t.t (* * Guild.t *)
+| GUILD_ROLE_CREATE of Role_t.t (* * Guild_t.t *)
+| GUILD_ROLE_UPDATE of Role_t.t (* * Guild_t.t *)
+| GUILD_ROLE_DELETE of Role_t.t (* * Guild_t.t *)
| MESSAGE_CREATE of Message_t.t
-| MESSAGE_UPDATE of Message_t.t
-| MESSAGE_DELETE of Message_t.t
-| MESSAGE_BULK_DELETE of Message_t.t list
-| MESSAGE_REACTION_ADD of (* Message.t * *) Reaction_t.t
-| MESSAGE_REACTION_REMOVE of (* Message.t * *) Reaction_t.t
-| MESSAGE_REACTION_REMOVE_ALL of (* Message.t * *) Reaction_t.t list
-| PRESENCE_UPDATE of Presence_t.t
+| MESSAGE_UPDATE of Message_t.message_update
+| MESSAGE_DELETE of Snowflake.t * Snowflake.t
+| MESSAGE_BULK_DELETE of Snowflake.t list
+| MESSAGE_REACTION_ADD of Reaction_t.reaction_event
+| MESSAGE_REACTION_REMOVE of Reaction_t.reaction_event
+| MESSAGE_REACTION_REMOVE_ALL of Reaction_t.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
-
-let wrap_role ~guild_id role =
- let open Role_t in
- let {id;name;colour;hoist;position;permissions;managed;mentionable} = role in
- {id;name;colour;hoist;position;permissions;managed;mentionable;guild_id}
-
-let wrap_member ~guild_id member =
- let open Member_t in
- let {nick;roles;joined_at;deaf;mute;user} = member in
- {nick;roles;joined_at;deaf;mute;user;guild_id}
-
-let wrap_channel s : Channel_t.t =
- let module J = Yojson.Safe in
- match J.(from_string s |> Util.member "kind" |> Util.to_int) with
- | 0 -> `GuildText (Channel_j.guild_text_of_string s)
- | 1 -> `Private (Channel_j.dm_of_string s)
- | 2 -> `GuildVoice (Channel_j.guild_voice_of_string s)
- | 3 -> `Group (Channel_j.group_of_string s)
- | 4 -> `Category (Channel_j.category_of_string s)
- | _ -> raise (Invalid_event s)
-
-let event_of_string ~contents t = match t with
- | "HELLO" -> HELLO (Yojson.Safe.from_string contents)
- | "READY" -> READY (Yojson.Safe.from_string contents)
- | "RESUMED" -> RESUMED (Yojson.Safe.from_string contents)
- | "INVALID_SESSION" -> INVALID_SESSION (Yojson.Safe.from_string contents)
- | "CHANNEL_CREATE" -> CHANNEL_CREATE (wrap_channel contents)
- | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (wrap_channel contents)
- | "CHANNEL_DELETE" -> CHANNEL_DELETE (wrap_channel contents)
- | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE (Yojson.Safe.from_string contents)
- | "GUILD_CREATE" -> GUILD_CREATE (Guild_j.t_of_string contents)
- | "GUILD_UPDATE" -> GUILD_UPDATE (Guild_j.t_of_string contents)
- | "GUILD_DELETE" -> GUILD_DELETE (Guild_j.t_of_string contents)
- | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban_j.t_of_string contents)
- | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban_j.t_of_string contents)
- | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE (Yojson.Safe.from_string contents)
- | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE (Yojson.Safe.from_string contents)
- | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (let Member_t.{guild_id;member} = Member_j.member_update_of_string contents in wrap_member ~guild_id member)
- | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (let Member_t.{guild_id;member} = Member_j.member_update_of_string contents in wrap_member ~guild_id member)
- | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (let Member_t.{guild_id;member} = Member_j.member_update_of_string contents in wrap_member ~guild_id member)
- | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Member_j.t_of_string))
- | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (let Role_t.{guild_id;role} = Role_j.role_update_of_string contents in wrap_role ~guild_id role)
- | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (let Role_t.{guild_id;role} = Role_j.role_update_of_string contents in wrap_role ~guild_id role)
- | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (let Role_t.{guild_id;role} = Role_j.role_update_of_string contents in wrap_role ~guild_id role)
- | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_j.t_of_string contents)
- | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_j.t_of_string contents)
- | "MESSAGE_DELETE" -> MESSAGE_DELETE (Message_j.t_of_string contents)
- | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Message_j.t_of_string))
- | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_j.t_of_string contents)
- | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_j.t_of_string contents)
- | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.(from_string contents |> Util.to_list) |> List.map ~f:(fun m -> Yojson.Safe.to_string m |> Reaction_j.t_of_string))
- | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence_j.t_of_string contents)
- | "TYPING_START" -> TYPING_START (Yojson.Safe.from_string contents)
- | "USER_UPDATE" -> USER_UPDATE (Yojson.Safe.from_string contents)
- | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE (Yojson.Safe.from_string contents)
- | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE (Yojson.Safe.from_string contents)
- | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE (Yojson.Safe.from_string contents)
- | s -> raise (Invalid_event s) \ No newline at end of file
+let event_of_yojson ~contents t = match t with
+ | "HELLO" -> HELLO contents
+ | "READY" -> READY contents
+ | "RESUMED" -> RESUMED contents
+ | "INVALID_SESSION" -> INVALID_SESSION contents
+ | "CHANNEL_CREATE" -> CHANNEL_CREATE (Channel_t.(channel_wrapper_of_yojson_exn contents |> wrap))
+ | "CHANNEL_UPDATE" -> CHANNEL_UPDATE (Channel_t.(channel_wrapper_of_yojson_exn contents |> wrap))
+ | "CHANNEL_DELETE" -> CHANNEL_DELETE (Channel_t.(channel_wrapper_of_yojson_exn contents |> wrap))
+ | "CHANNEL_PINS_UPDATE" -> CHANNEL_PINS_UPDATE contents
+ | "GUILD_CREATE" -> GUILD_CREATE (Guild_t.(pre_of_yojson_exn contents |> wrap))
+ | "GUILD_UPDATE" -> GUILD_UPDATE (Guild_t.(pre_of_yojson_exn contents |> wrap))
+ | "GUILD_DELETE" -> GUILD_DELETE (Guild_t.(pre_of_yojson_exn contents |> wrap))
+ | "GUILD_BAN_ADD" -> GUILD_BAN_ADD (Ban_t.of_yojson_exn contents)
+ | "GUILD_BAN_REMOVE" -> GUILD_BAN_REMOVE (Ban_t.of_yojson_exn contents)
+ | "GUILD_EMOJIS_UPDATE" -> GUILD_EMOJIS_UPDATE contents
+ | "GUILD_INTEGRATIONS_UPDATE" -> GUILD_INTEGRATIONS_UPDATE contents
+ | "GUILD_MEMBER_ADD" -> GUILD_MEMBER_ADD (Member_t.of_yojson_exn contents)
+ | "GUILD_MEMBER_REMOVE" -> GUILD_MEMBER_REMOVE (Member_t.member_wrapper_of_yojson_exn contents)
+ | "GUILD_MEMBER_UPDATE" -> GUILD_MEMBER_UPDATE (Member_t.member_update_of_yojson_exn contents)
+ | "GUILD_MEMBERS_CHUNK" -> GUILD_MEMBERS_CHUNK (Yojson.Safe.Util.to_list contents |> List.map ~f:Member_t.of_yojson_exn)
+ | "GUILD_ROLE_CREATE" -> GUILD_ROLE_CREATE (let Role_t.{guild_id;role} = Role_t.role_update_of_yojson_exn contents in Role_t.wrap ~guild_id role)
+ | "GUILD_ROLE_UPDATE" -> GUILD_ROLE_UPDATE (let Role_t.{guild_id;role} = Role_t.role_update_of_yojson_exn contents in Role_t.wrap ~guild_id role)
+ | "GUILD_ROLE_DELETE" -> GUILD_ROLE_DELETE (let Role_t.{guild_id;role} = Role_t.role_update_of_yojson_exn contents in Role_t.wrap ~guild_id role)
+ | "MESSAGE_CREATE" -> MESSAGE_CREATE (Message_t.of_yojson_exn contents)
+ | "MESSAGE_UPDATE" -> MESSAGE_UPDATE (Message_t.message_update_of_yojson_exn contents)
+ | "MESSAGE_DELETE" -> MESSAGE_DELETE (Yojson.Safe.Util.(member "id" contents |> Snowflake.of_yojson_exn), Yojson.Safe.Util.(member "channel_id" contents |> Snowflake.of_yojson_exn))
+ | "MESSAGE_BULK_DELETE" -> MESSAGE_BULK_DELETE (Yojson.Safe.Util.to_list contents |> List.map ~f:Snowflake.of_yojson_exn)
+ | "MESSAGE_REACTION_ADD" -> MESSAGE_REACTION_ADD (Reaction_t.reaction_event_of_yojson_exn contents)
+ | "MESSAGE_REACTION_REMOVE" -> MESSAGE_REACTION_REMOVE (Reaction_t.reaction_event_of_yojson_exn contents)
+ | "MESSAGE_REACTION_REMOVE_ALL" -> MESSAGE_REACTION_REMOVE_ALL (Yojson.Safe.Util.to_list contents |> List.map ~f:Reaction_t.of_yojson_exn)
+ | "PRESENCE_UPDATE" -> PRESENCE_UPDATE (Presence.of_yojson_exn contents)
+ | "TYPING_START" -> TYPING_START contents
+ | "USER_UPDATE" -> USER_UPDATE contents
+ | "VOICE_STATE_UPDATE" -> VOICE_STATE_UPDATE contents
+ | "VOICE_SERVER_UPDATE" -> VOICE_SERVER_UPDATE contents
+ | "WEBHOOKS_UPDATE" -> WEBHOOKS_UPDATE contents
+ | s -> raise @@ Invalid_event s \ No newline at end of file
diff --git a/lib/guild.atd b/lib/guild.atd
deleted file mode 100644
index c290b5f..0000000
--- a/lib/guild.atd
+++ /dev/null
@@ -1,36 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-type member <ocaml from="Member" t="member"> = abstract
-type role <ocaml from="Role" t="role"> = abstract
-type channel <ocaml from="Channel" t="channel_wrapper"> = abstract
-type emoji <ocaml from="Emoji" t="t"> = abstract
-
-
-type t = {
- id: snowflake;
- name: string;
- ?icon: string option;
- ?splash: string option;
- owner_id: snowflake;
- region: string;
- ?afk_channel_id: snowflake option;
- afk_timeout: int;
- ?embed_enabled: bool option;
- ?embed_channel_id: snowflake option;
- verification_level: int;
- default_message_notifications: int;
- explicit_content_filter: int;
- roles: role list;
- emojis: emoji list;
- features: string list;
- mfa_level: int;
- ?application_id: snowflake option;
- ?widget_enabled: bool option;
- ?widget_channel: channel option;
- ?system_channel: channel option;
- ~large: bool;
- ~unavailable: bool;
- ?member_count: int option;
- ~members: member list;
- ~channels: channel list;
-} \ No newline at end of file
diff --git a/lib/http.ml b/lib/http.ml
index f04a49f..9ef9334 100644
--- a/lib/http.ml
+++ b/lib/http.ml
@@ -2,7 +2,8 @@ module Make(T : S.Token) = struct
open Core
open Async
open Cohttp
- include T
+
+ let token = T.token
module Base = struct
exception Invalid_Method
@@ -35,12 +36,11 @@ module Make(T : S.Token) = struct
| None -> raise Bad_response_headers)
>>= fun () ->
match resp |> Response.status |> Code.code_of_status with
- | 200 -> body |> Cohttp_async.Body.to_string >>= Deferred.Or_error.return
+ | 200 -> body |> Cohttp_async.Body.to_string >>| Yojson.Safe.from_string >>= Deferred.Or_error.return
| code ->
body |> Cohttp_async.Body.to_string >>= fun body ->
Deferred.Or_error.errorf "Unsuccessful response received: %d - %s" code body
-
let request ?(body=`Null) m path =
rl := Rl.update ~f:(function
| None ->
diff --git a/lib/http.mli b/lib/http.mli
deleted file mode 100644
index 858420a..0000000
--- a/lib/http.mli
+++ /dev/null
@@ -1 +0,0 @@
-module Make(T : S.Token) : S.Http \ No newline at end of file
diff --git a/lib/member.atd b/lib/member.atd
deleted file mode 100644
index c87e40c..0000000
--- a/lib/member.atd
+++ /dev/null
@@ -1,25 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-
-type partial_member = {
- ?nick: string option;
- roles: snowflake list;
- joined_at: string;
- deaf: bool;
- mute: bool;
-}
-
-type member = {
- inherit partial_member;
- user: user;
-}
-
-type member_update = {
- guild_id <json name="id">: snowflake;
- member: member;
-}
-
-type t = {
- inherit member;
- guild_id: snowflake;
-} \ No newline at end of file
diff --git a/lib/message.atd b/lib/message.atd
deleted file mode 100644
index 8611f6a..0000000
--- a/lib/message.atd
+++ /dev/null
@@ -1,29 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-type member <ocaml from="Member" t="t"> = abstract
-type partial_member <ocaml from="Member" t="partial_member"> = abstract
-type attachment <ocaml from="Attachment" t="t"> = abstract
-type embed <ocaml from="Embed" t="t"> = abstract
-type reaction <ocaml from="Reaction" t="t"> = abstract
-
-type t = {
- id: snowflake;
- author: user;
- channel_id: snowflake;
- ?member: partial_member option;
- ?guild_id: snowflake option;
- content: string;
- timestamp: string;
- ?edited_timestamp: string option;
- tts: bool;
- mention_everyone: bool;
- mentions: snowflake list;
- ?role_mentions: snowflake list option;
- attachments: attachment list;
- embeds: embed list;
- ?reactions: snowflake list option;
- ?nonce: snowflake option;
- pinned: bool;
- ?webhook_id: snowflake option;
- kind <json name="type">: int;
-} \ No newline at end of file
diff --git a/lib/models.ml b/lib/models.ml
index 250de34..bfcc428 100644
--- a/lib/models.ml
+++ b/lib/models.ml
@@ -1,17 +1,10 @@
module Make(H : S.Http) = struct
- module Http = H
- module Activity = Activity.Make(H)
- module Attachment = Attachment.Make(H)
module Ban = Ban.Make(H)
module Channel = Channel.Make(H)
- module Embed = Embed.Make(H)
- module Emoji = Emoji.Make(H)
module Guild = Guild.Make(H)
module Member = Member.Make(H)
module Message = Message.Make(H)
- module Presence = Presence.Make(H)
module Reaction = Reaction.Make(H)
module Role = Role.Make(H)
- module Snowflake = Snowflake.Make(H)
module User = User.Make(H)
end \ No newline at end of file
diff --git a/lib/models.mli b/lib/models.mli
deleted file mode 100644
index 01a8893..0000000
--- a/lib/models.mli
+++ /dev/null
@@ -1 +0,0 @@
-module Make(H : S.Http) : S.Models \ No newline at end of file
diff --git a/lib/models/activity.ml b/lib/models/activity.ml
index 6fe69b8..8e6ff80 100644
--- a/lib/models/activity.ml
+++ b/lib/models/activity.ml
@@ -1,3 +1,7 @@
-module Make(Http : S.Http) = struct
- type t = Activity_t.t
-end \ No newline at end of file
+open Core
+
+type t = {
+ name: string;
+ kind: int [@key "type"];
+ url: string [@default ""];
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml
index cd04da8..c56b389 100644
--- a/lib/models/attachment.ml
+++ b/lib/models/attachment.ml
@@ -1,3 +1,11 @@
-module Make(Http : S.Http) = struct
- type t = Attachment_t.t
-end \ No newline at end of file
+open Core
+
+type t = {
+ id: Snowflake.t;
+ filename: string;
+ size: int;
+ url: string;
+ proxy_url: string;
+ height: int [@default -1];
+ width: int [@default -1];
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/ban_t.ml b/lib/models/ban_t.ml
new file mode 100644
index 0000000..b49eefc
--- /dev/null
+++ b/lib/models/ban_t.ml
@@ -0,0 +1,6 @@
+open Core
+
+type t = {
+ reason: string [@default ""];
+ user: User_t.t;
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/channel.ml b/lib/models/channel.ml
index 15202b1..3fab452 100644
--- a/lib/models/channel.ml
+++ b/lib/models/channel.ml
@@ -1,22 +1,14 @@
-exception Invalid_message
-exception No_message_found
-
-let get_id (ch:Channel_t.t) = match ch with
-| `Group g -> g.id
-| `Private p -> p.id
-| `GuildText t -> t.id
-| `GuildVoice v -> v.id
-| `Category c -> c.id
-
module Make(Http : S.Http) = struct
open Async
open Core
+ include Channel_t
- type t = Channel_t.t
-
+ exception Invalid_message
+ exception No_message_found
+
let say ~content ch =
Http.create_message (get_id ch) (`Assoc [("content", `String content)])
- >>| Result.map ~f:Message_j.t_of_string
+ >>| Result.map ~f:Message_t.of_yojson_exn
let send_message ?embed ?content ?file ?(tts=false) ch =
let embed = match embed with
@@ -36,13 +28,13 @@ module Make(Http : S.Http) = struct
("content", content);
("file", file);
("tts", `Bool tts);
- ]) >>| Result.map ~f:Message_j.t_of_string
+ ]) >>| Result.map ~f:Message_t.of_yojson_exn
let delete ch =
Http.delete_channel (get_id ch) >>| Result.map ~f:ignore
let get_message ~id ch =
- Http.get_message (get_id ch) id >>| Result.map ~f:Message_j.t_of_string
+ Http.get_message (get_id ch) id >>| Result.map ~f:Message_t.of_yojson_exn
let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
let kind = match mode with
@@ -54,20 +46,14 @@ module Make(Http : S.Http) = struct
| Some id -> id
| None -> raise No_message_found in
Http.get_messages (get_id ch) id kind >>| Result.map ~f:(fun l ->
- Yojson.Safe.(from_string l
- |> Util.to_list)
- |> List.map ~f:(fun i ->
- Yojson.Safe.to_string i
- |> Message_j.t_of_string))
-
+ Yojson.Safe.Util.to_list l
+ |> List.map ~f:Message_t.of_yojson_exn)
+
let broadcast_typing ch =
Http.broadcast_typing (get_id ch) >>| Result.map ~f:ignore
let get_pins ch =
Http.get_pinned_messages (get_id ch) >>| Result.map ~f:(fun l ->
- Yojson.Safe.(from_string l
- |> Util.to_list)
- |> List.map ~f:(fun i ->
- Yojson.Safe.to_string i
- |> Message_j.t_of_string))
+ Yojson.Safe.Util.to_list l
+ |> List.map ~f:Message_t.of_yojson_exn)
end \ No newline at end of file
diff --git a/lib/models/channel_t.ml b/lib/models/channel_t.ml
new file mode 100644
index 0000000..dce1d54
--- /dev/null
+++ b/lib/models/channel_t.ml
@@ -0,0 +1,118 @@
+open Core
+
+exception Invalid_channel of Yojson.Safe.json
+
+type group = {
+ id: Snowflake.t;
+ last_message_id: Snowflake.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+ icon: string option [@default None];
+ name: string option [@default None];
+ owner_id: Snowflake.t;
+ recipients: User_t.t list [@default []];
+} [@@deriving sexp, yojson { strict = false}]
+
+type dm = {
+ id: Snowflake.t;
+ last_message_id: Snowflake.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type guild_text = {
+ id: Snowflake.t;
+ last_message_id: Snowflake.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+ category_id: Snowflake.t option [@default None][@key "parent_id"];
+ guild_id: Snowflake.t option [@default None];
+ name: string;
+ position: int;
+ topic: string option [@default None];
+ nsfw: bool;
+ slow_mode_timeout: int option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type guild_voice = {
+ id: Snowflake.t;
+ category_id: Snowflake.t option [@default None][@key "parent_id"];
+ guild_id: Snowflake.t option [@default None];
+ name: string;
+ position: int;
+ user_limit: int [@default -1];
+ bitrate: int option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type category = {
+ id: Snowflake.t;
+ guild_id: Snowflake.t option [@default None];
+ position: int;
+ name: string;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t =
+| Group of group
+| Private of dm
+| GuildText of guild_text
+| GuildVoice of guild_voice
+| Category of category
+[@@deriving sexp, yojson { strict = false}]
+
+type channel_wrapper = {
+ id: Snowflake.t;
+ kind: int [@key "type"];
+ guild_id: Snowflake.t option [@default None];
+ position: int option [@default None];
+ name: string option [@default None];
+ topic: string option [@default None];
+ nsfw: bool option [@default None];
+ last_message_id: Snowflake.t option [@default None];
+ bitrate: int option [@default None];
+ user_limit: int option [@default None];
+ slow_mode_timeout: int option [@default None];
+ recipients: User_t.t list option [@default None];
+ icon: string option [@default None];
+ owner_id: Snowflake.t option [@default None];
+ application_id: Snowflake.t option [@default None];
+ category_id: Snowflake.t option [@default None][@key "parent_id"];
+ last_pin_timestamp: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+let unwrap_as_guild_text {id;guild_id;position;name;topic;nsfw;last_message_id;slow_mode_timeout;category_id;last_pin_timestamp;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ let nsfw = Option.value ~default:false nsfw in
+ { id; guild_id; position; name; topic; nsfw; last_message_id; slow_mode_timeout; category_id; last_pin_timestamp }
+
+let unwrap_as_guild_voice {id;guild_id;position;name;bitrate;user_limit;category_id;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ let user_limit = Option.value ~default:(-1) user_limit in
+ { id; guild_id; position; name; user_limit; bitrate ; category_id; }
+
+let unwrap_as_dm {id;last_message_id;last_pin_timestamp;_} =
+ { id; last_message_id; last_pin_timestamp; }
+
+let unwrap_as_group {id;name;last_message_id;recipients;icon;owner_id;last_pin_timestamp;_} =
+ let recipients = Option.value ~default:[] recipients in
+ let owner_id = Option.value_exn owner_id in
+ { id; name; last_message_id; recipients; icon; owner_id; last_pin_timestamp; }
+
+let unwrap_as_category {id;guild_id;position;name;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ { id; guild_id; position; name; }
+
+let wrap s =
+ match s.kind with
+ | 0 -> GuildText (unwrap_as_guild_text s)
+ | 1 -> Private (unwrap_as_dm s)
+ | 2 -> GuildVoice (unwrap_as_guild_voice s)
+ | 3 -> Group (unwrap_as_group s)
+ | 4 -> Category (unwrap_as_category s)
+ | _ -> raise (Invalid_channel (channel_wrapper_to_yojson s))
+
+let get_id = function
+| Group g -> g.id
+| Private p -> p.id
+| GuildText t -> t.id
+| GuildVoice v -> v.id
+| Category c -> c.id \ No newline at end of file
diff --git a/lib/models/embed.ml b/lib/models/embed.ml
index ce25e78..4faaba7 100644
--- a/lib/models/embed.ml
+++ b/lib/models/embed.ml
@@ -1,8 +1,54 @@
-module Make(Http : S.Http) = struct
- type footer = Embed_t.footer
- type image = Embed_t.image
- type video = Embed_t.video
- type provider = Embed_t.provider
- type field = Embed_t.field
- type t = Embed_t.t
-end \ No newline at end of file
+open Core
+
+type footer = {
+ text: string;
+ icon_url: string option [@default None];
+ proxy_icon_url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type image = {
+ url: string option [@default None];
+ proxy_url: string option [@default None];
+ height: int option [@default None];
+ width: int option [@default None];
+} [@@deriving sexp, yojson]
+
+type video = {
+ url: string option [@default None];
+ height: int option [@default None];
+ width: int option [@default None];
+} [@@deriving sexp, yojson]
+
+type provider = {
+ name: string option [@default None];
+ url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type author = {
+ name: string option [@default None];
+ url: string option [@default None];
+ icon_url: string option [@default None];
+ proxy_icon_url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type field = {
+ name: string;
+ value: string;
+ inline: bool [@default true];
+} [@@deriving sexp, yojson]
+
+type t = {
+ title: string option [@default None];
+ kind: string option [@default None][@key "type"];
+ description: string option [@default None];
+ url: string option [@default None];
+ timestamp: string option [@default None];
+ colour: int option [@default None];
+ footer: footer option [@default None];
+ image: image option [@default None];
+ thumbnail: image option [@default None];
+ video: video option [@default None];
+ provider: provider option [@default None];
+ author: author option [@default None];
+ fields: field list [@default []];
+} [@@deriving sexp, yojson { strict = false }] \ No newline at end of file
diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml
index ece5bcd..2b7cf1d 100644
--- a/lib/models/emoji.ml
+++ b/lib/models/emoji.ml
@@ -1,3 +1,16 @@
-module Make(Http : S.Http) = struct
- type t = Emoji_t.t
-end \ No newline at end of file
+open Core
+
+type partial_emoji = {
+ id: Snowflake.t option [@default None];
+ name: string;
+} [@@deriving sexp, yojson { strict = false }]
+
+type t = {
+ id: Snowflake.t option [@default None];
+ name: string;
+ roles: Snowflake.t list [@default []];
+ user: User_t.t option [@default None];
+ require_colons: bool option [@default None];
+ managed: bool option [@default None];
+ animated: bool option [@default None];
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/guild.ml b/lib/models/guild.ml
index 733fc9f..60652df 100644
--- a/lib/models/guild.ml
+++ b/lib/models/guild.ml
@@ -1,9 +1,7 @@
module Make(Http : S.Http) = struct
open Core
open Async
- open Guild_t
-
- type t = Guild_t.t
+ include Guild_t
let ban_user ~id ?(reason="") ?(days=0) guild =
Http.guild_ban_add guild.id id (`Assoc [
@@ -16,7 +14,7 @@ module Make(Http : S.Http) = struct
("name", `String name);
("image", `String image);
("roles", `List []);
- ]) >>| Result.map ~f:Emoji_j.t_of_string
+ ]) >>| Result.map ~f:Emoji.of_yojson_exn
let create_role ~name ?colour ?permissions ?hoist ?mentionable guild =
let payload = ("name", `String name) :: [] in
@@ -33,10 +31,8 @@ module Make(Http : S.Http) = struct
| Some m -> ("mentionable", `Bool m) :: payload
| None -> payload
in Http.guild_role_add guild.id (`Assoc payload)
- >>| Result.map ~f:(fun r ->
- Role_j.role_of_string r
- |> Event.wrap_role ~guild_id:guild.id)
-
+ >>| Result.map ~f:(fun r -> Role_t.role_of_yojson_exn r |> Role_t.wrap ~guild_id:guild.id)
+
let create_channel ~mode ~name guild =
let kind = match mode with
| `Text -> 0
@@ -45,29 +41,26 @@ module Make(Http : S.Http) = struct
in Http.create_guild_channel guild.id (`Assoc [
("name", `String name);
("type", `Int kind);
- ]) >>| Result.map ~f:Channel_j.t_of_string
-
+ ]) >>| Result.map ~f:Channel_t.of_yojson_exn
+
let delete guild =
Http.delete_guild guild.id >>| Result.map ~f:ignore
let get_ban ~id guild =
- Http.get_ban guild.id id >>| Result.map ~f:Ban_j.t_of_string
-
+ Http.get_ban guild.id id >>| Result.map ~f:Ban_t.of_yojson_exn
+
let get_bans guild =
Http.get_bans guild.id >>| Result.map ~f:(fun bans ->
- Yojson.Safe.from_string bans
- |> Yojson.Safe.Util.to_list
- |> List.map ~f:(fun ban ->
- Yojson.Safe.to_string ban
- |> Ban_j.t_of_string))
+ Yojson.Safe.Util.to_list bans
+ |> List.map ~f:Ban_t.of_yojson_exn)
let get_channel ~id guild =
- match List.find ~f:(fun c -> c.id = id) guild.channels with
- | Some c -> Channel_j.(string_of_channel_wrapper c |> t_of_string) |> Deferred.Or_error.return
- | None -> Http.get_channel id >>| Result.map ~f:Event.wrap_channel
-
+ match List.find ~f:(fun c -> Channel_t.get_id c = id) guild.channels with
+ | Some c -> Deferred.Or_error.return c
+ | None -> Http.get_channel id >>| Result.map ~f:(fun c -> Channel_t.(channel_wrapper_of_yojson_exn c |> wrap))
+
let get_emoji ~id guild =
- Http.get_emoji guild.id id >>| Result.map ~f:Emoji_j.t_of_string
+ Http.get_emoji guild.id id >>| Result.map ~f:Emoji.of_yojson_exn
(* TODO add invite abstraction? *)
let get_invites guild =
@@ -76,19 +69,16 @@ module Make(Http : S.Http) = struct
let get_member ~id guild =
match List.find ~f:(fun m -> m.user.id = id) guild.members with
| Some m -> Deferred.Or_error.return m
- | None -> Http.get_member guild.id id >>| Result.map ~f:Member_j.member_of_string
+ | None -> Http.get_member guild.id id >>| Result.map ~f:Member_t.of_yojson_exn
let get_prune_count ~days guild =
Http.guild_prune_count guild.id days >>| Result.map ~f:(fun prune ->
- Yojson.Safe.(from_string prune
- |> Util.member "pruned"
- |> Util.to_int))
+ Yojson.Safe.Util.(member "pruned" prune |> to_int))
(* TODO add HTTP fallback *)
let get_role ~id guild =
- let role = List.find ~f:(fun r -> r.id = id) guild.roles in
- Option.(role >>| Event.wrap_role ~guild_id:guild.id)
-
+ List.find ~f:(fun r -> r.id = id) guild.roles
+
(* TODO add webhook abstraction? *)
let get_webhooks guild =
Http.get_guild_webhooks guild.id
@@ -108,33 +98,28 @@ module Make(Http : S.Http) = struct
let prune ~days guild =
Http.guild_prune_start guild.id days >>| Result.map ~f:(fun prune ->
- Yojson.Safe.(from_string prune
- |> Util.member "pruned"
- |> Util.to_int))
-
+ Yojson.Safe.Util.(member "pruned" prune |> to_int))
+
let request_members guild =
Http.get_members guild.id >>| Result.map ~f:(fun members ->
- Yojson.Safe.from_string members
- |> Yojson.Safe.Util.to_list
- |> List.map ~f:(fun ban ->
- Yojson.Safe.to_string ban
- |> Member_j.t_of_string))
+ Yojson.Safe.Util.to_list members
+ |> List.map ~f:Member_t.of_yojson_exn)
let set_afk_channel ~id guild = Http.edit_guild guild.id (`Assoc [
("afk_channel_id", `Int id);
- ]) >>| Result.map ~f:Guild_j.t_of_string
+ ]) >>| Result.map ~f:of_yojson_exn
let set_afk_timeout ~timeout guild = Http.edit_guild guild.id (`Assoc [
("afk_timeout", `Int timeout);
- ]) >>| Result.map ~f:Guild_j.t_of_string
+ ]) >>| Result.map ~f:of_yojson_exn
let set_name ~name guild = Http.edit_guild guild.id (`Assoc [
("name", `String name);
- ]) >>| Result.map ~f:Guild_j.t_of_string
+ ]) >>| Result.map ~f:of_yojson_exn
let set_icon ~icon guild = Http.edit_guild guild.id (`Assoc [
("icon", `String icon);
- ]) >>| Result.map ~f:Guild_j.t_of_string
+ ]) >>| Result.map ~f:of_yojson_exn
let unban_user ~id ?reason guild =
let payload = match reason with
diff --git a/lib/models/guild_t.ml b/lib/models/guild_t.ml
new file mode 100644
index 0000000..6bb5090
--- /dev/null
+++ b/lib/models/guild_t.ml
@@ -0,0 +1,67 @@
+open Core
+
+type pre = {
+ id: Snowflake.t;
+ name: string;
+ icon: string option [@default None];
+ splash: string option [@default None];
+ owner_id: Snowflake.t;
+ region: string;
+ afk_channel_id: Snowflake.t option [@default None];
+ afk_timeout: int;
+ embed_enabled: bool option [@default None];
+ embed_channel_id: Snowflake.t option [@default None];
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role_t.role list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option [@default None];
+ widget_enabled: bool option [@default None];
+ widget_channel: Channel_t.channel_wrapper option [@default None];
+ system_channel: Channel_t.channel_wrapper option [@default None];
+ large: bool;
+ unavailable: bool;
+ member_count: int option [@default None];
+ members: Member_t.member list;
+ channels: Channel_t.channel_wrapper list;
+} [@@deriving sexp, yojson { strict = false }]
+
+type t = {
+ id: Snowflake.t;
+ name: string;
+ icon: string option [@default None];
+ splash: string option [@default None];
+ owner_id: Snowflake.t;
+ region: string;
+ afk_channel_id: Snowflake.t option [@default None];
+ afk_timeout: int;
+ embed_enabled: bool option [@default None];
+ embed_channel_id: Snowflake.t option [@default None];
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role_t.t list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option [@default None];
+ widget_enabled: bool option [@default None];
+ widget_channel: Channel_t.t option [@default None];
+ system_channel: Channel_t.t option [@default None];
+ large: bool;
+ unavailable: bool;
+ member_count: int option [@default None];
+ members: Member_t.t list;
+ channels: Channel_t.t list;
+} [@@deriving sexp, yojson { strict = false }]
+
+let wrap ({id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel;system_channel;large;unavailable;member_count;members;channels}:pre) =
+ let roles = List.map ~f:(Role_t.wrap ~guild_id:id) roles in
+ let members = List.map ~f:(Member_t.wrap ~guild_id:id) members in
+ let channels = List.map ~f:Channel_t.wrap channels in
+ let widget_channel = Option.map ~f:Channel_t.wrap widget_channel in
+ let system_channel = Option.map ~f:Channel_t.wrap system_channel in
+ {id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel;system_channel;large;unavailable;member_count;members;channels} \ No newline at end of file
diff --git a/lib/models/member.ml b/lib/models/member.ml
index 7fa9c03..190d865 100644
--- a/lib/models/member.ml
+++ b/lib/models/member.ml
@@ -1,4 +1,7 @@
module Make(Http : S.Http) = struct
+ type partial_member = Member_t.partial_member
+ type member = Member_t.member
+ type member_update = Member_t.member_update
type t = Member_t.t
(* val add_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.t
val remove_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.t
diff --git a/lib/models/member_t.ml b/lib/models/member_t.ml
new file mode 100644
index 0000000..e6edb61
--- /dev/null
+++ b/lib/models/member_t.ml
@@ -0,0 +1,43 @@
+open Core
+
+type partial_member = {
+ nick: string option [@default None];
+ roles: Snowflake.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+} [@@deriving sexp, yojson { strict = false}]
+
+type member = {
+ nick: string option [@default None];
+ roles: Snowflake.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: User_t.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+type member_wrapper = {
+ guild_id: Snowflake.t;
+ user: User_t.t;
+} [@@deriving sexp, yojson { strict = false }]
+
+type member_update = {
+ guild_id: Snowflake.t;
+ roles: Snowflake.t list [@default []];
+ user: User_t.t;
+ nick: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ nick: string option [@default None];
+ roles: Snowflake.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: User_t.t;
+ guild_id: Snowflake.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+let wrap ~guild_id ({nick;roles;joined_at;deaf;mute;user}:member) =
+ {nick;roles;joined_at;deaf;mute;user;guild_id} \ No newline at end of file
diff --git a/lib/models/message.ml b/lib/models/message.ml
index ffd7583..bce361c 100644
--- a/lib/models/message.ml
+++ b/lib/models/message.ml
@@ -1,46 +1,42 @@
module Make(Http : S.Http) = struct
open Async
- open Message_t
+ include Message_t
- type t = Message_t.t
-
- let add_reaction msg (emoji:Emoji_t.t) =
+ let add_reaction msg (emoji:Emoji.t) =
let e = match emoji.id with
| Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.create_reaction msg.channel_id msg.id e
- let remove_reaction msg (emoji:Emoji_t.t) (user:User_t.t) =
+ let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) =
let e = match emoji.id with
| Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.delete_reaction msg.channel_id msg.id e user.id
-
+
let clear_reactions msg =
Http.delete_reactions msg.channel_id msg.id
-
+
let delete msg =
Http.delete_message msg.channel_id msg.id
-
+
let pin msg =
Http.pin_message msg.channel_id msg.id
-
+
let unpin msg =
Http.unpin_message msg.channel_id msg.id
-
+
let reply msg cont =
let rep = `Assoc [("content", `String cont)] in
Http.create_message msg.channel_id rep
let set_content msg cont =
- Message_j.string_of_t { msg with content = cont; }
- |> Yojson.Safe.from_string
+ to_yojson { msg with content = cont; }
|> Http.edit_message msg.channel_id msg.id
let set_embed msg embed =
- Message_j.string_of_t { msg with embeds = [embed]; }
- |> Yojson.Safe.from_string
+ to_yojson { msg with embeds = [embed]; }
|> Http.edit_message msg.channel_id msg.id
end \ No newline at end of file
diff --git a/lib/models/message_t.ml b/lib/models/message_t.ml
new file mode 100644
index 0000000..c4253d5
--- /dev/null
+++ b/lib/models/message_t.ml
@@ -0,0 +1,45 @@
+open Core
+
+type message_update = {
+ id: Snowflake.t;
+ author: User_t.t option [@default None];
+ channel_id: Snowflake.t;
+ member: Member_t.partial_member option [@default None];
+ guild_id: Snowflake.t option [@default None];
+ content: string option [@default None];
+ timestamp: string option [@default None];
+ editedimestamp: string option [@default None];
+ tts: bool option [@default None];
+ mention_everyone: bool option [@default None];
+ mentions: Snowflake.t list [@default []];
+ role_mentions: Snowflake.t list [@default []];
+ attachments: Attachment.t list [@default []];
+ embeds: Embed.t list [@default []];
+ reactions: Snowflake.t list [@default []];
+ nonce: Snowflake.t option [@default None];
+ pinned: bool option [@default None];
+ webhook_id: Snowflake.t option [@default None];
+ kind: int option [@default None][@key "type"];
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ id: Snowflake.t;
+ author: User_t.t;
+ channel_id: Snowflake.t;
+ member: Member_t.partial_member option [@default None];
+ guild_id: Snowflake.t option [@default None];
+ content: string;
+ timestamp: string;
+ editedimestamp: string option [@default None];
+ tts: bool;
+ mention_everyone: bool;
+ (* mentions: Snowflake.t list [@default []]; *)
+ (* role_mentions: Snowflake.t list [@default []]; *)
+ attachments: Attachment.t list [@default []];
+ embeds: Embed.t list [@default []];
+ reactions: Snowflake.t list [@default []];
+ nonce: Snowflake.t option [@default None];
+ pinned: bool;
+ webhook_id: Snowflake.t option [@default None];
+ kind: int [@key "type"];
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/presence.ml b/lib/models/presence.ml
index 2ce9a51..ab245a7 100644
--- a/lib/models/presence.ml
+++ b/lib/models/presence.ml
@@ -1,3 +1,10 @@
-module Make(Http : S.Http) = struct
- type t = Presence_t.t
-end \ No newline at end of file
+open Core
+
+type t = {
+ user: User_t.partial_user;
+ roles: Snowflake.t list;
+ game: Activity.t option [@default None];
+ guild_id: Snowflake.t;
+ status: string;
+ activities: Activity.t list;
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml
index 23de12f..3134bc3 100644
--- a/lib/models/reaction.ml
+++ b/lib/models/reaction.ml
@@ -1,6 +1,4 @@
module Make(Http : S.Http) = struct
- (* open Reaction_t *)
-
type t = Reaction_t.t
(* let delete reaction user =
diff --git a/lib/models/reaction_t.ml b/lib/models/reaction_t.ml
new file mode 100644
index 0000000..c382b68
--- /dev/null
+++ b/lib/models/reaction_t.ml
@@ -0,0 +1,14 @@
+open Core
+
+type reaction_event = {
+ user_id: Snowflake.t;
+ channel_id: Snowflake.t;
+ message_id: Snowflake.t;
+ guild_id: Snowflake.t option [@default None];
+ emoji: Emoji.partial_emoji;
+} [@@deriving sexp, yojson]
+
+type t = {
+ count: int;
+ emoji: Emoji.t;
+} [@@deriving sexp, yojson { strict = false}] \ No newline at end of file
diff --git a/lib/models/role.ml b/lib/models/role.ml
index aa931d6..1d641cb 100644
--- a/lib/models/role.ml
+++ b/lib/models/role.ml
@@ -1,13 +1,13 @@
module Make(Http : S.Http) = struct
- open Role_t
-
+ type role = Role_t.role
+ type role_update = Role_t.role_update
type t = Role_t.t
let edit_role ~body (role:t) = Http.guild_role_edit role.guild_id role.id body
let allow_mention role =
edit_role ~body:(`Assoc [("mentionable", `Bool true)]) role
-
+
let delete (role:t) = Http.guild_role_remove role.guild_id role.id
let disallow_mention role =
diff --git a/lib/models/role_t.ml b/lib/models/role_t.ml
new file mode 100644
index 0000000..e41f31d
--- /dev/null
+++ b/lib/models/role_t.ml
@@ -0,0 +1,32 @@
+open Core
+
+type role = {
+ id: Snowflake.t;
+ name: string;
+ colour: int [@key "color"];
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+} [@@deriving sexp, yojson { strict = false}]
+
+type role_update = {
+ role: role;
+ guild_id: Snowflake.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ id: Snowflake.t;
+ name: string;
+ colour: int [@key "color"];
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+ guild_id: Snowflake.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+let wrap ~guild_id ({id;name;colour;hoist;position;permissions;managed;mentionable}:role) =
+ {id;name;colour;hoist;position;permissions;managed;mentionable;guild_id} \ No newline at end of file
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml
index 6b52ec6..0122da8 100644
--- a/lib/models/snowflake.ml
+++ b/lib/models/snowflake.ml
@@ -1,16 +1,22 @@
-module Make(Http : S.Http) = struct
- open Core
+open Core
- type t = Snowflake_t.t
+type t = Int.t [@@deriving sexp]
- let timestamp snowflake =
- let offset = (snowflake lsr 22) / 1000 in
- 1_420_070_400 + offset
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string
- let timestamp_iso snowflake =
- let t = timestamp snowflake in
- Date.(
- of_time ~zone:Time.Zone.utc
- Time.(of_span_since_epoch @@ Span.of_int_sec t)
- |> format) "%FT%T+00:00"
-end \ No newline at end of file
+let of_yojson d =
+ try of_yojson_exn d |> Ok
+ with Yojson.Safe.Util.Type_error (why,_) -> Error why
+
+let to_yojson s : Yojson.Safe.json = `String (Int.to_string s)
+
+let timestamp snowflake =
+ let offset = (snowflake lsr 22) / 1000 in
+ 1_420_070_400 + offset
+
+let timestamp_iso snowflake =
+ let t = timestamp snowflake in
+ Date.(
+ of_time ~zone:Time.Zone.utc
+ Time.(of_span_since_epoch @@ Span.of_int_sec t)
+ |> format) "%FT%T+00:00" \ No newline at end of file
diff --git a/lib/models/user.ml b/lib/models/user.ml
index cd91a39..8edcea1 100644
--- a/lib/models/user.ml
+++ b/lib/models/user.ml
@@ -1,17 +1,15 @@
module Make(Http : S.Http) = struct
open Core
- open User_t
-
- type t = User_t.t
+ include User_t
let tag user =
- Printf.sprintf "%s#%d" user.username user.discriminator
+ Printf.sprintf "%s#%s" user.username user.discriminator
- let mention (user:User_t.t) =
+ let mention user =
Printf.sprintf "<@%d>" user.id
let default_avatar user =
- let avatar = user.discriminator % 5 in
+ let avatar = Int.of_string user.discriminator % 5 in
Endpoints.cdn_default_avatar avatar
let face user = match user.avatar with
diff --git a/lib/models/user_t.ml b/lib/models/user_t.ml
new file mode 100644
index 0000000..52dbaf4
--- /dev/null
+++ b/lib/models/user_t.ml
@@ -0,0 +1,13 @@
+open Core
+
+type partial_user = {
+ id: Snowflake.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ id: Snowflake.t;
+ username: string;
+ discriminator: string;
+ avatar: string option [@default None];
+ bot: bool [@default false];
+} [@@deriving sexp, yojson { strict = false }] \ No newline at end of file
diff --git a/lib/presence.atd b/lib/presence.atd
deleted file mode 100644
index da9b3fd..0000000
--- a/lib/presence.atd
+++ /dev/null
@@ -1,13 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type user <ocaml from="User" t="t"> = abstract
-type partial_user <ocaml from="User" t="partial_user"> = abstract
-type activity <ocaml from="Activity" t="t"> = abstract
-
-type t = {
- user: partial_user;
- roles: snowflake list;
- ?game: activity option;
- guild_id: snowflake;
- status: string;
- activities: activity list;
-} \ No newline at end of file
diff --git a/lib/reaction.atd b/lib/reaction.atd
deleted file mode 100644
index aa41483..0000000
--- a/lib/reaction.atd
+++ /dev/null
@@ -1,6 +0,0 @@
-type emoji <ocaml from="Emoji" t="t"> = abstract
-
-type t = {
- count: int;
- emoji: emoji;
-} \ No newline at end of file
diff --git a/lib/role.atd b/lib/role.atd
deleted file mode 100644
index d442a92..0000000
--- a/lib/role.atd
+++ /dev/null
@@ -1,22 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-
-type role = {
- id: snowflake;
- name: string;
- colour <json name="color">: int;
- hoist: bool;
- position: int;
- permissions: int;
- managed: bool;
- mentionable: bool;
-}
-
-type role_update = {
- role: role;
- guild_id: snowflake;
-}
-
-type t = {
- inherit role;
- guild_id: snowflake;
- } \ No newline at end of file
diff --git a/lib/s.ml b/lib/s.ml
index 315a704..86446aa 100644
--- a/lib/s.ml
+++ b/lib/s.ml
@@ -4,12 +4,17 @@ module type Token = sig
val token : string
end
-module type Activity = sig
- type t = Activity_t.t
-end
-
-module type Attachment = sig
- type t = Attachment_t.t
+module type Message = sig
+ type t = Message_t.t
+ val add_reaction : t -> Emoji.t -> Yojson.Safe.json Deferred.Or_error.t
+ val remove_reaction : t -> Emoji.t -> User_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val clear_reactions : t -> Yojson.Safe.json Deferred.Or_error.t
+ val delete : t -> Yojson.Safe.json Deferred.Or_error.t
+ val pin : t -> Yojson.Safe.json Deferred.Or_error.t
+ val unpin : t -> Yojson.Safe.json Deferred.Or_error.t
+ val reply : t -> string -> Yojson.Safe.json Deferred.Or_error.t
+ val set_content : t -> string -> Yojson.Safe.json Deferred.Or_error.t
+ val set_embed : t -> Embed.t -> Yojson.Safe.json Deferred.Or_error.t
end
module type Ban = sig
@@ -18,138 +23,102 @@ end
module type Channel = sig
type t = Channel_t.t
- val say : content:string -> Channel_t.t -> Message_t.t Deferred.Or_error.t
+ val say : content:string -> t -> Message_t.t Deferred.Or_error.t
val send_message :
?embed:Yojson.Safe.json ->
?content:string ->
?file:string ->
?tts:bool ->
- Channel_t.t ->
+ t ->
Message_t.t Deferred.Or_error.t
- val delete : Channel_t.t -> unit Deferred.Or_error.t
- val get_message : id:Snowflake_t.t -> Channel_t.t -> Message_t.t Deferred.Or_error.t
+ val delete : t -> unit Deferred.Or_error.t
+ val get_message : id:Snowflake.t -> t -> Message_t.t Deferred.Or_error.t
val get_messages :
?mode:[ `Before | `After | `Around ] ->
- ?id:Snowflake_t.t ->
+ ?id:Snowflake.t ->
?limit:int ->
- Channel_t.t ->
+ t ->
Message_t.t list Deferred.Or_error.t
- val broadcast_typing : Channel_t.t -> unit Deferred.Or_error.t
- val get_pins : Channel_t.t -> Message_t.t list Deferred.Or_error.t
+ val broadcast_typing : t -> unit Deferred.Or_error.t
+ val get_pins : t -> Message_t.t list Deferred.Or_error.t
(* TODO more things related to guild channels *)
end
-module type Embed = sig
- type footer = Embed_t.footer
- type image = Embed_t.image
- type video = Embed_t.video
- type provider = Embed_t.provider
- type field = Embed_t.field
- type t = Embed_t.t
-end
-
-module type Emoji = sig
- type t = Emoji_t.t
-end
-
-module type Guild = sig
- type t = Guild_t.t
- val ban_user : id:Snowflake_t.t -> ?reason:string -> ?days:int -> Guild_t.t -> unit Deferred.Or_error.t
- val create_emoji : name:string -> image:string -> Guild_t.t -> Emoji_t.t Deferred.Or_error.t
- val create_role :
- name:string ->
- ?colour:int ->
- ?permissions:int ->
- ?hoist:bool ->
- ?mentionable:bool ->
- Guild_t.t ->
- Role_t.t Deferred.Or_error.t
- val create_channel : mode:[ `Text | `Voice | `Category ] -> name:string -> Guild_t.t -> Channel_t.t Deferred.Or_error.t
- val delete : Guild_t.t -> unit Deferred.Or_error.t
- val get_ban : id:Snowflake_t.t -> Guild_t.t -> Ban_t.t Deferred.Or_error.t
- val get_bans : Guild_t.t -> Ban_t.t list Deferred.Or_error.t
- val get_channel : id:Snowflake_t.t -> Guild_t.t -> Channel_t.t Deferred.Or_error.t
- val get_emoji : id:Snowflake_t.t -> Guild_t.t -> Emoji_t.t Deferred.Or_error.t
- val get_invites : Guild_t.t -> string Deferred.Or_error.t
- val get_member : id:Snowflake_t.t -> Guild_t.t -> Member_t.member Deferred.Or_error.t
- val get_prune_count : days:int -> Guild_t.t -> int Deferred.Or_error.t
- val get_role : id:Snowflake_t.t -> Guild_t.t -> Role_t.t option
- val get_webhooks : Guild_t.t -> string Deferred.Or_error.t
- val kick_user : id:Snowflake_t.t -> ?reason:string -> Guild_t.t -> unit Deferred.Or_error.t
- val leave : Guild_t.t -> string Deferred.Or_error.t
- val list_voice_regions : Guild_t.t -> string Deferred.Or_error.t
- val prune : days:int -> Guild_t.t -> int Deferred.Or_error.t
- val request_members : Guild_t.t -> Member_t.t list Deferred.Or_error.t
- val set_afk_channel : id:Snowflake_t.t -> Guild_t.t -> Guild_t.t Deferred.Or_error.t
- val set_afk_timeout : timeout:int -> Guild_t.t -> Guild_t.t Deferred.Or_error.t
- val set_name : name:string -> Guild_t.t -> Guild_t.t Deferred.Or_error.t
- val set_icon : icon:string -> Guild_t.t -> Guild_t.t Deferred.Or_error.t
- val unban_user : id:Snowflake_t.t -> ?reason:string -> Guild_t.t -> unit Deferred.Or_error.t
-end
-
module type Member = sig
type t = Member_t.t
- (* val add_role : Member_t.t -> Role_t.t -> string Deferred.Or_error.t
- val remove_role : Member_t.t -> Role_t.t -> string Deferred.Or_error.t
- val ban : ?reason:string -> ?days:int -> Member_t.t -> string Deferred.Or_error.t
- val ban : ?reason:string -> Member_t.t -> string Deferred.Or_error.t
- val kick : ?reason:string -> Member_t.t -> string Deferred.Or_error.t
- val mute : Member_t.t -> string Deferred.Or_error.t
- val deafen : Member_t.t -> string Deferred.Or_error.t
- val unmute : Member_t.t -> string Deferred.Or_error.t
- val undeafen : Member_t.t -> string Deferred.Or_error.t *)
-end
-
-module type Message = sig
- type t = Message_t.t
- val add_reaction : Message_t.t -> Emoji_t.t -> string Deferred.Or_error.t
- val remove_reaction : Message_t.t -> Emoji_t.t -> User_t.t -> string Deferred.Or_error.t
- val clear_reactions : Message_t.t -> string Deferred.Or_error.t
- val delete : Message_t.t -> string Deferred.Or_error.t
- val pin : Message_t.t -> string Deferred.Or_error.t
- val unpin : Message_t.t -> string Deferred.Or_error.t
- val reply : Message_t.t -> string -> string Deferred.Or_error.t
- val set_content : Message_t.t -> string -> string Deferred.Or_error.t
- val set_embed : Message_t.t -> Embed_t.t -> string Deferred.Or_error.t
-end
-
-module type Presence = sig
- type t = Presence_t.t
+ (* val add_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val remove_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val ban : ?reason:string -> ?days:int -> Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val ban : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val kick : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val mute : Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val deafen : Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val unmute : Member_t.t -> Yojson.Safe.json Deferred.Or_error.t
+ val undeafen : Member_t.t -> Yojson.Safe.json Deferred.Or_error.t *)
end
module type Reaction = sig
type t = Reaction_t.t
- (* val delete : Reaction_t.t -> string Deferred.Or_error.t
+ (* val delete : Reaction_t.t -> Yojson.Safe.json Deferred.Or_error.t
val get_users : Reaction_t.t -> int -> User_t.t list Deferred.Or_error.t
- val get_users_after : Reaction_t.t -> Snowflake_t.t -> int -> User_t.t list Deferred.Or_error.t
- val get_users_before : Reaction_t.t -> Snowflake_t.t -> int -> User_t.t list Deferred.Or_error.t *)
+ val get_users_after : Reaction_t.t -> Snowflake.t -> int -> User_t.t list Deferred.Or_error.t
+ val get_users_before : Reaction_t.t -> Snowflake.t -> int -> User_t.t list Deferred.Or_error.t *)
end
module type Role = sig
type t = Role_t.t
- val allow_mention : Role_t.t -> string Deferred.Or_error.t
- val delete : Role_t.t -> string Deferred.Or_error.t
- val disallow_mention : Role_t.t -> string Deferred.Or_error.t
- val hoist : Role_t.t -> string Deferred.Or_error.t
- val set_colour : colour:int -> Role_t.t -> string Deferred.Or_error.t
- val set_name : name:string -> Role_t.t -> string Deferred.Or_error.t
- val unhoist : Role_t.t -> string Deferred.Or_error.t
-end
-
-module type Snowflake = sig
- type t = Snowflake_t.t
- val timestamp : Snowflake_t.t -> int
- val timestamp_iso : Snowflake_t.t -> string
+ val allow_mention : t -> Yojson.Safe.json Deferred.Or_error.t
+ val delete : t -> Yojson.Safe.json Deferred.Or_error.t
+ val disallow_mention : t -> Yojson.Safe.json Deferred.Or_error.t
+ val hoist : t -> Yojson.Safe.json Deferred.Or_error.t
+ val set_colour : colour:int -> t -> Yojson.Safe.json Deferred.Or_error.t
+ val set_name : name:string -> t -> Yojson.Safe.json Deferred.Or_error.t
+ val unhoist : t -> Yojson.Safe.json Deferred.Or_error.t
end
module type User = sig
type t = User_t.t
- val tag : User_t.t -> string
- val mention : User_t.t -> string
- val default_avatar : User_t.t -> string
- val face : User_t.t -> string
- (* val private_channel : User_t.t -> Channel_t.t *)
- (* val send : User_t.t -> string Deferred.Or_error.t *)
+ val tag : t -> string
+ val mention : t -> string
+ val default_avatar : t -> string
+ val face : t -> string
+ (* val private_channel : t -> Channel_t.t *)
+ (* val send : t -> Yojson.Safe.json Deferred.Or_error.t *)
+end
+
+module type Guild = sig
+ type t = Guild_t.t
+ val ban_user : id:Snowflake.t -> ?reason:string -> ?days:int -> t -> unit Deferred.Or_error.t
+ val create_emoji : name:string -> image:string -> t -> Emoji.t Deferred.Or_error.t
+ val create_role :
+ name:string ->
+ ?colour:int ->
+ ?permissions:int ->
+ ?hoist:bool ->
+ ?mentionable:bool ->
+ t ->
+ Role_t.t Deferred.Or_error.t
+ val create_channel : mode:[ `Text | `Voice | `Category ] -> name:string -> t -> Channel_t.t Deferred.Or_error.t
+ val delete : t -> unit Deferred.Or_error.t
+ val get_ban : id:Snowflake.t -> t -> Ban_t.t Deferred.Or_error.t
+ val get_bans : t -> Ban_t.t list Deferred.Or_error.t
+ val get_channel : id:Snowflake.t -> t -> Channel_t.t Deferred.Or_error.t
+ val get_emoji : id:Snowflake.t -> t -> Emoji.t Deferred.Or_error.t
+ val get_invites : t -> Yojson.Safe.json Deferred.Or_error.t
+ val get_member : id:Snowflake.t -> t -> Member_t.t Deferred.Or_error.t
+ val get_prune_count : days:int -> t -> int Deferred.Or_error.t
+ val get_role : id:Snowflake.t -> t -> Role_t.t option
+ val get_webhooks : t -> Yojson.Safe.json Deferred.Or_error.t
+ val kick_user : id:Snowflake.t -> ?reason:string -> t -> unit Deferred.Or_error.t
+ val leave : t -> Yojson.Safe.json Deferred.Or_error.t
+ val list_voice_regions : t -> Yojson.Safe.json Deferred.Or_error.t
+ val prune : days:int -> t -> int Deferred.Or_error.t
+ val request_members : t -> Member_t.t list Deferred.Or_error.t
+ val set_afk_channel : id:Snowflake.t -> t -> t Deferred.Or_error.t
+ val set_afk_timeout : timeout:int -> t -> t Deferred.Or_error.t
+ val set_name : name:string -> t -> t Deferred.Or_error.t
+ val set_icon : icon:string -> t -> t Deferred.Or_error.t
+ val unban_user : id:Snowflake.t -> ?reason:string -> t -> unit Deferred.Or_error.t
end
module type Http = sig
@@ -167,193 +136,186 @@ module type Http = sig
val process_response :
string ->
Cohttp_async.Response.t * Cohttp_async.Body.t ->
- string Deferred.Or_error.t
+ Yojson.Safe.json Deferred.Or_error.t
val request :
?body:Yojson.Safe.json ->
[> `DELETE | `GET | `PATCH | `POST | `PUT ] ->
string ->
- string Deferred.Or_error.t
+ Yojson.Safe.json Deferred.Or_error.t
end
(* Auto-generated signatures *)
- val get_gateway : unit -> string Core.Or_error.t Conduit_async.io
- val get_gateway_bot : unit -> string Core.Or_error.t Conduit_async.io
- val get_channel : int -> string Core.Or_error.t Conduit_async.io
+ val get_gateway : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_gateway_bot : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_channel : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val modify_channel :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val delete_channel : int -> string Core.Or_error.t Conduit_async.io
- val get_messages : int -> int -> string * int -> string Core.Or_error.t Conduit_async.io
- val get_message : int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val delete_channel : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_messages : int -> int -> string * int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_message : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_message :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_reaction :
- int -> int -> string -> string Core.Or_error.t Conduit_async.io
+ int -> int -> string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_own_reaction :
- int -> int -> string -> string Core.Or_error.t Conduit_async.io
+ int -> int -> string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_reaction :
- int -> int -> string -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> string -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val get_reactions :
- int -> int -> string -> string Core.Or_error.t Conduit_async.io
+ int -> int -> string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_reactions :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_message :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_message :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val bulk_delete :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_channel_permissions :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_channel_invites : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_channel_invites : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_channel_invite :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_channel_permission :
- int -> int -> string Core.Or_error.t Conduit_async.io
- val broadcast_typing : int -> string Core.Or_error.t Conduit_async.io
- val get_pinned_messages : int -> string Core.Or_error.t Conduit_async.io
- val pin_message : int -> int -> string Core.Or_error.t Conduit_async.io
- val unpin_message : int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val broadcast_typing : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_pinned_messages : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val pin_message : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val unpin_message : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val group_recipient_add :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val group_recipient_remove :
- int -> int -> string Core.Or_error.t Conduit_async.io
- val get_emojis : int -> string Core.Or_error.t Conduit_async.io
- val get_emoji : int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_emojis : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_emoji : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_emoji :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_emoji :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val delete_emoji : int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val delete_emoji : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_guild :
- Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_guild : int -> string Core.Or_error.t Conduit_async.io
+ Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guild : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_guild :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val delete_guild : int -> string Core.Or_error.t Conduit_async.io
- val get_guild_channels : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val delete_guild : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guild_channels : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_guild_channel :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val modify_guild_channel_positions :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_member : int -> int -> string Core.Or_error.t Conduit_async.io
- val get_members : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_member : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_members : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val add_member :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_member :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val remove_member :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val change_nickname :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val add_member_role :
- int -> int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val remove_member_role :
- int -> int -> int -> string Core.Or_error.t Conduit_async.io
- val get_bans : int -> string Core.Or_error.t Conduit_async.io
- val get_ban : int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_bans : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_ban : int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_ban_add :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_ban_remove :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_roles : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_roles : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_role_add :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_roles_edit :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_role_edit :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_role_remove :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_prune_count :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val guild_prune_start :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val get_guild_voice_regions :
- int -> string Core.Or_error.t Conduit_async.io
- val get_guild_invites : int -> string Core.Or_error.t Conduit_async.io
- val get_integrations : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guild_invites : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_integrations : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val add_integration :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_integration :
int ->
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_integration :
- int -> int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val sync_integration :
- int -> int -> string Core.Or_error.t Conduit_async.io
- val get_guild_embed : int -> string Core.Or_error.t Conduit_async.io
+ int -> int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guild_embed : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_guild_embed :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_vanity_url : int -> string Core.Or_error.t Conduit_async.io
- val get_invite : string -> string Core.Or_error.t Conduit_async.io
- val delete_invite : string -> string Core.Or_error.t Conduit_async.io
- val get_current_user : unit -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_vanity_url : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_invite : string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val delete_invite : string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_current_user : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_current_user :
- Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_guilds : unit -> string Core.Or_error.t Conduit_async.io
- val leave_guild : int -> string Core.Or_error.t Conduit_async.io
+ Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guilds : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val leave_guild : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val get_private_channels :
- unit -> string Core.Or_error.t Conduit_async.io
+ unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_dm :
- Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_group_dm :
- Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_connections : unit -> string Core.Or_error.t Conduit_async.io
- val get_user : int -> string Core.Or_error.t Conduit_async.io
- val get_voice_regions : unit -> string Core.Or_error.t Conduit_async.io
+ Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_connections : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_user : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_voice_regions : unit -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val create_webhook :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val get_channel_webhooks : int -> string Core.Or_error.t Conduit_async.io
- val get_guild_webhooks : int -> string Core.Or_error.t Conduit_async.io
- val get_webhook : int -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_channel_webhooks : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_guild_webhooks : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val get_webhook : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val get_webhook_with_token :
- int -> string -> string Core.Or_error.t Conduit_async.io
+ int -> string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_webhook :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val edit_webhook_with_token :
int ->
- string -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
- val delete_webhook : int -> string Core.Or_error.t Conduit_async.io
+ string -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
+ val delete_webhook : int -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val delete_webhook_with_token :
- int -> string -> string Core.Or_error.t Conduit_async.io
+ int -> string -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val execute_webhook :
int ->
- string -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ string -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val execute_slack_webhook :
int ->
- string -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ string -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val execute_git_webhook :
int ->
- string -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ string -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
val get_audit_logs :
- int -> Yojson.Safe.json -> string Core.Or_error.t Conduit_async.io
+ int -> Yojson.Safe.json -> Yojson.Safe.json Core.Or_error.t Conduit_async.io
end
module type Models = sig
- module Http : Http
- module Activity : Activity
- module Attachment : Attachment
module Ban : Ban
module Channel : Channel
- module Embed : Embed
- module Emoji : Emoji
module Guild : Guild
module Member : Member
module Message : Message
- module Presence : Presence
module Reaction : Reaction
module Role : Role
- module Snowflake : Snowflake
module User : User
end
@@ -368,12 +330,12 @@ module type Handler_f = sig
end
module type Dispatch = sig
- val dispatch : ev:string -> string -> unit
+ val dispatch : ev:string -> Yojson.Safe.json -> unit
end
module type Sharder = sig
exception Invalid_Payload
- exception Failure_to_Establish_Heartbeat
+ exception Failureo_Establish_Heartbeat
type t
@@ -406,7 +368,7 @@ module type Sharder = sig
val request_guild_members :
?query:string ->
?limit:int ->
- guild:Snowflake_t.t ->
+ guild:Snowflake.t ->
shard ->
shard Deferred.t
@@ -430,7 +392,7 @@ module type Sharder = sig
val request_guild_members :
?query:string ->
?limit:int ->
- guild:Snowflake_t.t ->
+ guild:Snowflake.t ->
t ->
Shard.shard list Deferred.t
-end \ No newline at end of file
+end
diff --git a/lib/sharder.ml b/lib/sharder.ml
index b1c84a6..f417f92 100644
--- a/lib/sharder.ml
+++ b/lib/sharder.ml
@@ -1,4 +1,4 @@
-module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
+module Make(H : S.Http)(D : S.Dispatch) = struct
open Async
open Core
open Websocket_async
@@ -21,14 +21,10 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
type 'a t = {
mutable state: 'a;
- mutable binds: ('a -> unit) list;
}
let identify_lock = Mutex.create ()
- let bind ~f t =
- t.binds <- f :: t.binds
-
let parse (frame:[`Ok of Frame.t | `Eof]) =
match frame with
| `Ok s -> begin
@@ -70,7 +66,7 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
Ivar.fill_if_empty shard.ready ();
J.(member "session_id" data |> to_string_option)
end else None in
- D.dispatch ~ev:t (Yojson.Safe.to_string data);
+ D.dispatch ~ev:t data;
return { shard with
seq = seq;
session = session;
@@ -289,7 +285,7 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
let module J = Yojson.Safe.Util in
H.get_gateway_bot () >>= fun data ->
let data = match data with
- | Ok d -> Yojson.Safe.from_string d
+ | Ok d -> d
| Error e -> Error.raise e
in
let url = J.(member "url" data |> to_string) in
@@ -312,7 +308,6 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
>>| fun s -> (t.state <- s; t)
end)
>>= fun t ->
- List.iter ~f:(fun f -> f t.state) t.binds;
ev_loop t
in
let rec gen_shards l a =
@@ -321,7 +316,7 @@ module Make(H : S.Http)(D : S.Dispatch) : S.Sharder = struct
| (id, total) ->
Shard.create ~url ~shards:(id, total) ()
>>= fun shard ->
- let t = Shard.{ state = shard; binds = []; } in
+ let t = Shard.{ state = shard; } in
ev_loop t >>> ignore;
gen_shards (id+1, total) (t :: a)
in
diff --git a/lib/sharder.mli b/lib/sharder.mli
deleted file mode 100644
index 8d04c8d..0000000
--- a/lib/sharder.mli
+++ /dev/null
@@ -1 +0,0 @@
-module Make(H : S.Http)(D : S.Dispatch) : S.Sharder \ No newline at end of file
diff --git a/lib/snowflake.atd b/lib/snowflake.atd
deleted file mode 100644
index 98dc032..0000000
--- a/lib/snowflake.atd
+++ /dev/null
@@ -1 +0,0 @@
-type t = int \ No newline at end of file
diff --git a/lib/user.atd b/lib/user.atd
deleted file mode 100644
index 588242d..0000000
--- a/lib/user.atd
+++ /dev/null
@@ -1,13 +0,0 @@
-type snowflake <ocaml from="Snowflake" t="t"> = abstract
-
-type partial_user = {
- id: snowflake;
-}
-
-type t = {
- inherit partial_user;
- username: string;
- discriminator: int <json repr="string">;
- ?avatar: string option;
- ~bot <ocaml default="false">: bool;
-} \ No newline at end of file