aboutsummaryrefslogtreecommitdiff
path: root/lib/models/channel
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-27 14:09:33 -0700
committerAdelyn Breedlove <[email protected]>2019-01-27 14:09:33 -0700
commitfbd3597c7ab798cf10a447eb2b477dd4e3ed6d33 (patch)
tree16d1ef889e9c6f1090dd911e6fb31392625066c2 /lib/models/channel
parenthopeful reconnection fix (diff)
downloaddisml-fbd3597c7ab798cf10a447eb2b477dd4e3ed6d33.tar.xz
disml-fbd3597c7ab798cf10a447eb2b477dd4e3ed6d33.zip
Switch to ID abstractions internally
Diffstat (limited to 'lib/models/channel')
-rw-r--r--lib/models/channel/channel_t.ml48
-rw-r--r--lib/models/channel/channel_t.mli38
-rw-r--r--lib/models/channel/message/message.ml61
-rw-r--r--lib/models/channel/message/message_t.ml10
-rw-r--r--lib/models/channel/message/message_t.mli10
-rw-r--r--lib/models/channel/message/reaction_t.ml8
-rw-r--r--lib/models/channel/message/reaction_t.mli8
7 files changed, 90 insertions, 93 deletions
diff --git a/lib/models/channel/channel_t.ml b/lib/models/channel/channel_t.ml
index dce1d54..62d6ac0 100644
--- a/lib/models/channel/channel_t.ml
+++ b/lib/models/channel/channel_t.ml
@@ -3,27 +3,27 @@ open Core
exception Invalid_channel of Yojson.Safe.json
type group = {
- id: Snowflake.t;
- last_message_id: Snowflake.t option [@default None];
+ 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: Snowflake.t;
+ owner_id: User_id_t.t;
recipients: User_t.t list [@default []];
} [@@deriving sexp, yojson { strict = false}]
type dm = {
- id: Snowflake.t;
- last_message_id: Snowflake.t option [@default None];
+ 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: Snowflake.t;
- last_message_id: Snowflake.t option [@default None];
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option [@default None];
last_pin_timestamp: string option [@default None];
- category_id: Snowflake.t option [@default None][@key "parent_id"];
- guild_id: Snowflake.t 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];
@@ -32,9 +32,9 @@ type guild_text = {
} [@@deriving sexp, yojson { strict = false}]
type guild_voice = {
- id: Snowflake.t;
- category_id: Snowflake.t option [@default None][@key "parent_id"];
- guild_id: Snowflake.t option [@default None];
+ 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];
@@ -42,8 +42,8 @@ type guild_voice = {
} [@@deriving sexp, yojson { strict = false}]
type category = {
- id: Snowflake.t;
- guild_id: Snowflake.t option [@default None];
+ id: Channel_id_t.t;
+ guild_id: Guild_id_t.t option [@default None];
position: int;
name: string;
} [@@deriving sexp, yojson { strict = false}]
@@ -57,22 +57,22 @@ type t =
[@@deriving sexp, yojson { strict = false}]
type channel_wrapper = {
- id: Snowflake.t;
+ id: Channel_id_t.t;
kind: int [@key "type"];
- guild_id: Snowflake.t option [@default None];
+ 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: Snowflake.t 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: Snowflake.t option [@default None];
+ owner_id: User_id_t.t option [@default None];
application_id: Snowflake.t option [@default None];
- category_id: Snowflake.t option [@default None][@key "parent_id"];
+ category_id: Channel_id_t.t option [@default None][@key "parent_id"];
last_pin_timestamp: string option [@default None];
} [@@deriving sexp, yojson { strict = false}]
@@ -111,8 +111,8 @@ let wrap s =
| _ -> raise (Invalid_channel (channel_wrapper_to_yojson s))
let get_id = function
-| Group g -> g.id
-| Private p -> p.id
-| GuildText t -> t.id
-| GuildVoice v -> v.id
-| Category c -> c.id \ No newline at end of file
+| 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 f3974d4..9deea82 100644
--- a/lib/models/channel/channel_t.mli
+++ b/lib/models/channel/channel_t.mli
@@ -2,29 +2,29 @@ exception Invalid_channel of Yojson.Safe.json
(** Represents a Group channel object. *)
type group = {
- id: Snowflake.t;
- last_message_id: Snowflake.t option;
+ 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: Snowflake.t;
+ 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: Snowflake.t;
- last_message_id: Snowflake.t option;
+ 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: Snowflake.t;
- last_message_id: Snowflake.t option;
+ id: Channel_id_t.t;
+ last_message_id: Message_id.t option;
last_pin_timestamp: string option;
- category_id: Snowflake.t option;
- guild_id: Snowflake.t option;
+ category_id: Channel_id_t.t option;
+ guild_id: Guild_id_t.t option;
name: string;
position: int;
topic: string option;
@@ -34,9 +34,9 @@ type guild_text = {
(** Represents a voice channel in a guild. *)
type guild_voice = {
- id: Snowflake.t;
- category_id: Snowflake.t option;
- guild_id: Snowflake.t option;
+ 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;
@@ -45,8 +45,8 @@ type guild_voice = {
(** Represents a guild category. *)
type category = {
- id: Snowflake.t;
- guild_id: Snowflake.t option;
+ id: Channel_id_t.t;
+ guild_id: Guild_id_t.t option;
position: int;
name: string;
} [@@deriving sexp, yojson]
@@ -62,22 +62,22 @@ type t =
(** Intermediate used internally. *)
type channel_wrapper = {
- id: Snowflake.t;
+ id: Channel_id_t.t;
kind: int;
- guild_id: Snowflake.t option;
+ guild_id: Guild_id_t.t option;
position: int option;
name: string option;
topic: string option;
nsfw: bool option;
- last_message_id: Snowflake.t 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: Snowflake.t option;
+ owner_id: User_id_t.t option;
application_id: Snowflake.t option;
- category_id: Snowflake.t option;
+ category_id: Channel_id_t.t option;
last_pin_timestamp: string option;
} [@@deriving sexp, yojson]
diff --git a/lib/models/channel/message/message.ml b/lib/models/channel/message/message.ml
index 39ee0f3..a64c09d 100644
--- a/lib/models/channel/message/message.ml
+++ b/lib/models/channel/message/message.ml
@@ -1,70 +1,67 @@
-open Core
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 msg.channel_id msg.id e
+ 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 msg.channel_id msg.id e user.id
+ Http.delete_reaction channel_id id e user_id
let clear_reactions msg =
- Http.delete_reactions msg.channel_id msg.id
+ 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 =
- Http.delete_message msg.channel_id msg.id
+ 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 =
- Http.pin_message msg.channel_id msg.id
+ 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 =
- Http.unpin_message msg.channel_id msg.id
+ 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 cont =
- let rep = `Assoc [("content", `String cont)] in
- Http.create_message msg.channel_id rep
-
+let reply msg content =
+ Channel_id.say content msg.channel_id
-let reply_with ?embed ?content ?file ?(tts=false) msg =
- let embed = match embed with
- | Some e -> Embed.to_yojson e
- | None -> `Null in
- let content = match content with
- | Some c -> `String c
- | None -> `Null in
- let file = match file with
- | Some f -> `String f
- | None -> `Null in
- let () = match embed, content with
- | `Null, `Null -> raise Channel.Invalid_message
- | _ -> () in
- Http.create_message (msg.channel_id) (`Assoc [
- ("embed", embed);
- ("content", content);
- ("file", file);
- ("tts", `Bool tts);
- ])
+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 msg.channel_id msg.id
+ |> 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 msg.channel_id msg.id
+ |> Http.edit_message channel_id id
\ 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 47b5803..20dc03f 100644
--- a/lib/models/channel/message/message_t.ml
+++ b/lib/models/channel/message/message_t.ml
@@ -1,18 +1,18 @@
open Core
type t = {
- id: Snowflake.t;
+ id: Message_id.t;
author: User_t.t;
- channel_id: Snowflake.t;
+ channel_id: Channel_id_t.t;
member: Member_t.partial_member option [@default None];
- guild_id: Snowflake.t option [@default None];
+ guild_id: Guild_id_t.t option [@default None];
content: string;
timestamp: string;
editedimestamp: string option [@default None];
tts: bool;
mention_everyone: bool;
- (* mentions: Snowflake.t list [@default []]; *)
- (* role_mentions: Snowflake.t list [@default []]; *)
+ mentions: User_id_t.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 []];
diff --git a/lib/models/channel/message/message_t.mli b/lib/models/channel/message/message_t.mli
index 14086fe..d829dc5 100644
--- a/lib/models/channel/message/message_t.mli
+++ b/lib/models/channel/message/message_t.mli
@@ -1,17 +1,17 @@
(** Represents a message object. *)
type t = {
- id: Snowflake.t;
+ id: Message_id.t;
author: User_t.t;
- channel_id: Snowflake.t;
+ channel_id: Channel_id_t.t;
member: Member_t.partial_member option;
- guild_id: Snowflake.t option;
+ guild_id: Guild_id_t.t option;
content: string;
timestamp: string;
editedimestamp: string option;
tts: bool;
mention_everyone: bool;
- (* mentions: Snowflake.t list; *)
- (* role_mentions: Snowflake.t list; *)
+ mentions: User_id_t.t list;
+ role_mentions: Role_id.t list;
attachments: Attachment.t list;
embeds: Embed.t list;
reactions: Snowflake.t list;
diff --git a/lib/models/channel/message/reaction_t.ml b/lib/models/channel/message/reaction_t.ml
index c382b68..1aa3c84 100644
--- a/lib/models/channel/message/reaction_t.ml
+++ b/lib/models/channel/message/reaction_t.ml
@@ -1,10 +1,10 @@
open Core
type reaction_event = {
- user_id: Snowflake.t;
- channel_id: Snowflake.t;
- message_id: Snowflake.t;
- guild_id: Snowflake.t option [@default None];
+ 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]
diff --git a/lib/models/channel/message/reaction_t.mli b/lib/models/channel/message/reaction_t.mli
index db95521..6c2782a 100644
--- a/lib/models/channel/message/reaction_t.mli
+++ b/lib/models/channel/message/reaction_t.mli
@@ -1,9 +1,9 @@
(** Represents a single reaction as received over the gateway. *)
type reaction_event = {
- user_id: Snowflake.t;
- channel_id: Snowflake.t;
- message_id: Snowflake.t;
- guild_id: Snowflake.t option;
+ 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]