aboutsummaryrefslogtreecommitdiff
path: root/lib/models
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-16 23:36:59 -0700
committerAdelyn Breedlove <[email protected]>2019-01-16 23:36:59 -0700
commit6354dbd89d354e5e2499b4c2bea5d5fa95e020df (patch)
treea0fd199097bdc675628d5bd735017d92d2067e08 /lib/models
parentMerge branch 'switch-to-deriving_yojson' into 'master' (diff)
downloaddisml-6354dbd89d354e5e2499b4c2bea5d5fa95e020df.tar.xz
disml-6354dbd89d354e5e2499b4c2bea5d5fa95e020df.zip
eliminate all functors in favour of a simpler approach
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/ban.ml4
-rw-r--r--lib/models/ban.mli1
-rw-r--r--lib/models/channel.ml116
-rw-r--r--lib/models/channel.mli22
-rw-r--r--lib/models/guild.ml254
-rw-r--r--lib/models/guild.mli34
-rw-r--r--lib/models/member.ml25
-rw-r--r--lib/models/member.mli10
-rw-r--r--lib/models/message.ml82
-rw-r--r--lib/models/message.mli12
-rw-r--r--lib/models/reaction.ml7
-rw-r--r--lib/models/reaction.mli5
-rw-r--r--lib/models/role.ml34
-rw-r--r--lib/models/role.mli10
-rw-r--r--lib/models/user.ml34
-rw-r--r--lib/models/user.mli7
16 files changed, 367 insertions, 290 deletions
diff --git a/lib/models/ban.ml b/lib/models/ban.ml
index f84fe62..45f7679 100644
--- a/lib/models/ban.ml
+++ b/lib/models/ban.ml
@@ -1,3 +1 @@
-module Make(Http : S.Http) = struct
- type t = Ban_t.t
-end \ No newline at end of file
+include Ban_t \ No newline at end of file
diff --git a/lib/models/ban.mli b/lib/models/ban.mli
new file mode 100644
index 0000000..d1050b0
--- /dev/null
+++ b/lib/models/ban.mli
@@ -0,0 +1 @@
+type t = Ban_t.t \ No newline at end of file
diff --git a/lib/models/channel.ml b/lib/models/channel.ml
index 3fab452..c3524ef 100644
--- a/lib/models/channel.ml
+++ b/lib/models/channel.ml
@@ -1,59 +1,57 @@
-module Make(Http : S.Http) = struct
- open Async
- open Core
- include Channel_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_t.of_yojson_exn
-
- let send_message ?embed ?content ?file ?(tts=false) ch =
- let embed = match embed with
- | Some e -> e
- | None -> `Null in
- let content = match content with
- | Some c -> `String c
- | None -> `Null in
- let file = match file with
- | Some f -> `String f
- | None -> `Null in
- let () = match embed, content with
- | `Null, `Null -> raise Invalid_message
- | _ -> () in
- Http.create_message (get_id ch) (`Assoc [
- ("embed", embed);
- ("content", content);
- ("file", file);
- ("tts", `Bool tts);
- ]) >>| 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_t.of_yojson_exn
-
- let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
- let kind = match mode with
- | `Around -> "around", limit
- | `Before -> "before", limit
- | `After -> "after", limit
- in
- let id = match id with
- | Some id -> id
- | None -> raise No_message_found in
- Http.get_messages (get_id ch) id kind >>| Result.map ~f:(fun l ->
- 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.Util.to_list l
- |> List.map ~f:Message_t.of_yojson_exn)
-end \ No newline at end of file
+open Async
+open Core
+include Channel_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_t.of_yojson_exn
+
+let send_message ?embed ?content ?file ?(tts=false) ch =
+ let embed = match embed with
+ | Some e -> e
+ | None -> `Null in
+ let content = match content with
+ | Some c -> `String c
+ | None -> `Null in
+ let file = match file with
+ | Some f -> `String f
+ | None -> `Null in
+ let () = match embed, content with
+ | `Null, `Null -> raise Invalid_message
+ | _ -> () in
+ Http.create_message (get_id ch) (`Assoc [
+ ("embed", embed);
+ ("content", content);
+ ("file", file);
+ ("tts", `Bool tts);
+ ]) >>| 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_t.of_yojson_exn
+
+let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
+ let kind = match mode with
+ | `Around -> "around", limit
+ | `Before -> "before", limit
+ | `After -> "after", limit
+ in
+ let id = match id with
+ | Some id -> id
+ | None -> raise No_message_found in
+ Http.get_messages (get_id ch) id kind >>| Result.map ~f:(fun l ->
+ 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.Util.to_list l
+ |> List.map ~f:Message_t.of_yojson_exn) \ No newline at end of file
diff --git a/lib/models/channel.mli b/lib/models/channel.mli
new file mode 100644
index 0000000..4d67e94
--- /dev/null
+++ b/lib/models/channel.mli
@@ -0,0 +1,22 @@
+open Async
+
+type t = Channel_t.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 ->
+ 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 ->
+ ?limit:int ->
+ 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 *) \ No newline at end of file
diff --git a/lib/models/guild.ml b/lib/models/guild.ml
index 60652df..c1b9925 100644
--- a/lib/models/guild.ml
+++ b/lib/models/guild.ml
@@ -1,129 +1,127 @@
-module Make(Http : S.Http) = struct
- open Core
- open Async
- include Guild_t
-
- let ban_user ~id ?(reason="") ?(days=0) guild =
- Http.guild_ban_add guild.id id (`Assoc [
- ("delete-message-days", `Int days);
- ("reason", `String reason);
- ]) >>| Result.map ~f:ignore
-
- let create_emoji ~name ~image guild =
- Http.create_emoji guild.id (`Assoc [
- ("name", `String name);
- ("image", `String image);
- ("roles", `List []);
- ]) >>| Result.map ~f:Emoji.of_yojson_exn
-
- let create_role ~name ?colour ?permissions ?hoist ?mentionable guild =
- let payload = ("name", `String name) :: [] in
- let payload = match permissions with
- | Some p -> ("permissions", `Int p) :: payload
- | None -> payload
- in let payload = match colour with
- | Some c -> ("color", `Int c) :: payload
- | None -> payload
- in let payload = match hoist with
- | Some h -> ("hoist", `Bool h) :: payload
- | None -> payload
- in let payload = match mentionable with
- | Some m -> ("mentionable", `Bool m) :: payload
- | None -> payload
- in Http.guild_role_add guild.id (`Assoc payload)
- >>| 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
- | `Voice -> 2
- | `Category -> 4
- in Http.create_guild_channel guild.id (`Assoc [
- ("name", `String name);
- ("type", `Int kind);
- ]) >>| 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_t.of_yojson_exn
-
- let get_bans guild =
- Http.get_bans guild.id >>| Result.map ~f:(fun bans ->
- 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 -> 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.of_yojson_exn
-
- (* TODO add invite abstraction? *)
- let get_invites guild =
- Http.get_guild_invites guild.id
-
- 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_t.of_yojson_exn
-
- let get_prune_count ~days guild =
- Http.guild_prune_count guild.id days >>| Result.map ~f:(fun prune ->
- Yojson.Safe.Util.(member "pruned" prune |> to_int))
-
- (* TODO add HTTP fallback *)
- let get_role ~id guild =
- List.find ~f:(fun r -> r.id = id) guild.roles
-
- (* TODO add webhook abstraction? *)
- let get_webhooks guild =
- Http.get_guild_webhooks guild.id
-
- let kick_user ~id ?reason guild =
- let payload = match reason with
- | Some r -> `Assoc [("reason", `String r)]
- | None -> `Null
- in Http.remove_member guild.id id payload >>| Result.map ~f:ignore
-
- let leave guild =
- Http.leave_guild guild.id
-
- (* TODO Voice region abstractions? *)
- let list_voice_regions guild =
- Http.get_guild_voice_regions guild.id
-
- let prune ~days guild =
- Http.guild_prune_start guild.id days >>| Result.map ~f:(fun prune ->
- Yojson.Safe.Util.(member "pruned" prune |> to_int))
-
- let request_members guild =
- Http.get_members guild.id >>| Result.map ~f:(fun members ->
- 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:of_yojson_exn
-
- let set_afk_timeout ~timeout guild = Http.edit_guild guild.id (`Assoc [
- ("afk_timeout", `Int timeout);
- ]) >>| Result.map ~f:of_yojson_exn
-
- let set_name ~name guild = Http.edit_guild guild.id (`Assoc [
+open Core
+open Async
+include Guild_t
+
+let ban_user ~id ?(reason="") ?(days=0) guild =
+ Http.guild_ban_add guild.id id (`Assoc [
+ ("delete-message-days", `Int days);
+ ("reason", `String reason);
+ ]) >>| Result.map ~f:ignore
+
+let create_emoji ~name ~image guild =
+ Http.create_emoji guild.id (`Assoc [
("name", `String name);
- ]) >>| Result.map ~f:of_yojson_exn
-
- let set_icon ~icon guild = Http.edit_guild guild.id (`Assoc [
- ("icon", `String icon);
- ]) >>| Result.map ~f:of_yojson_exn
-
- let unban_user ~id ?reason guild =
- let payload = match reason with
- | Some r -> `Assoc [("reason", `String r)]
- | None -> `Null
- in Http.guild_ban_remove guild.id id payload >>| Result.map ~f:ignore
-end \ No newline at end of file
+ ("image", `String image);
+ ("roles", `List []);
+ ]) >>| Result.map ~f:Emoji.of_yojson_exn
+
+let create_role ~name ?colour ?permissions ?hoist ?mentionable guild =
+ let payload = ("name", `String name) :: [] in
+ let payload = match permissions with
+ | Some p -> ("permissions", `Int p) :: payload
+ | None -> payload
+ in let payload = match colour with
+ | Some c -> ("color", `Int c) :: payload
+ | None -> payload
+ in let payload = match hoist with
+ | Some h -> ("hoist", `Bool h) :: payload
+ | None -> payload
+ in let payload = match mentionable with
+ | Some m -> ("mentionable", `Bool m) :: payload
+ | None -> payload
+ in Http.guild_role_add guild.id (`Assoc payload)
+ >>| 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
+ | `Voice -> 2
+ | `Category -> 4
+ in Http.create_guild_channel guild.id (`Assoc [
+ ("name", `String name);
+ ("type", `Int kind);
+ ]) >>| 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_t.of_yojson_exn
+
+let get_bans guild =
+ Http.get_bans guild.id >>| Result.map ~f:(fun bans ->
+ 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 -> 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.of_yojson_exn
+
+(* TODO add invite abstraction? *)
+let get_invites guild =
+ Http.get_guild_invites guild.id
+
+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_t.of_yojson_exn
+
+let get_prune_count ~days guild =
+ Http.guild_prune_count guild.id days >>| Result.map ~f:(fun prune ->
+ Yojson.Safe.Util.(member "pruned" prune |> to_int))
+
+(* TODO add HTTP fallback *)
+let get_role ~id guild =
+ List.find ~f:(fun r -> r.id = id) guild.roles
+
+(* TODO add webhook abstraction? *)
+let get_webhooks guild =
+ Http.get_guild_webhooks guild.id
+
+let kick_user ~id ?reason guild =
+ let payload = match reason with
+ | Some r -> `Assoc [("reason", `String r)]
+ | None -> `Null
+ in Http.remove_member guild.id id payload >>| Result.map ~f:ignore
+
+let leave guild =
+ Http.leave_guild guild.id
+
+(* TODO Voice region abstractions? *)
+let list_voice_regions guild =
+ Http.get_guild_voice_regions guild.id
+
+let prune ~days guild =
+ Http.guild_prune_start guild.id days >>| Result.map ~f:(fun prune ->
+ Yojson.Safe.Util.(member "pruned" prune |> to_int))
+
+let request_members guild =
+ Http.get_members guild.id >>| Result.map ~f:(fun members ->
+ 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:of_yojson_exn
+
+let set_afk_timeout ~timeout guild = Http.edit_guild guild.id (`Assoc [
+ ("afk_timeout", `Int timeout);
+ ]) >>| Result.map ~f:of_yojson_exn
+
+let set_name ~name guild = Http.edit_guild guild.id (`Assoc [
+ ("name", `String name);
+ ]) >>| Result.map ~f:of_yojson_exn
+
+let set_icon ~icon guild = Http.edit_guild guild.id (`Assoc [
+ ("icon", `String icon);
+ ]) >>| Result.map ~f:of_yojson_exn
+
+let unban_user ~id ?reason guild =
+ let payload = match reason with
+ | Some r -> `Assoc [("reason", `String r)]
+ | None -> `Null
+ in Http.guild_ban_remove guild.id id payload >>| Result.map ~f:ignore \ No newline at end of file
diff --git a/lib/models/guild.mli b/lib/models/guild.mli
new file mode 100644
index 0000000..daedc3c
--- /dev/null
+++ b/lib/models/guild.mli
@@ -0,0 +1,34 @@
+open Async
+
+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 \ No newline at end of file
diff --git a/lib/models/member.ml b/lib/models/member.ml
index 190d865..03674b7 100644
--- a/lib/models/member.ml
+++ b/lib/models/member.ml
@@ -1,15 +1,10 @@
-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
- val ban : ?reason:string -> ?days:int -> Member_t.t -> Yojson.Safe.json Deferred.t
- val ban : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t
- val kick : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t
- val mute : Member_t.t -> Yojson.Safe.json Deferred.t
- val deafen : Member_t.t -> Yojson.Safe.json Deferred.t
- val unmute : Member_t.t -> Yojson.Safe.json Deferred.t
- val undeafen : Member_t.t -> Yojson.Safe.json Deferred.t *)
-end \ No newline at end of file
+include Member_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
+val ban : ?reason:string -> ?days:int -> Member_t.t -> Yojson.Safe.json Deferred.t
+val ban : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t
+val kick : ?reason:string -> Member_t.t -> Yojson.Safe.json Deferred.t
+val mute : Member_t.t -> Yojson.Safe.json Deferred.t
+val deafen : Member_t.t -> Yojson.Safe.json Deferred.t
+val unmute : Member_t.t -> Yojson.Safe.json Deferred.t
+val undeafen : Member_t.t -> Yojson.Safe.json Deferred.t *) \ No newline at end of file
diff --git a/lib/models/member.mli b/lib/models/member.mli
new file mode 100644
index 0000000..627e903
--- /dev/null
+++ b/lib/models/member.mli
@@ -0,0 +1,10 @@
+type t = Member_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 *) \ No newline at end of file
diff --git a/lib/models/message.ml b/lib/models/message.ml
index bce361c..6cb54b4 100644
--- a/lib/models/message.ml
+++ b/lib/models/message.ml
@@ -1,42 +1,40 @@
-module Make(Http : S.Http) = struct
- open Async
- include Message_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) (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 =
- to_yojson { msg with content = cont; }
- |> Http.edit_message msg.channel_id msg.id
-
- let set_embed msg embed =
- to_yojson { msg with embeds = [embed]; }
- |> Http.edit_message msg.channel_id msg.id
-end \ No newline at end of file
+open Async
+include Message_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) (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 =
+ to_yojson { msg with content = cont; }
+ |> Http.edit_message msg.channel_id msg.id
+
+let set_embed msg embed =
+ to_yojson { msg with embeds = [embed]; }
+ |> Http.edit_message msg.channel_id msg.id \ No newline at end of file
diff --git a/lib/models/message.mli b/lib/models/message.mli
new file mode 100644
index 0000000..c8c2155
--- /dev/null
+++ b/lib/models/message.mli
@@ -0,0 +1,12 @@
+open Async
+
+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 \ No newline at end of file
diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml
index 3134bc3..c4ab326 100644
--- a/lib/models/reaction.ml
+++ b/lib/models/reaction.ml
@@ -1,6 +1 @@
-module Make(Http : S.Http) = struct
- type t = Reaction_t.t
-
- (* let delete reaction user =
- Http.delete_reaction *)
-end \ No newline at end of file
+include Reaction_t \ No newline at end of file
diff --git a/lib/models/reaction.mli b/lib/models/reaction.mli
new file mode 100644
index 0000000..08572df
--- /dev/null
+++ b/lib/models/reaction.mli
@@ -0,0 +1,5 @@
+type t = Reaction_t.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 -> 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 *) \ No newline at end of file
diff --git a/lib/models/role.ml b/lib/models/role.ml
index 1d641cb..ee6bb0a 100644
--- a/lib/models/role.ml
+++ b/lib/models/role.ml
@@ -1,27 +1,23 @@
-module Make(Http : S.Http) = struct
- type role = Role_t.role
- type role_update = Role_t.role_update
- type t = Role_t.t
+include Role_t
- let edit_role ~body (role:t) = Http.guild_role_edit role.guild_id role.id body
+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 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 delete (role:t) = Http.guild_role_remove role.guild_id role.id
- let disallow_mention role =
- edit_role ~body:(`Assoc [("mentionable", `Bool false)]) role
+let disallow_mention role =
+ edit_role ~body:(`Assoc [("mentionable", `Bool false)]) role
- let hoist role =
- edit_role ~body:(`Assoc [("hoist", `Bool true)]) role
+let hoist role =
+ edit_role ~body:(`Assoc [("hoist", `Bool true)]) role
- let set_colour ~colour role =
- edit_role ~body:(`Assoc [("color", `Int colour)]) role
+let set_colour ~colour role =
+ edit_role ~body:(`Assoc [("color", `Int colour)]) role
- let set_name ~name role =
- edit_role ~body:(`Assoc [("name", `String name)]) role
+let set_name ~name role =
+ edit_role ~body:(`Assoc [("name", `String name)]) role
- let unhoist role =
- edit_role ~body:(`Assoc [("hoist", `Bool false)]) role
-end \ No newline at end of file
+let unhoist role =
+ edit_role ~body:(`Assoc [("hoist", `Bool false)]) role \ No newline at end of file
diff --git a/lib/models/role.mli b/lib/models/role.mli
new file mode 100644
index 0000000..5eca8c1
--- /dev/null
+++ b/lib/models/role.mli
@@ -0,0 +1,10 @@
+open Async
+
+type t = Role_t.t
+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 \ No newline at end of file
diff --git a/lib/models/user.ml b/lib/models/user.ml
index 8edcea1..bd6583c 100644
--- a/lib/models/user.ml
+++ b/lib/models/user.ml
@@ -1,22 +1,20 @@
-module Make(Http : S.Http) = struct
- open Core
- include User_t
+open Core
+include User_t
- let tag user =
- Printf.sprintf "%s#%s" user.username user.discriminator
+let tag user =
+ Printf.sprintf "%s#%s" user.username user.discriminator
- let mention user =
- Printf.sprintf "<@%d>" user.id
+let mention user =
+ Printf.sprintf "<@%d>" user.id
- let default_avatar user =
- let avatar = Int.of_string user.discriminator % 5 in
- Endpoints.cdn_default_avatar avatar
+let default_avatar user =
+ let avatar = Int.of_string user.discriminator % 5 in
+ Endpoints.cdn_default_avatar avatar
- let face user = match user.avatar with
- | Some avatar ->
- let ext = if String.is_substring ~substring:"a_" avatar
- then "gif"
- else "png" in
- Endpoints.cdn_avatar user.id avatar ext
- | None -> default_avatar user
-end \ No newline at end of file
+let face user = match user.avatar with
+ | Some avatar ->
+ let ext = if String.is_substring ~substring:"a_" avatar
+ then "gif"
+ else "png" in
+ Endpoints.cdn_avatar user.id avatar ext
+ | None -> default_avatar user \ No newline at end of file
diff --git a/lib/models/user.mli b/lib/models/user.mli
new file mode 100644
index 0000000..af873e1
--- /dev/null
+++ b/lib/models/user.mli
@@ -0,0 +1,7 @@
+type t = User_t.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 *) \ No newline at end of file