Skip to content

Commit

Permalink
Refactored more of RuriLib's code
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Oct 15, 2024
1 parent 7035548 commit 035712a
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 72 deletions.
2 changes: 1 addition & 1 deletion RuriLib.Http/RuriLib.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Authors>Ruri</Authors>
<Version>1.0.1</Version>
<Description>This is a library that provides a custom HTTP client, in addition to an HttpMessageHandler to be used with the default HttpClient of System.Net</Description>
<Copyright>Ruri 2022</Copyright>
<Copyright>Ruri 2024</Copyright>
<RepositoryUrl>https://github.com/openbullet/OpenBullet2/tree/master/RuriLib.Http</RepositoryUrl>
<PackageTags>http; proxy; socks; client; custom;</PackageTags>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion RuriLib.Parallelization/RuriLib.Parallelization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Authors>Ruri</Authors>
<Description>This is a library that can perform multiple tasks (yes, a lot, even infinitely many) that act on some input and return a certain output.</Description>
<Copyright>Ruri 2022</Copyright>
<Copyright>Ruri 2024</Copyright>
<PackageProjectUrl>https://github.com/openbullet/OpenBullet2/tree/master/RuriLib.Parallelization</PackageProjectUrl>
<RepositoryUrl>https://github.com/openbullet/OpenBullet2/tree/master/RuriLib.Parallelization</RepositoryUrl>
<PackageTags>parallelization; task; tasks; manager; taskmanager; multithreading; parallel; multithread; async;</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion RuriLib.Proxies/RuriLib.Proxies.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Copyright>Ruri 2022</Copyright>
<Copyright>Ruri 2024</Copyright>
<PackageProjectUrl>https://github.com/openbullet/OpenBullet2/tree/master/RuriLib.Proxies</PackageProjectUrl>
<Description>This is a library that can proxy a `TcpClient` via a proxy server. Supported protocols: HTTP(S), SOCKS4, SOCKS4a, SOCKS5, No proxy</Description>
<PackageTags>proxy; proxies; http; socks; socks4; socks4a; socks5; tcpclient;</PackageTags>
Expand Down
6 changes: 6 additions & 0 deletions RuriLib/Attributes/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ public class Variable : Attribute
// ReSharper disable once InconsistentNaming
public string? defaultVariableName;

/// <summary>
/// Marks the parameter as a variable with no default name.
/// </summary>
public Variable()
{

}

