diff options
| author | Mishio595 <[email protected]> | 2018-11-18 12:39:21 -0700 |
|---|---|---|
| committer | Mishio595 <[email protected]> | 2018-11-18 12:39:21 -0700 |
| commit | 515ca7c7e354086017e33bcea8315d8c2c3d07cc (patch) | |
| tree | 02d0bab4b0b047e8ffb42395ff82a581eca2de06 | |
| parent | Event dispatch and client abstraction (diff) | |
| download | disml-515ca7c7e354086017e33bcea8315d8c2c3d07cc.tar.xz disml-515ca7c7e354086017e33bcea8315d8c2c3d07cc.zip | |
Ping bot example
| -rw-r--r-- | bin/bot.ml | 9 | ||||
| -rw-r--r-- | lib/client/sharder.mli | 2 |
2 files changed, 9 insertions, 2 deletions
@@ -9,6 +9,7 @@ let main () = in let client = Client.make token in Client.on "MESSAGE_CREATE" client (fun msg -> + let msg_time = Time.(to_span_since_epoch @@ now ()) in let content = Yojson.Basic.Util.(member "content" msg |> to_string) in let channel = Yojson.Basic.Util.(member "channel_id" msg |> to_string) in if String.is_prefix ~prefix:"!?ping" content then @@ -16,7 +17,13 @@ let main () = ("content", `String "Pong!"); ("tts", `Bool false); ] - >>> fun _ -> print_endline "Message sent!"; + >>> fun resp -> + let message_id = Yojson.Basic.Util.(member "id" resp |> to_string) in + let rtt = Time.(to_span_since_epoch @@ sub (now ()) msg_time) in + Http.edit_message channel message_id @@ `Assoc [ + ("content", `String ("Pong! `" ^ (Float.to_string @@ Time.Span.to_ms rtt) ^ " ms`")); + ] + >>> fun _ -> print_endline "Message Edited!" ); Client.start client >>> fun client -> diff --git a/lib/client/sharder.mli b/lib/client/sharder.mli index b49c264..0fd16d6 100644 --- a/lib/client/sharder.mli +++ b/lib/client/sharder.mli @@ -20,7 +20,7 @@ type handler = { guild_member_add: (Yojson.Basic.json -> unit) option; guild_member_remove: (Yojson.Basic.json -> unit) option; guild_member_update: (Yojson.Basic.json -> unit) option; - guild_members_chunk: (Yojson.Basic.json -> unit) option; (* Not sure if this should be exposed *) + guild_members_chunk: (Yojson.Basic.json -> unit) option; guild_role_create: (Yojson.Basic.json -> unit) option; guild_role_delete: (Yojson.Basic.json -> unit) option; guild_role_update: (Yojson.Basic.json -> unit) option; |