aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMishio595 <[email protected]>2018-10-14 08:29:52 -0600
committerMishio595 <[email protected]>2018-10-14 08:29:52 -0600
commitc42603da68df3610d063d7b232b53bb45e0183e1 (patch)
tree9666bd4f51e7e6679c6dd5fa6cd97ee29fb3117d /lib
downloaddisml-c42603da68df3610d063d7b232b53bb45e0183e1.tar.xz
disml-c42603da68df3610d063d7b232b53bb45e0183e1.zip
Initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/animus.ml1
-rw-r--r--lib/endpoints.ml94
-rw-r--r--lib/gateway.ml0
-rw-r--r--lib/http.ml43
4 files changed, 138 insertions, 0 deletions
diff --git a/lib/animus.ml b/lib/animus.ml
new file mode 100644
index 0000000..baf4112
--- /dev/null
+++ b/lib/animus.ml
@@ -0,0 +1 @@
+Lwt_main.run (Lwt_io.printf "Hello, World!") \ No newline at end of file
diff --git a/lib/endpoints.ml b/lib/endpoints.ml
new file mode 100644
index 0000000..08f479d
--- /dev/null
+++ b/lib/endpoints.ml
@@ -0,0 +1,94 @@
+let gateway = "/gateway"
+let gateway_bot = "/gateway/bot"
+
+let channel channel_id = "/channels/"^channel_id
+let channel_messages channel_id = "/channels/"^channel_id^"/messages"
+
+let channel_message channel_id msg_id =
+ "/channels/"^channel_id^"/messages/"^msg_id
+
+let channel_reaction_me channel_id msg_id emoji =
+ "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji^"/@me"
+
+let channel_reaction channel_id msg_id emoji user_id =
+ "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji^"/"^user_id
+
+let channel_reactions_get channel_id msg_id emoji =
+ "/channels/"^channel_id^"/messages/"^msg_id^"/reactions/"^emoji
+
+let channel_reactions_delete channel_id msg_id =
+ "/channels/"^channel_id^"/messages/"^msg_id^"/reactions"
+
+let channel_bulk_delete channel_id = "/channels/"^channel_id
+
+let channel_permission channel_id overwrite_id =
+ "/channels/"^channel_id^"/permissions/"^overwrite_id
+
+let channel_permissions channel_id = "/channels"^channel_id^"/permissions"
+let channels = "/channels"
+let channel_call_ring channel_id = "/channels/"^channel_id^"/call/ring"
+let channel_invites channel_id = "/channels/"^channel_id^"/invites"
+let channel_typing channel_id = "/channels/"^channel_id^"/typing"
+let channel_pins channel_id = "/channels/"^channel_id^"/pins"
+let channel_pin channel_id msg_id = "/channels/"^channel_id^"/pins/"^msg_id
+
+let guilds = "/guilds"
+let guild guild_id = "/guilds/"^guild_id
+let guild_channels guild_id = "/guilds/"^guild_id^"/channels"
+let guild_members guild_id = "/guilds/"^guild_id^"/members"
+let guild_member guild_id user_id = "/guilds/"^guild_id^"/members/"^user_id
+
+let guild_member_role guild_id user_id role_id =
+ "/guilds/"^guild_id^"/members/"^user_id^"/roles/"^role_id
+
+let guild_bans guild_id = "/guilds/"^guild_id^"/bans"
+let guild_ban guild_id user_id = "/guilds/"^guild_id^"/bans"^user_id
+let guild_roles guild_id = "/guilds/"^guild_id^"/roles"
+let guild_role guild_id role_id = "/guilds/"^guild_id^"/roles"^role_id
+let guild_prune guild_id = "/guilds/"^guild_id^"/prune"
+let guild_voice_regions guild_id = "/guilds/"^guild_id^"/regions"
+let guild_invites guild_id = "/guilds/"^guild_id^"/invites"
+let guild_integrations guild_id = "/guilds/"^guild_id^"/integrations"
+
+let guild_integration guild_id integration_id =
+ "/guilds/"^guild_id^"/integrations/"^integration_id
+
+let guild_integration_sync guild_id integration_id =
+ "/guilds/"^guild_id^"/integrations/"^integration_id^"/sync"
+
+let guild_embed guild_id = "/guilds/"^guild_id^"/embed"
+let guild_emojis guild_id = "/guilds/"^guild_id^"/emojis"
+let guild_emoji guild_id emoji_id = "/guilds/"^guild_id^"/emojis/"^emoji_id
+
+let webhooks_guild guild_id = "/guilds/"^guild_id^"/webhooks"
+let webhooks_channel channel_id = "/channels/"^channel_id^"/webhooks"
+let webhook webhook_id = "/webhooks/"^webhook_id
+let webhook_token webhook_id token = "/webhooks/"^webhook_id^"/"^token
+
+let webhook_git webhook_id token =
+ "/webhooks/"^webhook_id^"/"^token^"/github"
+
+let webhook_slack webhook_id token =
+ "/webhooks/"^webhook_id^"/"^token^"/slack"
+
+let user user_id = "/users/"^user_id
+
+let me = "/users/@me"
+let me_guilds = "/users/@me/guilds"
+let me_guild guild_id = "/users/@me/guilds/"^guild_id
+let me_channels = "/users/@me/channels"
+let me_connections = "/users/@me/connections"
+
+let invite code = "/invites/"^code
+let regions = "/voice/regions"
+
+let application_information = "/oauth2/applications/@me"
+
+let group_recipient group_id user_id = "/channels/"^group_id^"/recipients/"^user_id
+let guild_me_nick guild_id = "/guilds/"^guild_id^"/members/@me/nick"
+
+let cdn_avatar id avatar image_format = "/avatars/"^id^"/"^avatar^"."^image_format
+let cdn_embed_avatar image_name = "/embed/avatars/"^image_name^".png"
+let cdn_emoji id image_format = "/emojis/"^id^"."^image_format
+let cdn_icon id icon image_format = "/icons/"^id^"/"^icon^"."^image_format
+let cdn_avatar id splash image_format = "/splashes/"^id^"/"^splash^"."^image_format \ No newline at end of file
diff --git a/lib/gateway.ml b/lib/gateway.ml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/gateway.ml
diff --git a/lib/http.ml b/lib/http.ml
new file mode 100644
index 0000000..ba73fd9
--- /dev/null
+++ b/lib/http.ml
@@ -0,0 +1,43 @@
+open Lwt.Infix
+open Cohttp
+open Cohttp_lwt_unix
+
+module Base = struct
+ exception Invalid_Method
+
+ let base_url = "https://discordapp.com/api/v7"
+ let cdn_url = "https://cdn.discordapp.com"
+
+ let process_url path =
+ Uri.of_string (base_url ^ path)
+
+ let process_request_body body =
+ body
+ |> Yojson.Basic.to_string
+ |> Cohttp_lwt.Body.of_string
+
+ let process_request_headers () =
+ let token = try
+ Sys.getenv "DISCORD_TOKEN"
+ with Not_found -> failwith "Please provide a token" in
+ let h = Header.init_with "User-Agent" "Animus v0.1.0" in
+ let h = Header.add h "Authorization" ("Bot " ^ token) in
+ Header.add h "Content-Type" "application/json"
+
+ (* TODO Finish processor *)
+ let process_response (resp, body) =
+ body |> Cohttp_lwt.Body.to_string >|= Yojson.Basic.from_string
+
+ let request ?(body=`Null) m path =
+ let uri = process_url path in
+ let headers = process_request_headers () in
+ let body = process_request_body body in
+ (match m with
+ | `DELETE -> Client.delete ~headers ~body uri
+ | `GET -> Client.get ~headers uri
+ | `PATCH -> Client.patch ~headers ~body uri
+ | `POST -> Client.post ~headers ~body uri
+ | `PUT -> Client.put ~headers ~body uri
+ | _ -> raise Invalid_Method)
+ >|= process_response
+end \ No newline at end of file