diff options
| author | Matias Goldfeld <[email protected]> | 2021-02-07 20:21:47 -0500 |
|---|---|---|
| committer | Matias Goldfeld <[email protected]> | 2021-02-07 20:21:47 -0500 |
| commit | b2f081fff12093a7d3434859ebd621608dde6c7d (patch) | |
| tree | 5ea4f7d6ff82727d62b01fb2d234a4f8ab66aa2b /lib/models/channel | |
| parent | Removed generated version numbers (diff) | |
| download | disml-master.tar.xz disml-master.zip | |
Reverted earlier changes for goodHEADorigin/masterorigin/HEADmaster
Diffstat (limited to 'lib/models/channel')
| -rw-r--r-- | lib/models/channel/channel.ml | 17 | ||||
| -rw-r--r-- | lib/models/channel/channel.mli | 2 | ||||
| -rw-r--r-- | lib/models/channel/channel_t.ml | 16 | ||||
| -rw-r--r-- | lib/models/channel/channel_t.mli | 14 | ||||
| -rw-r--r-- | lib/models/channel/message/attachment.ml | 2 | ||||
| -rw-r--r-- | lib/models/channel/message/attachment.mli | 2 | ||||
| -rw-r--r-- | lib/models/channel/message/embed.ml | 14 | ||||
| -rw-r--r-- | lib/models/channel/message/embed.mli | 14 | ||||
| -rw-r--r-- | lib/models/channel/message/message.ml | 10 | ||||
| -rw-r--r-- | lib/models/channel/message/message_t.ml | 2 | ||||
| -rw-r--r-- | lib/models/channel/message/message_t.mli | 2 | ||||
| -rw-r--r-- | lib/models/channel/message/reaction_t.ml | 4 | ||||
| -rw-r--r-- | lib/models/channel/message/reaction_t.mli | 4 |
13 files changed, 53 insertions, 50 deletions
diff --git a/lib/models/channel/channel.ml b/lib/models/channel/channel.ml index 52eda02..47cf500 100644 --- a/lib/models/channel/channel.ml +++ b/lib/models/channel/channel.ml @@ -6,7 +6,7 @@ exception No_message_found let send_message ?embed ?content ?file ?(tts=false) ch =
let embed = match embed with
- | Some e -> Embed.yojson_of_t e
+ | Some e -> Embed.to_yojson e
| None -> `Null in
let content = match content with
| Some c -> `String c
@@ -33,13 +33,16 @@ let delete ch = let get_message ~id ch =
Http.get_message (get_id ch) id
-let get_messages ?(mode=`Around) ~id ?(limit=50) ch =
+let get_messages ?(mode=`Around) ?id ?(limit=50) ch =
let kind = match mode with
- | `Around -> "around", id
- | `Before -> "before", id
- | `After -> "after", id
+ | `Around -> "around", limit
+ | `Before -> "before", limit
+ | `After -> "after", limit
in
- Http.get_messages (get_id ch) limit kind
+ let id = match id with
+ | Some id -> id
+ | None -> raise No_message_found in
+ Http.get_messages (get_id ch) id kind
let broadcast_typing ch =
Http.broadcast_typing (get_id ch)
@@ -48,5 +51,5 @@ let get_pins ch = Http.get_pinned_messages (get_id ch)
let bulk_delete msgs ch =
- let msgs = `List (List.map ~f:(fun id -> `Intlit (Int64.to_string id)) msgs) in
+ let msgs = `List (List.map ~f:(fun id -> `Int id) msgs) in
Http.bulk_delete (get_id ch) msgs
\ No newline at end of file diff --git a/lib/models/channel/channel.mli b/lib/models/channel/channel.mli index cb01533..0d7431b 100644 --- a/lib/models/channel/channel.mli +++ b/lib/models/channel/channel.mli @@ -36,7 +36,7 @@ val delete : t -> Channel_t.t Deferred.Or_error.t val get_message : id:Snowflake.t -> t -> Message_t.t Deferred.Or_error.t
val get_messages :
?mode:[ `Before | `After | `Around ] ->
- id:Snowflake.t ->
+ ?id:Snowflake.t ->
?limit:int ->
t ->
Message_t.t list Deferred.Or_error.t
diff --git a/lib/models/channel/channel_t.ml b/lib/models/channel/channel_t.ml index a103090..e332c36 100644 --- a/lib/models/channel/channel_t.ml +++ b/lib/models/channel/channel_t.ml @@ -10,13 +10,13 @@ type group = { name: string option [@default None];
owner_id: User_id_t.t;
recipients: User_t.t list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type guild_text = {
id: Channel_id_t.t;
@@ -30,7 +30,7 @@ type guild_text = { nsfw: bool;
slow_mode_timeout: int option [@default None];
permission_overwrites: Overwrites.t list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type guild_voice = {
id: Channel_id_t.t;
@@ -41,7 +41,7 @@ type guild_voice = { user_limit: int [@default -1];
bitrate: int option [@default None];
permission_overwrites: Overwrites.t list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type category = {
id: Channel_id_t.t;
@@ -49,7 +49,7 @@ type category = { position: int;
name: string;
permission_overwrites: Overwrites.t list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type t = [
| `Group of group
@@ -57,7 +57,7 @@ type t = [ | `GuildText of guild_text
| `GuildVoice of guild_voice
| `Category of category
-] [@@deriving sexp, yojson]
+] [@@deriving sexp, yojson { strict = false; exn = true }]
type channel_wrapper = {
id: Channel_id_t.t;
@@ -78,7 +78,7 @@ type channel_wrapper = { category_id: Channel_id_t.t option [@default None][@key "parent_id"];
last_pin_timestamp: string option [@default None];
permission_overwrites: Overwrites.t list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
let unwrap_as_guild_text {id;guild_id;position;name;topic;nsfw;last_message_id;slow_mode_timeout;category_id;last_pin_timestamp;permission_overwrites;_} =
let position = Option.value_exn position in
@@ -112,7 +112,7 @@ let wrap s = | 2 -> `GuildVoice (unwrap_as_guild_voice s)
| 3 -> `Group (unwrap_as_group s)
| 4 -> `Category (unwrap_as_category s)
- | _ -> raise (Invalid_channel (yojson_of_channel_wrapper s))
+ | _ -> raise (Invalid_channel (channel_wrapper_to_yojson s))
let get_id (c:t) = match c with
| `Group g -> let `Channel_id id = g.id in id
diff --git a/lib/models/channel/channel_t.mli b/lib/models/channel/channel_t.mli index f5d538b..c6c6a0b 100644 --- a/lib/models/channel/channel_t.mli +++ b/lib/models/channel/channel_t.mli @@ -9,14 +9,14 @@ type group = { name: string option;
owner_id: User_id_t.t;
recipients: User_t.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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]
+} [@@deriving sexp, yojson { exn = true }]
(** Represents a text channel in a guild. *)
type guild_text = {
@@ -31,7 +31,7 @@ type guild_text = { nsfw: bool;
slow_mode_timeout: int option;
permission_overwrites: Overwrites.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** Represents a voice channel in a guild. *)
type guild_voice = {
@@ -43,7 +43,7 @@ type guild_voice = { user_limit: int;
bitrate: int option;
permission_overwrites: Overwrites.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** Represents a guild category. *)
type category = {
@@ -52,7 +52,7 @@ type category = { position: int;
name: string;
permission_overwrites: Overwrites.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** Wrapper variant for all channel types. *)
type t = [
@@ -61,7 +61,7 @@ type t = [ | `GuildText of guild_text
| `GuildVoice of guild_voice
| `Category of category
-] [@@deriving sexp, yojson]
+] [@@deriving sexp, yojson { exn = true }]
(** Intermediate used internally. *)
type channel_wrapper = {
@@ -83,7 +83,7 @@ type channel_wrapper = { category_id: Channel_id_t.t option;
last_pin_timestamp: string option;
permission_overwrites: Overwrites.t list;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
val unwrap_as_guild_text : channel_wrapper -> guild_text
diff --git a/lib/models/channel/message/attachment.ml b/lib/models/channel/message/attachment.ml index cf52078..d720a81 100644 --- a/lib/models/channel/message/attachment.ml +++ b/lib/models/channel/message/attachment.ml @@ -8,4 +8,4 @@ type t = { proxy_url: string; height: int [@default -1]; width: int [@default -1]; -} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ No newline at end of file diff --git a/lib/models/channel/message/attachment.mli b/lib/models/channel/message/attachment.mli index f935471..56006dc 100644 --- a/lib/models/channel/message/attachment.mli +++ b/lib/models/channel/message/attachment.mli @@ -6,4 +6,4 @@ type t = { proxy_url: string;
height: int;
width: int;
-} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file diff --git a/lib/models/channel/message/embed.ml b/lib/models/channel/message/embed.ml index e7ebbcc..0dd7343 100644 --- a/lib/models/channel/message/embed.ml +++ b/lib/models/channel/message/embed.ml @@ -4,38 +4,38 @@ type footer = { text: string;
icon_url: string option [@default None];
proxy_icon_url: string option [@default None];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type video = {
url: string option [@default None];
height: int option [@default None];
width: int option [@default None];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type provider = {
name: string option [@default None];
url: string option [@default None];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
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]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type field = {
name: string;
value: string;
inline: bool [@default false];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
type t = {
title: string option [@default None];
@@ -51,7 +51,7 @@ type t = { provider: provider option [@default None];
author: author option [@default None];
fields: field list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
let default = {
title = None;
diff --git a/lib/models/channel/message/embed.mli b/lib/models/channel/message/embed.mli index 17fea52..fb86c94 100644 --- a/lib/models/channel/message/embed.mli +++ b/lib/models/channel/message/embed.mli @@ -3,7 +3,7 @@ type footer = { text: string;
icon_url: string option;
proxy_icon_url: string option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** An image object belonging to an embed. *)
type image = {
@@ -11,20 +11,20 @@ type image = { proxy_url: string option;
height: int option;
width: int option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** A video object belonging to an embed. *)
type video = {
url: string option;
height: int option;
width: int option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** A provider object belonging to an embed. *)
type provider = {
name: string option;
url: string option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** An author object belonging to an embed. *)
type author = {
@@ -32,14 +32,14 @@ type author = { url: string option;
icon_url: string option;
proxy_icon_url: string option;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** A field object belonging to an embed. *)
type field = {
name: string;
value: string;
inline: bool;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** An embed object. See this {{:https://leovoel.github.io/embed-visualizer/}embed visualiser} if you need help understanding each component. *)
type t = {
@@ -56,7 +56,7 @@ type t = { provider: provider option;
author: author option;
fields: field list [@default []];
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { strict = false; exn = true }]
(** An embed where all values are empty. *)
val default : t
diff --git a/lib/models/channel/message/message.ml b/lib/models/channel/message/message.ml index 2aaa0da..7f03638 100644 --- a/lib/models/channel/message/message.ml +++ b/lib/models/channel/message/message.ml @@ -6,7 +6,7 @@ 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:%Ld" emoji.name i
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.create_reaction channel_id id e
@@ -15,9 +15,9 @@ let add_reaction msg (emoji:Emoji.t) = 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.get_id user.id in
+ let `User_id user_id = user.id in
let e = match emoji.id with
- | Some i -> Printf.sprintf "%s:%Ld" emoji.name i
+ | Some i -> Printf.sprintf "%s:%d" emoji.name i
| None -> emoji.name
in
Http.delete_reaction channel_id id e user_id
@@ -57,13 +57,13 @@ let reply_with ?embed ?content ?files ?tts ?(reply_mention=false) msg = let set_content msg cont =
let `Message_id id = msg.id in
let `Channel_id channel_id = msg.channel_id in
- yojson_of_t { msg with content = cont; }
+ 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
- yojson_of_t { msg with embeds = [embed]; }
+ to_yojson { msg with embeds = [embed]; }
|> Http.edit_message channel_id id
diff --git a/lib/models/channel/message/message_t.ml b/lib/models/channel/message/message_t.ml index 0f8e08e..31fc88c 100644 --- a/lib/models/channel/message/message_t.ml +++ b/lib/models/channel/message/message_t.ml @@ -20,4 +20,4 @@ type t = { pinned: bool;
webhook_id: Snowflake.t option [@default None];
kind: int [@key "type"];
-} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ 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 ba8c62a..907565c 100644 --- a/lib/models/channel/message/message_t.mli +++ b/lib/models/channel/message/message_t.mli @@ -19,4 +19,4 @@ type t = { 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 +} [@@deriving sexp, yojson { exn = true }]
\ 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 b072b01..e8ec5a0 100644 --- a/lib/models/channel/message/reaction_t.ml +++ b/lib/models/channel/message/reaction_t.ml @@ -6,9 +6,9 @@ type reaction_event = { message_id: Message_id.t;
guild_id: Guild_id_t.t option [@default None];
emoji: Emoji.partial_emoji;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
type t = {
count: int;
emoji: Emoji.t;
-} [@@deriving sexp, yojson]
\ No newline at end of file +} [@@deriving sexp, yojson { strict = false; exn = true }]
\ 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 ace8f55..f9b2a98 100644 --- a/lib/models/channel/message/reaction_t.mli +++ b/lib/models/channel/message/reaction_t.mli @@ -5,10 +5,10 @@ type reaction_event = { message_id: Message_id.t;
guild_id: Guild_id_t.t option;
emoji: Emoji.partial_emoji;
-} [@@deriving sexp, yojson]
+} [@@deriving sexp, yojson { exn = true }]
(** 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 +} [@@deriving sexp, yojson { exn = true }]
\ No newline at end of file |