aboutsummaryrefslogtreecommitdiff
path: root/bin/bot.ml
diff options
context:
space:
mode:
Diffstat (limited to 'bin/bot.ml')
-rw-r--r--bin/bot.ml40
1 files changed, 10 insertions, 30 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index 08a182e..7d7f714 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -1,41 +1,21 @@
open Async
open Core
-open Disml
-let hook_events client =
- 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
- Http.create_message channel @@ `Assoc [
- ("content", `String "Pong!");
- ("tts", `Bool false);
- ]
- >>> 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.on "GUILD_CREATE" client (fun guild -> print_endline Yojson.Basic.Util.(member "name" guild |> to_string))
+module Client = Disml.Client.Make(struct
+ let token = match Sys.getenv "DISCORD_TOKEN" with
+ | Some t -> t
+ | None -> failwith "No token in env"
+end)(Handler)
let main () =
- let token = match Sys.getenv "DISCORD_TOKEN" with
- | Some s -> s
- | None -> failwith "No token"
- in
- let client = Client.make token in
- hook_events client;
- Client.start client
+ Client.start ()
>>> 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)
+ print_endline "Setting status";
+ Client.set_status ~status:(`String "Hello!") client
+ >>> ignore)
let _ =
- Scheduler.go_main ~main () \ No newline at end of file
+ Scheduler.go_main ~main ()