aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-11-18 12:04:19 -0700
committerMishio595 <[email protected]>2018-11-18 12:04:19 -0700
commita7340eba42bcef93a4e6f9ece7c86043f9a01747 (patch)
tree7ec65e89673ad8d9e70b12482206e27e9fa77704 /bin
parentRewrite from Lwt to Async (diff)
downloaddisml-a7340eba42bcef93a4e6f9ece7c86043f9a01747.tar.xz
disml-a7340eba42bcef93a4e6f9ece7c86043f9a01747.zip
Event dispatch and client abstraction
Diffstat (limited to 'bin')
-rw-r--r--bin/bot.ml23
1 files changed, 20 insertions, 3 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index 34f24ea..83e7063 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -1,4 +1,5 @@
open Async
+open Core
open Disml
let main () =
@@ -6,8 +7,24 @@ let main () =
| Some s -> s
| None -> failwith "No token"
in
- Sharder.start token
- |> ignore
+ let client = Client.make token in
+ Client.on "MESSAGE_CREATE" client (fun msg ->
+ 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
+ Http.create_message channel @@ `Assoc [
+ ("content", `String "Pong!");
+ ("tts", `Bool false);
+ ]
+ >>> fun _ -> print_endline "Message sent!";
+ );
+ Client.start client
+ >>> fun client ->
+ Clock.every
+ (Time.Span.create ~sec:60 ())
+ (fun () ->
+ Client.set_status_with client (fun shard -> `String ("Current seq: " ^ (Int.to_string shard.seq)))
+ |> ignore)
let _ =
- Scheduler.go_main ~main:(main) () \ No newline at end of file
+ Scheduler.go_main ~main () \ No newline at end of file