Skip to content

Commit

Permalink
fix #1 and #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanel Kukic committed Jun 30, 2020
1 parent 5b15960 commit 75cd908
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/.idea/.idea.sphk/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/.idea.sphk/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 46 additions & 7 deletions src/sphk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;

namespace sphk
Expand All @@ -34,10 +35,17 @@ internal class Program
// The program's entrypoint
public static void Main(string[] args)
{
// welcome and version information
Version _version = Assembly.GetExecutingAssembly().GetName().Version;
string __version = $@"{_version.Major}.{_version.Minor}.{_version.Build}.{_version.Revision}";
Console.WriteLine("sphk");
Console.WriteLine($"CLI version {__version}");
Console.WriteLine("Copyright 2020 3reetop");
Console.WriteLine("Licensed under the terms of the MIT License");
Console.WriteLine("-----------------------");
// If we did not specify any commandline arguments, show a basic help message and exit with code 1
if (args.Length == 0)
{
Console.WriteLine("SpamHook version 4, by 3reetop\n");
Console.WriteLine("Please specify the location of your .json configuration file!\n");
Console.WriteLine("If you want to generate a file, run this program with the 'generate' command.");
Console.WriteLine(
Expand Down Expand Up @@ -226,6 +234,7 @@ public static void Spam()
timeout_length = timeout_length * 1000;

// If the user wants to spam this webhook forever (which is what -1 means)
string output = "";
if (times_to_spam == -1)
{
// Create an integer holding the number of the request we're currently on
Expand All @@ -241,20 +250,35 @@ public static void Spam()
if (status == 0)
{
// Print a success message to standard output
Console.WriteLine($@"Successfully sent request {request_number}");
output = $@"Successfully sent request {request_number}";
if (_debug)
{
output += " (204 No Content response)";
}
Console.WriteLine(output);
}
// Otherwise, if the value of the status integer is 1, meaning we reached Discord's
// ratelimit
else if (status == 1)
{
output = $@"We've hit the ratelimit on request number {request_number}";
if (_debug)
{
output += " (429 Too Many Requests response)";
}
// Print a ratelimit warning to standard output
Console.WriteLine($@"We've hit the ratelimit on request number {request_number}");
Console.WriteLine(output);
}
// Otherwise, if the value of the status integer is 2, meaning the request failed
else if (status == 2)
{
output = $@"An error was encountered when trying to send request {request_number}";
if (_debug)
{
output += " (400 Bad Request response)";
}
// Print a failure message to standard output
Console.WriteLine($@"An error was encountered when trying to send request {request_number}");
Console.WriteLine(output);
}
// Usually, you shouldn't be able to reach this block of code below
// But if you somehow do, might as well put a nice little easter egg in there, eh?
Expand Down Expand Up @@ -287,23 +311,38 @@ public static void Spam()
// was successful
if (status == 0)
{
output = $@"Successfully sent request {i} out of {times_to_spam}";
if (_debug)
{
output += " (204 No Content response)";
}
// Then print a success message to standard output
Console.WriteLine($@"Successfully sent request {i} out of {times_to_spam}");
Console.WriteLine(output);
}
// Otherwise, if the return code from SendRequest() was 1, meaning
// that we hit Discord's rate limit
else if (status == 1)
{
output = $@"We've hit the ratelimit on request number {i} out of {times_to_spam}";
if (_debug)
{
output += " (429 Too Many Requests response)";
}
// Then print a ratelimit warning to standard output
Console.WriteLine($@"We've hit the ratelimit on request number {i} out of {times_to_spam}");
Console.WriteLine(output);
}
// Otherwise, if the return code from SendRequest() was 2, meaning the
// request was a failure
else if (status == 2)
{
output = $@"An error was encountered when trying to send request {i} out of {times_to_spam}";
if (_debug)
{
output += " (400 Bad Request response)";
}
// Then print a failure message to standard output
Console.WriteLine(
$@"An error was encountered when trying to send request {i} out of {times_to_spam}");
output);
}
// Usually, you shouldn't be able to reach this block of code below
// But, if you somehow do, might as well put a nice little easter egg in there, eh?
Expand Down
4 changes: 2 additions & 2 deletions src/sphk/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
24 changes: 10 additions & 14 deletions src/sphk_gui/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace sphk_gui
public partial class Form1 : Form
{
// Create a publicly accessible boolean that determines if we're in debug mode
public bool is_debug;
public static bool is_debug = false;
private SpamForm _form = new SpamForm(is_debug);
public Form1()
{
InitializeComponent();
Expand Down Expand Up @@ -148,15 +149,8 @@ private void generateConfigFileButton_Click(object sender, EventArgs e)
else
{
// If the user cancels the SaveFileDialog by clicking the Cancel button, show a warning
DialogResult res = MessageBox.Show("An error was encountered when trying to open the dialog.",
MessageBox.Show("Please select a file to save the config to!",
"Oops", MessageBoxButtons.OK, MessageBoxIcon.Question);
switch (res)
{
// And then once the user acknowledges the warning, close the Form
default:
Close();
break;
}
}
}

Expand All @@ -165,26 +159,28 @@ private void generateConfigFileButton_Click(object sender, EventArgs e)
private void debugModeCheck_CheckedChanged(object sender, EventArgs e)
{
// If the debug mode checkbox is checked, set the is_debug boolean to true
// and set the is_debug property in our SpamForm instance to false
if (debugModeCheck.Checked)
{
is_debug = true;
_form.is_debug = true;
}
// If the debug mode checkbox is not checked, set the is_debug boolean to false
// and set the is_debug property in our SpamForm instance to false
else
{
is_debug = false;
_form.is_debug = false;
}
}

// The function below gets called when you press the "Start Spamming" button
// in the GUI
private void startSpamButton_Click_1(object sender, EventArgs e)
{
// Create a new instance of the SpamForm and display it
// The SpamForm handles everything from here in it's Load event handler
// so this is all we need to do here.
SpamForm form = new SpamForm();
form.ShowDialog();
// Use the instance of SpamForm we created at the very beginning
// and call it's ShowDialog method
_form.ShowDialog();
}
}
}
4 changes: 2 additions & 2 deletions src/sphk_gui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
Loading

0 comments on commit 75cd908

Please sign in to comment.