-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrixieBot.cs
105 lines (94 loc) · 2.73 KB
/
TrixieBot.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//// To build: dotnet publish -r win10-x64
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace TrixieBot
{
public class TrixieBot
{
public Config config;
public Keys keys;
public TrixieBot()
{
// Read Config
config = JsonConvert.DeserializeObject<Config>(System.IO.File.ReadAllText("config.json"));
Console.WriteLine(DateTime.Now.ToString("M/d HH:mm") + " Configuation read");
}
public async Task<bool> Start()
{
// Start Telegram
Task<bool> telegram;
if (config.Keys.TelegramKey != string.Empty)
{
var telegramProtocol = new TelegramProtocol(config);
telegram = telegramProtocol.Start();
}
else
{
telegram = Task.FromResult(false);
}
// Start Discord
Task<bool> discord;
if (config.Keys.DiscordToken != string.Empty)
{
var discordProtocol = new DiscordProtocol(config);
discord = discordProtocol.Start();
}
else
{
discord = Task.FromResult(false);
}
// Wait for all tasks to end (which shouldn't ever happen)
await Task.WhenAll(telegram, discord).ConfigureAwait(false);
return false;
}
}
#region "Config Structs"
public struct Keys
{
public string TelegramKey;
public string DiscordToken;
public string WundergroundKey;
public string BingKey;
public string WolframAppID;
public string BattleNetKey;
public string CoinBaseAPIKey;
public string CoinBaseAPISecret;
public string BittrexAPIKey;
public string BittrexAPISecret;
}
public struct Rss
{
public string URL;
public string Format; // "RSS" or "Atom"
public string Type; // "Latest" to only send the top item, or "All" to send all items since the MostRecent pull
public string Protocol;
public string Destination;
public DateTime MostRecent;
}
public struct Config
{
public Keys Keys;
public Rss[] Rss;
}
#endregion
#region "RSS & Atom Structs"
public struct RSSItem
{
public string Title;
public string Link;
public string Description;
public string Guid;
public DateTime? PubDate;
}
public struct AtomEntry
{
public string Category;
public string Content;
public string Id;
public string Link;
public DateTime Updated;
public string Title;
}
#endregion
}