-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
77 lines (66 loc) · 2.91 KB
/
Program.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
74
75
76
77
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
// Invite link: https://discordapp.com/oauth2/authorize?client_id=502450987643043857&scope=bot
namespace DiscordBot
{
public class Program
{
public static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
var client = new DiscordSocketClient();
client.Log += Log;
client.MessageReceived += MessageReceived;
string token = "DISCORD TOKEN GOES HERE";
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
await Task.Delay(-1);
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg);
return Task.CompletedTask;
}
public async Task MessageReceived(SocketMessage message)
{
foreach(var attachment in message.Attachments)
{
if(attachment.Height==128 && attachment.Width==128){
var filePath = "C:\\Users\\KyleN\\OneDrive\\Documents\\Spore Files\\PNG Decoder\\Cached\\"+attachment.Filename;
Console.WriteLine($"Downloading {attachment.Url} and saving to {filePath}");
using (var webClient = new WebClient())
{
var uri = new Uri(attachment.Url);
webClient.DownloadProgressChanged += wc_DownloadProgressChanged;
try{
webClient.DownloadFile(uri, filePath);
}
catch(Exception e){
Console.WriteLine(e.Message);
}
}
try{
var asset = new Asset(filePath);
await message.Channel.SendMessageAsync(asset.getInfo());
if(message.Content.Contains("!xml")) await message.Channel.SendFileAsync(filePath+".xml");
if(message.Content.Contains("!advanced")) await message.Channel.SendMessageAsync(asset.getInfoAdvanced());
if(message.Content.Contains("!api")) await message.Channel.SendMessageAsync(asset.getApiUrls());
if(message.Content.Contains("!pollinator")) await message.Channel.SendMessageAsync(asset.getPollinatorUrls());
}
catch{
await message.Channel.SendMessageAsync($"That creation couldn't be recognized.");
}
}
}
}
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Console.WriteLine($"{e.ProgressPercentage} ({e.BytesReceived}/{e.TotalBytesToReceive})");
}
}
}