-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscordMessage.cs
73 lines (61 loc) · 1.86 KB
/
DiscordMessage.cs
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
71
72
73
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace CSCordEmbedsHelper
{
[Serializable]
public class DiscordMessage
{
[JsonProperty("username")]
public string Username { get; set; }
[JsonProperty("avatar_url")]
public string AvatarUrl { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
[JsonProperty("tts")]
public bool TTS { get; set; }
[JsonProperty("embeds")]
public List<Embed> Embeds { get; set; } = new List<Embed>();
public DiscordMessage SetUsername(string username)
{
Username = username;
return this;
}
public DiscordMessage SetAvatar(string avatar)
{
AvatarUrl = avatar;
return this;
}
public DiscordMessage SetContent(string content)
{
Content = content;
return this;
}
public DiscordMessage SetTTS(bool tts)
{
TTS = tts;
return this;
}
public Embed AddEmbed()
{
var embed = new Embed(this);
Embeds.Add(embed);
return embed;
}
public void SendMessage(string url)
{
var webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
webClient.UploadString(url, JsonConvert.SerializeObject(this));
}
public Task SendMessageAsync(string url)
{
var webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");
webClient.UploadStringAsync(new Uri(url), JsonConvert.SerializeObject(this));
return Task.CompletedTask;
}
}
}