aboutsummaryrefslogtreecommitdiff
path: root/lib/models/id/channel_id.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/id/channel_id.ml')
-rw-r--r--lib/models/id/channel_id.ml55
1 files changed, 54 insertions, 1 deletions
diff --git a/lib/models/id/channel_id.ml b/lib/models/id/channel_id.ml
index be4bfab..1017ad1 100644
--- a/lib/models/id/channel_id.ml
+++ b/lib/models/id/channel_id.ml
@@ -1,2 +1,55 @@
+open Core
include Channel_id_t
-include Impl.Channel(Channel_id_t) \ No newline at end of file
+
+exception Invalid_message
+exception No_message_found
+
+let send_message ?embed ?content ?file ?(tts=false) ch =
+ let embed = match embed with
+ | Some e -> Embed.to_yojson 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);
+ ])
+
+let say content ch =
+ send_message ~content ch
+
+let delete ch =
+ Http.delete_channel (get_id ch)
+
+let get_message ~id ch =
+ Http.get_message (get_id ch) id
+
+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
+
+let broadcast_typing ch =
+ Http.broadcast_typing (get_id ch)
+
+let get_pins ch =
+ Http.get_pinned_messages (get_id ch)
+
+let bulk_delete msgs ch =
+ let msgs = `List (List.map ~f:(fun id -> `Int id) msgs) in
+ Http.bulk_delete (get_id ch) msgs \ No newline at end of file