-
Notifications
You must be signed in to change notification settings - Fork 1
/
BoxOffice.cs
59 lines (47 loc) · 1.95 KB
/
BoxOffice.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
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using Newtonsoft.Json;
namespace RottenTomatoes
{
public static class BoxOffice
{
public static async Task Print(SocketSlashCommand command)
{
var data = await WebUtils.DownloadString("https://www.rottentomatoes.com/browse/in-theaters?minTomato=0&maxTomato=100&genres=1;2;4;5;6;8;9;10;11;13;18;14&sortBy=popularity");
data = data.CutBeforeAndAfter("document.getElementById('main-row')", "mps,")
.CutBefore("},")
.CutBefore("},");
data = data.Substring(0, data.LastIndexOf("]") + 1);
dynamic resultItems = JsonConvert.DeserializeObject(data);
var result = new StringBuilder();
string icon;
for (int i = 0; i < 10; i++)
{
switch (resultItems[i].tomatoIcon.ToString())
{
case "certified_fresh":
icon = "<:certified_fresh:737761619375030422>";
break;
case "fresh":
icon = "<:fresh:737761619299270737>";
break;
case "rotten":
icon = "<:rotten:737761619299532874>";
break;
default:
icon = "";
break;
}
result.AppendLine($"`{i + 1}` {resultItems[i].title} `{resultItems[i].theaterReleaseDate}` {(resultItems[i].tomatoScore == null ? "N/A" : resultItems[i].tomatoScore + "%")} {icon}");
}
await command.FollowupAsync(null, embed: new EmbedBuilder()
.WithTitle("Top Box Office")
.WithColor(EmbedUtils.Red)
.WithFooter("Via RottenTomatoes.com")
.WithDescription(result.ToString())
.Build());
}
}
}