aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2018-12-17 13:13:10 -0700
committerAdelyn Breelove <[email protected]>2018-12-17 13:13:10 -0700
commit57df76de6441899b659e30c6a8e9d7572b85f7a0 (patch)
tree3825d09337f03c447bb86ce66834b4fd39a8083b
parentAdd a few sigs (diff)
downloaddisml-57df76de6441899b659e30c6a8e9d7572b85f7a0.tar.xz
disml-57df76de6441899b659e30c6a8e9d7572b85f7a0.zip
Some abstractions
-rw-r--r--lib/endpoints.ml3
-rw-r--r--lib/http.ml17
-rw-r--r--lib/models/gen/guild.atd4
-rw-r--r--lib/models/gen/guild_j.ml172
-rw-r--r--lib/models/gen/guild_j.mli4
-rw-r--r--lib/models/gen/guild_t.ml4
-rw-r--r--lib/models/gen/guild_t.mli4
-rw-r--r--lib/models/gen/role.atd12
-rw-r--r--lib/models/gen/role_j.ml645
-rw-r--r--lib/models/gen/role_j.mli54
-rw-r--r--lib/models/gen/role_t.ml14
-rw-r--r--lib/models/gen/role_t.mli14
-rw-r--r--lib/models/gen/user.atd12
-rw-r--r--lib/models/gen/user_j.ml8
-rw-r--r--lib/models/gen/user_j.mli2
-rw-r--r--lib/models/gen/user_t.ml2
-rw-r--r--lib/models/gen/user_t.mli2
-rw-r--r--lib/models/guild.ml98
-rw-r--r--lib/models/role.ml23
-rw-r--r--lib/models/snowflake.ml12
-rw-r--r--lib/models/user.ml20
-rw-r--r--lib/s.ml66
22 files changed, 1003 insertions, 189 deletions
diff --git a/lib/endpoints.ml b/lib/endpoints.ml
index 12563b0..c23ae88 100644
--- a/lib/endpoints.ml
+++ b/lib/endpoints.ml
@@ -59,4 +59,5 @@ let guild_audit_logs = sprintf "/guilds/%d/audit-logs"
let cdn_embed_avatar = sprintf "/embed/avatars/%s.png"
let cdn_emoji = sprintf "/emojis/%s.%s"
let cdn_icon = sprintf "/icons/%d/%s.%s"
-let cdn_avatar = sprintf "/splashes/%d/%s.%s" \ No newline at end of file
+let cdn_avatar = sprintf "/avatars/%d/%s.%s"
+let cdn_default_avatar = sprintf "/embed/avatars/%d" \ No newline at end of file
diff --git a/lib/http.ml b/lib/http.ml
index 810bdc3..abc2b28 100644
--- a/lib/http.ml
+++ b/lib/http.ml
@@ -1,4 +1,5 @@
module Make(T : S.Token) = struct
+ open Core
open Async
open Cohttp
include T
@@ -187,8 +188,8 @@ module Make(T : S.Token) = struct
let edit_member guild_id user_id body =
Base.request ~body `PATCH (Endpoints.guild_member guild_id user_id)
- let remove_member guild_id user_id =
- Base.request `DELETE (Endpoints.guild_member guild_id user_id)
+ let remove_member guild_id user_id body =
+ Base.request ~body `DELETE (Endpoints.guild_member guild_id user_id)
let change_nickname guild_id body =
Base.request ~body `PATCH (Endpoints.guild_me_nick guild_id)
@@ -208,8 +209,8 @@ module Make(T : S.Token) = struct
let guild_ban_add guild_id user_id body =
Base.request ~body `PUT (Endpoints.guild_ban guild_id user_id)
- let guild_ban_remove guild_id user_id =
- Base.request `DELETE (Endpoints.guild_ban guild_id user_id)
+ let guild_ban_remove guild_id user_id body =
+ Base.request ~body `DELETE (Endpoints.guild_ban guild_id user_id)
let get_roles guild_id =
Base.request `GET (Endpoints.guild_roles guild_id)
@@ -226,11 +227,11 @@ module Make(T : S.Token) = struct
let guild_role_remove guild_id role_id =
Base.request `DELETE (Endpoints.guild_role guild_id role_id)
- let guild_prune_count guild_id =
- Base.request `GET (Endpoints.guild_prune guild_id)
+ let guild_prune_count guild_id days =
+ Base.request `GET ((Endpoints.guild_prune guild_id) ^ "?days=" ^ Int.to_string days)
- let guild_prune_start guild_id body =
- Base.request ~body `POST (Endpoints.guild_prune guild_id)
+ let guild_prune_start guild_id days =
+ Base.request `POST ((Endpoints.guild_prune guild_id) ^ "?days=" ^ Int.to_string days)
let get_guild_voice_regions guild_id =
Base.request `GET (Endpoints.guild_voice_regions guild_id)
diff --git a/lib/models/gen/guild.atd b/lib/models/gen/guild.atd
index c622eea..3bb40d9 100644
--- a/lib/models/gen/guild.atd
+++ b/lib/models/gen/guild.atd
@@ -31,6 +31,6 @@ type t = {
?large: bool option;
?unavailable: bool option;
?member_count: int option;
- ?members: member list option;
- ?channels: channel list option;
+ ~members: member list;
+ ~channels: channel list;
} \ No newline at end of file
diff --git a/lib/models/gen/guild_j.ml b/lib/models/gen/guild_j.ml
index 9f7b069..210dee8 100644
--- a/lib/models/gen/guild_j.ml
+++ b/lib/models/gen/guild_j.ml
@@ -38,8 +38,8 @@ type t = Guild_t.t = {
large: bool option;
unavailable: bool option;
member_count: int option;
- members: member list option;
- channels: channel list option
+ members: member list;
+ channels: channel list
}
let write_user = (
@@ -406,133 +406,19 @@ let read__2 = (
)
let _2_of_string s =
read__2 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
-let write__11 = (
+let write__10 = (
Atdgen_runtime.Oj_run.write_list (
write_channel
)
)
-let string_of__11 ?(len = 1024) x =
- let ob = Bi_outbuf.create len in
- write__11 ob x;
- Bi_outbuf.contents ob
-let read__11 = (
- Atdgen_runtime.Oj_run.read_list (
- read_channel
- )
-)
-let _11_of_string s =
- read__11 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
-let write__12 = (
- Atdgen_runtime.Oj_run.write_option (
- write__11
- )
-)
-let string_of__12 ?(len = 1024) x =
- let ob = Bi_outbuf.create len in
- write__12 ob x;
- Bi_outbuf.contents ob
-let read__12 = (
- fun p lb ->
- Yojson.Safe.read_space p lb;
- match Yojson.Safe.start_any_variant p lb with
- | `Edgy_bracket -> (
- match Yojson.Safe.read_ident p lb with
- | "None" ->
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_gt p lb;
- (None : _ option)
- | "Some" ->
- Atdgen_runtime.Oj_run.read_until_field_value p lb;
- let x = (
- read__11
- ) p lb
- in
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_gt p lb;
- (Some x : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
- | `Double_quote -> (
- match Yojson.Safe.finish_string p lb with
- | "None" ->
- (None : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
- | `Square_bracket -> (
- match Atdgen_runtime.Oj_run.read_string p lb with
- | "Some" ->
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_comma p lb;
- Yojson.Safe.read_space p lb;
- let x = (
- read__11
- ) p lb
- in
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_rbr p lb;
- (Some x : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
-)
-let _12_of_string s =
- read__12 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
-let write__10 = (
- Atdgen_runtime.Oj_run.write_option (
- write__9
- )
-)
let string_of__10 ?(len = 1024) x =
let ob = Bi_outbuf.create len in
write__10 ob x;
Bi_outbuf.contents ob
let read__10 = (
- fun p lb ->
- Yojson.Safe.read_space p lb;
- match Yojson.Safe.start_any_variant p lb with
- | `Edgy_bracket -> (
- match Yojson.Safe.read_ident p lb with
- | "None" ->
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_gt p lb;
- (None : _ option)
- | "Some" ->
- Atdgen_runtime.Oj_run.read_until_field_value p lb;
- let x = (
- read__9
- ) p lb
- in
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_gt p lb;
- (Some x : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
- | `Double_quote -> (
- match Yojson.Safe.finish_string p lb with
- | "None" ->
- (None : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
- | `Square_bracket -> (
- match Atdgen_runtime.Oj_run.read_string p lb with
- | "Some" ->
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_comma p lb;
- Yojson.Safe.read_space p lb;
- let x = (
- read__9
- ) p lb
- in
- Yojson.Safe.read_space p lb;
- Yojson.Safe.read_rbr p lb;
- (Some x : _ option)
- | x ->
- Atdgen_runtime.Oj_run.invalid_variant_tag p x
- )
+ Atdgen_runtime.Oj_run.read_list (
+ read_channel
+ )
)
let _10_of_string s =
read__10 (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
@@ -837,7 +723,7 @@ let write_t : _ -> t -> _ = (
)
ob x;
);
- (match x.members with None -> () | Some x ->
+ if x.members <> [] then (
if !is_first then
is_first := false
else
@@ -846,18 +732,18 @@ let write_t : _ -> t -> _ = (
(
write__9
)
- ob x;
+ ob x.members;
);
- (match x.channels with None -> () | Some x ->
+ if x.channels <> [] then (
if !is_first then
is_first := false
else
Bi_outbuf.add_char ob ',';
Bi_outbuf.add_string ob "\"channels\":";
(
- write__11
+ write__10
)
- ob x;
+ ob x.channels;
);
Bi_outbuf.add_char ob '}';
)
@@ -893,8 +779,8 @@ let read_t = (
let field_large = ref (None) in
let field_unavailable = ref (None) in
let field_member_count = ref (None) in
- let field_members = ref (None) in
- let field_channels = ref (None) in
+ let field_members = ref ([]) in
+ let field_channels = ref ([]) in
let bits0 = ref 0 in
try
Yojson.Safe.read_space p lb;
@@ -1381,21 +1267,17 @@ let read_t = (
| 24 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_members := (
- Some (
- (
- read__9
- ) p lb
- )
+ (
+ read__9
+ ) p lb
);
)
| 25 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_channels := (
- Some (
- (
- read__11
- ) p lb
- )
+ (
+ read__10
+ ) p lb
);
)
| _ -> (
@@ -1887,21 +1769,17 @@ let read_t = (
| 24 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_members := (
- Some (
- (
- read__9
- ) p lb
- )
+ (
+ read__9
+ ) p lb
);
)
| 25 ->
if not (Yojson.Safe.read_null_if_possible p lb) then (
field_channels := (
- Some (
- (
- read__11
- ) p lb
- )
+ (
+ read__10
+ ) p lb
);
)
| _ -> (
diff --git a/lib/models/gen/guild_j.mli b/lib/models/gen/guild_j.mli
index d430b2a..7eca304 100644
--- a/lib/models/gen/guild_j.mli
+++ b/lib/models/gen/guild_j.mli
@@ -38,8 +38,8 @@ type t = Guild_t.t = {
large: bool option;
unavailable: bool option;
member_count: int option;
- members: member list option;
- channels: channel list option
+ members: member list;
+ channels: channel list
}
val write_user :
diff --git a/lib/models/gen/guild_t.ml b/lib/models/gen/guild_t.ml
index 9ffe83f..fe2a59c 100644
--- a/lib/models/gen/guild_t.ml
+++ b/lib/models/gen/guild_t.ml
@@ -38,6 +38,6 @@ type t = {
large: bool option;
unavailable: bool option;
member_count: int option;
- members: member list option;
- channels: channel list option
+ members: member list;
+ channels: channel list
}
diff --git a/lib/models/gen/guild_t.mli b/lib/models/gen/guild_t.mli
index 9ffe83f..fe2a59c 100644
--- a/lib/models/gen/guild_t.mli
+++ b/lib/models/gen/guild_t.mli
@@ -38,6 +38,6 @@ type t = {
large: bool option;
unavailable: bool option;
member_count: int option;
- members: member list option;
- channels: channel list option
+ members: member list;
+ channels: channel list
}
diff --git a/lib/models/gen/role.atd b/lib/models/gen/role.atd
index a6bdcba..8e3f6aa 100644
--- a/lib/models/gen/role.atd
+++ b/lib/models/gen/role.atd
@@ -1,6 +1,6 @@
type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type t = {
+type role = {
id: snowflake;
name: string;
colour <json name="color">: int;
@@ -9,4 +9,14 @@ type t = {
permissions: int;
managed: bool;
mentionable: bool;
+}
+
+type role_update = {
+ role: role;
+ id: snowflake;
+}
+
+type t = {
+ inherit role;
+ guild_id: snowflake;
} \ No newline at end of file
diff --git a/lib/models/gen/role_j.ml b/lib/models/gen/role_j.ml
index a15b6cf..4761c70 100644
--- a/lib/models/gen/role_j.ml
+++ b/lib/models/gen/role_j.ml
@@ -11,9 +11,23 @@ type t = Role_t.t = {
position: int;
permissions: int;
managed: bool;
+ mentionable: bool;
+ guild_id: snowflake
+}
+
+type role = Role_t.role = {
+ id: snowflake;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
mentionable: bool
}
+type role_update = Role_t.role_update = { role: role; id: snowflake }
+
let write_snowflake = (
Snowflake_j.write_t
)
@@ -102,6 +116,15 @@ let write_t : _ -> t -> _ = (
Yojson.Safe.write_bool
)
ob x.mentionable;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"guild_id\":";
+ (
+ write_snowflake
+ )
+ ob x.guild_id;
Bi_outbuf.add_char ob '}';
)
let string_of_t ?(len = 1024) x =
@@ -120,6 +143,471 @@ let read_t = (
let field_permissions = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_managed = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let field_mentionable = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_guild_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let bits0 = ref 0 in
+ try
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_object_end lb;
+ Yojson.Safe.read_space p lb;
+ let f =
+ fun s pos len ->
+ if pos < 0 || len < 0 || pos + len > String.length s then
+ invalid_arg "out-of-bounds substring position or length";
+ match len with
+ | 2 -> (
+ if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | 4 -> (
+ if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 5 -> (
+ match String.unsafe_get s pos with
+ | 'c' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then (
+ 2
+ )
+ else (
+ -1
+ )
+ )
+ | 'h' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then (
+ 3
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 7 -> (
+ if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
+ 6
+ )
+ else (
+ -1
+ )
+ )
+ | 8 -> (
+ match String.unsafe_get s pos with
+ | 'g' -> (
+ if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then (
+ 8
+ )
+ else (
+ -1
+ )
+ )
+ | 'p' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then (
+ 4
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 11 -> (
+ match String.unsafe_get s pos with
+ | 'm' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then (
+ 7
+ )
+ else (
+ -1
+ )
+ )
+ | 'p' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then (
+ 5
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ in
+ let i = Yojson.Safe.map_ident p f lb in
+ Atdgen_runtime.Oj_run.read_until_field_value p lb;
+ (
+ match i with
+ | 0 ->
+ field_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 1 ->
+ field_name := (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | 2 ->
+ field_colour := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x4;
+ | 3 ->
+ field_hoist := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x8;
+ | 4 ->
+ field_position := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x10;
+ | 5 ->
+ field_permissions := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x20;
+ | 6 ->
+ field_managed := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x40;
+ | 7 ->
+ field_mentionable := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x80;
+ | 8 ->
+ field_guild_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x100;
+ | _ -> (
+ Yojson.Safe.skip_json p lb
+ )
+ );
+ while true do
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_object_sep p lb;
+ Yojson.Safe.read_space p lb;
+ let f =
+ fun s pos len ->
+ if pos < 0 || len < 0 || pos + len > String.length s then
+ invalid_arg "out-of-bounds substring position or length";
+ match len with
+ | 2 -> (
+ if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | 4 -> (
+ if String.unsafe_get s pos = 'n' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'm' && String.unsafe_get s (pos+3) = 'e' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 5 -> (
+ match String.unsafe_get s pos with
+ | 'c' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'o' && String.unsafe_get s (pos+4) = 'r' then (
+ 2
+ )
+ else (
+ -1
+ )
+ )
+ | 'h' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 's' && String.unsafe_get s (pos+4) = 't' then (
+ 3
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 7 -> (
+ if String.unsafe_get s pos = 'm' && String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'a' && String.unsafe_get s (pos+4) = 'g' && String.unsafe_get s (pos+5) = 'e' && String.unsafe_get s (pos+6) = 'd' then (
+ 6
+ )
+ else (
+ -1
+ )
+ )
+ | 8 -> (
+ match String.unsafe_get s pos with
+ | 'g' -> (
+ if String.unsafe_get s (pos+1) = 'u' && String.unsafe_get s (pos+2) = 'i' && String.unsafe_get s (pos+3) = 'l' && String.unsafe_get s (pos+4) = 'd' && String.unsafe_get s (pos+5) = '_' && String.unsafe_get s (pos+6) = 'i' && String.unsafe_get s (pos+7) = 'd' then (
+ 8
+ )
+ else (
+ -1
+ )
+ )
+ | 'p' -> (
+ if String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 's' && String.unsafe_get s (pos+3) = 'i' && String.unsafe_get s (pos+4) = 't' && String.unsafe_get s (pos+5) = 'i' && String.unsafe_get s (pos+6) = 'o' && String.unsafe_get s (pos+7) = 'n' then (
+ 4
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | 11 -> (
+ match String.unsafe_get s pos with
+ | 'm' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 't' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 'o' && String.unsafe_get s (pos+6) = 'n' && String.unsafe_get s (pos+7) = 'a' && String.unsafe_get s (pos+8) = 'b' && String.unsafe_get s (pos+9) = 'l' && String.unsafe_get s (pos+10) = 'e' then (
+ 7
+ )
+ else (
+ -1
+ )
+ )
+ | 'p' -> (
+ if String.unsafe_get s (pos+1) = 'e' && String.unsafe_get s (pos+2) = 'r' && String.unsafe_get s (pos+3) = 'm' && String.unsafe_get s (pos+4) = 'i' && String.unsafe_get s (pos+5) = 's' && String.unsafe_get s (pos+6) = 's' && String.unsafe_get s (pos+7) = 'i' && String.unsafe_get s (pos+8) = 'o' && String.unsafe_get s (pos+9) = 'n' && String.unsafe_get s (pos+10) = 's' then (
+ 5
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ in
+ let i = Yojson.Safe.map_ident p f lb in
+ Atdgen_runtime.Oj_run.read_until_field_value p lb;
+ (
+ match i with
+ | 0 ->
+ field_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 1 ->
+ field_name := (
+ (
+ Atdgen_runtime.Oj_run.read_string
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | 2 ->
+ field_colour := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x4;
+ | 3 ->
+ field_hoist := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x8;
+ | 4 ->
+ field_position := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x10;
+ | 5 ->
+ field_permissions := (
+ (
+ Atdgen_runtime.Oj_run.read_int
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x20;
+ | 6 ->
+ field_managed := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x40;
+ | 7 ->
+ field_mentionable := (
+ (
+ Atdgen_runtime.Oj_run.read_bool
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x80;
+ | 8 ->
+ field_guild_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x100;
+ | _ -> (
+ Yojson.Safe.skip_json p lb
+ )
+ );
+ done;
+ assert false;
+ with Yojson.End_of_object -> (
+ if !bits0 <> 0x1ff then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "id"; "name"; "colour"; "hoist"; "position"; "permissions"; "managed"; "mentionable"; "guild_id" |];
+ (
+ {
+ id = !field_id;
+ name = !field_name;
+ colour = !field_colour;
+ hoist = !field_hoist;
+ position = !field_position;
+ permissions = !field_permissions;
+ managed = !field_managed;
+ mentionable = !field_mentionable;
+ guild_id = !field_guild_id;
+ }
+ : t)
+ )
+)
+let t_of_string s =
+ read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
+let write_role : _ -> role -> _ = (
+ fun ob x ->
+ Bi_outbuf.add_char ob '{';
+ let is_first = ref true in
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"id\":";
+ (
+ write_snowflake
+ )
+ ob x.id;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"name\":";
+ (
+ Yojson.Safe.write_string
+ )
+ ob x.name;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"color\":";
+ (
+ Yojson.Safe.write_int
+ )
+ ob x.colour;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"hoist\":";
+ (
+ Yojson.Safe.write_bool
+ )
+ ob x.hoist;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"position\":";
+ (
+ Yojson.Safe.write_int
+ )
+ ob x.position;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"permissions\":";
+ (
+ Yojson.Safe.write_int
+ )
+ ob x.permissions;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"managed\":";
+ (
+ Yojson.Safe.write_bool
+ )
+ ob x.managed;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"mentionable\":";
+ (
+ Yojson.Safe.write_bool
+ )
+ ob x.mentionable;
+ Bi_outbuf.add_char ob '}';
+)
+let string_of_role ?(len = 1024) x =
+ let ob = Bi_outbuf.create len in
+ write_role ob x;
+ Bi_outbuf.contents ob
+let read_role = (
+ fun p lb ->
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_lcurl p lb;
+ let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_name = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_colour = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_hoist = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_position = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_permissions = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_managed = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_mentionable = ref (Obj.magic (Sys.opaque_identity 0.0)) in
let bits0 = ref 0 in
try
Yojson.Safe.read_space p lb;
@@ -442,8 +930,159 @@ let read_t = (
managed = !field_managed;
mentionable = !field_mentionable;
}
- : t)
+ : role)
)
)
-let t_of_string s =
- read_t (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
+let role_of_string s =
+ read_role (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
+let write_role_update : _ -> role_update -> _ = (
+ fun ob x ->
+ Bi_outbuf.add_char ob '{';
+ let is_first = ref true in
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"role\":";
+ (
+ write_role
+ )
+ ob x.role;
+ if !is_first then
+ is_first := false
+ else
+ Bi_outbuf.add_char ob ',';
+ Bi_outbuf.add_string ob "\"id\":";
+ (
+ write_snowflake
+ )
+ ob x.id;
+ Bi_outbuf.add_char ob '}';
+)
+let string_of_role_update ?(len = 1024) x =
+ let ob = Bi_outbuf.create len in
+ write_role_update ob x;
+ Bi_outbuf.contents ob
+let read_role_update = (
+ fun p lb ->
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_lcurl p lb;
+ let field_role = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let field_id = ref (Obj.magic (Sys.opaque_identity 0.0)) in
+ let bits0 = ref 0 in
+ try
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_object_end lb;
+ Yojson.Safe.read_space p lb;
+ let f =
+ fun s pos len ->
+ if pos < 0 || len < 0 || pos + len > String.length s then
+ invalid_arg "out-of-bounds substring position or length";
+ match len with
+ | 2 -> (
+ if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 4 -> (
+ if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ in
+ let i = Yojson.Safe.map_ident p f lb in
+ Atdgen_runtime.Oj_run.read_until_field_value p lb;
+ (
+ match i with
+ | 0 ->
+ field_role := (
+ (
+ read_role
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 1 ->
+ field_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | _ -> (
+ Yojson.Safe.skip_json p lb
+ )
+ );
+ while true do
+ Yojson.Safe.read_space p lb;
+ Yojson.Safe.read_object_sep p lb;
+ Yojson.Safe.read_space p lb;
+ let f =
+ fun s pos len ->
+ if pos < 0 || len < 0 || pos + len > String.length s then
+ invalid_arg "out-of-bounds substring position or length";
+ match len with
+ | 2 -> (
+ if String.unsafe_get s pos = 'i' && String.unsafe_get s (pos+1) = 'd' then (
+ 1
+ )
+ else (
+ -1
+ )
+ )
+ | 4 -> (
+ if String.unsafe_get s pos = 'r' && String.unsafe_get s (pos+1) = 'o' && String.unsafe_get s (pos+2) = 'l' && String.unsafe_get s (pos+3) = 'e' then (
+ 0
+ )
+ else (
+ -1
+ )
+ )
+ | _ -> (
+ -1
+ )
+ in
+ let i = Yojson.Safe.map_ident p f lb in
+ Atdgen_runtime.Oj_run.read_until_field_value p lb;
+ (
+ match i with
+ | 0 ->
+ field_role := (
+ (
+ read_role
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x1;
+ | 1 ->
+ field_id := (
+ (
+ read_snowflake
+ ) p lb
+ );
+ bits0 := !bits0 lor 0x2;
+ | _ -> (
+ Yojson.Safe.skip_json p lb
+ )
+ );
+ done;
+ assert false;
+ with Yojson.End_of_object -> (
+ if !bits0 <> 0x3 then Atdgen_runtime.Oj_run.missing_fields p [| !bits0 |] [| "role"; "id" |];
+ (
+ {
+ role = !field_role;
+ id = !field_id;
+ }
+ : role_update)
+ )
+)
+let role_update_of_string s =
+ read_role_update (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
diff --git a/lib/models/gen/role_j.mli b/lib/models/gen/role_j.mli
index b4ea78c..f908204 100644
--- a/lib/models/gen/role_j.mli
+++ b/lib/models/gen/role_j.mli
@@ -11,9 +11,23 @@ type t = Role_t.t = {
position: int;
permissions: int;
managed: bool;
+ mentionable: bool;
+ guild_id: snowflake
+}
+
+type role = Role_t.role = {
+ id: snowflake;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
mentionable: bool
}
+type role_update = Role_t.role_update = { role: role; id: snowflake }
+
val write_snowflake :
Bi_outbuf.t -> snowflake -> unit
(** Output a JSON value of type {!snowflake}. *)
@@ -54,3 +68,43 @@ val t_of_string :
string -> t
(** Deserialize JSON data of type {!t}. *)
+val write_role :
+ Bi_outbuf.t -> role -> unit
+ (** Output a JSON value of type {!role}. *)
+
+val string_of_role :
+ ?len:int -> role -> string
+ (** Serialize a value of type {!role}
+ into a JSON string.
+ @param len specifies the initial length
+ of the buffer used internally.
+ Default: 1024. *)
+
+val read_role :
+ Yojson.Safe.lexer_state -> Lexing.lexbuf -> role
+ (** Input JSON data of type {!role}. *)
+
+val role_of_string :
+ string -> role
+ (** Deserialize JSON data of type {!role}. *)
+
+val write_role_update :
+ Bi_outbuf.t -> role_update -> unit
+ (** Output a JSON value of type {!role_update}. *)
+
+val string_of_role_update :
+ ?len:int -> role_update -> string
+ (** Serialize a value of type {!role_update}
+ into a JSON string.
+ @param len specifies the initial length
+ of the buffer used internally.
+ Default: 1024. *)
+
+val read_role_update :
+ Yojson.Safe.lexer_state -> Lexing.lexbuf -> role_update
+ (** Input JSON data of type {!role_update}. *)
+
+val role_update_of_string :
+ string -> role_update
+ (** Deserialize JSON data of type {!role_update}. *)
+
diff --git a/lib/models/gen/role_t.ml b/lib/models/gen/role_t.ml
index a4e83c5..0954156 100644
--- a/lib/models/gen/role_t.ml
+++ b/lib/models/gen/role_t.ml
@@ -11,5 +11,19 @@ type t = {
position: int;
permissions: int;
managed: bool;
+ mentionable: bool;
+ guild_id: snowflake
+}
+
+type role = {
+ id: snowflake;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
mentionable: bool
}
+
+type role_update = { role: role; id: snowflake }
diff --git a/lib/models/gen/role_t.mli b/lib/models/gen/role_t.mli
index a4e83c5..0954156 100644
--- a/lib/models/gen/role_t.mli
+++ b/lib/models/gen/role_t.mli
@@ -11,5 +11,19 @@ type t = {
position: int;
permissions: int;
managed: bool;
+ mentionable: bool;
+ guild_id: snowflake
+}
+
+type role = {
+ id: snowflake;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
mentionable: bool
}
+
+type role_update = { role: role; id: snowflake }
diff --git a/lib/models/gen/user.atd b/lib/models/gen/user.atd
index 106b3b0..588242d 100644
--- a/lib/models/gen/user.atd
+++ b/lib/models/gen/user.atd
@@ -1,13 +1,13 @@
type snowflake <ocaml from="Snowflake" t="t"> = abstract
-type t = {
+type partial_user = {
id: snowflake;
+}
+
+type t = {
+ inherit partial_user;
username: string;
- discriminator: string;
+ discriminator: int <json repr="string">;
?avatar: string option;
~bot <ocaml default="false">: bool;
-}
-
-type partial_user = {
- id: snowflake;
} \ No newline at end of file
diff --git a/lib/models/gen/user_j.ml b/lib/models/gen/user_j.ml
index 552a20d..e281a7f 100644
--- a/lib/models/gen/user_j.ml
+++ b/lib/models/gen/user_j.ml
@@ -6,7 +6,7 @@ type snowflake = Snowflake_t.t
type t = User_t.t = {
id: snowflake;
username: string;
- discriminator: string;
+ discriminator: int;
avatar: string option;
bot: bool
}
@@ -110,7 +110,7 @@ let write_t : _ -> t -> _ = (
Bi_outbuf.add_char ob ',';
Bi_outbuf.add_string ob "\"discriminator\":";
(
- Yojson.Safe.write_string
+ Yojson.Safe.write_int
)
ob x.discriminator;
(match x.avatar with None -> () | Some x ->
@@ -225,7 +225,7 @@ let read_t = (
| 2 ->
field_discriminator := (
(
- Atdgen_runtime.Oj_run.read_string
+ Atdgen_runtime.Oj_run.read_int
) p lb
);
bits0 := !bits0 lor 0x4;
@@ -325,7 +325,7 @@ let read_t = (
| 2 ->
field_discriminator := (
(
- Atdgen_runtime.Oj_run.read_string
+ Atdgen_runtime.Oj_run.read_int
) p lb
);
bits0 := !bits0 lor 0x4;
diff --git a/lib/models/gen/user_j.mli b/lib/models/gen/user_j.mli
index 576768e..0da284a 100644
--- a/lib/models/gen/user_j.mli
+++ b/lib/models/gen/user_j.mli
@@ -6,7 +6,7 @@ type snowflake = Snowflake_t.t
type t = User_t.t = {
id: snowflake;
username: string;
- discriminator: string;
+ discriminator: int;
avatar: string option;
bot: bool
}
diff --git a/lib/models/gen/user_t.ml b/lib/models/gen/user_t.ml
index 294cf0a..f08b782 100644
--- a/lib/models/gen/user_t.ml
+++ b/lib/models/gen/user_t.ml
@@ -6,7 +6,7 @@ type snowflake = Snowflake_t.t
type t = {
id: snowflake;
username: string;
- discriminator: string;
+ discriminator: int;
avatar: string option;
bot: bool
}
diff --git a/lib/models/gen/user_t.mli b/lib/models/gen/user_t.mli
index 294cf0a..f08b782 100644
--- a/lib/models/gen/user_t.mli
+++ b/lib/models/gen/user_t.mli
@@ -6,7 +6,7 @@ type snowflake = Snowflake_t.t
type t = {
id: snowflake;
username: string;
- discriminator: string;
+ discriminator: int;
avatar: string option;
bot: bool
}
diff --git a/lib/models/guild.ml b/lib/models/guild.ml
index 36b7d4b..ade67be 100644
--- a/lib/models/guild.ml
+++ b/lib/models/guild.ml
@@ -1,2 +1,100 @@
module Make(Http : S.Http) = struct
+ open Core
+ open Async
+ open Guild_t
+
+ let ban_user ~id ?(reason="") ?(days=0) guild =
+ Http.guild_ban_add guild.id id (`Assoc [
+ ("delete-message-days", `Int days);
+ ("reason", `String reason);
+ ])
+
+ let create_emoji ~name ~image guild =
+ Http.create_emoji guild.id (`Assoc [
+ ("name", `String name);
+ ("image", `String image);
+ ("roles", `List []);
+ ])
+
+ let create_role ~name ?colour ?permissions ?hoist ?mentionable guild =
+ let payload = ("name", `String name) :: [] in
+ let payload = match permissions with
+ | Some p -> ("permissions", `Int p) :: payload
+ | None -> payload
+ in let payload = match colour with
+ | Some c -> ("color", `Int c) :: payload
+ | None -> payload
+ in let payload = match hoist with
+ | Some h -> ("hoist", `Bool h) :: payload
+ | None -> payload
+ in let payload = match mentionable with
+ | Some m -> ("mentionable", `Bool m) :: payload
+ | None -> payload
+ in Http.guild_role_add guild.id (`Assoc payload)
+
+ let create_channel ~mode ~name guild =
+ let kind = match mode with
+ | `Text -> 0
+ | `Voice -> 2
+ | `Category -> 4
+ in Http.create_guild_channel guild.id (`Assoc [
+ ("name", `String name);
+ ("type", `Int kind);
+ ])
+
+ let delete guild = Http.delete_guild guild.id
+ let get_ban ~id guild = Http.get_ban guild.id id
+ let get_bans guild = Http.get_bans guild.id
+
+ let get_channel ~id guild =
+ match List.find ~f:(fun c -> c.id = id) guild.channels with
+ | Some c -> return c
+ | None -> Http.get_channel id >>| fun c ->
+ c |> Yojson.Safe.to_string |> Channel_j.t_of_string
+
+ let get_emoji ~id guild = Http.get_emoji guild.id id
+ let get_invites guild = Http.get_guild_invites guild.id
+
+ let get_member ~id guild =
+ match List.find ~f:(fun m -> m.user.id = id) guild.members with
+ | Some m -> return m
+ | None -> Http.get_member guild.id id >>| fun m ->
+ m |> Yojson.Safe.to_string |> Member_j.t_of_string
+
+ let get_prune_count ~days guild = Http.guild_prune_count guild.id days
+ let get_role ~id guild = List.find ~f:(fun r -> r.id = id) guild.roles
+ let get_webhooks guild = Http.get_guild_webhooks guild.id
+
+ let kick_user ~id ?reason guild =
+ let payload = match reason with
+ | Some r -> `Assoc [("reason", `String r)]
+ | None -> `Null
+ in Http.remove_member guild.id id payload
+
+ let leave guild = Http.leave_guild guild.id
+ let list_voice_regions guild = Http.get_guild_voice_regions guild.id
+ let prune ~days guild = Http.guild_prune_start guild.id days
+ let request_members guild = Http.get_members guild.id
+
+ let set_afk_channel ~id guild = Http.edit_guild guild.id (`Assoc [
+ ("afk_channel_id", `Int id);
+ ])
+
+ let set_afk_timeout ~timeout guild = Http.edit_guild guild.id (`Assoc [
+ ("afk_timeout", `Int timeout);
+ ])
+
+ let set_name ~name guild = Http.edit_guild guild.id (`Assoc [
+ ("name", `String name);
+ ])
+
+ let set_icon ~icon guild = Http.edit_guild guild.id (`Assoc [
+ ("icon", `String icon);
+ ])
+
+ let unban_user ~id ?reason guild =
+ let payload = match reason with
+ | Some r -> `Assoc [("reason", `String r)]
+ | None -> `Null
+ in Http.guild_ban_remove guild.id id payload
end \ No newline at end of file
diff --git a/lib/models/role.ml b/lib/models/role.ml
index 36b7d4b..10272a7 100644
--- a/lib/models/role.ml
+++ b/lib/models/role.ml
@@ -1,2 +1,25 @@
module Make(Http : S.Http) = struct
+ open Role_t
+
+ let edit_role ~body role = Http.guild_role_edit role.guild_id role.id body
+
+ let allow_mention role =
+ edit_role ~body:(`Assoc [("mentionable", `Bool true)]) role
+
+ let delete role = Http.guild_role_remove role.guild_id role.id
+
+ let disallow_mention role =
+ edit_role ~body:(`Assoc [("mentionable", `Bool false)]) role
+
+ let hoist role =
+ edit_role ~body:(`Assoc [("hoist", `Bool true)]) role
+
+ let set_colour ~colour role =
+ edit_role ~body:(`Assoc [("color", `Int colour)]) role
+
+ let set_name ~name role =
+ edit_role ~body:(`Assoc [("name", `String name)]) role
+
+ let unhoist role =
+ edit_role ~body:(`Assoc [("hoist", `Bool false)]) role
end \ No newline at end of file
diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml
index 36b7d4b..305043e 100644
--- a/lib/models/snowflake.ml
+++ b/lib/models/snowflake.ml
@@ -1,2 +1,14 @@
module Make(Http : S.Http) = struct
+ open Core
+
+ let timestamp snowflake =
+ let offset = (snowflake lsr 22) / 1000 in
+ 1_420_070_400 + offset
+
+ let timestamp_iso snowflake =
+ let t = timestamp snowflake in
+ Date.(
+ of_time ~zone:Time.Zone.utc
+ Time.(of_span_since_epoch @@ Span.of_int_sec t)
+ |> format) "%FT%T+00:00"
end \ No newline at end of file
diff --git a/lib/models/user.ml b/lib/models/user.ml
index 36b7d4b..13ee1cf 100644
--- a/lib/models/user.ml
+++ b/lib/models/user.ml
@@ -1,2 +1,22 @@
module Make(Http : S.Http) = struct
+ open Core
+ open User_t
+
+ let tag user =
+ Printf.sprintf "%s#%d" user.username user.discriminator
+
+ let mention (user:User_t.t) =
+ Printf.sprintf "<@%d>" user.id
+
+ let default_avatar user =
+ let avatar = user.discriminator % 5 in
+ Endpoints.cdn_default_avatar avatar
+
+ let face user = match user.avatar with
+ | Some avatar ->
+ let ext = if String.is_substring ~substring:"a_" avatar
+ then "gif"
+ else "png" in
+ Endpoints.cdn_avatar user.id avatar ext
+ | None -> default_avatar user
end \ No newline at end of file
diff --git a/lib/s.ml b/lib/s.ml
index b945218..d46726f 100644
--- a/lib/s.ml
+++ b/lib/s.ml
@@ -16,7 +16,39 @@ module type Embed = sig end
module type Emoji = sig end
-module type Guild = sig end
+module type Guild = sig
+ val ban_user : id:Snowflake_t.t -> ?reason:string -> ?days:int -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val create_emoji : name:string -> image:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val create_role :
+ name:string ->
+ ?colour:int ->
+ ?permissions:int ->
+ ?hoist:bool ->
+ ?mentionable:bool ->
+ Guild_t.t ->
+ Yojson.Safe.json Deferred.t
+ val create_channel : mode:[ `Text | `Voice | `Category ] -> name:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val delete : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_ban : id:Snowflake_t.t -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_bans : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_channel : id:Snowflake_t.t -> Guild_t.t -> Channel_t.t Deferred.t
+ val get_emoji : id:Snowflake_t.t -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_invites : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_member : id:Snowflake_t.t -> Guild_t.t -> Member_t.t Deferred.t
+ val get_prune_count : days:int -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val get_role : id:Snowflake_t.t -> Guild_t.t -> Role_t.t option
+ val get_webhooks : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val kick_user : id:Snowflake_t.t -> ?reason:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val leave : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val list_voice_regions : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val prune : days:int -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val request_members : Guild_t.t -> Yojson.Safe.json Deferred.t
+ val set_afk_channel : id:Snowflake_t.t -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val set_afk_timeout : timeout:int -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val set_name : name:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val set_icon : icon:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+ val unban_user : id:Snowflake_t.t -> ?reason:string -> Guild_t.t -> Yojson.Safe.json Deferred.t
+end
module type Member = sig
(* val add_role : Member_t.t -> Role_t.t -> Yojson.Safe.json Deferred.t
@@ -46,11 +78,29 @@ module type Presence = sig end
module type Reaction = sig end
-module type Role = sig end
+module type Role = sig
+ val allow_mention : Role_t.t -> Yojson.Safe.json Deferred.t
+ val delete : Role_t.t -> Yojson.Safe.json Deferred.t
+ val disallow_mention : Role_t.t -> Yojson.Safe.json Deferred.t
+ val hoist : Role_t.t -> Yojson.Safe.json Deferred.t
+ val set_colour : colour:int -> Role_t.t -> Yojson.Safe.json Deferred.t
+ val set_name : name:string -> Role_t.t -> Yojson.Safe.json Deferred.t
+ val unhoist : Role_t.t -> Yojson.Safe.json Deferred.t
+end
-module type Snowflake = sig end
+module type Snowflake = sig
+ val timestamp : Snowflake_t.t -> int
+ val timestamp_iso : Snowflake_t.t -> string
+end
-module type User = sig end
+module type User = sig
+ val tag : User_t.t -> string
+ val mention : User_t.t -> string
+ val default_avatar : User_t.t -> string
+ val face : User_t.t -> string
+ (* val private_channel : User_t.t -> Channel_t.t *)
+ (* val send : User_t.t -> Yojson.Safe.json Deferred.t *)
+end
module type Http = sig
val token : string
@@ -138,7 +188,7 @@ module type Http = sig
int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
val edit_member :
int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
- val remove_member : int -> int -> Yojson.Safe.json Conduit_async.io
+ val remove_member : int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
val change_nickname :
int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
val add_member_role :
@@ -149,7 +199,7 @@ module type Http = sig
val get_ban : int -> int -> Yojson.Safe.json Conduit_async.io
val guild_ban_add :
int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
- val guild_ban_remove : int -> int -> Yojson.Safe.json Conduit_async.io
+ val guild_ban_remove : int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
val get_roles : int -> Yojson.Safe.json Conduit_async.io
val guild_role_add :
int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
@@ -158,9 +208,9 @@ module type Http = sig
val guild_role_edit :
int -> int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
val guild_role_remove : int -> int -> Yojson.Safe.json Conduit_async.io
- val guild_prune_count : int -> Yojson.Safe.json Conduit_async.io
+ val guild_prune_count : int -> int -> Yojson.Safe.json Conduit_async.io
val guild_prune_start :
- int -> Yojson.Safe.json -> Yojson.Safe.json Conduit_async.io
+ int -> int -> Yojson.Safe.json Conduit_async.io
val get_guild_voice_regions : int -> Yojson.Safe.json Conduit_async.io
val get_guild_invites : int -> Yojson.Safe.json Conduit_async.io
val get_integrations : int -> Yojson.Safe.json Conduit_async.io