-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quoting.cs
65 lines (52 loc) · 2.21 KB
/
Quoting.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
using Discord;
using Discord.Webhook;
using Discord.WebSocket;
using QuoteBot.Data;
namespace QuoteBot;
public class Quoting {
public static async Task QuoteMessage(DiscordSocketClient client,
ulong guild,
string quoteeName,
string quoterName,
ulong quoterId,
string quoteeData,
string msg,
IUser? quotee = null,
ulong? quotedMsgChannel = null,
ulong? quotedMsgId = null) {
ITextChannel? quotesChannel = await client.GetQuotesChannel(guild);
if (quotesChannel == null) {
throw new Exception("Quotes channel isn't defined");
}
string form = Program.Storage.GetQuoteForm(guild)!; // Should be defined if channel is
IMessage createdMsg;
switch (form) {
case "embed": {
EmbedBuilder embedBuilder = new();
embedBuilder.WithTitle(quoteeName);
embedBuilder.WithDescription($"\"{msg}\"");
embedBuilder.WithFooter("Quoted by " + quoterName);
embedBuilder.WithColor(Color.Green);
createdMsg = await quotesChannel.SendMessageAsync(embed: embedBuilder.Build());
break;
}
case "fake-msg": {
IWebhook? webhook = (await quotesChannel.GetWebhooksAsync()).FirstOrDefault() ?? await quotesChannel.CreateWebhookAsync("Quotes");
DiscordWebhookClient webhookClient = new(webhook);
ulong newMsgId = await webhookClient.SendMessageAsync(text: msg,
username: quoteeName,
avatarUrl: quotee?.GetAvatarUrl());
createdMsg = await quotesChannel.GetMessageAsync(newMsgId);
break;
}
case "bot-msg": {
createdMsg = await quotesChannel.SendMessageAsync($"{quoteeName}: \"{msg}\"");
break;
}
default:
throw new Exception("Invalid quote form in db.");
}
Quote quote = new(quoterId, quoteeData, guild, createdMsg.Id, msg, quotedMsgChannel, quotedMsgId);
Program.Storage.CreateQuote(quote);
}
}