aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/channel.ml10
-rw-r--r--lib/client.ml4
-rw-r--r--lib/guild.ml10
-rw-r--r--lib/message.ml12
-rw-r--r--lib/model.ml26
-rw-r--r--lib/models/attachment.ml9
-rw-r--r--lib/models/channel.ml17
-rw-r--r--lib/models/embed.ml44
-rw-r--r--lib/models/emoji.ml9
-rw-r--r--lib/models/guild.ml28
-rw-r--r--lib/models/member.ml8
-rw-r--r--lib/models/message.ml21
-rw-r--r--lib/models/reaction.ml4
-rw-r--r--lib/models/role.ml10
-rw-r--r--lib/models/snowflake.ml16
-rw-r--r--lib/models/user.ml7
-rw-r--r--lib/s.ml4
-rw-r--r--lib/sharder.ml20
18 files changed, 180 insertions, 79 deletions
diff --git a/lib/channel.ml b/lib/channel.ml
deleted file mode 100644
index 904bbde..0000000
--- a/lib/channel.ml
+++ /dev/null
@@ -1,10 +0,0 @@
-type t = {
- id: string;
- name: string;
-}
-
-let from_json term =
- let module J = Yojson.Basic.Util in
- let id = J.(member "id" term |> to_string) in
- let name = J.(member "name" term |> to_string) in
- { id; name; }
diff --git a/lib/client.ml b/lib/client.ml
index 7c2d532..374287c 100644
--- a/lib/client.ml
+++ b/lib/client.ml
@@ -2,7 +2,7 @@ open Async
type t = {
sharder: Sharder.t Ivar.t;
- handler: (string * Model.t) Pipe.Writer.t;
+ handler: string Pipe.Writer.t;
token: string;
}
@@ -14,7 +14,7 @@ let make ~handler token =
}
let start ?count client =
- Sharder.start ?count ~handler:client.handler client.token
+ Sharder.start ?count client.token
>>| fun sharder ->
Ivar.fill_if_empty client.sharder sharder;
client
diff --git a/lib/guild.ml b/lib/guild.ml
deleted file mode 100644
index 904bbde..0000000
--- a/lib/guild.ml
+++ /dev/null
@@ -1,10 +0,0 @@
-type t = {
- id: string;
- name: string;
-}
-
-let from_json term =
- let module J = Yojson.Basic.Util in
- let id = J.(member "id" term |> to_string) in
- let name = J.(member "name" term |> to_string) in
- { id; name; }
diff --git a/lib/message.ml b/lib/message.ml
deleted file mode 100644
index 5b632d7..0000000
--- a/lib/message.ml
+++ /dev/null
@@ -1,12 +0,0 @@
-type t = {
- id: string;
- content: string;
- channel: string;
-}
-
-let from_json term =
- let module J = Yojson.Basic.Util in
- let id = J.(member "id" term |> to_string) in
- let content = J.(member "content" term |> to_string) in
- let channel = J.(member "channel_id" term |> to_string) in
- { id; content; channel; }
diff --git a/lib/model.ml b/lib/model.ml
deleted file mode 100644
index c44a289..0000000
--- a/lib/model.ml
+++ /dev/null
@@ -1,26 +0,0 @@
-module Make(M: S.Model) = struct
- include M
-end
-
-module Message = Make(Message)
-module Guild = Make(Guild)
-module Channel = Make(Channel)
-
-exception Type_Mismatch
-
-type t =
- | Message of Message.t
- | Guild of Guild.t
- | Channel of Channel.t
-
-let to_message = function
- | Message m -> m
- | _ -> raise Type_Mismatch
-
-let to_guild = function
- | Guild m -> m
- | _ -> raise Type_Mismatch
-
-let to_channel = function
- | Channel m -> m
- | _ -> raise Type_Mismatch \ No newline at end of file
diff --git a/lib/models/attachment.ml b/lib/models/attachment.ml
new file mode 100644
index 0000000..095743d
--- /dev/null
+++ b/lib/models/attachment.ml
@@ -0,0 +1,9 @@
+type t = {
+ id: Snowflake.t;
+ filename: string;
+ size: int;
+ url: string;
+ proxy_url: string;
+ height: int option;
+ width: int option;
+} \ No newline at end of file
diff --git a/lib/models/channel.ml b/lib/models/channel.ml
new file mode 100644
index 0000000..78051c3
--- /dev/null
+++ b/lib/models/channel.ml
@@ -0,0 +1,17 @@
+type t = {
+ id: Snowflake.t;
+ kind: int;
+ (* guild: Guild.t option; *)
+ position: int option;
+ permission_overwrites: (int list) option;
+ name: string option;
+ topic: string option;
+ nsfw: bool option;
+ bitrate: int option;
+ user_limit: int option;
+ recipients: (User.t list) option;
+ icon: string option;
+ owner_id: Snowflake.t option;
+ application_id: Snowflake.t option;
+ parent_id: Snowflake.t option;
+} \ No newline at end of file
diff --git a/lib/models/embed.ml b/lib/models/embed.ml
new file mode 100644
index 0000000..6ba1115
--- /dev/null
+++ b/lib/models/embed.ml
@@ -0,0 +1,44 @@
+type footer = {
+ text: string;
+ icon_url: string option;
+ proxy_icon_url: string option;
+}
+
+type image = {
+ url: string option;
+ proxy_url: string option;
+ height: int option;
+ width: int option;
+}
+
+type video = {
+ url: string option;
+ height: int option;
+ width: int option;
+}
+
+type provider = {
+ name: string option;
+ url: string option;
+}
+
+type field = {
+ name: string;
+ value: string;
+ inline: bool option;
+}
+
+type t = {
+ title: string option;
+ kind: string option;
+ description: string option;
+ url: string option;
+ timestamp: string option;
+ colour: int option;
+ footer: footer option;
+ image: image option;
+ thumbnail: image option;
+ video: video option;
+ provider: provider option;
+ fields: (field list) option;
+} \ No newline at end of file
diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml
new file mode 100644
index 0000000..3d89867
--- /dev/null
+++ b/lib/models/emoji.ml
@@ -0,0 +1,9 @@
+type t = {
+ id: Snowflake.t;
+ name: string;
+ roles: (Role.t list) option;
+ user: User.t option;
+ require_colons: bool option;
+ managed: bool;
+ animated: bool;
+} \ No newline at end of file
diff --git a/lib/models/guild.ml b/lib/models/guild.ml
new file mode 100644
index 0000000..364a4d5
--- /dev/null
+++ b/lib/models/guild.ml
@@ -0,0 +1,28 @@
+type t = {
+ id: Snowflake.t;
+ name: string;
+ icon: string;
+ splash: string;
+ owner: User.t;
+ region: string;
+ afk_channel: Channel.t option;
+ afk_timeout: int;
+ embed_enabled: bool;
+ embed_channel: Channel.t;
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role.t list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option;
+ widget_enabled: bool option;
+ widget_channel: Channel.t option;
+ system_channel: Channel.t option;
+ large: bool;
+ unavailable: bool;
+ member_count: int;
+ members: Member.t list;
+ channels: Channel.t list;
+} \ No newline at end of file
diff --git a/lib/models/member.ml b/lib/models/member.ml
new file mode 100644
index 0000000..1cbe50b
--- /dev/null
+++ b/lib/models/member.ml
@@ -0,0 +1,8 @@
+type t = {
+ user: User.t;
+ nick: string option;
+ roles: Role.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+} \ No newline at end of file
diff --git a/lib/models/message.ml b/lib/models/message.ml
new file mode 100644
index 0000000..6c2e80d
--- /dev/null
+++ b/lib/models/message.ml
@@ -0,0 +1,21 @@
+type t = {
+ id: Snowflake.t;
+ author: User.t;
+ channel: Channel.t;
+ member: Member.t option;
+ guild: Guild.t option;
+ content: string;
+ timestamp: string;
+ edited_timestamp: string option;
+ tts: bool;
+ mention_everyone: bool;
+ mentions: User.t list;
+ role_mentions: Role.t list;
+ attachments: Attachment.t list;
+ embeds: Embed.t list;
+ reactions: Reaction.t list;
+ nonce: Snowflake.t option;
+ pinned: bool;
+ webhook_id: Snowflake.t;
+ kind: int;
+} \ No newline at end of file
diff --git a/lib/models/reaction.ml b/lib/models/reaction.ml
new file mode 100644
index 0000000..b427505
--- /dev/null
+++ b/lib/models/reaction.ml
@@ -0,0 +1,4 @@
+type t = {
+ count: int;
+ emoji: Emoji.t;
+} \ No newline at end of file
diff --git a/lib/models/role.ml b/lib/models/role.ml
new file mode 100644
index 0000000..debba60
--- /dev/null
+++ b/lib/models/role.ml
@@ -0,0 +1,10 @@
+type t = {
+ id: Snowflake.t;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+} \ No newline at end of file
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml
new file mode 100644
index 0000000..ed80b62
--- /dev/null
+++ b/lib/models/snowflake.ml
@@ -0,0 +1,16 @@
+type t = {
+ id: int;
+ as_string: string;
+}
+
+let to_int t = t.id
+let to_string t = t.as_string
+
+let from_int i = {
+ id = i;
+ as_string = string_of_int i;
+}
+let from_string s = {
+ id = int_of_string s;
+ as_string = s;
+} \ No newline at end of file
diff --git a/lib/models/user.ml b/lib/models/user.ml
new file mode 100644
index 0000000..05cf570
--- /dev/null
+++ b/lib/models/user.ml
@@ -0,0 +1,7 @@
+type t = {
+ id: Snowflake.t;
+ username: string;
+ discriminator: string;
+ avatar: string;
+ bot: bool;
+} \ No newline at end of file
diff --git a/lib/s.ml b/lib/s.ml
deleted file mode 100644
index 6c6456a..0000000
--- a/lib/s.ml
+++ /dev/null
@@ -1,4 +0,0 @@
-module type Model = sig
- type t
- val from_json : Yojson.Basic.json -> t
-end \ No newline at end of file
diff --git a/lib/sharder.ml b/lib/sharder.ml
index 9e2ef74..5d665b9 100644
--- a/lib/sharder.ml
+++ b/lib/sharder.ml
@@ -9,7 +9,6 @@ module Shard = struct
mutable hb: unit Ivar.t option;
mutable seq: int;
mutable session: string option;
- handler: (string * Model.t) Pipe.Writer.t;
token: string;
shard: int * int;
write: string Pipe.Writer.t;
@@ -55,19 +54,11 @@ module Shard = struct
shard.seq <- seq;
let t = J.(member "t" payload |> to_string) in
let data = J.member "d" payload in
- let _ = match t with
- | "READY" ->
+ if t = "READY" then begin
Ivar.fill_if_empty shard.ready ();
let session = J.(member "session_id" data |> to_string) in
shard.session <- Some session
- | "MESSAGE_CREATE" ->
- let msg = Model.Message.from_json data in
- Pipe.write shard.handler (t, Message msg) >>> ignore
- | "GUILD_CREATE" ->
- let guild = Model.Guild.from_json data in
- Pipe.write shard.handler (t, Guild guild) >>> ignore
- | _ -> ()
- in
+ end;
return shard
let set_status shard status =
@@ -168,7 +159,7 @@ module Shard = struct
print_endline @@ "Invalid Opcode:" ^ Opcode.to_string opcode;
return shard
- let create ~url ~shards ~token ~handler () =
+ let create ~url ~shards ~token () =
let open Core in
let uri = (url ^ "?v=6&encoding=json") |> Uri.of_string in
let extra_headers = Http.Base.process_request_headers () in
@@ -194,7 +185,6 @@ module Shard = struct
let shard = {
read;
write;
- handler;
ready = Ivar.create ();
hb = None;
seq = 0;
@@ -227,7 +217,7 @@ type t = {
shards: Shard.t list;
}
-let start ?count ~handler token =
+let start ?count token =
let module J = Yojson.Basic.Util in
Http.get_gateway_bot () >>= fun data ->
let url = J.(member "url" data |> to_string) in
@@ -240,7 +230,7 @@ let start ?count ~handler token =
match l with
| (id, total) when id >= total -> return a
| (id, total) ->
- Shard.create ~url ~shards:(id, total) ~token ~handler ()
+ Shard.create ~url ~shards:(id, total) ~token ()
>>= fun shard ->
let a = shard :: a in
gen_shards (id+1, total) a