diff options
| author | Adelyn Breedlove <[email protected]> | 2019-02-11 17:23:59 +0000 |
|---|---|---|
| committer | Adelyn Breedlove <[email protected]> | 2019-02-11 17:23:59 +0000 |
| commit | 7c9b809078b5cd53e3d54c0004c683da2ec679af (patch) | |
| tree | 5a1b165b597fc1ad4167115d9a23b12852a4636b /lib/models/id/channel_id.ml | |
| parent | Merge branch 'sharder_fixes' into 'master' (diff) | |
| download | disml-7c9b809078b5cd53e3d54c0004c683da2ec679af.tar.xz disml-7c9b809078b5cd53e3d54c0004c683da2ec679af.zip | |
Add a cache
Diffstat (limited to 'lib/models/id/channel_id.ml')
| -rw-r--r-- | lib/models/id/channel_id.ml | 55 |
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 |