-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
51 lines (45 loc) · 1.74 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
using CommandLine;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace Multibot
{
public class Options
{
[Option('c', "config", Required = true, HelpText = "Path to YAML config file.")]
public required string ConfigFile { get; set; }
}
class Program
{
static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsedAsync(o => {
using var reader = new StreamReader(o.ConfigFile);
var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
// Load config
var cfg = deserializer.Deserialize<Config>(reader);
var admins = cfg.Admins ?? new List<string>();
// Initialize and start bots
var bots = new List<Multibot>();
foreach (var creds in cfg.Bots)
{
creds.LoginUrl = cfg.LoginUrl;
creds.LoginLocation = cfg.LoginLocation;
var bot = new Multibot(creds, admins);
bot.Start();
bots.Add(bot);
}
Console.CancelKeyPress += async delegate
{
// Wait for all bots to disconnect
var stopTasks = bots.Select(b => b.Stop()).ToArray();
await Task.WhenAll(stopTasks);
};
// Run until cancelled
while (true) { }
});
}
}
}