Skip to content

Commit

Permalink
Functionality added & Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FooqX authored Jan 30, 2022
1 parent 2d685d8 commit e692edc
Showing 1 changed file with 104 additions and 38 deletions.
142 changes: 104 additions & 38 deletions Source.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Console.Title = "Discord Webhooks Generator";

Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("=~=~=~=~=~=~=~=~=~=~=~=~= DWG v2.0.0 =~=~=~=~=~=~=~=~=~=~=~=~=");
Console.WriteLine("~~ Discord webhooks generator v2.1.1");
Console.ResetColor();

Console.Write("Webhook amount >> ");
Expand Down Expand Up @@ -29,22 +29,43 @@
Environment.Exit(0);
}

// ~~~ Webhooks.txt file path
// --- Webhooks.txt file path
string webhookPath = "C:\\Users\\" + Environment.UserName + "\\Downloads\\webhooks.txt";

// ~~~ Old webhooks cleaning
// --- Old webhooks cleaning
if (File.Exists(webhookPath)) {
Console.Write("Clean webhooks (Y)es/(N)o >> ");

if ("y".Equals(Console.ReadLine().ToLower())) {
Console.WriteLine("- webhooks.txt " + new FileInfo(webhookPath).Length + " KB ~> 0 KB");
FileStream fs = File.OpenWrite(webhookPath);
fs.SetLength(0);
fs.Dispose();
fs.Close();
try {
// Truncating file
using FileStream fs = File.OpenWrite(webhookPath);
fs.SetLength(0);
fs.Dispose();
fs.Close();
} catch (Exception e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error. " + e.Message);
Console.ResetColor();

Console.Write("\nPress any key to continue...");
Console.ReadKey();
Environment.Exit(0);
}
}
} else {
File.Create(webhookPath);
try {
File.Create(webhookPath);
} catch (Exception e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error. " + e.Message);
Console.ResetColor();

Console.Write("\nPress any key to continue...");
Console.ReadKey();
Environment.Exit(0);
}
}

// ~~~ Token rand string generator
Expand All @@ -67,7 +88,7 @@ string RandomToken(int n = 68) {

return new string(r);
}
// maybe in these two theres a proble

string RandomNumber(int n = 18) {
char[] r = new char[n];

Expand All @@ -77,33 +98,43 @@ string RandomNumber(int n = 18) {

return new string(r);
}
Console.WriteLine("\nPreparing...");
Console.WriteLine("Note: Please be patient, because this can take a while depending on webhook amount");
Console.WriteLine("\nWriting unbuffered webhooks...");

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n──────────── Generating webhooks ────────────");
Console.ResetColor();

Console.Write("Writing unbuffered webhooks...");

try {
// Opening streamwriter
using StreamWriter sw = File.AppendText(path: webhookPath);

// Opening streamwriter with append mode
using StreamWriter sw = File.AppendText(webhookPath);

// Configuring streamwriter for performance
sw.AutoFlush = false;
sw.NewLine = "\n";

// Generating webhooks (unbuffered)
for (uint i = 0; i < webhookCount; i++) {
sw.WriteLine($"https://discord.com/api/webhooks/{RandomNumber()}/{RandomToken()}");
}

Console.WriteLine(" Done!");

// Buffering
Console.WriteLine("Done writing!\nBuffering...");
sw.Flush(); // Flushing the stream so it writes changes
Console.WriteLine("Done buffering!");
Console.Write("Buffering...");
sw.Flush();
Console.WriteLine(" Done!");

// Disposing streamwriter
Console.Write("Disposing StreamWriter...");
sw.Dispose();
Console.WriteLine(" Done!");

// Closing streamwriter
Console.WriteLine("Disposing StreamWriter...");
sw.Dispose(); // Releasing all resources used up by streamwriter
Console.WriteLine("Closing StreamWriter...");
sw.Close(); // Closing streamwriter
Console.WriteLine("Done closing & disposing StreamWriter!\n");
Console.Write("Closing StreamWriter...");
sw.Close();
Console.WriteLine(" Done!");
} catch (Exception e) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error. " + e.Message);
Expand All @@ -115,21 +146,56 @@ string RandomNumber(int n = 18) {
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Successfully generated all webhooks!");
Console.WriteLine("\n──────────── Information ────────────");
Console.ResetColor();

long fileSize = new FileInfo(webhookPath).Length;

Console.WriteLine("Status: Successfully generated " + webhookCount + " webhooks!");
Console.WriteLine($"File size: {fileSize} KB ({fileSize / 1024 / 1024} MB)");
Console.WriteLine("File location: " + webhookPath);

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("─────────────────────────────────────");
Console.ResetColor();

Console.Write("Press any key to open webhooks file and terminate the program...");
Console.ReadKey();
using (System.Diagnostics.Process cmd = new()) {
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();

cmd.StandardInput.WriteLine(webhookPath);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
if (webhookCount == 1) {
Console.Write("Press any key to copy the webhook and terminate the program...");
Console.ReadKey();

using StreamReader webhook = File.OpenText(webhookPath);
string content = webhook.ReadLine();

using (System.Diagnostics.Process cmd = new()) {
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();

cmd.StandardInput.WriteLine("echo|set/p=" + content + "|clip");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
}
} else {
Console.Write("Press any key to open webhooks file and terminate the program...");
Console.ReadKey();

using (System.Diagnostics.Process cmd = new()) {
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();

cmd.StandardInput.WriteLine(webhookPath);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
}
}

Environment.Exit(0);

0 comments on commit e692edc

Please sign in to comment.