aboutsummaryrefslogtreecommitdiff
path: root/lib/models/channel.ml
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 /lib/models/channel.ml
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
Diffstat (limited to 'lib/models/channel.ml')
-rw-r--r--lib/models/channel.ml38
1 files changed, 12 insertions, 26 deletions
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