diff options
| author | Adelyn Breedlove <[email protected]> | 2019-01-28 10:31:51 -0700 |
|---|---|---|
| committer | Adelyn Breedlove <[email protected]> | 2019-01-28 10:31:51 -0700 |
| commit | 8662e92987c437f59d09896a247ec2b5d82c4528 (patch) | |
| tree | f004cc14598351d4ad6b19d8e993d2f629c5e738 /lib/models | |
| parent | Add more docs (diff) | |
| download | disml-8662e92987c437f59d09896a247ec2b5d82c4528.tar.xz disml-8662e92987c437f59d09896a247ec2b5d82c4528.zip | |
Publish docs updates
Diffstat (limited to 'lib/models')
50 files changed, 1596 insertions, 1577 deletions
diff --git a/lib/models/channel/channel.ml b/lib/models/channel/channel.ml index 68b3a97..6ccc66d 100644 --- a/lib/models/channel/channel.ml +++ b/lib/models/channel/channel.ml @@ -1,3 +1,3 @@ -include Channel_t - +include Channel_t
+
include Impl.Channel(Channel_t)
\ No newline at end of file diff --git a/lib/models/channel/channel.mli b/lib/models/channel/channel.mli index feb7323..3eece7d 100644 --- a/lib/models/channel/channel.mli +++ b/lib/models/channel/channel.mli @@ -1,3 +1,3 @@ -include module type of Channel_t -include S.ChannelImpl with +include module type of Channel_t
+include S.ChannelImpl with
type t := Channel_t.t
\ No newline at end of file diff --git a/lib/models/channel/channel_t.ml b/lib/models/channel/channel_t.ml index 62d6ac0..b02fa31 100644 --- a/lib/models/channel/channel_t.ml +++ b/lib/models/channel/channel_t.ml @@ -1,118 +1,118 @@ -open Core - -exception Invalid_channel of Yojson.Safe.json - -type group = { - id: Channel_id_t.t; - last_message_id: Message_id.t option [@default None]; - last_pin_timestamp: string option [@default None]; - icon: string option [@default None]; - name: string option [@default None]; - owner_id: User_id_t.t; - recipients: User_t.t list [@default []]; -} [@@deriving sexp, yojson { strict = false}] - -type dm = { - id: Channel_id_t.t; - last_message_id: Message_id.t option [@default None]; - last_pin_timestamp: string option [@default None]; -} [@@deriving sexp, yojson { strict = false}] - -type guild_text = { - id: Channel_id_t.t; - last_message_id: Message_id.t option [@default None]; - last_pin_timestamp: string option [@default None]; - category_id: Channel_id_t.t option [@default None][@key "parent_id"]; - guild_id: Guild_id_t.t option [@default None]; - name: string; - position: int; - topic: string option [@default None]; - nsfw: bool; - slow_mode_timeout: int option [@default None]; -} [@@deriving sexp, yojson { strict = false}] - -type guild_voice = { - id: Channel_id_t.t; - category_id: Channel_id_t.t option [@default None][@key "parent_id"]; - guild_id: Guild_id_t.t option [@default None]; - name: string; - position: int; - user_limit: int [@default -1]; - bitrate: int option [@default None]; -} [@@deriving sexp, yojson { strict = false}] - -type category = { - id: Channel_id_t.t; - guild_id: Guild_id_t.t option [@default None]; - position: int; - name: string; -} [@@deriving sexp, yojson { strict = false}] - -type t = -| Group of group -| Private of dm -| GuildText of guild_text -| GuildVoice of guild_voice -| Category of category -[@@deriving sexp, yojson { strict = false}] - -type channel_wrapper = { - id: Channel_id_t.t; - kind: int [@key "type"]; - guild_id: Guild_id_t.t option [@default None]; - position: int option [@default None]; - name: string option [@default None]; - topic: string option [@default None]; - nsfw: bool option [@default None]; - last_message_id: Message_id.t option [@default None]; - bitrate: int option [@default None]; - user_limit: int option [@default None]; - slow_mode_timeout: int option [@default None]; - recipients: User_t.t list option [@default None]; - icon: string option [@default None]; - owner_id: User_id_t.t option [@default None]; - application_id: Snowflake.t option [@default None]; - category_id: Channel_id_t.t option [@default None][@key "parent_id"]; - last_pin_timestamp: string option [@default None]; -} [@@deriving sexp, yojson { strict = false}] - -let unwrap_as_guild_text {id;guild_id;position;name;topic;nsfw;last_message_id;slow_mode_timeout;category_id;last_pin_timestamp;_} = - let position = Option.value_exn position in - let name = Option.value_exn name in - let nsfw = Option.value ~default:false nsfw in - { id; guild_id; position; name; topic; nsfw; last_message_id; slow_mode_timeout; category_id; last_pin_timestamp } - -let unwrap_as_guild_voice {id;guild_id;position;name;bitrate;user_limit;category_id;_} = - let position = Option.value_exn position in - let name = Option.value_exn name in - let user_limit = Option.value ~default:(-1) user_limit in - { id; guild_id; position; name; user_limit; bitrate ; category_id; } - -let unwrap_as_dm {id;last_message_id;last_pin_timestamp;_} = - { id; last_message_id; last_pin_timestamp; } - -let unwrap_as_group {id;name;last_message_id;recipients;icon;owner_id;last_pin_timestamp;_} = - let recipients = Option.value ~default:[] recipients in - let owner_id = Option.value_exn owner_id in - { id; name; last_message_id; recipients; icon; owner_id; last_pin_timestamp; } - -let unwrap_as_category {id;guild_id;position;name;_} = - let position = Option.value_exn position in - let name = Option.value_exn name in - { id; guild_id; position; name; } - -let wrap s = - match s.kind with - | 0 -> GuildText (unwrap_as_guild_text s) - | 1 -> Private (unwrap_as_dm s) - | 2 -> GuildVoice (unwrap_as_guild_voice s) - | 3 -> Group (unwrap_as_group s) - | 4 -> Category (unwrap_as_category s) - | _ -> raise (Invalid_channel (channel_wrapper_to_yojson s)) - -let get_id = function -| Group g -> let `Channel_id id = g.id in id -| Private p -> let `Channel_id id = p.id in id -| GuildText t -> let `Channel_id id = t.id in id -| GuildVoice v -> let `Channel_id id = v.id in id +open Core
+
+exception Invalid_channel of Yojson.Safe.json
+
+type group = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+ icon: string option [@default None];
+ name: string option [@default None];
+ owner_id: User_id_t.t;
+ recipients: User_t.t list [@default []];
+} [@@deriving sexp, yojson { strict = false}]
+
+type dm = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type guild_text = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option [@default None];
+ last_pin_timestamp: string option [@default None];
+ category_id: Channel_id_t.t option [@default None][@key "parent_id"];
+ guild_id: Guild_id_t.t option [@default None];
+ name: string;
+ position: int;
+ topic: string option [@default None];
+ nsfw: bool;
+ slow_mode_timeout: int option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type guild_voice = {
+ id: Channel_id_t.t;
+ category_id: Channel_id_t.t option [@default None][@key "parent_id"];
+ guild_id: Guild_id_t.t option [@default None];
+ name: string;
+ position: int;
+ user_limit: int [@default -1];
+ bitrate: int option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type category = {
+ id: Channel_id_t.t;
+ guild_id: Guild_id_t.t option [@default None];
+ position: int;
+ name: string;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t =
+| Group of group
+| Private of dm
+| GuildText of guild_text
+| GuildVoice of guild_voice
+| Category of category
+[@@deriving sexp, yojson { strict = false}]
+
+type channel_wrapper = {
+ id: Channel_id_t.t;
+ kind: int [@key "type"];
+ guild_id: Guild_id_t.t option [@default None];
+ position: int option [@default None];
+ name: string option [@default None];
+ topic: string option [@default None];
+ nsfw: bool option [@default None];
+ last_message_id: Message_id.t option [@default None];
+ bitrate: int option [@default None];
+ user_limit: int option [@default None];
+ slow_mode_timeout: int option [@default None];
+ recipients: User_t.t list option [@default None];
+ icon: string option [@default None];
+ owner_id: User_id_t.t option [@default None];
+ application_id: Snowflake.t option [@default None];
+ category_id: Channel_id_t.t option [@default None][@key "parent_id"];
+ last_pin_timestamp: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+let unwrap_as_guild_text {id;guild_id;position;name;topic;nsfw;last_message_id;slow_mode_timeout;category_id;last_pin_timestamp;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ let nsfw = Option.value ~default:false nsfw in
+ { id; guild_id; position; name; topic; nsfw; last_message_id; slow_mode_timeout; category_id; last_pin_timestamp }
+
+let unwrap_as_guild_voice {id;guild_id;position;name;bitrate;user_limit;category_id;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ let user_limit = Option.value ~default:(-1) user_limit in
+ { id; guild_id; position; name; user_limit; bitrate ; category_id; }
+
+let unwrap_as_dm {id;last_message_id;last_pin_timestamp;_} =
+ { id; last_message_id; last_pin_timestamp; }
+
+let unwrap_as_group {id;name;last_message_id;recipients;icon;owner_id;last_pin_timestamp;_} =
+ let recipients = Option.value ~default:[] recipients in
+ let owner_id = Option.value_exn owner_id in
+ { id; name; last_message_id; recipients; icon; owner_id; last_pin_timestamp; }
+
+let unwrap_as_category {id;guild_id;position;name;_} =
+ let position = Option.value_exn position in
+ let name = Option.value_exn name in
+ { id; guild_id; position; name; }
+
+let wrap s =
+ match s.kind with
+ | 0 -> GuildText (unwrap_as_guild_text s)
+ | 1 -> Private (unwrap_as_dm s)
+ | 2 -> GuildVoice (unwrap_as_guild_voice s)
+ | 3 -> Group (unwrap_as_group s)
+ | 4 -> Category (unwrap_as_category s)
+ | _ -> raise (Invalid_channel (channel_wrapper_to_yojson s))
+
+let get_id = function
+| Group g -> let `Channel_id id = g.id in id
+| Private p -> let `Channel_id id = p.id in id
+| GuildText t -> let `Channel_id id = t.id in id
+| GuildVoice v -> let `Channel_id id = v.id in id
| Category c -> let `Channel_id id = c.id in id
\ No newline at end of file diff --git a/lib/models/channel/channel_t.mli b/lib/models/channel/channel_t.mli index 9deea82..711b319 100644 --- a/lib/models/channel/channel_t.mli +++ b/lib/models/channel/channel_t.mli @@ -1,96 +1,96 @@ -exception Invalid_channel of Yojson.Safe.json - -(** Represents a Group channel object. *) -type group = { - id: Channel_id_t.t; - last_message_id: Message_id.t option; - last_pin_timestamp: string option; - icon: string option; - name: string option; - owner_id: User_id_t.t; - recipients: User_t.t list; -} [@@deriving sexp, yojson] - -(** Represents a private channel with a single user. *) -type dm = { - id: Channel_id_t.t; - last_message_id: Message_id.t option; - last_pin_timestamp: string option; -} [@@deriving sexp, yojson] - -(** Represents a text channel in a guild. *) -type guild_text = { - id: Channel_id_t.t; - last_message_id: Message_id.t option; - last_pin_timestamp: string option; - category_id: Channel_id_t.t option; - guild_id: Guild_id_t.t option; - name: string; - position: int; - topic: string option; - nsfw: bool; - slow_mode_timeout: int option; -} [@@deriving sexp, yojson] - -(** Represents a voice channel in a guild. *) -type guild_voice = { - id: Channel_id_t.t; - category_id: Channel_id_t.t option; - guild_id: Guild_id_t.t option; - name: string; - position: int; - user_limit: int; - bitrate: int option; -} [@@deriving sexp, yojson] - -(** Represents a guild category. *) -type category = { - id: Channel_id_t.t; - guild_id: Guild_id_t.t option; - position: int; - name: string; -} [@@deriving sexp, yojson] - -(** Wrapper variant for all channel types. *) -type t = -| Group of group -| Private of dm -| GuildText of guild_text -| GuildVoice of guild_voice -| Category of category -[@@deriving sexp, yojson] - -(** Intermediate used internally. *) -type channel_wrapper = { - id: Channel_id_t.t; - kind: int; - guild_id: Guild_id_t.t option; - position: int option; - name: string option; - topic: string option; - nsfw: bool option; - last_message_id: Message_id.t option; - bitrate: int option; - user_limit: int option; - slow_mode_timeout: int option; - recipients: User_t.t list option; - icon: string option; - owner_id: User_id_t.t option; - application_id: Snowflake.t option; - category_id: Channel_id_t.t option; - last_pin_timestamp: string option; -} [@@deriving sexp, yojson] - -val unwrap_as_guild_text : channel_wrapper -> guild_text - -val unwrap_as_guild_voice : channel_wrapper -> guild_voice - -val unwrap_as_dm : channel_wrapper -> dm - -val unwrap_as_group : channel_wrapper -> group - -val unwrap_as_category : channel_wrapper -> category - -val wrap : channel_wrapper -> t - +exception Invalid_channel of Yojson.Safe.json
+
+(** Represents a Group channel object. *)
+type group = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option;
+ last_pin_timestamp: string option;
+ icon: string option;
+ name: string option;
+ owner_id: User_id_t.t;
+ recipients: User_t.t list;
+} [@@deriving sexp, yojson]
+
+(** Represents a private channel with a single user. *)
+type dm = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option;
+ last_pin_timestamp: string option;
+} [@@deriving sexp, yojson]
+
+(** Represents a text channel in a guild. *)
+type guild_text = {
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option;
+ last_pin_timestamp: string option;
+ category_id: Channel_id_t.t option;
+ guild_id: Guild_id_t.t option;
+ name: string;
+ position: int;
+ topic: string option;
+ nsfw: bool;
+ slow_mode_timeout: int option;
+} [@@deriving sexp, yojson]
+
+(** Represents a voice channel in a guild. *)
+type guild_voice = {
+ id: Channel_id_t.t;
+ category_id: Channel_id_t.t option;
+ guild_id: Guild_id_t.t option;
+ name: string;
+ position: int;
+ user_limit: int;
+ bitrate: int option;
+} [@@deriving sexp, yojson]
+
+(** Represents a guild category. *)
+type category = {
+ id: Channel_id_t.t;
+ guild_id: Guild_id_t.t option;
+ position: int;
+ name: string;
+} [@@deriving sexp, yojson]
+
+(** Wrapper variant for all channel types. *)
+type t =
+| Group of group
+| Private of dm
+| GuildText of guild_text
+| GuildVoice of guild_voice
+| Category of category
+[@@deriving sexp, yojson]
+
+(** Intermediate used internally. *)
+type channel_wrapper = {
+ id: Channel_id_t.t;
+ kind: int;
+ guild_id: Guild_id_t.t option;
+ position: int option;
+ name: string option;
+ topic: string option;
+ nsfw: bool option;
+ last_message_id: Message_id.t option;
+ bitrate: int option;
+ user_limit: int option;
+ slow_mode_timeout: int option;
+ recipients: User_t.t list option;
+ icon: string option;
+ owner_id: User_id_t.t option;
+ application_id: Snowflake.t option;
+ category_id: Channel_id_t.t option;
+ last_pin_timestamp: string option;
+} [@@deriving sexp, yojson]
+
+val unwrap_as_guild_text : channel_wrapper -> guild_text
+
+val unwrap_as_guild_voice : channel_wrapper -> guild_voice
+
+val unwrap_as_dm : channel_wrapper -> dm
+
+val unwrap_as_group : channel_wrapper -> group
+
+val unwrap_as_category : channel_wrapper -> category
+
+val wrap : channel_wrapper -> t
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/channel/message/attachment.mli b/lib/models/channel/message/attachment.mli index 2780011..f935471 100644 --- a/lib/models/channel/message/attachment.mli +++ b/lib/models/channel/message/attachment.mli @@ -1,9 +1,9 @@ -type t = { - id: Snowflake.t; - filename: string; - size: int; - url: string; - proxy_url: string; - height: int; - width: int; +type t = {
+ id: Snowflake.t;
+ filename: string;
+ size: int;
+ url: string;
+ proxy_url: string;
+ height: int;
+ width: int;
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/channel/message/embed.ml b/lib/models/channel/message/embed.ml index 9f9aacd..584d3c7 100644 --- a/lib/models/channel/message/embed.ml +++ b/lib/models/channel/message/embed.ml @@ -1,121 +1,121 @@ -open Core - -type footer = { - text: string; - icon_url: string option [@default None]; - proxy_icon_url: string option [@default None]; -} [@@deriving sexp, yojson] - -type image = { - url: string option [@default None]; - proxy_url: string option [@default None]; - height: int option [@default None]; - width: int option [@default None]; -} [@@deriving sexp, yojson] - -type video = { - url: string option [@default None]; - height: int option [@default None]; - width: int option [@default None]; -} [@@deriving sexp, yojson] - -type provider = { - name: string option [@default None]; - url: string option [@default None]; -} [@@deriving sexp, yojson] - -type author = { - name: string option [@default None]; - url: string option [@default None]; - icon_url: string option [@default None]; - proxy_icon_url: string option [@default None]; -} [@@deriving sexp, yojson] - -type field = { - name: string; - value: string; - inline: bool [@default false]; -} [@@deriving sexp, yojson] - -type t = { - title: string option [@default None]; - kind: string option [@default None][@key "type"]; - description: string option [@default None]; - url: string option [@default None]; - timestamp: string option [@default None]; - colour: int option [@default None][@key "color"]; - footer: footer option [@default None]; - image: image option [@default None]; - thumbnail: image option [@default None]; - video: video option [@default None]; - provider: provider option [@default None]; - author: author option [@default None]; - fields: field list [@default []]; -} [@@deriving sexp, yojson { strict = false }] - -let default = { - title = None; - kind = None; - description = None; - url = None; - timestamp = None; - colour = None; - footer = None; - image = None; - thumbnail = None; - video = None; - provider = None; - author = None; - fields = []; -} - -let default_footer = { - text = ""; - icon_url = None; - proxy_icon_url = None; -} - -let default_image = { - url = None; - proxy_url = None; - height = None; - width = None; -} - -let default_video = { - url = None; - width = None; - height = None; -} - -let default_provider = { - name = None; - url = None; -} - -let default_author = { - name = None; - url = None; - icon_url = None; - proxy_icon_url = None; -} - -let title v e = { e with title = Some v } -let description v e = { e with description = Some v } -let url v e = { e with url = Some v } -let timestamp v e = { e with timestamp = Some v } -let colour v e = { e with colour = Some v } -let color v e = { e with colour = Some v } -let footer f e = { e with footer = Some (f default_footer) } -let image v e = { e with image = Some { default_image with url = Some v } } -let thumbnail v e = { e with thumbnail = Some { default_image with url = Some v } } -let author f e = { e with author = Some (f default_author) } -let field (name, value, inline) e = { e with fields = { name; value; inline; }::e.fields } -let fields l e = { e with fields = List.map ~f:(fun (name, value, inline) -> { name; value; inline; }) l } - -let footer_text v f : footer = { f with text = v } -let footer_icon v f : footer = { f with icon_url = Some v } - -let author_name v a : author = { a with name = Some v } -let author_url v a : author = { a with url = Some v } +open Core
+
+type footer = {
+ text: string;
+ icon_url: string option [@default None];
+ proxy_icon_url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type image = {
+ url: string option [@default None];
+ proxy_url: string option [@default None];
+ height: int option [@default None];
+ width: int option [@default None];
+} [@@deriving sexp, yojson]
+
+type video = {
+ url: string option [@default None];
+ height: int option [@default None];
+ width: int option [@default None];
+} [@@deriving sexp, yojson]
+
+type provider = {
+ name: string option [@default None];
+ url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type author = {
+ name: string option [@default None];
+ url: string option [@default None];
+ icon_url: string option [@default None];
+ proxy_icon_url: string option [@default None];
+} [@@deriving sexp, yojson]
+
+type field = {
+ name: string;
+ value: string;
+ inline: bool [@default false];
+} [@@deriving sexp, yojson]
+
+type t = {
+ title: string option [@default None];
+ kind: string option [@default None][@key "type"];
+ description: string option [@default None];
+ url: string option [@default None];
+ timestamp: string option [@default None];
+ colour: int option [@default None][@key "color"];
+ footer: footer option [@default None];
+ image: image option [@default None];
+ thumbnail: image option [@default None];
+ video: video option [@default None];
+ provider: provider option [@default None];
+ author: author option [@default None];
+ fields: field list [@default []];
+} [@@deriving sexp, yojson { strict = false }]
+
+let default = {
+ title = None;
+ kind = None;
+ description = None;
+ url = None;
+ timestamp = None;
+ colour = None;
+ footer = None;
+ image = None;
+ thumbnail = None;
+ video = None;
+ provider = None;
+ author = None;
+ fields = [];
+}
+
+let default_footer = {
+ text = "";
+ icon_url = None;
+ proxy_icon_url = None;
+}
+
+let default_image = {
+ url = None;
+ proxy_url = None;
+ height = None;
+ width = None;
+}
+
+let default_video = {
+ url = None;
+ width = None;
+ height = None;
+}
+
+let default_provider = {
+ name = None;
+ url = None;
+}
+
+let default_author = {
+ name = None;
+ url = None;
+ icon_url = None;
+ proxy_icon_url = None;
+}
+
+let title v e = { e with title = Some v }
+let description v e = { e with description = Some v }
+let url v e = { e with url = Some v }
+let timestamp v e = { e with timestamp = Some v }
+let colour v e = { e with colour = Some v }
+let color v e = { e with colour = Some v }
+let footer f e = { e with footer = Some (f default_footer) }
+let image v e = { e with image = Some { default_image with url = Some v } }
+let thumbnail v e = { e with thumbnail = Some { default_image with url = Some v } }
+let author f e = { e with author = Some (f default_author) }
+let field (name, value, inline) e = { e with fields = { name; value; inline; }::e.fields }
+let fields l e = { e with fields = List.map ~f:(fun (name, value, inline) -> { name; value; inline; }) l }
+
+let footer_text v f : footer = { f with text = v }
+let footer_icon v f : footer = { f with icon_url = Some v }
+
+let author_name v a : author = { a with name = Some v }
+let author_url v a : author = { a with url = Some v }
let author_icon v a : author = { a with icon_url = Some v }
\ No newline at end of file diff --git a/lib/models/channel/message/embed.mli b/lib/models/channel/message/embed.mli index 411d8cc..d30d015 100644 --- a/lib/models/channel/message/embed.mli +++ b/lib/models/channel/message/embed.mli @@ -1,128 +1,128 @@ -(** A footer object belonging to an embed. *) -type footer = { - text: string; - icon_url: string option; - proxy_icon_url: string option; -} [@@deriving sexp, yojson] - -(** An image object belonging to an embed. *) -type image = { - url: string option; - proxy_url: string option; - height: int option; - width: int option; -} [@@deriving sexp, yojson] - -(** A video object belonging to an embed. *) -type video = { - url: string option; - height: int option; - width: int option; -} [@@deriving sexp, yojson] - -(** A provider object belonging to an embed. *) -type provider = { - name: string option; - url: string option; -} [@@deriving sexp, yojson] - -(** An author object belonging to an embed. *) -type author = { - name: string option; - url: string option; - icon_url: string option; - proxy_icon_url: string option; -} [@@deriving sexp, yojson] - -(** A field object belonging to an embed. *) -type field = { - name: string; - value: string; - inline: bool; -} [@@deriving sexp, yojson] - -(** An embed object. See this {{:https://leovoel.github.io/embed-visualizer/}embed visualiser} if you need help understanding each component. *) -type t = { - title: string option; - kind: string option[@key "type"]; - description: string option; - url: string option; - timestamp: string option; - colour: int option[@key "color"]; - footer: footer option; - image: image option; - thumbnail: image option; - video: video option; - provider: provider option; - author: author option; - fields: field list [@default []]; -} [@@deriving sexp, yojson { strict = false }] - -(** An embed where all values are empty. *) -val default : t - -(** A footer where all values are empty. *) -val default_footer : footer - -(** An image where all values are empty. *) -val default_image : image - -(** A video where all values are empty. *) -val default_video : video - -(** A provider where all values are empty. *) -val default_provider : provider - -(** An author where all values are empty. *) -val default_author : author - -(** Set the title of an embed. *) -val title : string -> t -> t - -(** Set the description of an embed. *) -val description : string -> t -> t - -(** Set the URL of an embed. *) -val url : string -> t -> t - -(** Set the timestamp of an embed. *) -val timestamp : string -> t -> t - -(** Set the colour of an embed. *) -val colour : int -> t -> t - -(** Identical to {!colour} but with US English spelling. *) -val color : int -> t -> t - -(** Set the footer of an embed. The function passes {!default_footer} and must return a footer. *) -val footer : (footer -> footer) -> t -> t - -(** Set the image URL of an embed. *) -val image : string -> t -> t - -(** Set the thumbnail URL of an embed. *) -val thumbnail : string -> t -> t - -(** Set the author of an embed. The function passes {!default_author} and must return an author. *) -val author : (author -> author) -> t -> t - -(** Add a field to an embed. Takes a tuple in [(name, value, inline)] order. {b Fields added this way will appear in reverse order in the embed.} *) -val field : string * string * bool -> t -> t - -(** Set the fields of an embed. Similar to {!val:field}, but because a complete list is passed, fields preserve order. *) -val fields : (string * string * bool) list -> t -> t - -(** Set the footer text. Typically used in the closure passed to {!val:footer}. *) -val footer_text : string -> footer -> footer - -(** Set the footer icon URL. Typically used in the closure passed to {!val:footer}. *) -val footer_icon : string -> footer -> footer - -(** Set the author name. Typically used in the closure passed to {!val:author}. *) -val author_name : string -> author -> author - -(** Set the author URL. Typically used in the closure passed to {!val:author}. *) -val author_url : string -> author -> author - -(** Set the author icon URL. Typically used in the closure passed to {!val:author}. *) +(** A footer object belonging to an embed. *)
+type footer = {
+ text: string;
+ icon_url: string option;
+ proxy_icon_url: string option;
+} [@@deriving sexp, yojson]
+
+(** An image object belonging to an embed. *)
+type image = {
+ url: string option;
+ proxy_url: string option;
+ height: int option;
+ width: int option;
+} [@@deriving sexp, yojson]
+
+(** A video object belonging to an embed. *)
+type video = {
+ url: string option;
+ height: int option;
+ width: int option;
+} [@@deriving sexp, yojson]
+
+(** A provider object belonging to an embed. *)
+type provider = {
+ name: string option;
+ url: string option;
+} [@@deriving sexp, yojson]
+
+(** An author object belonging to an embed. *)
+type author = {
+ name: string option;
+ url: string option;
+ icon_url: string option;
+ proxy_icon_url: string option;
+} [@@deriving sexp, yojson]
+
+(** A field object belonging to an embed. *)
+type field = {
+ name: string;
+ value: string;
+ inline: bool;
+} [@@deriving sexp, yojson]
+
+(** An embed object. See this {{:https://leovoel.github.io/embed-visualizer/}embed visualiser} if you need help understanding each component. *)
+type t = {
+ title: string option;
+ kind: string option[@key "type"];
+ description: string option;
+ url: string option;
+ timestamp: string option;
+ colour: int option[@key "color"];
+ footer: footer option;
+ image: image option;
+ thumbnail: image option;
+ video: video option;
+ provider: provider option;
+ author: author option;
+ fields: field list [@default []];
+} [@@deriving sexp, yojson { strict = false }]
+
+(** An embed where all values are empty. *)
+val default : t
+
+(** A footer where all values are empty. *)
+val default_footer : footer
+
+(** An image where all values are empty. *)
+val default_image : image
+
+(** A video where all values are empty. *)
+val default_video : video
+
+(** A provider where all values are empty. *)
+val default_provider : provider
+
+(** An author where all values are empty. *)
+val default_author : author
+
+(** Set the title of an embed. *)
+val title : string -> t -> t
+
+(** Set the description of an embed. *)
+val description : string -> t -> t
+
+(** Set the URL of an embed. *)
+val url : string -> t -> t
+
+(** Set the timestamp of an embed. *)
+val timestamp : string -> t -> t
+
+(** Set the colour of an embed. *)
+val colour : int -> t -> t
+
+(** Identical to {!colour} but with US English spelling. *)
+val color : int -> t -> t
+
+(** Set the footer of an embed. The function passes {!default_footer} and must return a footer. *)
+val footer : (footer -> footer) -> t -> t
+
+(** Set the image URL of an embed. *)
+val image : string -> t -> t
+
+(** Set the thumbnail URL of an embed. *)
+val thumbnail : string -> t -> t
+
+(** Set the author of an embed. The function passes {!default_author} and must return an author. *)
+val author : (author -> author) -> t -> t
+
+(** Add a field to an embed. Takes a tuple in [(name, value, inline)] order. {b Fields added this way will appear in reverse order in the embed.} *)
+val field : string * string * bool -> t -> t
+
+(** Set the fields of an embed. Similar to {!val:field}, but because a complete list is passed, fields preserve order. *)
+val fields : (string * string * bool) list -> t -> t
+
+(** Set the footer text. Typically used in the closure passed to {!val:footer}. *)
+val footer_text : string -> footer -> footer
+
+(** Set the footer icon URL. Typically used in the closure passed to {!val:footer}. *)
+val footer_icon : string -> footer -> footer
+
+(** Set the author name. Typically used in the closure passed to {!val:author}. *)
+val author_name : string -> author -> author
+
+(** Set the author URL. Typically used in the closure passed to {!val:author}. *)
+val author_url : string -> author -> author
+
+(** Set the author icon URL. Typically used in the closure passed to {!val:author}. *)
val author_icon : string -> author -> author
\ No newline at end of file diff --git a/lib/models/channel/message/message.ml b/lib/models/channel/message/message.ml index a64c09d..43929d2 100644 --- a/lib/models/channel/message/message.ml +++ b/lib/models/channel/message/message.ml @@ -1,67 +1,67 @@ -open Async -include Message_t - -let add_reaction msg (emoji:Emoji.t) = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - let e = match emoji.id with - | Some i -> Printf.sprintf "%s:%d" emoji.name i - | None -> emoji.name - in - Http.create_reaction channel_id id e - - -let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - let `User_id user_id = user.id in - let e = match emoji.id with - | Some i -> Printf.sprintf "%s:%d" emoji.name i - | None -> emoji.name - in - Http.delete_reaction channel_id id e user_id - - -let clear_reactions msg = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - Http.delete_reactions channel_id id - - -let delete msg = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - Http.delete_message channel_id id - - -let pin msg = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - Http.pin_message channel_id id - - -let unpin msg = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - Http.unpin_message channel_id id - - -let reply msg content = - Channel_id.say content msg.channel_id - -let reply_with ?embed ?content ?file ?tts msg = - Channel_id.send_message ?embed ?content ?file ?tts msg.channel_id - -let set_content msg cont = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - to_yojson { msg with content = cont; } - |> Http.edit_message channel_id id - - -let set_embed msg embed = - let `Message_id id = msg.id in - let `Channel_id channel_id = msg.channel_id in - to_yojson { msg with embeds = [embed]; } - |> Http.edit_message channel_id id +open Async
+include Message_t
+
+let add_reaction msg (emoji:Emoji.t) =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ let e = match emoji.id with
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
+ | None -> emoji.name
+ in
+ Http.create_reaction channel_id id e
+
+
+let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ let `User_id user_id = user.id in
+ let e = match emoji.id with
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
+ | None -> emoji.name
+ in
+ Http.delete_reaction channel_id id e user_id
+
+
+let clear_reactions msg =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ Http.delete_reactions channel_id id
+
+
+let delete msg =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ Http.delete_message channel_id id
+
+
+let pin msg =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ Http.pin_message channel_id id
+
+
+let unpin msg =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ Http.unpin_message channel_id id
+
+
+let reply msg content =
+ Channel_id.say content msg.channel_id
+
+let reply_with ?embed ?content ?file ?tts msg =
+ Channel_id.send_message ?embed ?content ?file ?tts msg.channel_id
+
+let set_content msg cont =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ to_yojson { msg with content = cont; }
+ |> Http.edit_message channel_id id
+
+
+let set_embed msg embed =
+ let `Message_id id = msg.id in
+ let `Channel_id channel_id = msg.channel_id in
+ to_yojson { msg with embeds = [embed]; }
+ |> Http.edit_message channel_id id
\ No newline at end of file diff --git a/lib/models/channel/message/message.mli b/lib/models/channel/message/message.mli index 09e62a4..56e1c98 100644 --- a/lib/models/channel/message/message.mli +++ b/lib/models/channel/message/message.mli @@ -1,20 +1,39 @@ -open Async - -include module type of Message_t - -val add_reaction : t -> Emoji.t -> unit Deferred.Or_error.t -val remove_reaction : t -> Emoji.t -> User_t.t -> unit Deferred.Or_error.t -val clear_reactions : t -> unit Deferred.Or_error.t -val delete : t -> unit Deferred.Or_error.t -val pin : t -> unit Deferred.Or_error.t -val unpin : t -> unit Deferred.Or_error.t -val reply : t -> string -> t Deferred.Or_error.t -val reply_with : - ?embed:Embed.t -> - ?content:string -> - ?file:string -> - ?tts:bool -> - t -> - Message_t.t Deferred.Or_error.t -val set_content : t -> string -> t Deferred.Or_error.t +open Async
+
+include module type of Message_t
+
+(** Add the given emoji as a reaction. *)
+val add_reaction : t -> Emoji.t -> unit Deferred.Or_error.t
+
+(** Remove the reaction. Must also specify the user. *)
+val remove_reaction : t -> Emoji.t -> User_t.t -> unit Deferred.Or_error.t
+
+(** Remove all reactions from the message. *)
+val clear_reactions : t -> unit Deferred.Or_error.t
+
+(** Delete the message. *)
+val delete : t -> unit Deferred.Or_error.t
+
+(** Pin the message. *)
+val pin : t -> unit Deferred.Or_error.t
+
+(** Unping the message. *)
+val unpin : t -> unit Deferred.Or_error.t
+
+(** Sugar for [Channel_id.say msg.channel_id content]. *)
+val reply : t -> string -> t Deferred.Or_error.t
+
+(** Sugar for [Channel_id.send_message ?embed ?content ?file ?tts msg.channel_id]. *)
+val reply_with :
+ ?embed:Embed.t ->
+ ?content:string ->
+ ?file:string ->
+ ?tts:bool ->
+ t ->
+ Message_t.t Deferred.Or_error.t
+
+(** Set the content of the message. *)
+val set_content : t -> string -> t Deferred.Or_error.t
+
+(** Set the embed of the message. *)
val set_embed : t -> Embed.t -> t Deferred.Or_error.t
\ No newline at end of file diff --git a/lib/models/channel/message/message_t.ml b/lib/models/channel/message/message_t.ml index 3c2e736..fc678f6 100644 --- a/lib/models/channel/message/message_t.ml +++ b/lib/models/channel/message/message_t.ml @@ -1,23 +1,23 @@ -open Core - -type t = { - id: Message_id.t; - author: User_t.t; - channel_id: Channel_id_t.t; - member: Member_t.partial_member option [@default None]; - guild_id: Guild_id_t.t option [@default None]; - content: string; - timestamp: string; - edited_timestamp: string option [@default None]; - tts: bool; - mention_everyone: bool; - mentions: User_t.t list [@default []]; - mention_roles: Role_id.t list [@default []]; - attachments: Attachment.t list [@default []]; - embeds: Embed.t list [@default []]; - reactions: Snowflake.t list [@default []]; - nonce: Snowflake.t option [@default None]; - pinned: bool; - webhook_id: Snowflake.t option [@default None]; - kind: int [@key "type"]; +open Core
+
+type t = {
+ id: Message_id.t;
+ author: User_t.t;
+ channel_id: Channel_id_t.t;
+ member: Member_t.partial_member option [@default None];
+ guild_id: Guild_id_t.t option [@default None];
+ content: string;
+ timestamp: string;
+ edited_timestamp: string option [@default None];
+ tts: bool;
+ mention_everyone: bool;
+ mentions: User_t.t list [@default []];
+ mention_roles: Role_id.t list [@default []];
+ attachments: Attachment.t list [@default []];
+ embeds: Embed.t list [@default []];
+ reactions: Snowflake.t list [@default []];
+ nonce: Snowflake.t option [@default None];
+ pinned: bool;
+ webhook_id: Snowflake.t option [@default None];
+ kind: int [@key "type"];
} [@@deriving sexp, yojson { strict = false}]
\ No newline at end of file diff --git a/lib/models/channel/message/message_t.mli b/lib/models/channel/message/message_t.mli index 1f691b5..de56655 100644 --- a/lib/models/channel/message/message_t.mli +++ b/lib/models/channel/message/message_t.mli @@ -1,22 +1,22 @@ -(** Represents a message object. *) -type t = { - id: Message_id.t; - author: User_t.t; - channel_id: Channel_id_t.t; - member: Member_t.partial_member option; - guild_id: Guild_id_t.t option; - content: string; - timestamp: string; - edited_timestamp: string option; - tts: bool; - mention_everyone: bool; - mentions: User_t.t list; - mention_roles: Role_id.t list; - attachments: Attachment.t list; - embeds: Embed.t list; - reactions: Snowflake.t list; - nonce: Snowflake.t option; - pinned: bool; - webhook_id: Snowflake.t option; - kind: int; +(** Represents a message object. *)
+type t = {
+ id: Message_id.t; (** Snowflake ID of the message. *)
+ author: User_t.t; (** User that authored the message. *)
+ channel_id: Channel_id_t.t; (** Channel ID the message exists in. *)
+ member: Member_t.partial_member option; (** A partial member if the message was sent in a guild. *)
+ guild_id: Guild_id_t.t option; (** Guild ID if the message was sent in a guild. *)
+ content: string; (** Content of the message. *)
+ timestamp: string; (** ISO8601 timestamp of when the message was created. *)
+ edited_timestamp: string option; (** Like timestamp, but for last edit, if any. *)
+ tts: bool; (** Whether the message used text-to-speech. *)
+ mention_everyone: bool; (** Whether the message mentioned [@everyone] or [@here] *)
+ mentions: User_t.t list; (** A List of users that were mentioned in the message. *)
+ mention_roles: Role_id.t list; (** A list of roles that were mentioned in the message. *)
+ attachments: Attachment.t list; (** A list of attachments. *)
+ embeds: Embed.t list; (** A List of embeds on the message. *)
+ reactions: Snowflake.t list; (** A list of reactions. *)
+ nonce: Snowflake.t option; (** Used in verification, safe to ignore. *)
+ pinned: bool; (** Whether the message is pinned. *)
+ webhook_id: Snowflake.t option; (** The webhook ID, if the message was sent by a webhook. *)
+ kind: int; (** See {{:https://discordapp.com/developers/docs/resources/channel#message-object-message-types}the discord docs} for message type enumeration. *)
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/channel/message/reaction_t.ml b/lib/models/channel/message/reaction_t.ml index 1aa3c84..7c78baf 100644 --- a/lib/models/channel/message/reaction_t.ml +++ b/lib/models/channel/message/reaction_t.ml @@ -1,14 +1,14 @@ -open Core - -type reaction_event = { - user_id: User_id_t.t; - channel_id: Channel_id_t.t; - message_id: Message_id.t; - guild_id: Guild_id_t.t option [@default None]; - emoji: Emoji.partial_emoji; -} [@@deriving sexp, yojson] - -type t = { - count: int; - emoji: Emoji.t; +open Core
+
+type reaction_event = {
+ user_id: User_id_t.t;
+ channel_id: Channel_id_t.t;
+ message_id: Message_id.t;
+ guild_id: Guild_id_t.t option [@default None];
+ emoji: Emoji.partial_emoji;
+} [@@deriving sexp, yojson]
+
+type t = {
+ count: int;
+ emoji: Emoji.t;
} [@@deriving sexp, yojson { strict = false}]
\ No newline at end of file diff --git a/lib/models/channel/message/reaction_t.mli b/lib/models/channel/message/reaction_t.mli index 6c2782a..ace8f55 100644 --- a/lib/models/channel/message/reaction_t.mli +++ b/lib/models/channel/message/reaction_t.mli @@ -1,14 +1,14 @@ -(** Represents a single reaction as received over the gateway. *) -type reaction_event = { - user_id: User_id_t.t; - channel_id: Channel_id_t.t; - message_id: Message_id.t; - guild_id: Guild_id_t.t option; - emoji: Emoji.partial_emoji; -} [@@deriving sexp, yojson] - -(** Represents a number of emojis used as a reaction on a message. *) -type t = { - count: int; - emoji: Emoji.t; +(** Represents a single reaction as received over the gateway. *)
+type reaction_event = {
+ user_id: User_id_t.t;
+ channel_id: Channel_id_t.t;
+ message_id: Message_id.t;
+ guild_id: Guild_id_t.t option;
+ emoji: Emoji.partial_emoji;
+} [@@deriving sexp, yojson]
+
+(** Represents a number of emojis used as a reaction on a message. *)
+type t = {
+ count: int;
+ emoji: Emoji.t;
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/emoji.ml b/lib/models/emoji.ml index 4d33615..63318a5 100644 --- a/lib/models/emoji.ml +++ b/lib/models/emoji.ml @@ -1,16 +1,16 @@ -open Core - -type partial_emoji = { - id: Snowflake.t option [@default None]; - name: string; -} [@@deriving sexp, yojson { strict = false }] - -type t = { - id: Snowflake.t option [@default None]; - name: string; - roles: Role_id.t list [@default []]; - user: User_t.t option [@default None]; - require_colons: bool [@default false]; - managed: bool [@default false]; - animated: bool [@default false]; +open Core
+
+type partial_emoji = {
+ id: Snowflake.t option [@default None];
+ name: string;
+} [@@deriving sexp, yojson { strict = false }]
+
+type t = {
+ id: Snowflake.t option [@default None];
+ name: string;
+ roles: Role_id.t list [@default []];
+ user: User_t.t option [@default None];
+ require_colons: bool [@default false];
+ managed: bool [@default false];
+ animated: bool [@default false];
} [@@deriving sexp, yojson { strict = false}]
\ No newline at end of file diff --git a/lib/models/emoji.mli b/lib/models/emoji.mli index 1660719..c159a0e 100644 --- a/lib/models/emoji.mli +++ b/lib/models/emoji.mli @@ -1,16 +1,16 @@ -(** A partial emoji, used internally. *) -type partial_emoji = { - id: Snowflake.t option; - name: string; -} [@@deriving sexp, yojson] - -(** A full emoji object. *) -type t = { - id: Snowflake.t option; (** Snowflake ID of the emoji. Only exists for custom emojis. *) - name: string; (** Name of the emoji. Either the emoji custom name or a unicode character. *) - roles: Role_id.t list; (** List of roles required to use this emoji. Is only non-empty on some integration emojis. *) - user: User_t.t option; (** User object of the person who uploaded the emoji. Only exists for custom emojis. *) - require_colons: bool; (** Whether the emoji must be wrapped in colons. Is false for unicode emojis. *) - managed: bool; (** Whether the emoji is managed by an integration. *) - animated: bool; (** Whether the emoji is animated. *) +(** A partial emoji, used internally. *)
+type partial_emoji = {
+ id: Snowflake.t option;
+ name: string;
+} [@@deriving sexp, yojson]
+
+(** A full emoji object. *)
+type t = {
+ id: Snowflake.t option; (** Snowflake ID of the emoji. Only exists for custom emojis. *)
+ name: string; (** Name of the emoji. Either the emoji custom name or a unicode character. *)
+ roles: Role_id.t list; (** List of roles required to use this emoji. Is only non-empty on some integration emojis. *)
+ user: User_t.t option; (** User object of the person who uploaded the emoji. Only exists for custom emojis. *)
+ require_colons: bool; (** Whether the emoji must be wrapped in colons. Is false for unicode emojis. *)
+ managed: bool; (** Whether the emoji is managed by an integration. *)
+ animated: bool; (** Whether the emoji is animated. *)
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/event_models.ml b/lib/models/event_models.ml index 3cb2aa3..b5eb80d 100644 --- a/lib/models/event_models.ml +++ b/lib/models/event_models.ml @@ -1,371 +1,371 @@ -open Core - -module ChannelCreate = struct - type t = { - channel: Channel_t.t; - } [@@deriving sexp] - - let deserialize ev = - let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in - { channel; } -end - -module ChannelDelete = struct - type t = { - channel: Channel_t.t; - } [@@deriving sexp] - - let deserialize ev = - let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in - { channel; } -end - -module ChannelUpdate = struct - type t = { - channel: Channel_t.t; - } [@@deriving sexp] - - let deserialize ev = - let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in - { channel; } -end - -module ChannelPinsUpdate = struct - type t = { - channel_id: Channel_id.t; - last_pin_timestamp: string option [@default None]; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module ChannelRecipientAdd = struct - type t = { - channel_id: Channel_id.t; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module ChannelRecipientRemove = struct - type t = { - channel_id: Channel_id.t; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildBanAdd = struct - type t = { - guild_id: Guild_id.t; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildBanRemove = struct - type t = { - guild_id: Guild_id.t; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildCreate = struct - type t = { - guild: Guild_t.t; - } [@@deriving sexp] - - let deserialize ev = - let guild = Guild_t.(pre_of_yojson_exn ev |> wrap) in - { guild; } -end - -module GuildDelete = struct - type t = { - id: Guild_id.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildUpdate = struct - type t = { - guild: Guild_t.t; - } [@@deriving sexp] - - let deserialize ev = - let guild = Guild_t.(pre_of_yojson_exn ev |> wrap) in - { guild; } -end - -module GuildEmojisUpdate = struct - type t = { - emojis: Emoji.t list; - guild_id: Guild_id.t - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -(* TODO guild integrations *) - -module GuildMemberAdd = struct - include Member_t - - let deserialize = of_yojson_exn -end - -module GuildMemberRemove = struct - type t = { - guild_id: Guild_id.t; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildMemberUpdate = struct - type t = { - guild_id: Guild_id.t; - nick: string option; - roles: Role_id.t list; - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildMembersChunk = struct - type t = { - guild_id: Guild_id.t; - members: (Snowflake.t * Member_t.t) list; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildRoleCreate = struct - type t = { - guild_id: Guild_id.t; - role: Role_t.role; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildRoleDelete = struct - type t = { - guild_id: Guild_id.t; - role_id: Role_id.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module GuildRoleUpdate = struct - type t = { - guild_id: Guild_id.t; - role: Role_t.role; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -(* TODO figure out if this is necessary *) -module GuildUnavailable = struct - type t = { - guild_id: Guild_id.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module MessageCreate = struct - type t = { - message: Message_t.t; - } [@@deriving sexp] - - let deserialize ev = - let message = Message_t.of_yojson_exn ev in - { message; } -end - -module MessageDelete = struct - type t = { - id: Message_id.t; - channel_id: Channel_id.t; - guild_id: Guild_id.t option [@default None]; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module MessageUpdate = struct - type t = { - id: Message_id.t; - author: User_t.t option [@default None]; - channel_id: Channel_id.t; - member: Member_t.partial_member option [@default None]; - guild_id: Guild_id.t option [@default None]; - content: string option [@default None]; - timestamp: string option [@default None]; - editedimestamp: string option [@default None]; - tts: bool option [@default None]; - mention_everyone: bool option [@default None]; - mentions: User_id.t list [@default []]; - role_mentions: Role_id.t list [@default []]; - attachments: Attachment.t list [@default []]; - embeds: Embed.t list [@default []]; - reactions: Snowflake.t list [@default []]; - nonce: Snowflake.t option [@default None]; - pinned: bool option [@default None]; - webhook_id: Snowflake.t option [@default None]; - kind: int option [@default None][@key "type"]; - } [@@deriving sexp, yojson { strict = false}] - - let deserialize = of_yojson_exn -end - -module MessageDeleteBulk = struct - type t = { - guild_id: Guild_id.t option [@default None]; - channel_id: Channel_id.t; - ids: Message_id.t list; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module PresenceUpdate = struct - include Presence - - let deserialize = of_yojson_exn -end - -(* module PresencesReplace = struct - type t = - - let deserialize = of_yojson_exn -end *) - -module ReactionAdd = struct - type t = { - user_id: User_id.t; - channel_id: Channel_id.t; - message_id: Message_id.t; - guild_id: Guild_id.t option [@default None]; - emoji: Emoji.partial_emoji; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module ReactionRemove = struct - type t = { - user_id: User_id.t; - channel_id: Channel_id.t; - message_id: Message_id.t; - guild_id: Guild_id.t option [@default None]; - emoji: Emoji.partial_emoji; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module ReactionRemoveAll = struct - type t = { - channel_id: Channel_id.t; - message_id: Message_id.t; - guild_id: Guild_id.t option [@default None]; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module Ready = struct - type t = { - version: int [@key "v"]; - user: User_t.t; - private_channels: Channel_id.t list; - guilds: Guild_t.unavailable list; - session_id: string; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module Resumed = struct - type t = { - trace: string option list [@key "_trace"]; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module TypingStart = struct - type t = { - channel_id: Channel_id.t; - guild_id: Guild_id.t option [@default None]; - timestamp: int; - user_id: User_id.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module UserUpdate = struct - type t = { - user: User_t.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize ev = - let user = User_t.of_yojson_exn ev in - { user; } -end - -module WebhookUpdate = struct - type t = { - channel_id: Channel_id.t; - guild_id: Guild_id.t; - } [@@deriving sexp, yojson { strict = false }] - - let deserialize = of_yojson_exn -end - -module Unknown = struct - type t = { - kind: string; - value: Yojson.Safe.json; - } - - let deserialize kind value = { kind; value; } -end - -(* module VoiceHeartbeat = struct - -end - -module VoiceHello = struct - -end - -module VoiceServerUpdate = struct - -end - -module VoiceSessionDescription = struct - -end - -module VoiceSpeaking = struct - -end - -module VoiceStateUpdate = struct - +open Core
+
+module ChannelCreate = struct
+ type t = {
+ channel: Channel_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in
+ { channel; }
+end
+
+module ChannelDelete = struct
+ type t = {
+ channel: Channel_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in
+ { channel; }
+end
+
+module ChannelUpdate = struct
+ type t = {
+ channel: Channel_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let channel = Channel_t.(channel_wrapper_of_yojson_exn ev |> wrap) in
+ { channel; }
+end
+
+module ChannelPinsUpdate = struct
+ type t = {
+ channel_id: Channel_id.t;
+ last_pin_timestamp: string option [@default None];
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module ChannelRecipientAdd = struct
+ type t = {
+ channel_id: Channel_id.t;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module ChannelRecipientRemove = struct
+ type t = {
+ channel_id: Channel_id.t;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildBanAdd = struct
+ type t = {
+ guild_id: Guild_id.t;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildBanRemove = struct
+ type t = {
+ guild_id: Guild_id.t;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildCreate = struct
+ type t = {
+ guild: Guild_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let guild = Guild_t.(pre_of_yojson_exn ev |> wrap) in
+ { guild; }
+end
+
+module GuildDelete = struct
+ type t = {
+ id: Guild_id.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildUpdate = struct
+ type t = {
+ guild: Guild_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let guild = Guild_t.(pre_of_yojson_exn ev |> wrap) in
+ { guild; }
+end
+
+module GuildEmojisUpdate = struct
+ type t = {
+ emojis: Emoji.t list;
+ guild_id: Guild_id.t
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+(* TODO guild integrations *)
+
+module GuildMemberAdd = struct
+ include Member_t
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildMemberRemove = struct
+ type t = {
+ guild_id: Guild_id.t;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildMemberUpdate = struct
+ type t = {
+ guild_id: Guild_id.t;
+ nick: string option;
+ roles: Role_id.t list;
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildMembersChunk = struct
+ type t = {
+ guild_id: Guild_id.t;
+ members: (Snowflake.t * Member_t.t) list;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildRoleCreate = struct
+ type t = {
+ guild_id: Guild_id.t;
+ role: Role_t.role;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildRoleDelete = struct
+ type t = {
+ guild_id: Guild_id.t;
+ role_id: Role_id.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module GuildRoleUpdate = struct
+ type t = {
+ guild_id: Guild_id.t;
+ role: Role_t.role;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+(* TODO figure out if this is necessary *)
+module GuildUnavailable = struct
+ type t = {
+ guild_id: Guild_id.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module MessageCreate = struct
+ type t = {
+ message: Message_t.t;
+ } [@@deriving sexp]
+
+ let deserialize ev =
+ let message = Message_t.of_yojson_exn ev in
+ { message; }
+end
+
+module MessageDelete = struct
+ type t = {
+ id: Message_id.t;
+ channel_id: Channel_id.t;
+ guild_id: Guild_id.t option [@default None];
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module MessageUpdate = struct
+ type t = {
+ id: Message_id.t;
+ author: User_t.t option [@default None];
+ channel_id: Channel_id.t;
+ member: Member_t.partial_member option [@default None];
+ guild_id: Guild_id.t option [@default None];
+ content: string option [@default None];
+ timestamp: string option [@default None];
+ editedimestamp: string option [@default None];
+ tts: bool option [@default None];
+ mention_everyone: bool option [@default None];
+ mentions: User_id.t list [@default []];
+ role_mentions: Role_id.t list [@default []];
+ attachments: Attachment.t list [@default []];
+ embeds: Embed.t list [@default []];
+ reactions: Snowflake.t list [@default []];
+ nonce: Snowflake.t option [@default None];
+ pinned: bool option [@default None];
+ webhook_id: Snowflake.t option [@default None];
+ kind: int option [@default None][@key "type"];
+ } [@@deriving sexp, yojson { strict = false}]
+
+ let deserialize = of_yojson_exn
+end
+
+module MessageDeleteBulk = struct
+ type t = {
+ guild_id: Guild_id.t option [@default None];
+ channel_id: Channel_id.t;
+ ids: Message_id.t list;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module PresenceUpdate = struct
+ include Presence
+
+ let deserialize = of_yojson_exn
+end
+
+(* module PresencesReplace = struct
+ type t =
+
+ let deserialize = of_yojson_exn
+end *)
+
+module ReactionAdd = struct
+ type t = {
+ user_id: User_id.t;
+ channel_id: Channel_id.t;
+ message_id: Message_id.t;
+ guild_id: Guild_id.t option [@default None];
+ emoji: Emoji.partial_emoji;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module ReactionRemove = struct
+ type t = {
+ user_id: User_id.t;
+ channel_id: Channel_id.t;
+ message_id: Message_id.t;
+ guild_id: Guild_id.t option [@default None];
+ emoji: Emoji.partial_emoji;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module ReactionRemoveAll = struct
+ type t = {
+ channel_id: Channel_id.t;
+ message_id: Message_id.t;
+ guild_id: Guild_id.t option [@default None];
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module Ready = struct
+ type t = {
+ version: int [@key "v"];
+ user: User_t.t;
+ private_channels: Channel_id.t list;
+ guilds: Guild_t.unavailable list;
+ session_id: string;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module Resumed = struct
+ type t = {
+ trace: string option list [@key "_trace"];
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module TypingStart = struct
+ type t = {
+ channel_id: Channel_id.t;
+ guild_id: Guild_id.t option [@default None];
+ timestamp: int;
+ user_id: User_id.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module UserUpdate = struct
+ type t = {
+ user: User_t.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize ev =
+ let user = User_t.of_yojson_exn ev in
+ { user; }
+end
+
+module WebhookUpdate = struct
+ type t = {
+ channel_id: Channel_id.t;
+ guild_id: Guild_id.t;
+ } [@@deriving sexp, yojson { strict = false }]
+
+ let deserialize = of_yojson_exn
+end
+
+module Unknown = struct
+ type t = {
+ kind: string;
+ value: Yojson.Safe.json;
+ }
+
+ let deserialize kind value = { kind; value; }
+end
+
+(* module VoiceHeartbeat = struct
+
+end
+
+module VoiceHello = struct
+
+end
+
+module VoiceServerUpdate = struct
+
+end
+
+module VoiceSessionDescription = struct
+
+end
+
+module VoiceSpeaking = struct
+
+end
+
+module VoiceStateUpdate = struct
+
end *)
\ No newline at end of file diff --git a/lib/models/guild/ban_t.mli b/lib/models/guild/ban_t.mli index 51d59e7..37e5cfa 100644 --- a/lib/models/guild/ban_t.mli +++ b/lib/models/guild/ban_t.mli @@ -1,4 +1,4 @@ -type t = { - reason: string option; (** The reason for the ban. *) - user: User_t.t; (** The banned user. *) +type t = {
+ reason: string option; (** The reason for the ban. *)
+ user: User_t.t; (** The banned user. *)
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/guild/guild.ml b/lib/models/guild/guild.ml index 812a49e..b1e8bfe 100644 --- a/lib/models/guild/guild.ml +++ b/lib/models/guild/guild.ml @@ -1,22 +1,22 @@ -open Core -open Async - -include Guild_t -include Impl.Guild(Guild_t) - -let get_member ~(id:User_id_t.t) guild = - match List.find ~f:(fun m -> m.user.id = id) guild.members with - | Some m -> Deferred.Or_error.return m - | None -> - let `User_id id = id in - Http.get_member (get_id guild) id - -let get_channel ~(id:Channel_id_t.t) guild = - let `Channel_id id = id in - match List.find ~f:(fun c -> Channel_t.get_id c = id) guild.channels with - | Some c -> Deferred.Or_error.return c - | None -> Http.get_channel id - -(* TODO add HTTP fallback *) -let get_role ~(id:Role_id.t) guild = +open Core
+open Async
+
+include Guild_t
+include Impl.Guild(Guild_t)
+
+let get_member ~(id:User_id_t.t) guild =
+ match List.find ~f:(fun m -> m.user.id = id) guild.members with
+ | Some m -> Deferred.Or_error.return m
+ | None ->
+ let `User_id id = id in
+ Http.get_member (get_id guild) id
+
+let get_channel ~(id:Channel_id_t.t) guild =
+ let `Channel_id id = id in
+ match List.find ~f:(fun c -> Channel_t.get_id c = id) guild.channels with
+ | Some c -> Deferred.Or_error.return c
+ | None -> Http.get_channel id
+
+(* TODO add HTTP fallback *)
+let get_role ~(id:Role_id.t) guild =
List.find ~f:(fun r -> r.id = id) guild.roles
\ No newline at end of file diff --git a/lib/models/guild/guild.mli b/lib/models/guild/guild.mli index e6f272c..be9300a 100644 --- a/lib/models/guild/guild.mli +++ b/lib/models/guild/guild.mli @@ -1,14 +1,14 @@ -open Async - -include module type of Guild_t -include S.GuildImpl with - type t := Guild_t.t - -(** Get a channel belonging to this guild. This does not make an HTTP request. *) -val get_channel : id:Channel_id_t.t -> t -> Channel_t.t Deferred.Or_error.t - -(** Get a member belonging to this guild. This does not make an HTTP request. *) -val get_member : id:User_id_t.t -> t -> Member_t.t Deferred.Or_error.t - -(** Get a role belonging to this guild. This does not make an HTTP request. *) +open Async
+
+include module type of Guild_t
+include S.GuildImpl with
+ type t := Guild_t.t
+
+(** Get a channel belonging to this guild. This does not make an HTTP request. *)
+val get_channel : id:Channel_id_t.t -> t -> Channel_t.t Deferred.Or_error.t
+
+(** Get a member belonging to this guild. This does not make an HTTP request. *)
+val get_member : id:User_id_t.t -> t -> Member_t.t Deferred.Or_error.t
+
+(** Get a role belonging to this guild. This does not make an HTTP request. *)
val get_role : id:Role_id.t -> t -> Role_t.t option
\ No newline at end of file diff --git a/lib/models/guild/guild_t.ml b/lib/models/guild/guild_t.ml index fa62a8f..9ad7cb9 100644 --- a/lib/models/guild/guild_t.ml +++ b/lib/models/guild/guild_t.ml @@ -1,72 +1,72 @@ -open Core - -type unavailable = { - id: Guild_id_t.t; -} [@@deriving sexp, yojson { strict = false }] - -type pre = { - id: Guild_id_t.t; - name: string; - icon: string option [@default None]; - splash: string option [@default None]; - owner_id: User_id_t.t; - region: string; - afk_channel_id: Channel_id_t.t option [@default None]; - afk_timeout: int; - embed_enabled: bool [@default false]; - embed_channel_id: Channel_id_t.t option [@default None]; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: Role_t.role list; - emojis: Emoji.t list; - features: string list; - mfa_level: int; - application_id: Snowflake.t option [@default None]; - widget_enabled: bool [@default false]; - widget_channel_id: Channel_id_t.t option [@default None]; - system_channel_id: Channel_id_t.t option [@default None]; - large: bool; - unavailable: bool; - member_count: int option [@default None]; - members: Member_t.member list; - channels: Channel_t.channel_wrapper list; -} [@@deriving sexp, yojson { strict = false }] - -type t = { - id: Guild_id_t.t; - name: string; - icon: string option [@default None]; - splash: string option [@default None]; - owner_id: User_id_t.t; - region: string; - afk_channel_id: Channel_id_t.t option [@default None]; - afk_timeout: int; - embed_enabled: bool [@default false]; - embed_channel_id: Channel_id_t.t option [@default None]; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: Role_t.t list; - emojis: Emoji.t list; - features: string list; - mfa_level: int; - application_id: Snowflake.t option [@default None]; - widget_enabled: bool [@default false]; - widget_channel_id: Channel_id_t.t option [@default None]; - system_channel_id: Channel_id_t.t option [@default None]; - large: bool; - unavailable: bool; - member_count: int option [@default None]; - members: Member_t.t list; - channels: Channel_t.t list; -} [@@deriving sexp, yojson { strict = false }] - -let wrap ({id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel_id;system_channel_id;large;unavailable;member_count;members;channels}:pre) = - let `Guild_id id = id in - let roles = List.map ~f:(Role_t.wrap ~guild_id:id) roles in - let members = List.map ~f:(Member_t.wrap ~guild_id:id) members in - let channels = List.map ~f:Channel_t.wrap channels in - {id = `Guild_id id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel_id;system_channel_id;large;unavailable;member_count;members;channels} - +open Core
+
+type unavailable = {
+ id: Guild_id_t.t;
+} [@@deriving sexp, yojson { strict = false }]
+
+type pre = {
+ id: Guild_id_t.t;
+ name: string;
+ icon: string option [@default None];
+ splash: string option [@default None];
+ owner_id: User_id_t.t;
+ region: string;
+ afk_channel_id: Channel_id_t.t option [@default None];
+ afk_timeout: int;
+ embed_enabled: bool [@default false];
+ embed_channel_id: Channel_id_t.t option [@default None];
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role_t.role list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option [@default None];
+ widget_enabled: bool [@default false];
+ widget_channel_id: Channel_id_t.t option [@default None];
+ system_channel_id: Channel_id_t.t option [@default None];
+ large: bool;
+ unavailable: bool;
+ member_count: int option [@default None];
+ members: Member_t.member list;
+ channels: Channel_t.channel_wrapper list;
+} [@@deriving sexp, yojson { strict = false }]
+
+type t = {
+ id: Guild_id_t.t;
+ name: string;
+ icon: string option [@default None];
+ splash: string option [@default None];
+ owner_id: User_id_t.t;
+ region: string;
+ afk_channel_id: Channel_id_t.t option [@default None];
+ afk_timeout: int;
+ embed_enabled: bool [@default false];
+ embed_channel_id: Channel_id_t.t option [@default None];
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role_t.t list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option [@default None];
+ widget_enabled: bool [@default false];
+ widget_channel_id: Channel_id_t.t option [@default None];
+ system_channel_id: Channel_id_t.t option [@default None];
+ large: bool;
+ unavailable: bool;
+ member_count: int option [@default None];
+ members: Member_t.t list;
+ channels: Channel_t.t list;
+} [@@deriving sexp, yojson { strict = false }]
+
+let wrap ({id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel_id;system_channel_id;large;unavailable;member_count;members;channels}:pre) =
+ let `Guild_id id = id in
+ let roles = List.map ~f:(Role_t.wrap ~guild_id:id) roles in
+ let members = List.map ~f:(Member_t.wrap ~guild_id:id) members in
+ let channels = List.map ~f:Channel_t.wrap channels in
+ {id = `Guild_id id;name;icon;splash;owner_id;region;afk_channel_id;afk_timeout;embed_enabled;embed_channel_id;verification_level;default_message_notifications;explicit_content_filter;roles;emojis;features;mfa_level;application_id;widget_enabled;widget_channel_id;system_channel_id;large;unavailable;member_count;members;channels}
+
let get_id guild = let `Guild_id id = guild.id in id
\ No newline at end of file diff --git a/lib/models/guild/guild_t.mli b/lib/models/guild/guild_t.mli index e1c0718..7296372 100644 --- a/lib/models/guild/guild_t.mli +++ b/lib/models/guild/guild_t.mli @@ -1,66 +1,66 @@ -type unavailable = { - id: Guild_id_t.t; -} [@@deriving sexp, yojson] - -(** Used internally. *) -type pre = { - id: Guild_id_t.t; - name: string; - icon: string option; - splash: string option; - owner_id: User_id_t.t; - region: string; - afk_channel_id: Channel_id_t.t option; - afk_timeout: int; - embed_enabled: bool; - embed_channel_id: Channel_id_t.t option; - verification_level: int; - default_message_notifications: int; - explicit_content_filter: int; - roles: Role_t.role list; - emojis: Emoji.t list; - features: string list; - mfa_level: int; - application_id: Snowflake.t option; - widget_enabled: bool; - widget_channel_id: Channel_id_t.t option; - system_channel_id: Channel_id_t.t option; - large: bool; - unavailable: bool; - member_count: int option; - members: Member_t.member list; - channels: Channel_t.channel_wrapper list; -} [@@deriving sexp, yojson] - -(** A Guild object *) -type t = { - id: Guild_id_t.t; (** The guild's snowflake ID. *) - name: string; (** The guild name. *) - icon: string option; (** The guild icon hash, if one is set. *) - splash: string option; (** The guild splash hash, if one is set. *) - owner_id: User_id_t.t; (** The user ID of the owner. *) - region: string; (** The region the guild is in. *) - afk_channel_id: Channel_id_t.t option; (** The AFK channel ID, if one is set. *) - afk_timeout: int; (** The time before a user is moved to the AFK channel. *) - embed_enabled: bool; (** Whether the embed is enabled. *) - embed_channel_id: Channel_id_t.t option; (** The channel ID of the embed channel, if it is enabled. *) - verification_level: int; (** See {{:https://discordapp.com/developers/docs/resources/guild#guild-object-verification-level} the discord docs} for details. *) - default_message_notifications: int; (** 0 = All messages, 1 = Only mentions *) - explicit_content_filter: int; (** 0 = Disabled, 1 = For members with no roles, 2 = All members *) - roles: Role_t.t list; (** List of roles in the guild. *) - emojis: Emoji.t list; (** List of custom emojis in the guild. *) - features: string list; (** A List of features enabled for the guild. *) - mfa_level: int; (** 0 = None, 1 = Elevated *) - application_id: Snowflake.t option; (** Snowflake ID if the guild is bot-created. *) - widget_enabled: bool; (** Whether the widget is enabled. *) - widget_channel_id: Channel_id_t.t option; (** The channel ID for the widget, if enabled. *) - system_channel_id: Channel_id_t.t option; (** The channel ID where system messages are sent. *) - large: bool; (** Whether the guild exceeds the configured large threshold. *) - unavailable: bool; (** Whether the guild is unavailable or not. *) - member_count: int option; (** Total number of members in the guild. *) - members: Member_t.t list; (** List of guild members. *) - channels: Channel_t.t list; (** List of guild channels. *) -} [@@deriving sexp, yojson] - -val wrap : pre -> t +type unavailable = {
+ id: Guild_id_t.t;
+} [@@deriving sexp, yojson]
+
+(** Used internally. *)
+type pre = {
+ id: Guild_id_t.t;
+ name: string;
+ icon: string option;
+ splash: string option;
+ owner_id: User_id_t.t;
+ region: string;
+ afk_channel_id: Channel_id_t.t option;
+ afk_timeout: int;
+ embed_enabled: bool;
+ embed_channel_id: Channel_id_t.t option;
+ verification_level: int;
+ default_message_notifications: int;
+ explicit_content_filter: int;
+ roles: Role_t.role list;
+ emojis: Emoji.t list;
+ features: string list;
+ mfa_level: int;
+ application_id: Snowflake.t option;
+ widget_enabled: bool;
+ widget_channel_id: Channel_id_t.t option;
+ system_channel_id: Channel_id_t.t option;
+ large: bool;
+ unavailable: bool;
+ member_count: int option;
+ members: Member_t.member list;
+ channels: Channel_t.channel_wrapper list;
+} [@@deriving sexp, yojson]
+
+(** A Guild object *)
+type t = {
+ id: Guild_id_t.t; (** The guild's snowflake ID. *)
+ name: string; (** The guild name. *)
+ icon: string option; (** The guild icon hash, if one is set. *)
+ splash: string option; (** The guild splash hash, if one is set. *)
+ owner_id: User_id_t.t; (** The user ID of the owner. *)
+ region: string; (** The region the guild is in. *)
+ afk_channel_id: Channel_id_t.t option; (** The AFK channel ID, if one is set. *)
+ afk_timeout: int; (** The time before a user is moved to the AFK channel. *)
+ embed_enabled: bool; (** Whether the embed is enabled. *)
+ embed_channel_id: Channel_id_t.t option; (** The channel ID of the embed channel, if it is enabled. *)
+ verification_level: int; (** See {{:https://discordapp.com/developers/docs/resources/guild#guild-object-verification-level} the discord docs} for details. *)
+ default_message_notifications: int; (** 0 = All messages, 1 = Only mentions *)
+ explicit_content_filter: int; (** 0 = Disabled, 1 = For members with no roles, 2 = All members *)
+ roles: Role_t.t list; (** List of roles in the guild. *)
+ emojis: Emoji.t list; (** List of custom emojis in the guild. *)
+ features: string list; (** A List of features enabled for the guild. *)
+ mfa_level: int; (** 0 = None, 1 = Elevated *)
+ application_id: Snowflake.t option; (** Snowflake ID if the guild is bot-created. *)
+ widget_enabled: bool; (** Whether the widget is enabled. *)
+ widget_channel_id: Channel_id_t.t option; (** The channel ID for the widget, if enabled. *)
+ system_channel_id: Channel_id_t.t option; (** The channel ID where system messages are sent. *)
+ large: bool; (** Whether the guild exceeds the configured large threshold. *)
+ unavailable: bool; (** Whether the guild is unavailable or not. *)
+ member_count: int option; (** Total number of members in the guild. *)
+ members: Member_t.t list; (** List of guild members. *)
+ channels: Channel_t.t list; (** List of guild channels. *)
+} [@@deriving sexp, yojson]
+
+val wrap : pre -> t
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/guild/member.ml b/lib/models/guild/member.ml index f083cce..c5a7455 100644 --- a/lib/models/guild/member.ml +++ b/lib/models/guild/member.ml @@ -1,57 +1,57 @@ -include Member_t - -let add_role ~(role:Role_t.t) member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - let `Role_id role_id = role.id in - Http.add_member_role guild_id user_id role_id - -let remove_role ~(role:Role_t.t) member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - let `Role_id role_id = role.id in - Http.remove_member_role guild_id user_id role_id - -let ban ?(reason="") ?(days=0) member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - Http.guild_ban_add guild_id user_id (`Assoc [ - ("delete-message-days", `Int days); - ("reason", `String reason); - ]) - -let kick ?reason member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - let payload = match reason with - | Some r -> `Assoc [("reason", `String r)] - | None -> `Null - in Http.remove_member guild_id user_id payload - -let mute member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - Http.edit_member guild_id user_id (`Assoc [ - ("mute", `Bool true); - ]) - -let deafen member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - Http.edit_member guild_id user_id (`Assoc [ - ("deaf", `Bool true); - ]) - -let unmute member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - Http.edit_member guild_id user_id (`Assoc [ - ("mute", `Bool false); - ]) - -let undeafen member = - let `Guild_id guild_id = member.guild_id in - let `User_id user_id = member.user.id in - Http.edit_member guild_id user_id (`Assoc [ - ("deaf", `Bool false); - ]) +include Member_t
+
+let add_role ~(role:Role_t.t) member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ let `Role_id role_id = role.id in
+ Http.add_member_role guild_id user_id role_id
+
+let remove_role ~(role:Role_t.t) member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ let `Role_id role_id = role.id in
+ Http.remove_member_role guild_id user_id role_id
+
+let ban ?(reason="") ?(days=0) member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ Http.guild_ban_add guild_id user_id (`Assoc [
+ ("delete-message-days", `Int days);
+ ("reason", `String reason);
+ ])
+
+let kick ?reason member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ let payload = match reason with
+ | Some r -> `Assoc [("reason", `String r)]
+ | None -> `Null
+ in Http.remove_member guild_id user_id payload
+
+let mute member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ Http.edit_member guild_id user_id (`Assoc [
+ ("mute", `Bool true);
+ ])
+
+let deafen member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ Http.edit_member guild_id user_id (`Assoc [
+ ("deaf", `Bool true);
+ ])
+
+let unmute member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ Http.edit_member guild_id user_id (`Assoc [
+ ("mute", `Bool false);
+ ])
+
+let undeafen member =
+ let `Guild_id guild_id = member.guild_id in
+ let `User_id user_id = member.user.id in
+ Http.edit_member guild_id user_id (`Assoc [
+ ("deaf", `Bool false);
+ ])
diff --git a/lib/models/guild/member_t.ml b/lib/models/guild/member_t.ml index 10f1cf0..ae6b894 100644 --- a/lib/models/guild/member_t.ml +++ b/lib/models/guild/member_t.ml @@ -1,43 +1,43 @@ -open Core - -type partial_member = { - nick: string option [@default None]; - roles: Role_id.t list; - joined_at: string; - deaf: bool; - mute: bool; -} [@@deriving sexp, yojson { strict = false}] - -type member = { - nick: string option [@default None]; - roles: Role_id.t list; - joined_at: string; - deaf: bool; - mute: bool; - user: User_t.t; -} [@@deriving sexp, yojson { strict = false}] - -type member_wrapper = { - guild_id: Guild_id_t.t; - user: User_t.t; -} [@@deriving sexp, yojson { strict = false }] - -type member_update = { - guild_id: Guild_id_t.t; - roles: Role_id.t list [@default []]; - user: User_t.t; - nick: string option [@default None]; -} [@@deriving sexp, yojson { strict = false}] - -type t = { - nick: string option [@default None]; - roles: Role_id.t list; - joined_at: string; - deaf: bool; - mute: bool; - user: User_t.t; - guild_id: Guild_id_t.t; -} [@@deriving sexp, yojson { strict = false}] - -let wrap ~guild_id ({nick;roles;joined_at;deaf;mute;user}:member) = +open Core
+
+type partial_member = {
+ nick: string option [@default None];
+ roles: Role_id.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+} [@@deriving sexp, yojson { strict = false}]
+
+type member = {
+ nick: string option [@default None];
+ roles: Role_id.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: User_t.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+type member_wrapper = {
+ guild_id: Guild_id_t.t;
+ user: User_t.t;
+} [@@deriving sexp, yojson { strict = false }]
+
+type member_update = {
+ guild_id: Guild_id_t.t;
+ roles: Role_id.t list [@default []];
+ user: User_t.t;
+ nick: string option [@default None];
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ nick: string option [@default None];
+ roles: Role_id.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: User_t.t;
+ guild_id: Guild_id_t.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+let wrap ~guild_id ({nick;roles;joined_at;deaf;mute;user}:member) =
{nick;roles;joined_at;deaf;mute;user;guild_id = `Guild_id guild_id}
\ No newline at end of file diff --git a/lib/models/guild/member_t.mli b/lib/models/guild/member_t.mli index 918885e..170504f 100644 --- a/lib/models/guild/member_t.mli +++ b/lib/models/guild/member_t.mli @@ -1,41 +1,41 @@ -type partial_member = { - nick: string option; - roles: Role_id.t list; - joined_at: string; - deaf: bool; - mute: bool; -} [@@deriving sexp, yojson] - -type member = { - nick: string option; - roles: Role_id.t list; - joined_at: string; - deaf: bool; - mute: bool; - user: User_t.t; -} [@@deriving sexp, yojson] - -type member_wrapper = { - guild_id: Guild_id_t.t; - user: User_t.t; -} [@@deriving sexp, yojson] - -type member_update = { - guild_id: Guild_id_t.t; - roles: Role_id.t list; - user: User_t.t; - nick: string option; -} [@@deriving sexp, yojson] - -(** A member object. *) -type t = { - nick: string option; (** The nickname of the member, if they have one set. *) - roles: Role_id.t list; (** The roles the member has. *) - joined_at: string; (** An ISO8601 timestamp of when the user joined. *) - deaf: bool; (** Whether the user is deafened. *) - mute: bool; (** Whether the user is muted. *) - user: User_t.t; (** The underlying user object for the member. *) - guild_id: Guild_id_t.t; (** The guild ID in which the member exists. *) -} [@@deriving sexp, yojson] - +type partial_member = {
+ nick: string option;
+ roles: Role_id.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+} [@@deriving sexp, yojson]
+
+type member = {
+ nick: string option;
+ roles: Role_id.t list;
+ joined_at: string;
+ deaf: bool;
+ mute: bool;
+ user: User_t.t;
+} [@@deriving sexp, yojson]
+
+type member_wrapper = {
+ guild_id: Guild_id_t.t;
+ user: User_t.t;
+} [@@deriving sexp, yojson]
+
+type member_update = {
+ guild_id: Guild_id_t.t;
+ roles: Role_id.t list;
+ user: User_t.t;
+ nick: string option;
+} [@@deriving sexp, yojson]
+
+(** A member object. *)
+type t = {
+ nick: string option; (** The nickname of the member, if they have one set. *)
+ roles: Role_id.t list; (** The roles the member has. *)
+ joined_at: string; (** An ISO8601 timestamp of when the user joined. *)
+ deaf: bool; (** Whether the user is deafened. *)
+ mute: bool; (** Whether the user is muted. *)
+ user: User_t.t; (** The underlying user object for the member. *)
+ guild_id: Guild_id_t.t; (** The guild ID in which the member exists. *)
+} [@@deriving sexp, yojson]
+
val wrap : guild_id:Snowflake.t -> member -> t
\ No newline at end of file diff --git a/lib/models/guild/role.ml b/lib/models/guild/role.ml index 46f908b..55e5813 100644 --- a/lib/models/guild/role.ml +++ b/lib/models/guild/role.ml @@ -1,29 +1,29 @@ -include Role_t - -let edit_role ~body (role:t) = - let `Role_id id = role.id in - let `Guild_id guild_id = role.guild_id in - Http.guild_role_edit guild_id id body - -let allow_mention role = - edit_role ~body:(`Assoc [("mentionable", `Bool true)]) role - -let delete (role:t) = - let `Role_id id = role.id in - let `Guild_id guild_id = role.guild_id in - Http.guild_role_remove guild_id 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 = +include Role_t
+
+let edit_role ~body (role:t) =
+ let `Role_id id = role.id in
+ let `Guild_id guild_id = role.guild_id in
+ Http.guild_role_edit guild_id id body
+
+let allow_mention role =
+ edit_role ~body:(`Assoc [("mentionable", `Bool true)]) role
+
+let delete (role:t) =
+ let `Role_id id = role.id in
+ let `Guild_id guild_id = role.guild_id in
+ Http.guild_role_remove guild_id 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
\ No newline at end of file diff --git a/lib/models/guild/role_t.ml b/lib/models/guild/role_t.ml index f012a15..cc461f3 100644 --- a/lib/models/guild/role_t.ml +++ b/lib/models/guild/role_t.ml @@ -1,27 +1,27 @@ -open Core - -type role = { - id: Role_id.t; - name: string; - colour: int [@key "color"]; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool; -} [@@deriving sexp, yojson { strict = false}] - -type t = { - id: Role_id.t; - name: string; - colour: int [@key "color"]; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool; - guild_id: Guild_id_t.t; -} [@@deriving sexp, yojson { strict = false}] - -let wrap ~guild_id ({id;name;colour;hoist;position;permissions;managed;mentionable}:role) = +open Core
+
+type role = {
+ id: Role_id.t;
+ name: string;
+ colour: int [@key "color"];
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ id: Role_id.t;
+ name: string;
+ colour: int [@key "color"];
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+ guild_id: Guild_id_t.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+let wrap ~guild_id ({id;name;colour;hoist;position;permissions;managed;mentionable}:role) =
{id;name;colour;hoist;position;permissions;managed;mentionable;guild_id = `Guild_id guild_id}
\ No newline at end of file diff --git a/lib/models/guild/role_t.mli b/lib/models/guild/role_t.mli index 6fd023f..1b69e25 100644 --- a/lib/models/guild/role_t.mli +++ b/lib/models/guild/role_t.mli @@ -1,27 +1,27 @@ -(** A role as Discord sends it. Only difference between this and {!t} is the lack of the guild_id field. *) -type role = { - id: Role_id.t; - name: string; - colour: int; - hoist: bool; - position: int; - permissions: int; - managed: bool; - mentionable: bool; -} [@@deriving sexp, yojson] - -(** A role object. *) -type t = { - id: Role_id.t; (** The role's snowflake ID. *) - name: string; (** The role's name. *) - colour: int; (** The integer representation of the role colour. *) - hoist: bool; (** Whether the role is hoisted. This property controls whether the role is separated on the sidebar. *) - position: int; (** The position of the role. [@everyone] begins the list at 0. *) - permissions: int; (** The integer representation of the permissions the role has. *) - managed: bool; (** Whether the guild is managed by an integration. *) - mentionable: bool; (** Whether the role can be mentioned. *) - guild_id: Guild_id_t.t; (** The guild ID this role belongs to. *) -} [@@deriving sexp, yojson] - -(** Convenience method to produce {!t} from {!role} and a snowflake. *) +(** A role as Discord sends it. Only difference between this and {!t} is the lack of the guild_id field. *)
+type role = {
+ id: Role_id.t;
+ name: string;
+ colour: int;
+ hoist: bool;
+ position: int;
+ permissions: int;
+ managed: bool;
+ mentionable: bool;
+} [@@deriving sexp, yojson]
+
+(** A role object. *)
+type t = {
+ id: Role_id.t; (** The role's snowflake ID. *)
+ name: string; (** The role's name. *)
+ colour: int; (** The integer representation of the role colour. *)
+ hoist: bool; (** Whether the role is hoisted. This property controls whether the role is separated on the sidebar. *)
+ position: int; (** The position of the role. [@everyone] begins the list at 0. *)
+ permissions: int; (** The integer representation of the permissions the role has. *)
+ managed: bool; (** Whether the guild is managed by an integration. *)
+ mentionable: bool; (** Whether the role can be mentioned. *)
+ guild_id: Guild_id_t.t; (** The guild ID this role belongs to. *)
+} [@@deriving sexp, yojson]
+
+(** Convenience method to produce {!t} from {!role} and a snowflake. *)
val wrap : guild_id:Snowflake.t -> role -> t
\ No newline at end of file diff --git a/lib/models/id/channel_id.ml b/lib/models/id/channel_id.ml index 67f81a5..be4bfab 100644 --- a/lib/models/id/channel_id.ml +++ b/lib/models/id/channel_id.ml @@ -1,2 +1,2 @@ -include Channel_id_t +include Channel_id_t
include Impl.Channel(Channel_id_t)
\ No newline at end of file diff --git a/lib/models/id/channel_id.mli b/lib/models/id/channel_id.mli index f352160..59b4d23 100644 --- a/lib/models/id/channel_id.mli +++ b/lib/models/id/channel_id.mli @@ -1,3 +1,3 @@ -include module type of Channel_id_t -include S.ChannelImpl with +include module type of Channel_id_t
+include S.ChannelImpl with
type t := Channel_id_t.t
\ No newline at end of file diff --git a/lib/models/id/channel_id_t.ml b/lib/models/id/channel_id_t.ml index 26bd984..e49beef 100644 --- a/lib/models/id/channel_id_t.ml +++ b/lib/models/id/channel_id_t.ml @@ -1,11 +1,11 @@ -type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp] - -let of_yojson a : (t, string) result = - match Snowflake.of_yojson a with - | Ok id -> Ok (`Channel_id id) - | Error err -> Error err - -let of_yojson_exn a : t = `Channel_id (Snowflake.of_yojson_exn a) -let to_yojson (`Channel_id id) = (Snowflake.to_yojson id) - +type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp]
+
+let of_yojson a : (t, string) result =
+ match Snowflake.of_yojson a with
+ | Ok id -> Ok (`Channel_id id)
+ | Error err -> Error err
+
+let of_yojson_exn a : t = `Channel_id (Snowflake.of_yojson_exn a)
+let to_yojson (`Channel_id id) = (Snowflake.to_yojson id)
+
let get_id (`Channel_id id) = id
\ No newline at end of file diff --git a/lib/models/id/channel_id_t.mli b/lib/models/id/channel_id_t.mli index 821c8b0..2e7c76f 100644 --- a/lib/models/id/channel_id_t.mli +++ b/lib/models/id/channel_id_t.mli @@ -1,3 +1,3 @@ -type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson] - +type t = [ `Channel_id of Snowflake.t ] [@@deriving sexp, yojson]
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/id/guild_id.ml b/lib/models/id/guild_id.ml index 051006b..79b4323 100644 --- a/lib/models/id/guild_id.ml +++ b/lib/models/id/guild_id.ml @@ -1,2 +1,2 @@ -include Guild_id_t +include Guild_id_t
include Impl.Guild(Guild_id_t)
\ No newline at end of file diff --git a/lib/models/id/guild_id.mli b/lib/models/id/guild_id.mli index 670a903..88e9fa7 100644 --- a/lib/models/id/guild_id.mli +++ b/lib/models/id/guild_id.mli @@ -1,3 +1,3 @@ -include module type of Guild_id_t -include S.GuildImpl with +include module type of Guild_id_t
+include S.GuildImpl with
type t := Guild_id_t.t
\ No newline at end of file diff --git a/lib/models/id/guild_id_t.ml b/lib/models/id/guild_id_t.ml index d023058..cd8eb58 100644 --- a/lib/models/id/guild_id_t.ml +++ b/lib/models/id/guild_id_t.ml @@ -1,11 +1,11 @@ -type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp] - -let of_yojson a : (t, string) result = - match Snowflake.of_yojson a with - | Ok id -> Ok (`Guild_id id) - | Error err -> Error err - -let of_yojson_exn a : t = `Guild_id (Snowflake.of_yojson_exn a) -let to_yojson (`Guild_id id) = (Snowflake.to_yojson id) - +type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp]
+
+let of_yojson a : (t, string) result =
+ match Snowflake.of_yojson a with
+ | Ok id -> Ok (`Guild_id id)
+ | Error err -> Error err
+
+let of_yojson_exn a : t = `Guild_id (Snowflake.of_yojson_exn a)
+let to_yojson (`Guild_id id) = (Snowflake.to_yojson id)
+
let get_id (`Guild_id id) = id
\ No newline at end of file diff --git a/lib/models/id/guild_id_t.mli b/lib/models/id/guild_id_t.mli index dc72deb..9c92d6c 100644 --- a/lib/models/id/guild_id_t.mli +++ b/lib/models/id/guild_id_t.mli @@ -1,3 +1,3 @@ -type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson] - +type t = [ `Guild_id of Snowflake.t ] [@@deriving sexp, yojson]
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/id/message_id.ml b/lib/models/id/message_id.ml index 4a4fbb3..10bcb1d 100644 --- a/lib/models/id/message_id.ml +++ b/lib/models/id/message_id.ml @@ -1,11 +1,11 @@ -type t = [ `Message_id of Snowflake.t ] [@@deriving sexp] - -let of_yojson a : (t, string) result = - match Snowflake.of_yojson a with - | Ok id -> Ok (`Message_id id) - | Error err -> Error err - -let of_yojson_exn a : t = `Message_id (Snowflake.of_yojson_exn a) -let to_yojson (`Message_id id) = (Snowflake.to_yojson id) - +type t = [ `Message_id of Snowflake.t ] [@@deriving sexp]
+
+let of_yojson a : (t, string) result =
+ match Snowflake.of_yojson a with
+ | Ok id -> Ok (`Message_id id)
+ | Error err -> Error err
+
+let of_yojson_exn a : t = `Message_id (Snowflake.of_yojson_exn a)
+let to_yojson (`Message_id id) = (Snowflake.to_yojson id)
+
let get_id (`Message_id id) = id
\ No newline at end of file diff --git a/lib/models/id/message_id.mli b/lib/models/id/message_id.mli index da50f72..90107b5 100644 --- a/lib/models/id/message_id.mli +++ b/lib/models/id/message_id.mli @@ -1,3 +1,3 @@ -type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson] - +type t = [ `Message_id of Snowflake.t ] [@@deriving sexp, yojson]
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/id/role_id.ml b/lib/models/id/role_id.ml index b3fa5a1..f055b1a 100644 --- a/lib/models/id/role_id.ml +++ b/lib/models/id/role_id.ml @@ -1,11 +1,11 @@ -type t = [ `Role_id of Snowflake.t ] [@@deriving sexp] - -let of_yojson a : (t, string) result = - match Snowflake.of_yojson a with - | Ok id -> Ok (`Role_id id) - | Error err -> Error err - -let of_yojson_exn a : t = `Role_id (Snowflake.of_yojson_exn a) -let to_yojson (`Role_id id) = (Snowflake.to_yojson id) - +type t = [ `Role_id of Snowflake.t ] [@@deriving sexp]
+
+let of_yojson a : (t, string) result =
+ match Snowflake.of_yojson a with
+ | Ok id -> Ok (`Role_id id)
+ | Error err -> Error err
+
+let of_yojson_exn a : t = `Role_id (Snowflake.of_yojson_exn a)
+let to_yojson (`Role_id id) = (Snowflake.to_yojson id)
+
let get_id (`Role_id id) = id
\ No newline at end of file diff --git a/lib/models/id/role_id.mli b/lib/models/id/role_id.mli index ededf3a..701e4a9 100644 --- a/lib/models/id/role_id.mli +++ b/lib/models/id/role_id.mli @@ -1,3 +1,3 @@ -type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson] - +type t = [ `Role_id of Snowflake.t ] [@@deriving sexp, yojson]
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/id/user_id.ml b/lib/models/id/user_id.ml index 77ce220..cc71764 100644 --- a/lib/models/id/user_id.ml +++ b/lib/models/id/user_id.ml @@ -1,2 +1,2 @@ -include User_id_t +include User_id_t
include Impl.User(User_id_t)
\ No newline at end of file diff --git a/lib/models/id/user_id.mli b/lib/models/id/user_id.mli index d7da91e..574c4f0 100644 --- a/lib/models/id/user_id.mli +++ b/lib/models/id/user_id.mli @@ -1,3 +1,3 @@ -include module type of User_id_t -include S.UserImpl with +include module type of User_id_t
+include S.UserImpl with
type t := User_id_t.t
\ No newline at end of file diff --git a/lib/models/id/user_id_t.ml b/lib/models/id/user_id_t.ml index 5ed9f14..f168daa 100644 --- a/lib/models/id/user_id_t.ml +++ b/lib/models/id/user_id_t.ml @@ -1,11 +1,11 @@ -type t = [ `User_id of Snowflake.t ] [@@deriving sexp] - -let of_yojson a : (t, string) result = - match Snowflake.of_yojson a with - | Ok id -> Ok (`User_id id) - | Error err -> Error err - -let of_yojson_exn a : t = `User_id (Snowflake.of_yojson_exn a) -let to_yojson (`User_id id) = (Snowflake.to_yojson id) - +type t = [ `User_id of Snowflake.t ] [@@deriving sexp]
+
+let of_yojson a : (t, string) result =
+ match Snowflake.of_yojson a with
+ | Ok id -> Ok (`User_id id)
+ | Error err -> Error err
+
+let of_yojson_exn a : t = `User_id (Snowflake.of_yojson_exn a)
+let to_yojson (`User_id id) = (Snowflake.to_yojson id)
+
let get_id (`User_id id) = id
\ No newline at end of file diff --git a/lib/models/id/user_id_t.mli b/lib/models/id/user_id_t.mli index 90211ab..0893a34 100644 --- a/lib/models/id/user_id_t.mli +++ b/lib/models/id/user_id_t.mli @@ -1,3 +1,3 @@ -type t = [ `User_id of Snowflake.t ] [@@deriving sexp, yojson] - +type t = [ `User_id of Snowflake.t ] [@@deriving sexp, yojson]
+
val get_id : t -> Snowflake.t
\ No newline at end of file diff --git a/lib/models/snowflake.ml b/lib/models/snowflake.ml index 3b55493..44b0a48 100644 --- a/lib/models/snowflake.ml +++ b/lib/models/snowflake.ml @@ -1,22 +1,22 @@ -open Core - -type t = Int.t [@@deriving sexp] - -let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string - -let of_yojson d = - try of_yojson_exn d |> Ok - with Yojson.Safe.Util.Type_error (why,_) -> Error why - -let to_yojson s : Yojson.Safe.json = `String (Int.to_string s) - -let timestamp snowflake = (snowflake lsr 22) + 1_420_070_400_000 - -let time_of_t snowflake = - let t = timestamp snowflake |> float_of_int in - Time.(Span.of_ms t - |> of_span_since_epoch) - -let timestamp_iso snowflake = - time_of_t snowflake +open Core
+
+type t = Int.t [@@deriving sexp]
+
+let of_yojson_exn d = Yojson.Safe.Util.to_string d |> Int.of_string
+
+let of_yojson d =
+ try of_yojson_exn d |> Ok
+ with Yojson.Safe.Util.Type_error (why,_) -> Error why
+
+let to_yojson s : Yojson.Safe.json = `String (Int.to_string s)
+
+let timestamp snowflake = (snowflake lsr 22) + 1_420_070_400_000
+
+let time_of_t snowflake =
+ let t = timestamp snowflake |> float_of_int in
+ Time.(Span.of_ms t
+ |> of_span_since_epoch)
+
+let timestamp_iso snowflake =
+ time_of_t snowflake
|> Time.(to_string_iso8601_basic ~zone:Zone.utc)
\ No newline at end of file diff --git a/lib/models/snowflake.mli b/lib/models/snowflake.mli index e7f6be3..475b94c 100644 --- a/lib/models/snowflake.mli +++ b/lib/models/snowflake.mli @@ -1,12 +1,12 @@ -open Core - -type t = Int.t [@@deriving sexp, yojson] - -(** Convert a snowflake into a {!Core.Time.t} *) -val time_of_t : t -> Time.t - -(** Convert a snowflake into a Unix timestamp. Millisecond precision. *) -val timestamp : t -> int - -(** Convert a snowflake into an ISO8601 timestamp string. This is equivalent to calling [Snowflake.time_of_t snowflake |> Time.(to_string_iso8601_basic ~zone:Zone.utc)] *) +open Core
+
+type t = Int.t [@@deriving sexp, yojson]
+
+(** Convert a snowflake into a {!Core.Time.t} *)
+val time_of_t : t -> Time.t
+
+(** Convert a snowflake into a Unix timestamp. Millisecond precision. *)
+val timestamp : t -> int
+
+(** Convert a snowflake into an ISO8601 timestamp string. This is equivalent to calling [Snowflake.time_of_t snowflake |> Time.(to_string_iso8601_basic ~zone:Zone.utc)] *)
val timestamp_iso : t -> string
\ No newline at end of file diff --git a/lib/models/user/activity.mli b/lib/models/user/activity.mli index 970ac59..1ddd4e7 100644 --- a/lib/models/user/activity.mli +++ b/lib/models/user/activity.mli @@ -1,6 +1,6 @@ -(** An activity object. *) -type t = { - name: string; (** The name of the activity. *) - kind: int; (** 0 = Playing, 1 = Streaming, 2 = Listening, 3 = Watching *) - url: string option; (** Stream URL. Only validated for kind = 1. *) +(** An activity object. *)
+type t = {
+ name: string; (** The name of the activity. *)
+ kind: int; (** 0 = Playing, 1 = Streaming, 2 = Listening, 3 = Watching *)
+ url: string option; (** Stream URL. Only validated for kind = 1. *)
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/user/presence.mli b/lib/models/user/presence.mli index 6c60d7f..d75d408 100644 --- a/lib/models/user/presence.mli +++ b/lib/models/user/presence.mli @@ -1,9 +1,9 @@ -(** A user presence. *) -type t = { - user: User_t.partial_user; (** A partial user that this presence belongs to. *) - roles: Role_id.t list; (** A list of roles that the user has. *) - game: Activity.t option; (** The current activity of the user, if any. *) - guild_id: Guild_id_t.t; (** The guild ID in which this presence exists. *) - status: string; (** One of [online], [idle], [offline], or [dnd]. *) - activities: Activity.t list; (** A list of all of the user's current activities. *) +(** A user presence. *)
+type t = {
+ user: User_t.partial_user; (** A partial user that this presence belongs to. *)
+ roles: Role_id.t list; (** A list of roles that the user has. *)
+ game: Activity.t option; (** The current activity of the user, if any. *)
+ guild_id: Guild_id_t.t; (** The guild ID in which this presence exists. *)
+ status: string; (** One of [online], [idle], [offline], or [dnd]. *)
+ activities: Activity.t list; (** A list of all of the user's current activities. *)
} [@@deriving sexp, yojson]
\ No newline at end of file diff --git a/lib/models/user/user.ml b/lib/models/user/user.ml index de7ce01..b8c3b25 100644 --- a/lib/models/user/user.ml +++ b/lib/models/user/user.ml @@ -1,23 +1,23 @@ -open Core -include User_t - -let tag user = - Printf.sprintf "%s#%s" user.username user.discriminator - -let mention user = - let `User_id id = user.id in - Printf.sprintf "<@%d>" id - -let default_avatar user = - let avatar = Int.of_string user.discriminator % 5 in - Endpoints.cdn_default_avatar avatar - -let face user = - let `User_id id = user.id in - match user.avatar with - | Some avatar -> - let ext = if String.is_substring ~substring:"a_" avatar - then "gif" - else "png" in - Endpoints.cdn_avatar id avatar ext +open Core
+include User_t
+
+let tag user =
+ Printf.sprintf "%s#%s" user.username user.discriminator
+
+let mention user =
+ let `User_id id = user.id in
+ Printf.sprintf "<@%d>" id
+
+let default_avatar user =
+ let avatar = Int.of_string user.discriminator % 5 in
+ Endpoints.cdn_default_avatar avatar
+
+let face user =
+ let `User_id id = user.id in
+ match user.avatar with
+ | Some avatar ->
+ let ext = if String.is_substring ~substring:"a_" avatar
+ then "gif"
+ else "png" in
+ Endpoints.cdn_avatar id avatar ext
| None -> default_avatar user
\ No newline at end of file diff --git a/lib/models/user/user_t.ml b/lib/models/user/user_t.ml index 89a6895..8958e84 100644 --- a/lib/models/user/user_t.ml +++ b/lib/models/user/user_t.ml @@ -1,13 +1,13 @@ -open Core - -type partial_user = { - id: User_id_t.t; -} [@@deriving sexp, yojson { strict = false}] - -type t = { - id: User_id_t.t; - username: string; - discriminator: string; - avatar: string option [@default None]; - bot: bool [@default false]; +open Core
+
+type partial_user = {
+ id: User_id_t.t;
+} [@@deriving sexp, yojson { strict = false}]
+
+type t = {
+ id: User_id_t.t;
+ username: string;
+ discriminator: string;
+ avatar: string option [@default None];
+ bot: bool [@default false];
} [@@deriving sexp, yojson { strict = false }]
\ No newline at end of file diff --git a/lib/models/user/user_t.mli b/lib/models/user/user_t.mli index 694fc1e..645df3e 100644 --- a/lib/models/user/user_t.mli +++ b/lib/models/user/user_t.mli @@ -1,13 +1,13 @@ -(** A partial user. Used internally. *) -type partial_user = { - id: User_id_t.t; -} [@@deriving sexp, yojson] - -(** A user object. *) -type t = { - id: User_id_t.t; (** The user's Snowflake ID, wrapped in the convenience [`User_id] type. *) - username: string; (** The username of the user. *) - discriminator: string; (** The 4 digits, as a string, that come after the '#' in a Discord username. *) - avatar: string option; (** The hash of the user avatar, if they have one set. See {!User.face} to get the avatar URL. *) - bot: bool; (** Whether the user is a bot. *) +(** A partial user. Used internally. *)
+type partial_user = {
+ id: User_id_t.t;
+} [@@deriving sexp, yojson]
+
+(** A user object. *)
+type t = {
+ id: User_id_t.t; (** The user's Snowflake ID, wrapped in the convenience [`User_id] type. *)
+ username: string; (** The username of the user. *)
+ discriminator: string; (** The 4 digits, as a string, that come after the '#' in a Discord username. *)
+ avatar: string option; (** The hash of the user avatar, if they have one set. See {!User.face} to get the avatar URL. *)
+ bot: bool; (** Whether the user is a bot. *)
} [@@deriving sexp, yojson]
\ No newline at end of file |