-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
150 lines (114 loc) · 3.89 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using OpenQA.Selenium;
using pajoma_nvtbot.Discord;
using pajoma_nvtbot.Utils;
using pajoma_nvtbot.Web;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
namespace pajoma_nvtbot
{
internal class Program
{
internal static bool g_run = true;
public static string m_NvtLink = null!;
public static Properties m_Basecfg = null! ;
#if !LINUX
[DllImport("Kernel32")]
static public extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
public delegate bool EventHandler(CtrlType sig);
public static EventHandler? m_Handler;
public enum CtrlType
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
public static bool Handler(CtrlType sig)
{
switch (sig)
{
case CtrlType.CTRL_C_EVENT:
case CtrlType.CTRL_LOGOFF_EVENT:
case CtrlType.CTRL_SHUTDOWN_EVENT:
case CtrlType.CTRL_CLOSE_EVENT:
StopSafely();
return false;
default:
return false;
}
}
public static void StopSafely()
{
foreach (Users.User u in m_UserList)
{
u.StopBotThread();
}
g_run = false;
return;
}
#endif
#if LINUX
public static void StopSafely()
{
//SAVE GLOBAL PROPERTIES FILES
if (m_Basecfg != null) m_Basecfg.Save();
foreach (Users.User u in m_UserList)
{
u.StopBotThread();
}
g_run = false;
return;
}
#endif
public static List<Users.User> m_UserList = new List<Users.User>();
static void Main(string[] args)
{
#if DEBUG
Console.WriteLine("------ DEBUGMODE!!!!");
#endif
#if !LINUX
Console.OutputEncoding = Encoding.Unicode;
m_Handler += new EventHandler(Handler);
SetConsoleCtrlHandler(m_Handler, true);
#endif
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Users/"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Users/");
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "config.ini"))
File.Create(AppDomain.CurrentDomain.BaseDirectory + "config.ini");
m_Basecfg = new Properties(AppDomain.CurrentDomain.BaseDirectory + "config.ini");
if (m_Basecfg.get("auth-token", "changeme").Equals("changeme"))
{
Console.WriteLine("Discord Bot Token not set! Please change it to a valid bot token in settings.cfg");
Console.ReadLine();
Program.StopSafely();
return;
}
if (m_Basecfg.get("url", "changeme").Equals("changeme"))
{
Console.WriteLine("Novatime WEB Url not set! Please change it to a valid bot token in settings.cfg");
Console.ReadLine();
Program.StopSafely();
return;
}
MainBot.Init(m_Basecfg.get("auth-token"));
MainBot.Start();
foreach (string file in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "Users/"))
{
Console.WriteLine("Found user " + file);
string fl = file.Replace(".ini", "").PadRight(1);
string[] xfl = fl.Split('/');
m_UserList.Add(new Users.User(int.Parse(xfl[xfl.Length - 1])));
}
while(g_run)
{
Thread.Sleep(60000);
}
while (true)
{
}
}
}
}