aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2018-11-18 19:05:53 +0000
committerAdelyn Breedlove <[email protected]>2018-11-18 19:05:53 +0000
commit84d98bd3b227ac2bba5163d4e616d73e355494ee (patch)
tree7ec65e89673ad8d9e70b12482206e27e9fa77704 /bin
parentMerge branch 'dev' into 'master' (diff)
parentEvent dispatch and client abstraction (diff)
downloaddisml-84d98bd3b227ac2bba5163d4e616d73e355494ee.tar.xz
disml-84d98bd3b227ac2bba5163d4e616d73e355494ee.zip
Merge branch 'dev' into 'master'
Add event dispatch and the Client module See merge request Mishio595/disml!4
Diffstat (limited to 'bin')
-rw-r--r--bin/bot.ml42
1 files changed, 26 insertions, 16 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index bf9f36e..83e7063 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -1,20 +1,30 @@
-open Lwt.Infix
+open Async
+open Core
open Disml
-let main sharder =
- Lwt_engine.on_timer 60.0 true begin
- fun _ev -> Sharder.set_status_with sharder @@ begin
- fun shard ->
- `String ("Current seq: " ^ string_of_int shard.seq)
- end
- >|= (fun _ -> print_endline "Status set!")
- |> ignore;
- end
+let main () =
+ let token = match Sys.getenv "DISCORD_TOKEN" with
+ | Some s -> s
+ | None -> failwith "No token"
+ in
+ 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 _ =
- Sharder.start @@ Sys.getenv "DISCORD_TOKEN"
- >>= (fun sharder ->
- main sharder
- |> ignore;
- sharder.promise)
- |> Lwt_main.run \ No newline at end of file
+ Scheduler.go_main ~main () \ No newline at end of file