-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
1872 lines (1586 loc) · 84.9 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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Discord;
using Discord.Commands;
using Discord.Net;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
namespace Red_Alert
{
public class Program
{
public List<Alert> alert;
public List<AlertHistory> json;
public List<Image> image;
private string location = "";
private string date = "";
private string title = "";
private string location_ = "";
private string date_ = "";
private string title_ = "";
private string website = "";
private string website_ = "";
private string alert_json = "";
private string alert_json_ = "";
private string desc_ = "";
private ulong slash_command;
private string id_string;
private ulong user_id;
public string log_;
public string DMS = "OFF";
public string image_url;
public string api_key;
public string image_json;
public string lat = "";
public string lng = "";
private ulong my_id = 292770890792566784; //change this for control over the bot
private static void Main(string[] args) => new Program().RunBotAsync().GetAwaiter().GetResult();
public DiscordSocketClient _client;
public CommandService _commands;
public IServiceProvider _services;
private SocketGuild arg;
public async Task RunBotAsync()
{
////////////////////////////////////////////////////
Console.Title = "Red Alert Discord Bot";
////////////////////////////////////////////////////
await Commends();
var socketConfig = new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.All,
};
_client = new DiscordSocketClient(socketConfig);
_commands = new CommandService();
_services = new ServiceCollection()
.AddSingleton(_client)
.AddSingleton(_commands)
.BuildServiceProvider();
string
Token = "YOUR DISCORD BOT TOKEN GOES HERE";
_client.ButtonExecuted += MyButtonHandler;
_client.Ready += deadlock;
_client.Ready += ServerNumber;
_client.Ready += RedAlert_Id;
//_client.Ready += GetImage_stage1;
//_client.Ready += GetImage_stage2;
_client.Ready += Client_Ready;
//_client.Ready += deadlock;
//_client.Ready += RedAlert_Invite;
_client.SelectMenuExecuted += MyMenuHandler;
_client.Ready += Azaka;
_client.ModalSubmitted += BugFeature;
_client.MessageReceived += _client_MessageReceived;
_client.SlashCommandExecuted += SlashCommandHandler;
_client.LeftGuild += _client_LeftGuild;
_client.JoinedGuild += RedAlert_Role;
//await Task.Run(Azaka);
await RegisterCommandsAsync();
await _client.LoginAsync(TokenType.Bot, Token);
await _client.StartAsync();
await Task.Delay(-1);
}
private async Task<Task> _client_LeftGuild(SocketGuild arg)
{
await RedAlert_Id();
return Task.CompletedTask;
}
private Task _client_MessageReceived(SocketMessage arg)
{
if (DMS == "ON")
{
if (arg.Author.IsBot == false)
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Message",
arg.Author.Username + " " + arg.Author.Id + " sent message: " + arg));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Message",
arg.Author.Username + " sent message: " + arg));
}
}
return Task.CompletedTask;
}
public Task log(LogMessage arg)
{
Console.WriteLine(arg);
log_ = log_ + "\n" + arg;
return Task.CompletedTask;
}
public Task deadlock()
{
_ = Task.Run(async () =>
{
///////////////////////////////////////////
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Gateway", "Started deadlock protection."));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Gateway", "Started deadlock protection."));
///////////////////////////////////////////
var connTime = 0;
while (true)
{
if (_client.ConnectionState != ConnectionState.Connected)
{
connTime++;
if (connTime.Equals(30))
{
///////////////////////////////////////////
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
///////////////////////////////////////////
// if only we could call the log event method ourselves without compile error.
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Critical, "Gateway",
"Has not been connected for 30 seconds. Assuming deadlock in connector."));
Console.WriteLine(new LogMessage(LogSeverity.Critical, "Gateway",
"Has not been connected for 30 seconds. Assuming deadlock in connector."));
Task.Delay(1000).Wait(1000);
// add log function here
string date = Convert.ToString(DateTime.Now);
date = date.Replace('/', '_').Replace(':', '_').Replace(' ', '_');
using (StreamWriter file = File.CreateText(@"logs/log_" + date + ".txt"))
{
file.Write(log_);
Console.WriteLine("Saved log at: " + @"logs/log" + date + ".txt");
}
System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
//Close the current process
Environment.Exit(0);
}
}
else if (_client.ConnectionState == ConnectionState.Connected && !connTime.Equals(0))
{
connTime = 0;
}
await Task.Delay(1000).ConfigureAwait(false);
}
});
///////////////////////////////////////////
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
///////////////////////////////////////////
///
return Task.CompletedTask;
}
public Task Commends()
{
_ = Task.Run(async () =>
{
while (true)
{
var cm = Console.ReadLine();
if (cm != null)
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Command", cm));
switch (cm)
{
case ("Remove Role"):
try
{
Console.WriteLine(
"Please notice! if the Red Alert bot role is lower in prority then the one you want to get you wont be able to remove the role! ");
Console.WriteLine("Enter guild ID: ");
UInt64 GUILD_ = Convert.ToUInt64(Console.ReadLine());
var guild = _client.GetGuild(GUILD_);
Console.WriteLine("Enter user ID: ");
UInt64 ID_ = Convert.ToUInt64(Console.ReadLine());
var user = guild.GetUser(ID_);
Console.WriteLine(user.Username);
Console.WriteLine("Would you like to serch role by ID?\n Yes/No");
string choise = Console.ReadLine();
if (choise == "Yes")
{
Console.WriteLine("Enter role ID: ");
UInt64 RoleID = Convert.ToUInt64(Console.ReadLine());
var role = guild.GetRole(RoleID);
Console.WriteLine(role.Name);
Console.WriteLine("If you agree to remove " + user.Username + " the role " +
role.Name + " please press enter.");
Console.ReadKey();
await ((SocketGuildUser)user).RemoveRoleAsync(role);
}
else
{
Console.WriteLine("Enter role name: ");
string RoleName = Console.ReadLine();
var role = guild.Roles.FirstOrDefault(x => x.Name == RoleName);
;
Console.WriteLine(role.Name);
Console.WriteLine("If you agree to remove " + user.Username + " the role " +
role.Name + " please press enter.");
Console.ReadKey();
await ((SocketGuildUser)user).RemoveRoleAsync(role);
}
Console.WriteLine("Role removed!");
}
catch (Exception e)
{
Console.WriteLine("Could Not add role :( ");
Console.WriteLine(e);
}
break;
case ("Role"):
try
{
Console.WriteLine(
"Please notice! if the Red Alert bot role is lower in prority then the one you want to get you wont be able to add the role! ");
Console.WriteLine("Enter guild ID: ");
UInt64 GUILD_ = Convert.ToUInt64(Console.ReadLine());
var guild = _client.GetGuild(GUILD_);
Console.WriteLine("Enter user ID: ");
UInt64 ID_ = Convert.ToUInt64(Console.ReadLine());
var user = guild.GetUser(ID_);
Console.WriteLine(user.Username);
Console.WriteLine("Would you like to serch role by ID?\n Yes/No");
string choise = Console.ReadLine();
if (choise == "Yes")
{
Console.WriteLine("Enter role ID: ");
UInt64 RoleID = Convert.ToUInt64(Console.ReadLine());
var role = guild.GetRole(RoleID);
Console.WriteLine(role.Name);
Console.WriteLine("If you agree to give " + user.Username + " the role " +
role.Name + " please press enter.");
Console.ReadKey();
await ((SocketGuildUser)user).AddRoleAsync(role);
}
else
{
Console.WriteLine("Enter role name: ");
string RoleName = Console.ReadLine();
var role = guild.Roles.FirstOrDefault(x => x.Name == RoleName);
;
Console.WriteLine(role.Name);
Console.WriteLine("If you agree to give " + user.Username + " the role " +
role.Name + " please press enter.");
Console.ReadKey();
await ((SocketGuildUser)user).AddRoleAsync(role);
}
Console.WriteLine("Role granted!");
}
catch (Exception e)
{
Console.WriteLine("Could Not add role :( ");
Console.WriteLine(e);
}
break;
case ("Exit"):
Environment.Exit(0);
break;
case ("Servers"):
for (int i = 0; i < _client.Guilds.Count; i++)
{
var guild = _client.Guilds.ToList()[i] as SocketGuild;
var user_ = _client.GetUserAsync(my_id).Result;
await UserExtensions.SendMessageAsync(user_, "Name: " + guild.Name.ToString() + " - ID: " + guild.Id);
}
break;
case ("Create Role"):
await RedAlert_Role(arg);
break;
case ("User"):
Console.WriteLine("Please Enter User ID: ");
ulong user_id = Convert.ToUInt64(Console.ReadLine());
try
{
var user_ = _client.GetUserAsync(user_id).Result;
Console.WriteLine("Please Enter User Messgae: ");
string MessageUser = Console.ReadLine();
await UserExtensions.SendMessageAsync(user_, MessageUser);
}
catch (Exception e)
{
Console.WriteLine(e);
}
break;
case ("Log"):
string date = Convert.ToString(DateTime.Now);
date = date.Replace('/', '_').Replace(':', '_').Replace(' ', '_');
using (StreamWriter file = File.CreateText(@"logs/log_" + date + ".txt"))
{
file.Write(log_);
Console.WriteLine("Saved log at: " + @"logs/log" + date + ".txt");
}
break;
case ("Client_Ready()"):
await Client_Ready();
break;
case ("Role Reset"):
///////////////////////////////////////////
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.White;
log_ = log_ + "\n" +
(new LogMessage(LogSeverity.Info, "Role", "Reseting Roles! \n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", "Reseting Roles! \n"));
///////////////////////////////////////////
for (int i = 0; i < _client.Guilds.Count; i++)
{
var guild = _client.Guilds.ToList()[i] as SocketGuild;
try
{
var role_ = guild.Roles.FirstOrDefault(x =>
x.Name == "Red Alert Notifications");
var role = guild.GetRole(role_.Id);
await role.DeleteAsync();
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Role",
"Removed role for: " + guild.Id));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role",
"Removed role for: " + guild.Id));
}
catch (Exception)
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Role",
"Role problem exists at: " + guild.Id));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role",
"Role problem exists at: " + guild.Id));
}
}
break;
case ("DMS"):
if (DMS == "OFF")
{
DMS = "ON";
Console.WriteLine("Now accepting dms!");
}
else
{
DMS = "OFF";
Console.WriteLine("Now dont accepting dms!");
}
break;
case ("Restart"):
Console.WriteLine("Restarting...\n");
Task.Delay(1000).Wait(1000);
//Start process, friendly name is something like MyApp.exe (from current bin directory)
System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.FriendlyName);
//Close the current process
Environment.Exit(0);
break;
case ("Message"):
Console.WriteLine("What Is The Message You Would Like To Send?");
string message = Console.ReadLine();
await RedAlert_SendMessage(message);
break;
case ("Channel"):
Console.WriteLine("What Is The Message You Would Like To Send?");
string message_ = Console.ReadLine();
Console.WriteLine("To Where? \n(Channel ID)");
ulong id__ = Convert.ToUInt64(Console.ReadLine());
var chnl_ = _client.GetChannel(id__) as IMessageChannel;
await chnl_.SendMessageAsync(message_);
Console.WriteLine("Done!");
break;
case ("ID"):
///////////////////////////////////////////
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.White;
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", "Checking IDs! \n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", "Checking IDs! \n"));
///////////////////////////////////////////
string id_string;
List<string> list = new List<string>();
using (StreamReader file = File.OpenText(@"id.txt"))
{
id_string = file.ReadToEnd();
}
string[] ids = id_string.Split(',');
for (int id_ = 1; id_ < ids.Length;)
{
ulong result = Convert.ToUInt64(ids[id_]);
var chnl = _client.GetChannel(result) as IMessageChannel;
try
{
if (chnl != null)
{
//append
list.Add("," + result);
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID",
Convert.ToString(result)));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID",
Convert.ToString(result)));
}
else
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID",
"Channel " + result +
" Cant be accessed, \n deleting channel from database now!"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID",
"Channel " + result +
" Cant be accessed, \n deleting channel from database now!"));
}
}
catch (Exception e)
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID",
"Channel " + result + e));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID",
"Channel " + result + e));
}
id_++;
//await Task.Delay(50);
}
using (StreamWriter file = File.CreateText(@"id.txt"))
{
foreach (string id in list)
{
file.Write(id);
}
}
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", "Done checking IDs!\n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", "Done checking IDs!\n"));
Console.WriteLine();
///////////////////////////////////////////
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
///////////////////////////////////////////
break;
default:
Console.WriteLine("Error! not a valid command.");
break;
}
}
}
});
return Task.CompletedTask;
}
public async Task SendEmbedAsync()
{
string website_l;
string image_url__ = "";
using (WebClient clinet = new WebClient())
{
clinet.Headers.Add("user-agent",
"Mozilla / 5.0(Windows NT 10.0; Win64; x64; rv: 99.0) Gecko / 20100101 Firefox / 99.0");
try
{
////////////////////////////////////////////
//Console.WriteLine("Still Looking....");
////////////////////////////////////////////
json = JsonConvert.DeserializeObject<List<AlertHistory>>(
clinet.DownloadString("https://www.oref.org.il/WarningMessages/History/AlertsHistory.json"));
location = (json[0].data);
date = ("Date: " + json[0].alertDate);
title = ("Title: " + json[0].title);
website = (@"~~" + "https://www.google.com/maps/search/" + json[0].data.Replace(" ", "_") + "~~");
}
catch (Exception)
{
try
{
var chnl = _client.GetChannel(slash_command) as IMessageChannel;
await chnl.SendMessageAsync("Could Not Find Last Alert.... :( ");
}
catch
{
string msg = "Could Not Find Last Alert.... :(";
// Get the user with the ID from your DiscordSocketClient
var user = _client.GetUserAsync(user_id).Result;
await UserExtensions.SendMessageAsync(user, msg);
}
}
}
string newlocation_;
if (json[0].data[0] == ' ')
{
newlocation_ = json[0].data.Remove(0, json[0].data.Length - 1);
}
else
{
newlocation_ = json[0].data;
}
string wae = newlocation_;
foreach (var VARIABLE in image)
{
if (VARIABLE.name.Contains(newlocation_))
{
lat = VARIABLE.lat;
lng = VARIABLE.lng;
website_l =
$"https://dev.virtualearth.net/REST/V1/Imagery/Metadata/Road/{lat},{lng}?zl=13&o=xml&key={api_key}";
string website_lo;
using (WebClient clinet = new WebClient())
{
clinet.Headers.Add("user-agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36");
website_lo = clinet.DownloadString(website_l);
}
//<ImageUrl>http://ecn.t3.tiles.virtualearth.net/tiles/a032010110123333.jpeg?g=12552</ImageUrl>
int one_ = website_lo.IndexOf(@"<ImageUrl>");
int two_ = website_lo.IndexOf(@"</ImageUrl>");
image_url__ = website_lo.Substring(one_ + 10, two_ - one_ - 10);
}
}
if (image_url__ == "")
{
image_url__ =
"https://cdn.discordapp.com/attachments/965774763396042763/1005619855849947297/image.png";
}
var embed = new EmbedBuilder()
{
ImageUrl = image_url__
}
.WithTitle("*Red Alert*")
.WithDescription("Most Recent Alert Was At:\n" + location + "\n" + date + "\n" + title +
"\n 📢 <:MISSILES:945771593676779601>" + "\n" + website)
.WithColor(Color.DarkRed);
if (location != null && location != "")
{
try
{
var chnl = _client.GetChannel(slash_command) as IMessageChannel;
await chnl.SendMessageAsync(embed: embed.Build());
}
catch
{
// Get the user with the ID from your DiscordSocketClient
var user = _client.GetUserAsync(user_id).Result;
await UserExtensions.SendMessageAsync(user, embed: embed.Build());
}
}
else
{
try
{
var chnl = _client.GetChannel(slash_command) as IMessageChannel;
await chnl.SendMessageAsync("Could Not Find Last Alert.... :( ");
}
catch
{
string msg = "Could Not Find Last Alert.... :(";
// Get the user with the ID from your DiscordSocketClient
var user = _client.GetUserAsync(user_id).Result;
await UserExtensions.SendMessageAsync(user, msg);
}
}
//Your embed needs to be built before it is able to be sent
}
public async Task Client_Ready()
{
_ = Task.Run(async () =>
{
var globalCommand = new SlashCommandBuilder();
globalCommand.WithName("set-up");
globalCommand.WithDescription(
"Preform This Command In Order To Set This Chanel As Alert Channel!📢 <:MISSILES:945771593676779601>");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("get-notifications");
globalCommand.WithDescription(
"Preform This Command In Order To Get Notifications Every Time There Is A Red Alert.📢");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("disable-notifications");
globalCommand.WithDescription(
"Preform This Command In Order To Remove Notifications On This Server.📢 ");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("recent-alert");
globalCommand.WithDescription("Preform This Command In Order To Get The Most Recent Alert!");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("all-alerts");
globalCommand.WithDescription(
"Preform This Command In Order To Get All Alerts In The Last 12 Hours!");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("contact-us");
globalCommand.WithDescription("Report A Bug! Or Request A Feature!");
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
globalCommand.WithName("rate-us");
globalCommand.WithDescription("Rate Us <3");
globalCommand.AddOption(new SlashCommandOptionBuilder()
.WithName("rating")
.WithDescription("The rating youre willing to give our bot")
.WithRequired(true)
.AddChoice("Terrible", 1)
.AddChoice("Meh", 2)
.AddChoice("Good", 3)
.AddChoice("Lovely", 4)
.AddChoice("Excellent!", 5)
.WithType(ApplicationCommandOptionType.Integer)
);
try
{
// With global commands we don't need the guild.
await _client.CreateGlobalApplicationCommandAsync(globalCommand.Build());
// Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development.
// For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command.
}
catch (HttpException exception)
{
// If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented);
// You can send this error somewhere or just print it to the console, for this example we're just going to print it.
Console.WriteLine(json);
}
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Client_Ready", "Completed"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Client_Ready", "Completed"));
}
);
}
public Task RedAlert_SendMessage(string message)
{
_ = Task.Run(() =>
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "RedAlert", "Send message started!"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "RedAlert", "Send message started!"));
int i = 0;
string id_string;
using (StreamReader file = File.OpenText(@"id.txt"))
{
id_string = file.ReadToEnd();
}
string[] ids = id_string.Split(',');
try
{
while (i < (ids.Length - 1))
{
i++;
ulong result = Convert.ToUInt64(ids[i]);
var chnl = _client.GetChannel(result) as IMessageChannel;
chnl.SendMessageAsync(message);
Task.Delay(50).Wait(50);
}
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "RedAlert", "Send message completed!"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "RedAlert", "Send message completed!"));
}
catch (Exception e)
{
log_ = log_ + "\n" +
(new LogMessage(LogSeverity.Info, "RedAlert", "Error in sending message!\n" + e));
Console.WriteLine(new LogMessage(LogSeverity.Info, "RedAlert", "Error in sending message!\n" + e));
}
});
return Task.CompletedTask;
}
public async Task RedAlert_Role(SocketGuild arg)
{
///////////////////////////////////////////
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Cyan;
Console.ForegroundColor = ConsoleColor.White;
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Role", "Checking Roles! \n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", "Checking Roles! \n"));
///////////////////////////////////////////
for (int i = 0; i < _client.Guilds.Count; i++)
{
var guild = _client.Guilds.ToList()[i] as SocketGuild;
try
{
var role_ = guild.Roles.FirstOrDefault(x => x.Name == "Red Alert Notifications");
if (role_ == null)
{
var role = await guild.CreateRoleAsync($"Red Alert Notifications");
log_ = log_ + "\n" +
(new LogMessage(LogSeverity.Info, "Role", "Creating role for: " + guild.Id));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", "Creating role for: " + guild.Id));
//Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", guild.Name.ToString() + "\n"));
}
else
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "Role",
"Role already exists at: " + guild.Id));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role",
"Role already exists at: " + guild.Id));
//Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", guild.Name.ToString() + "\n"));
}
}
catch (Exception)
{
log_ = log_ + "\n" +
(new LogMessage(LogSeverity.Info, "Role", "Role problem exists at: " + guild.Id));
Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", "Role problem exists at: " + guild.Id));
//Console.WriteLine(new LogMessage(LogSeverity.Info, "Role", guild.Name.ToString() + "\n"));
}
}
///////////////////////////////////////////
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
///////////////////////////////////////////
}
public Task RedAlert_Id()
{
///////////////////////////////////////////
Console.WriteLine();
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.White;
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", "Checking IDs! \n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", "Checking IDs! \n"));
///////////////////////////////////////////
string id_string;
List<string> list = new List<string>();
using (StreamReader file = File.OpenText(@"id.txt"))
{
id_string = file.ReadToEnd();
}
string[] ids = id_string.Split(',');
string[] ids_ = ids.Distinct().ToArray();
for (int id_ = 1; id_ < ids_.Length;)
{
ulong result = Convert.ToUInt64(ids_[id_]);
var chnl = _client.GetChannel(result) as IMessageChannel;
try
{
if (chnl != null)
{
//append
list.Add("," + result);
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", Convert.ToString(result)));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", Convert.ToString(result)));
}
else
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID",
"Channel " + result + " Cant be accessed, \n deleting channel from database now!"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID",
"Channel " + result + " Cant be accessed, \n deleting channel from database now!"));
}
}
catch (Exception e)
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", "Channel " + result + e));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", "Channel " + result + e));
}
id_++;
//await Task.Delay(50);
}
using (StreamWriter file = File.CreateText(@"id.txt"))
{
foreach (string id in list)
{
file.Write(id);
}
}
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "ID", "Done checking IDs!\n"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "ID", "Done checking IDs!\n"));
Console.WriteLine();
_ = RedAlert_Role(arg);
return Task.CompletedTask;
}
public Task RedAlert()
{
_ = Task.Run(() =>
{
log_ = log_ + "\n" + (new LogMessage(LogSeverity.Info, "RedAlert", "Send message started!"));
Console.WriteLine(new LogMessage(LogSeverity.Info, "RedAlert", "Send message started!"));