diff options
| -rw-r--r-- | bin/bot.ml | 17 | ||||
| -rw-r--r-- | lib/client.ml | 3 | ||||
| -rw-r--r-- | lib/client.mli | 1 |
3 files changed, 15 insertions, 6 deletions
@@ -2,6 +2,8 @@ open Async open Core open Disml +let client = Ivar.create () + let check_command (msg:Message.t) = let cmd, rest = match String.split ~on:' ' msg.content with | hd::tl -> hd, tl @@ -49,18 +51,27 @@ let check_command (msg:Message.t) = |> field ("field 1", "test", true) ) in Message.reply_with ~embed msg >>> ignore + | "!status" -> + let status = List.fold ~init:"" ~f:(^) rest in + Ivar.read client >>> fun client -> + Client.set_status ~status:(`String status) client + >>> ignore | _ -> () -let main () = +let setup_logger () = Logs.set_reporter (Logs_fmt.reporter ()); - Logs.set_level ~all:true (Some Logs.Debug); + Logs.set_level ~all:true (Some Logs.Debug) + +let main () = + setup_logger (); Client.message_create := check_command; let token = match Sys.getenv "DISCORD_TOKEN" with | Some t -> t | None -> failwith "No token in env" in Client.start token - >>> ignore + >>> fun c -> + Ivar.fill client c let _ = Scheduler.go_main ~main () diff --git a/lib/client.ml b/lib/client.ml index 3b0024d..72be653 100644 --- a/lib/client.ml +++ b/lib/client.ml @@ -4,14 +4,13 @@ include Dispatch type t = { sharder: Sharder.t; - token: string; } let start ?count token = Client_options.token := token; Sharder.start ?count () >>| fun sharder -> - { sharder; token; } + { sharder; } let set_status ~status client = Sharder.set_status ~status client.sharder diff --git a/lib/client.mli b/lib/client.mli index 333715f..3e79a39 100644 --- a/lib/client.mli +++ b/lib/client.mli @@ -6,7 +6,6 @@ include module type of Dispatch (** Type of the Client, it isn't recommended to access the fields directly. *) type t = { sharder: Sharder.t; - token: string; } (** Start the Client. This begins shard connections to Discord and event handlers should be registered prior to calling this. |