aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2019-01-21 13:50:14 -0700
committerAdelyn Breelove <[email protected]>2019-01-21 13:50:14 -0700
commit3dfa0c4d0247bfddae476372414808cd219004f8 (patch)
tree2b0b4b8f7846918c55b6b698454c9d63251dbd1a
parentFix sharding logic (diff)
downloaddisml-3dfa0c4d0247bfddae476372414808cd219004f8.tar.xz
disml-3dfa0c4d0247bfddae476372414808cd219004f8.zip
Add status change command example
-rw-r--r--bin/bot.ml17
-rw-r--r--lib/client.ml3
-rw-r--r--lib/client.mli1
3 files changed, 15 insertions, 6 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index 1aae20b..0acc0a1 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -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.