-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (65 loc) · 2.56 KB
/
Program.cs
File metadata and controls
80 lines (65 loc) · 2.56 KB
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
using jabber;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
namespace Jabber
{
class Program
{
static void Main(string[] args)
{
// ManualResetEvent threadBlocker = new ManualResetEvent(false);
// // Wait for control+c
// Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e)
// {
// threadBlocker.Set();
// };
JabberClient.Instance.OnJabberConnected += async delegate ()
{
//await JabberClient.Instance.JoinRoom("incursion_bot_testing@conference.goonfleet.com");
await JabberClient.Instance.JoinRoom("incursion-leadership@conference.goonfleet.com");
await JabberClient.Instance.JoinRoom("fcincursions@conference.goonfleet.com");
await JabberClient.Instance.JoinRoom("incursions@conference.goonfleet.com");
};
Commands.Register();
// TODO: I'm not sure if this is the best way to create one off things. Seems to be in a console app.
Task jabberTask = new Task(async () =>
{
await JabberClient.Instance.Run();
}, TaskCreationOptions.LongRunning);
Task commandTask = new Task(async () =>
{
await CommandDispatcher.Instance.ProcessQueue();
}, TaskCreationOptions.LongRunning);
jabberTask.Start();
commandTask.Start();
DateTime now = DateTime.Now;
Scheduler.IntervalInMinutes(now.Hour, now.Minute + 1, 5, async () =>
{
Incursions inc = Incursions.Get();
await inc.UpdateIncursions();
inc.Set();
});
CreateWebHostBuilder(args).Build().Run();
// Block
JabberClient.Instance.Disconnect().GetAwaiter().GetResult();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
// Get listen urls by default
string listenUrl = Environment.GetEnvironmentVariable("ASPNETCORE_URLS");
int port = 5000;
if(Config.GetInt("PORT", out port))
{
listenUrl = string.Format("http://*:{0};https://*:{1}", port, port + 1);
}
return WebHost.CreateDefaultBuilder(args)
.UseUrls(listenUrl)
.UseStartup<Startup>();
}
}
}