/// <summary>
/// Marks the parameter as a variable with the given default name.
/// </summary>
public Variable(string defaultVariableName)
{
this.defaultVariableName = defaultVariableName;
Expand Down
18 changes: 18 additions & 0 deletions RuriLib/Exceptions/BlockExecutionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

namespace RuriLib.Exceptions;

/// <summary>
/// The exception that is thrown when a block encounters an error during execution.
/// </summary>
public class BlockExecutionException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="BlockExecutionException"/> class.
/// </summary>
/// <param name="message">
/// The message that describes the error.
/// </param>
public BlockExecutionException(string message)
: base(message)
{

}

/// <summary>
/// Initializes a new instance of the <see cref="BlockExecutionException"/> class.
/// </summary>
/// <param name="message">
/// The message that describes the error.
/// </param>
/// <param name="innerException">
/// The exception that is the cause of the current exception.
/// </param>
public BlockExecutionException(string message, Exception innerException)
: base(message, innerException)
{
Expand Down
6 changes: 6 additions & 0 deletions RuriLib/Exceptions/InvalidProxyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace RuriLib.Exceptions;
/// </summary>
public class InvalidProxyException : Exception
{
/// <summary>
/// Creates a <see cref="InvalidProxyException"/> with a message that contains the invalid proxy.
/// </summary>
/// <param name="proxy">
/// The invalid proxy that could not be parsed.
/// </param>
public InvalidProxyException(string proxy)
: base($"The proxy {proxy} could not be parsed")
{
Expand Down
21 changes: 13 additions & 8 deletions RuriLib/Exceptions/InvalidWordlistTypeException.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using System;

namespace RuriLib.Exceptions
namespace RuriLib.Exceptions;

/// <summary>
/// An exception that is thrown when a Wordlist Type with the given name was not present
/// in the Environment settings.
/// </summary>
public class InvalidWordlistTypeException : Exception
{
/// <summary>
/// An exception that is thrown when a Wordlist Type with the given name was not present
/// in the Environment settings.
/// Creates a <see cref="InvalidWordlistTypeException"/> with a message that contains the invalid type.
/// </summary>
public class InvalidWordlistTypeException : Exception
/// <param name="type">
/// The invalid Wordlist Type that was not found in the Environment settings.
/// </param>
public InvalidWordlistTypeException(string type)
: base($"The Wordlist Type {type} was not found in the Environment settings")
{
public InvalidWordlistTypeException(string type)
: base($"The Wordlist Type {type} was not found in the Environment settings")
{

}
}
}
69 changes: 51 additions & 18 deletions RuriLib/Exceptions/LoliCodeParsingException.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
using System;

namespace RuriLib.Exceptions
namespace RuriLib.Exceptions;

/// <summary>
/// An exception that is thrown when an error occurs while parsing LoliCode.
/// </summary>
public class LoliCodeParsingException : Exception
{
public class LoliCodeParsingException : Exception
{
public int LineNumber { get; set; }
/// <summary>
/// The line number where the error occurred.
/// </summary>
public int LineNumber { get; set; }

public LoliCodeParsingException(int lineNumber)
{
LineNumber = lineNumber;
}
/// <summary>
/// Creates a new <see cref="LoliCodeParsingException"/>.
/// </summary>
/// <param name="lineNumber">
/// The line number where the error occurred.
/// </param>
public LoliCodeParsingException(int lineNumber)
{
LineNumber = lineNumber;
}

public LoliCodeParsingException(int lineNumber, string message)
: base($"[Line {lineNumber}] {message}")
{
LineNumber = lineNumber;
}
/// <summary>
/// Creates a new <see cref="LoliCodeParsingException"/>.
/// </summary>
/// <param name="lineNumber">
/// The line number where the error occurred.
/// </param>
/// <param name="message">
/// The error message.
/// </param>
public LoliCodeParsingException(int lineNumber, string message)
: base($"[Line {lineNumber}] {message}")
{
LineNumber = lineNumber;
}

public LoliCodeParsingException(int lineNumber, string message, Exception inner)
: base($"[Line {lineNumber}] {message}", inner)
{
LineNumber = lineNumber;
}
/// <summary>
/// Creates a new <see cref="LoliCodeParsingException"/>.
/// </summary>
/// <param name="lineNumber">
/// The line number where the error occurred.
/// </param>
/// <param name="message">
/// The error message.
/// </param>
/// <param name="inner">
/// The inner exception.
/// </param>
public LoliCodeParsingException(int lineNumber, string message, Exception inner)
: base($"[Line {lineNumber}] {message}", inner)
{
LineNumber = lineNumber;
}
}

17 changes: 10 additions & 7 deletions RuriLib/Exceptions/NoWordlistTypesException.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using System;

namespace RuriLib.Exceptions
namespace RuriLib.Exceptions;

/// <summary>
/// An exception that is thrown when no Wordlist Types were specified
/// in the Environment settings.
/// </summary>
public class NoWordlistTypesExceptions : Exception
{
/// <summary>
/// An exception that is thrown when no Wordlist Types were specified
/// in the Environment settings.
/// Creates a new <see cref="NoWordlistTypesExceptions"/>.
/// </summary>
public class NoWordlistTypesExceptions : Exception
public NoWordlistTypesExceptions() :
base("No Wordlist Types specified in the Environment settings")
{
public NoWordlistTypesExceptions() : base("No Wordlist Types specified in the Environment settings")
{

}
}
}
68 changes: 50 additions & 18 deletions RuriLib/Extensions/BoolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
using System;
using System.Collections.Generic;

namespace RuriLib.Extensions
namespace RuriLib.Extensions;

/// <summary>
/// Provides extension methods for <see cref="bool"/>.
/// </summary>
public static class BoolExtensions
{
public static class BoolExtensions
{
public static bool AsBool(this bool b)
=> b;
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="bool"/>.
/// </summary>
public static bool AsBool(this bool b)
=> b;

public static int AsInt(this bool b)
=> Convert.ToInt32(b);
/// <summary>
/// Converts a <see cref="bool"/> to an <see cref="int"/>.
/// Returns 1 if true, 0 if false.
/// </summary>
public static int AsInt(this bool b)
=> Convert.ToInt32(b);

public static float AsFloat(this bool b)
=> Convert.ToSingle(b);
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="float"/>.
/// Returns 1.0f if true, 0.0f if false.
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
public static float AsFloat(this bool b)
=> Convert.ToSingle(b);

public static byte[] AsBytes(this bool b)
=> BitConverter.GetBytes(b);
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="T:byte[]"/>.
/// Returns a single byte with value 1 if true, 0 if false.
/// </summary>
public static byte[] AsBytes(this bool b)
=> BitConverter.GetBytes(b);

public static string AsString(this bool b)
=> b.ToString();
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="string"/>.
/// Returns "True" if true, "False" if false.
/// </summary>
public static string AsString(this bool b)
=> b.ToString();

public static List<string> AsList(this bool b)
=> new List<string> { b.ToString() };
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="List{T}"/> of <see cref="string"/>.
/// Returns a list with a single element containing the string representation of the bool.
/// </summary>
public static List<string> AsList(this bool b)
=> [b.ToString()];

public static Dictionary<string, string> AsDict(this bool b)
=> new Dictionary<string, string> { { b.ToString(), "" } };
}
/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="Dictionary{TKey, TValue}"/> of <see cref="string"/>.
/// Returns a dictionary with a single key-value pair containing the string representation of the bool
/// as the key and an empty string as the value.
/// </summary>
public static Dictionary<string, string> AsDict(this bool b)
=> new() { { b.ToString(), "" } };
}
Loading

0 comments on commit 035712a

Please sign in to comment.