Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
depthbomb committed Feb 28, 2023
1 parent 94eb86c commit 6e016f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
6 changes: 1 addition & 5 deletions Scraps/Controls/DebugControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ namespace Scraps.Controls
{
public partial class DebugControl : UserControl
{
private readonly SettingsService _settings;

public DebugControl(SettingsService settings)
{
_settings = settings;

InitializeComponent();
}

Expand All @@ -48,7 +44,7 @@ private void _DeleteSettingsSubKeyButton_Click(object sender, EventArgs e)
{
try
{
Registry.CurrentUser.DeleteSubKey(_settings.FullSettingsKey);
Registry.CurrentUser.DeleteSubKey(SettingsService.FullSettingsKey);

Utils.ShowInfo(Utils.GetMainForm(), "Debug", "Settings subkey deleted, exiting");
}
Expand Down
26 changes: 10 additions & 16 deletions Scraps/Services/RaffleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public class RaffleService : IDisposable
private bool _alertedOfWonRaffles;
private CancellationToken _cancelToken;
private CancellationTokenSource _cancelTokenSource;
private System.Random _randomifier;

private readonly SettingsService _settings;
private readonly SoundPlayer _alertPlayer;
private readonly Logger _log = LogManager.GetCurrentClassLogger();
private readonly Random _rng = new();
private readonly HtmlParser _html = new();
private readonly SoundPlayer _alertPlayer = new(Audio.alert);
private readonly List<string> _raffleQueue = new();
private readonly List<string> _enteredRaffles = new();
private readonly Regex _csrfRegex = new(@"value=""(?<CsrfToken>[a-f\d]{64})""");
Expand All @@ -121,14 +121,10 @@ public class RaffleService : IDisposable
private readonly Regex _entryRegex = new(@"ScrapTF\.Raffles\.RedirectToRaffle\('(?<RaffleId>[A-Z0-9]{6,})'\)", RegexOptions.Compiled);
private readonly Regex _hashRegex = new(@"EnterRaffle\('(?<RaffleId>[A-Z0-9]{6,})', '(?<RaffleHash>[a-f0-9]{64})'", RegexOptions.Compiled);
private readonly Regex _limitRegex = new(@"total=""(?<Entered>\d+)"" data-max=""(?<Max>\d+)", RegexOptions.Compiled);



public RaffleService(SettingsService settings)
{
_settings = settings;
_alertPlayer = new SoundPlayer(Audio.alert);
_randomifier = new System.Random();
_settings = settings;
}

~RaffleService() => Dispose();
Expand Down Expand Up @@ -196,11 +192,11 @@ public async Task StartAsync()

Broadcast("Waiting to scan again");

int scanDelayJittered = _scanDelay + _randomifier.Next(0, _settings.GetInt("ScanJitter"));
int jitteredScanDelay = _scanDelay + _rng.Next(0, _settings.GetInt("ScanJitter"));

_log.Info("All raffles have been entered, scanning again after {Delay} seconds", scanDelayJittered / 1000);
_log.Info("All raffles have been entered, scanning again after {Delay} seconds", jitteredScanDelay / 1000);

await Task.Delay(scanDelayJittered, _cancelToken);
await Task.Delay(jitteredScanDelay, _cancelToken);

if (incrementScanDelay)
_scanDelay += 1000;
Expand Down Expand Up @@ -504,15 +500,13 @@ private async Task JoinRafflesAsync()
_log.Error("Unable to join raffle {Id}: {Message}", raffle, joinRaffleResponse?.Message ?? "Unknown");
}

int joinDelayJittered = _joinDelay + _randomifier.Next(0, _settings.GetInt("JoinJitter"));

_log.Info("Waiting for next raffle, attempting to join in {Delay} seconds", joinDelayJittered / 1000);
int jitteredJoinDelay = _joinDelay + _rng.Next(0, _settings.GetInt("JoinJitter"));

_log.Info("Waiting for next raffle, attempting to join in {Delay} seconds", jitteredJoinDelay / 1000);

Broadcast("Waiting to join next raffle");


await Task.Delay(joinDelayJittered, _cancelToken);

await Task.Delay(jitteredJoinDelay, _cancelToken);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Scraps/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class SettingsService
{
public event EventHandler<SettingsServiceSavedArgs> OnSaved;
public event EventHandler<SettingsServiceResetArgs> OnReset;
public readonly string FullSettingsKey = "Software\\Caprine Logic\\Scraps\\Settings";

public const string FullSettingsKey = "Software\\Caprine Logic\\Scraps\\Settings";

// Default settings values
private const string Cookie = "";
Expand Down

0 comments on commit 6e016f2

Please sign in to comment.