diff options
| author | Adelyn Breedlove <[email protected]> | 2018-12-15 18:02:29 +0000 |
|---|---|---|
| committer | Adelyn Breedlove <[email protected]> | 2018-12-15 18:02:29 +0000 |
| commit | 910ce60bba69b961c82e29ff1bb63bf4d3fe5519 (patch) | |
| tree | 690861418bed15de47e7cf5672d96fdacc9abe5e /bin | |
| parent | Merge branch 'patch-1' into 'master' (diff) | |
| parent | Merging (diff) | |
| download | disml-910ce60bba69b961c82e29ff1bb63bf4d3fe5519.tar.xz disml-910ce60bba69b961c82e29ff1bb63bf4d3fe5519.zip | |
Merge branch 'dev' into 'master'
Merge first semi-usable state of dev-branch in a while
See merge request Mishio595/disml!10
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/bot.ml | 40 | ||||
| -rw-r--r-- | bin/handler.ml | 47 |
2 files changed, 57 insertions, 30 deletions
@@ -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 () diff --git a/bin/handler.ml b/bin/handler.ml new file mode 100644 index 0000000..74eaefb --- /dev/null +++ b/bin/handler.ml @@ -0,0 +1,47 @@ +module Make(Models : Disml.S.Models) = struct + open Core + open Async + open Models + open Disml.Event + + let check_command (msg:Disml.Message_t.t) = + if String.is_prefix ~prefix:"!ping" msg.content then + Message.reply msg "Hello!" >>> ignore + + let handle_event = function + | HELLO _ -> print_endline "Received HELLO" + | READY _ -> print_endline "Received READY" + | RESUMED _ -> print_endline "Received RESUMED" + | INVALID_SESSION _ -> print_endline "Received INVALID_SESSION" + | CHANNEL_CREATE _ -> print_endline "Received CHANNEL_CREATE" + | CHANNEL_UPDATE _ -> print_endline "Received CHANNEL_UPDATE" + | CHANNEL_DELETE _ -> print_endline "Received CHANNEL_DELETE" + | CHANNEL_PINS_UPDATE _ -> print_endline "Received CHANNEL_PINS_UPDATE" + | GUILD_CREATE _ -> print_endline "Received GUILD_CREATE" + | GUILD_UPDATE _ -> print_endline "Received GUILD_UPDATE" + | GUILD_DELETE _ -> print_endline "Received GUILD_DELETE" + | GUILD_BAN_ADD _ -> print_endline "Received GUILD_BAN_ADD" + | GUILD_BAN_REMOVE _ -> print_endline "Received GUILD_BAN_REMOVE" + | GUILD_EMOJIS_UPDATE _ -> print_endline "Received GUILD_EMOJIS_UPDATE" + | GUILD_INTEGRATIONS_UPDATE _ -> print_endline "Received GUILD_INTEGRATIONS_UPDATE" + | GUILD_MEMBER_ADD _ -> print_endline "Received GUILD_MEMBER_ADD" + | GUILD_MEMBER_REMOVE _ -> print_endline "Received GUILD_MEMBER_REMOVE" + | GUILD_MEMBER_UPDATE _ -> print_endline "Received GUILD_MEMBER_UPDATE" + | GUILD_MEMBERS_CHUNK _ -> print_endline "Received GUILD_MEMBERS_CHUNK" + | GUILD_ROLE_CREATE _ -> print_endline "Received GUILD_ROLE_CREATE" + | GUILD_ROLE_UPDATE _ -> print_endline "Received GUILD_ROLE_UPDATE" + | GUILD_ROLE_DELETE _ -> print_endline "Received GUILD_ROLE_DELETE" + | MESSAGE_CREATE msg -> check_command msg; print_endline "Received MESSAGE_CREATE" + | MESSAGE_UPDATE _ -> print_endline "Received MESSAGE_UPDATE" + | MESSAGE_DELETE _ -> print_endline "Received MESSAGE_DELETE" + | MESSAGE_BULK_DELETE _ -> print_endline "Received MESSAGE_BULK_DELETE" + | MESSAGE_REACTION_ADD _ -> print_endline "Received MESSAGE_REACTION_ADD" + | MESSAGE_REACTION_REMOVE _ -> print_endline "Received MESSAGE_REACTION_REMOVE" + | MESSAGE_REACTION_REMOVE_ALL _ -> print_endline "Received MESSAGE_REACTION_REMOVE_ALL" + | PRESENCE_UPDATE _ -> print_endline "Received PRESENCE_UPDATE" + | TYPING_START _ -> print_endline "Received TYPING_START" + | USER_UPDATE _ -> print_endline "Received USER_UPDATE" + | VOICE_STATE_UPDATE _ -> print_endline "Received VOICE_STATE_UPDATE" + | VOICE_SERVER_UPDATE _ -> print_endline "Received VOICE_SERVER_UPDATE" + | WEBHOOKS_UPDATE _ -> print_endline "Received WEBHOOKS_UPDATE" +end
\ No newline at end of file |