-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
302 lines (243 loc) · 11.1 KB
/
Program.cs
File metadata and controls
302 lines (243 loc) · 11.1 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
using System.Reflection;
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Notifier.Classes;
using Timer = System.Timers.Timer;
namespace Notifier
{
internal class Program
{
private static DiscordSocketClient? _client;
private static IServiceProvider? _services;
private static Timer? _statustimer;
static bool useWarp = false;
public static long bot_started = long.MinValue;
static async void ProcessExitHandler(object sender, dynamic e)
{
if (useWarp) {
Logger.Print(Logger.Verbose, "Disposing Cloudflare WARP.");
await WarpInterface.DisposeWarpAsync();
}
}
static void Main(string[] args) => new Program().MainAsync(args).GetAwaiter().GetResult();
public async Task MainAsync(string[] args)
{
foreach (var arg in args)
{
switch (arg)
{
case "-w":
case "--warp":
useWarp = true;
break;
default:
break;
}
}
WarpInterface.InitWarp(useWarp);
AppDomain.CurrentDomain.ProcessExit += ProcessExitHandler!;
Console.CancelKeyPress += ProcessExitHandler!;
Logger.Print(Logger.Verbose, args != null && args.Length > 0 ? string.Join(", ", args) : "No arguments.");
bot_started = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
_client = new DiscordSocketClient(new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIntents.MessageContent
});
_client.Log += Log;
string json = File.ReadAllText("auth.json");
var data = JsonConvert.DeserializeObject<dynamic>(json);
string? token = data?.token;
if (token == null)
{
Logger.Print(Logger.Error, "Token not found or not set.");
return;
}
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
await _client.SetStatusAsync(UserStatus.DoNotDisturb);
_services = ConfigureServices();
var interactions = _services.GetRequiredService<InteractionService>();
await interactions.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
_client.InteractionCreated += HandleInteractionAsync;
_client.Ready += async () =>
{
try
{
await interactions.RegisterCommandsToGuildAsync(Globals.GetAs<ulong>("GuildId"));
// Logger.Print(Logger.Info, "Slash commands registered to guild.");
}
catch (Exception ex)
{
Logger.Print(Logger.Error, ex.Message);
}
};
await RBX.CheckDifferentAsync();
RBX.InitializeTimer();
await ChangeStatusAsync();
InitializeStatusTimer();
await Task.Delay(-1);
}
private static ServiceProvider ConfigureServices()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(_client!);
serviceCollection.AddSingleton(new InteractionService(_client!));
return serviceCollection.BuildServiceProvider();
}
private async Task HandleInteractionAsync(SocketInteraction interaction)
{
try
{
var context = new SocketInteractionContext(_client!, interaction);
var interactions = _services!.GetRequiredService<InteractionService>();
await interactions.ExecuteCommandAsync(context, _services);
}
catch (Exception ex)
{
Logger.Print(Logger.Error, ex.Message);
}
}
private Task Log(LogMessage msg)
{
var message = msg.ToString();
var severityMap = new Dictionary<LogSeverity, Logger.LogType>
{
{ LogSeverity.Critical, Logger.Critical },
{ LogSeverity.Error, Logger.Error },
{ LogSeverity.Warning, Logger.Warning },
{ LogSeverity.Info, Logger.Info },
{ LogSeverity.Verbose, Logger.Verbose },
{ LogSeverity.Debug, Logger.Debug }
};
var type = severityMap.TryGetValue(msg.Severity, out var logType) ? logType : Logger.Regular;
Logger.Print(type, message);
return Task.CompletedTask;
}
public static async Task FireUnpatch(string message, string version, string unp_p_atch)
{
if (_client == null) return;
var embedBuilder = new EmbedBuilder();
if (unp_p_atch == "unpatch")
{
embedBuilder.Color = new Color(81, 255, 164);
embedBuilder.Title = $"`🟩` [ {Globals.Get("AppName")} | WindowsPlayer | LIVE ]";
embedBuilder.Description = $"{Globals.Get("AppName")} has been updated for the latest Roblox Version";
embedBuilder.AddField("Version", $"`{version}`");
Logger.Print(Logger.Update, $"An update for {Globals.Get("AppName")} has been released.");
}
else if (unp_p_atch == "patch")
{
embedBuilder.Color = new Color(255, 100, 90);
embedBuilder.Title = $"`🟥` [ {Globals.Get("AppName")} | WindowsPlayer | LIVE ]";
embedBuilder.Description = $"{Globals.Get("AppName")} is currently patched";
Logger.Print(Logger.Update, $"A patch for {Globals.Get("AppName")} was fired.");
}
if (message != "ignore")
embedBuilder.AddField("Notes", message);
embedBuilder.Footer = new EmbedFooterBuilder
{
Text = $"LEx Update Notifier",
IconUrl = $"{Globals.Get("AppEmojiUrl")}"
};
var guild = await EnsureGuildConnection();
if (guild == null) return;
var channel = guild.GetTextChannel(Globals.GetAs<ulong>("UpdatesChannelIdText"));
if (channel == null)
{
Logger.Print(Logger.Error, "Channel not found.");
return;
}
string vcName = unp_p_atch == "unpatch" ? "\uD83D\uDFE9 Operational" : "\uD83D\uDD35 Not working";
await channel.SendMessageAsync(
unp_p_atch == "unpatch" ? $"{Globals.Get("AppName")} has been updated {Globals.Get("AppUpdatesRole")}" : $"{Globals.Get("AppName")} has been patched",
false,
embedBuilder.Build()
);
if (_client.GetChannel(Globals.GetAs<ulong>("StatusChannelIdVoice")) is SocketVoiceChannel versionChannel)
await versionChannel.ModifyAsync(prop => prop.Name = vcName);
else
Logger.Print(Logger.Error, "Channel (VersionChannelVerbose) was null.");
}
private static async Task<SocketGuild> EnsureGuildConnection()
{
var guild = _client!.GetGuild(Globals.GetAs<ulong>("GuildId"));
if (guild == null || !(guild?.IsConnected ?? false))
{
Logger.Print(Logger.Info, "Guild not found, attempting to connect.");
int maxAttempts = 30;
for (int attempts = 0; attempts < maxAttempts; attempts++)
{
await Task.Delay(1000);
guild = _client.GetGuild(Globals.GetAs<ulong>("GuildId"));
if (guild?.IsConnected == true)
{
Logger.Print(Logger.Info, "Guild connected successfully.");
return guild;
}
}
Logger.Print(Logger.Error, "Maximum connection attempts reached. Connection failed.");
}
return guild!;
}
public static async Task Fire(RBX.Version version, RBX.Types typeUpdate)
{
if (_client == null) return;
var embedBuilder = new EmbedBuilder
{
Footer = new EmbedFooterBuilder
{
Text = "Roblox Update Notifier",
IconUrl = "https://cdn.discordapp.com/emojis/1143655222917480528.webp?size=96&quality=lossless" // If you want to change the road of blocks emoji do it then
}
};
switch (typeUpdate)
{
case RBX.Types.Yes:
embedBuilder.Color = new Color(255, 100, 90);
embedBuilder.Title = "`🔴` [ Roblox | WindowsPlayer | LIVE ]";
embedBuilder.Description = "Roblox has pushed a new update";
break;
case RBX.Types.Revert:
embedBuilder.Color = new Color(81, 255, 164);
embedBuilder.Title = "`🟢` [ Roblox | WindowsPlayer | LIVE ]";
embedBuilder.Description = "Roblox has reverted";
break;
case RBX.Types.Error:
default:
return;
}
embedBuilder.AddField("Version", $"`{version.ClientVersionUpload}`", true);
var guild = await EnsureGuildConnection();
if (guild == null) return;
var channel = guild.GetTextChannel(Globals.GetAs<ulong>("UpdatesChannelIdText"));
if (channel == null)
{
Logger.Print(Logger.Error, "Channel not found.");
return;
}
await channel.SendMessageAsync($"An update has been detected {Globals.Get("RobloxUpdatesRoleId")}", false, embedBuilder.Build());
Logger.Print(Logger.Update, "An update has been detected.");
if (_client.GetChannel(Globals.GetAs<ulong>("RobloxVersionIdVoice")) is SocketVoiceChannel versionChannel)
await versionChannel.ModifyAsync(prop => prop.Name = version.ClientVersionUpload);
else
Logger.Print(Logger.Error, "Channel (VersionChannelVerbose) was null.");
}
public static void InitializeStatusTimer()
{
_statustimer = new Timer(TimeSpan.FromMinutes(3).TotalMilliseconds);
_statustimer.Elapsed += async (sender, e) => await ChangeStatusAsync();
_statustimer.AutoReset = true;
_statustimer.Enabled = true;
}
private static async Task ChangeStatusAsync()
{
if (_client == null)
return;
string[] statusList = ["for updates 👀", $"{Globals.Get("AppName")} grow 🐲", "for Roblox changes 🤖", "Excel mop the the floor"];
await _client.SetGameAsync(statusList[new Random().Next(0, statusList.Length)], null, ActivityType.Watching);
}
}
}