aboutsummaryrefslogtreecommitdiff
path: root/lib/models/channel/message/message.ml
blob: 39ee0f3d846987dd51bc08ad882681946863b3d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
open Core
open Async
include Message_t

let add_reaction msg (emoji:Emoji.t) =
    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
   

let remove_reaction msg (emoji:Emoji.t) (user:User_t.t) =
    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
   

let clear_reactions msg =
    Http.delete_reactions msg.channel_id msg.id
   

let delete msg =
    Http.delete_message msg.channel_id msg.id
   

let pin msg =
    Http.pin_message msg.channel_id msg.id
   

let unpin msg =
    Http.unpin_message msg.channel_id msg.id
   

let reply msg cont =
    let rep = `Assoc [("content", `String cont)] in
    Http.create_message msg.channel_id rep
   

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 set_content msg cont =
    to_yojson { msg with content = cont; }
    |> Http.edit_message msg.channel_id msg.id
   

let set_embed msg embed =
    to_yojson { msg with embeds = [embed]; }
    |> Http.edit_message msg.channel_id msg.id