-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
107 lines (86 loc) · 3.76 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
using discordamx.Plugin;
using discordamx.Scripting;
using DSharpPlus;
using DSharpPlus.Entities;
using System.Runtime.InteropServices;
using System.Text;
namespace discordamx
{
internal static partial class Program
{
public static string VERSION = "0.0.3";
public static bool m_Run = true;
public static Properties m_Properties = null!;
private static ConsoleColor m_DefForegrColor;
private static bool m_Setup = false;
public static DiscordConfiguration dConfig = null!;
public static bool m_ScriptingInited = false;
public static List<DiscordChannel> m_DmUsers = null!;
public static List<Scripting.DiscordEmbedBuilder> m_Embeds = null!;
public static List<Scripting.Guild> m_ScriptGuilds = null!;
public static Logger m_Logger = null!;
public static List<ScriptTimer> m_ScriptTimers = null!;
public static CommandManager m_CommandManager = null!;
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
private delegate bool EventHandler(CtrlType sig);
static EventHandler _handler = null!;
enum CtrlType
{
CTRL_C_EVENT = 0,
CTRL_BREAK_EVENT = 1,
CTRL_CLOSE_EVENT = 2,
CTRL_LOGOFF_EVENT = 5,
CTRL_SHUTDOWN_EVENT = 6
}
private 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:
StopEverything();
return false;
default:
return false;
}
}
static void Main(string[] args)
{
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Logs/"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Logs/");
m_Logger = new Logger();
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Scripts/"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Scripts/");
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Plugins/"))
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Plugins/");
Console.OutputEncoding = System.Text.Encoding.Unicode;
m_DefForegrColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
//Set the console handler, catching events such as close.76
_handler += new EventHandler(Handler);
SetConsoleCtrlHandler(_handler, true);
Setup(args);
m_CommandManager.RegisterCommand("popel", null, "Test befehl", "mycallback");
while (m_Run)
{
//Listen for input - handle it locally - trigger script event too.
ProcessLocalInput();
Thread.Sleep(100);
}
}
public static void StopEverything(int errcode = 0)
{
m_Run = false;
foreach (Script script in Manager.m_Scripts)
{
Manager.UnloadScript(script);
}
PluginLoader.UnloadPlugins(); //Really just calls OnUnload and we hope they clean up their shit themselves.
Console.ForegroundColor = m_DefForegrColor;
Environment.Exit(errcode);
}
}
}