-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.cs
127 lines (94 loc) · 4 KB
/
Setup.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
using System;
using DSharpPlus;
using System.Runtime.InteropServices;
using discordamx.Discord;
using DSharpPlus.Entities;
using discordamx.Plugin;
namespace discordamx
{
internal static partial class Program
{
//Coreinfo
static bool m_isWindows;
static bool m_isLinux;
static void Setup(string[] args)
{
if (m_Setup) return;
Program.m_ScriptGuilds = new List<Scripting.Guild>();
Program.m_ScriptTimers = new List<Scripting.ScriptTimer>();
m_DmUsers = new List<DiscordChannel>();
Program.m_Embeds = new List<Scripting.DiscordEmbedBuilder>();
Console.ForegroundColor = ConsoleColor.Yellow;
#if DEBUG
Program.m_Logger.Warning(" RUNNING IN DEBUG MODE with user " + Environment.UserName);
#endif
Console.ForegroundColor = ConsoleColor.White;
Program.m_Logger.Write(" -> DiscordAMX BETA 2 © 2023-2024 - www.fanter.eu <-");
//Environment - Set the OS
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) m_isWindows = true;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) m_isLinux = true;
else StopEverything();
if (m_isWindows) Program.m_Logger.Write("INIT: -> Running on Windows.");
else if (m_isLinux) Program.m_Logger.Write("INIT: Running on Linux. (Make sure you are always up to date!");
//Handle commands.
Console.CancelKeyPress += delegate {
StopEverything();
return;
};
Program.dConfig = new DiscordConfiguration()
{
TokenType = TokenType.Bot,
AlwaysCacheMembers = false,
MessageCacheSize = 4065,
Intents = DiscordIntents.DirectMessageReactions
| DiscordIntents.DirectMessages
| DiscordIntents.GuildMessageReactions
| DiscordIntents.MessageContents
| DiscordIntents.GuildBans
| DiscordIntents.GuildEmojis
| DiscordIntents.GuildInvites
| DiscordIntents.GuildMembers
| DiscordIntents.GuildMessages
| DiscordIntents.Guilds
| DiscordIntents.GuildVoiceStates
| DiscordIntents.GuildWebhooks,
AutoReconnect = true
};
//check if main config exists..
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "discordamx.properties"))
{
//Set defaults
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "discordamx.properties", "#You need to know how to create a bot with the Discord Developer Portal website. Use the internet for tutorials. Add your own bot's token below:\ndiscord-bot-token=changeme");
}
m_Properties = new Properties(AppDomain.CurrentDomain.BaseDirectory + "discordamx.properties");
if (m_Properties != null)
{
Program.dConfig.Token = m_Properties.get("discord-bot-token");
//Start the discord bot
Bot.RunAsync(dConfig).GetAwaiter().GetResult();
Console.ForegroundColor = ConsoleColor.Yellow;
Program.m_Logger.Debug("Waiting for first guild data download to finish..");
while (!Program.m_ScriptingInited)
{
Thread.Sleep(900);
}
Console.Write("\n");
}
else
{
StopEverything();
return;
}
//Load the plugins
PluginLoader.LoadPluginsAsync();
//Load all the other files.
Scripting.Manager.LoadFiles();
//Handle key commands.
Console.CancelKeyPress += delegate {
StopEverything();
return;
};
m_Setup = true;
}
}
}