aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/bot.ml6
-rw-r--r--lib/models/message.ml12
-rw-r--r--lib/models/message.mli18
3 files changed, 25 insertions, 11 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index 197efb4..a42fd16 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -8,7 +8,11 @@ let check_command (msg:Message.t) =
| [] -> "", []
in match cmd with
| "!ping" ->
- Message.reply msg "Pong!" >>> ignore
+ Message.reply msg "Pong!" >>= begin fun msg ->
+ let msg = match msg with Ok m -> m | Error e -> Error.raise e in
+ let diff = Time.diff (Time.now ()) (Time.of_string msg.timestamp) in
+ Message.set_content msg (Printf.sprintf "Pong! `%d ms`" (Time.Span.to_ms diff |> Float.to_int))
+ end >>> ignore
| "spam" ->
let count = Option.((List.hd rest >>| Int.of_string) |> value ~default:0) in
List.range 0 count
diff --git a/lib/models/message.ml b/lib/models/message.ml
index 6cb54b4..5bc06b7 100644
--- a/lib/models/message.ml
+++ b/lib/models/message.ml
@@ -1,3 +1,4 @@
+open Core
open Async
include Message_t
@@ -7,6 +8,7 @@ let add_reaction msg (emoji:Emoji.t) =
| None -> emoji.name
in
Http.create_reaction msg.channel_id msg.id e
+ >>| Result.map ~f:ignore
let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) =
let e = match emoji.id with
@@ -14,27 +16,35 @@ let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) =
| None -> emoji.name
in
Http.delete_reaction msg.channel_id msg.id e user.id
+ >>| Result.map ~f:ignore
let clear_reactions msg =
Http.delete_reactions msg.channel_id msg.id
+ >>| Result.map ~f:ignore
let delete msg =
Http.delete_message msg.channel_id msg.id
+ >>| Result.map ~f:ignore
let pin msg =
Http.pin_message msg.channel_id msg.id
+ >>| Result.map ~f:ignore
let unpin msg =
Http.unpin_message msg.channel_id msg.id
+ >>| Result.map ~f:ignore
let reply msg cont =
let rep = `Assoc [("content", `String cont)] in
Http.create_message msg.channel_id rep
+ >>| Result.map ~f:Message_t.of_yojson_exn
let set_content msg cont =
to_yojson { msg with content = cont; }
|> Http.edit_message msg.channel_id msg.id
+ >>| Result.map ~f:Message_t.of_yojson_exn
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
+ |> Http.edit_message msg.channel_id msg.id
+ >>| Result.map ~f:Message_t.of_yojson_exn \ No newline at end of file
diff --git a/lib/models/message.mli b/lib/models/message.mli
index 040eb5e..40c87d4 100644
--- a/lib/models/message.mli
+++ b/lib/models/message.mli
@@ -2,12 +2,12 @@ open Async
include module type of Message_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
+val add_reaction : t -> Emoji.t -> unit Deferred.Or_error.t
+val remove_reaction : t -> Emoji.t -> User_t.t -> unit Deferred.Or_error.t
+val clear_reactions : t -> unit Deferred.Or_error.t
+val delete : t -> unit Deferred.Or_error.t
+val pin : t -> unit Deferred.Or_error.t
+val unpin : t -> unit Deferred.Or_error.t
+val reply : t -> string -> t Deferred.Or_error.t
+val set_content : t -> string -> t Deferred.Or_error.t
+val set_embed : t -> Embed.t -> t Deferred.Or_error.t \ No newline at end of file