aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breedlove <[email protected]>2019-01-20 23:19:35 -0700
committerAdelyn Breedlove <[email protected]>2019-01-20 23:19:35 -0700
commit9be6b59da80a04d5ea82da5b7d69b15ac1872673 (patch)
tree7855f10f6e4d5f968104cccb30b9f191568538bb
parentimprove embed example (diff)
downloaddisml-9be6b59da80a04d5ea82da5b7d69b15ac1872673.tar.xz
disml-9be6b59da80a04d5ea82da5b7d69b15ac1872673.zip
Improve embed builders
-rw-r--r--bin/bot.ml20
-rw-r--r--lib/models/embed.ml21
2 files changed, 24 insertions, 17 deletions
diff --git a/bin/bot.ml b/bin/bot.ml
index bc7a1b7..37c7dc8 100644
--- a/bin/bot.ml
+++ b/bin/bot.ml
@@ -37,16 +37,16 @@ let check_command (msg:Message.t) =
|> url "https://gitlab.com/Mishio595/disml"
|> timestamp Time.(now () |> to_string_iso8601_basic ~zone:Time.Zone.utc)
|> colour 0xff
- |> footer { Embed.default_footer with text = "boop" }
- |> image { Embed.default_image with url = Some image_url }
- |> thumbnail { Embed.default_image with url = Some image_url }
- |> author { Embed.default_author with
- name = Some "Adelyn";
- url = Some "https://gitlab.com/Mishio595/disml";
- icon_url = Some image_url }
- |> field { name = "field 1"; value = "test"; inline = true; }
- |> field { name = "field 2"; value = "test"; inline = true; }
- |> field { name = "field 3"; value = "test"; inline = true; }
+ |> footer (fun f -> footer_text "boop" f)
+ |> image image_url
+ |> thumbnail image_url
+ |> author (fun a -> a
+ |> author_name "Adelyn"
+ |> author_icon image_url
+ |> author_url "https://gitlab.com/Mishio595/disml")
+ |> field ("field 1", "test", true)
+ |> field ("field 2", "test", true)
+ |> field ("field 3", "test", true)
) in
Message.reply_with ~embed msg >>> ignore
| _ -> ()
diff --git a/lib/models/embed.ml b/lib/models/embed.ml
index 86f8ece..9f9aacd 100644
--- a/lib/models/embed.ml
+++ b/lib/models/embed.ml
@@ -34,7 +34,7 @@ type author = {
type field = {
name: string;
value: string;
- inline: bool [@default true];
+ inline: bool [@default false];
} [@@deriving sexp, yojson]
type t = {
@@ -106,9 +106,16 @@ 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 v e = { e with footer = Some v }
-let image v e = { e with image = Some v }
-let thumbnail v e = { e with thumbnail = Some v }
-let author v e = { e with author = Some v }
-let field v e = { e with fields = v::e.fields }
-let fields v e = { e with fields = v } \ No newline at end of file
+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