Skip to content

Commit

Permalink
add say verify
Browse files Browse the repository at this point in the history
  • Loading branch information
TitleHHHH authored and TitleHHHH committed Dec 27, 2023
1 parent a1276fc commit eac02f3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
using HolyClient.Abstractions.StressTest;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Text.RegularExpressions;

namespace HolyClient.StressTest
{
public class TestBehavior : IStressTestBehavior
public class DefaultBehavior : IStressTestBehavior
{
[System.ComponentModel.DisplayName("Spam text")]
public string SpamText { get; set; } = "Hello";
public string SpamText { get; set; } = "!Hello from Minecraft Holy Client";

[System.ComponentModel.DisplayName("Spam timeout")]
public int SpamTimeout { get; set; } = 5000;


private static Regex SayVerifyRegex = new(@"\.say \/verify (\d+)");

public Task Activate(CompositeDisposable disposables, IEnumerable<IStressTestBot> bots, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -47,13 +56,40 @@ public Task Activate(CompositeDisposable disposables, IEnumerable<IStressTestBot
cts = new();
try
{


await Task.Delay(500);

await bot.Client.SendChat("/reg 21qwerty 21qwerty");

try
{
using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
//{

var m = await bot.Client.OnChatMessage
.Where(x => x.Message.Contains("verify"))
.Skip(3)
.FirstAsync()
.ToTask(cts.Token);

var code = SayVerifyRegex.Match(m.Message).Value;

await bot.Client.SendChat(code);
//}
}
catch (Exception ex)
{
//Console.WriteLine(ex);
}

while (!cts.IsCancellationRequested)
{
await bot.Client.SendChat(SpamText);
await Task.Delay(1000);
if (SpamTimeout <= 0)
await Task.Delay(1000);
else
await Task.Delay(SpamTimeout);
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion src/CoreLibs/HolyClient.StressTest/StressTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public async Task Start(Serilog.ILogger logger)
}
else
{
TestBehavior testBehavior = new();
DefaultBehavior testBehavior = new();
await testBehavior.Activate(disposables, stressTestBots, cancellationTokenSource.Token);
}
CurrentState = StressTestServiceState.Running;
Expand Down
2 changes: 1 addition & 1 deletion src/HolyClient/Services/PluginProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class DefaultPluginSource : IPluginSource

public T CreateInstance<T>() where T : IStressTestBehavior
{
IStressTestBehavior beh = new TestBehavior();
IStressTestBehavior beh = new DefaultBehavior();
return (T)beh;
}
}
Expand Down

0 comments on commit eac02f3

Please sign in to comment.