diff --git a/Tests/CodexTests/UtilityTests/ClusterSpeedTests.cs b/Tests/CodexTests/UtilityTests/ClusterSpeedTests.cs index 9e647ea..7800e13 100644 --- a/Tests/CodexTests/UtilityTests/ClusterSpeedTests.cs +++ b/Tests/CodexTests/UtilityTests/ClusterSpeedTests.cs @@ -3,7 +3,7 @@ using Logging; using NUnit.Framework; using Utils; -namespace CodexTests.ScalabilityTests +namespace CodexTests.UtilityTests { [TestFixture] public class ClusterDiscSpeedTests : DistTest @@ -18,7 +18,7 @@ namespace CodexTests.ScalabilityTests ) { long targetSize = (long)(1024 * 1024 * 1024) * 2; - long bufferSizeBytes = ((long)bufferSizeKb) * 1024; + long bufferSizeBytes = (long)bufferSizeKb * 1024; var filename = nameof(DiscSpeedTest); @@ -28,7 +28,7 @@ namespace CodexTests.ScalabilityTests var writeSpeed = PerformWrite(targetSize, bufferSizeBytes, filename); Thread.Sleep(2000); var readSpeed = PerformRead(targetSize, bufferSizeBytes, filename); - + Log($"Write speed: {writeSpeed} per second."); Log($"Read speed: {readSpeed} per second."); } diff --git a/Tools/BiblioTech/Configuration.cs b/Tools/BiblioTech/Configuration.cs index 9164cf7..ffbf4c6 100644 --- a/Tools/BiblioTech/Configuration.cs +++ b/Tools/BiblioTech/Configuration.cs @@ -34,28 +34,12 @@ namespace BiblioTech [Uniform("mint-tt", "mt", "MINTTT", true, "Amount of TestTokens minted by the mint command.")] public int MintTT { get; set; } = 1073741824; - public string EndpointsPath - { - get - { - return Path.Combine(DataPath, "endpoints"); - } - } + [Uniform("no-discord", "nd", "NODISCORD", false, "For debugging: Bypasses all Discord API calls.")] + public int NoDiscord { get; set; } = 0; - public string UserDataPath - { - get - { - return Path.Combine(DataPath, "users"); - } - } - - public string LogPath - { - get - { - return Path.Combine(DataPath, "logs"); - } - } + public string EndpointsPath => Path.Combine(DataPath, "endpoints"); + public string UserDataPath => Path.Combine(DataPath, "users"); + public string LogPath => Path.Combine(DataPath, "logs"); + public bool DebugNoDiscord => NoDiscord == 1; } } diff --git a/Tools/BiblioTech/LoggingRoleDriver.cs b/Tools/BiblioTech/LoggingRoleDriver.cs new file mode 100644 index 0000000..9275a7a --- /dev/null +++ b/Tools/BiblioTech/LoggingRoleDriver.cs @@ -0,0 +1,24 @@ +using BiblioTech.Rewards; +using DiscordRewards; +using Logging; +using Newtonsoft.Json; + +namespace BiblioTech +{ + public class LoggingRoleDriver : IDiscordRoleDriver + { + private readonly ILog log; + + public LoggingRoleDriver(ILog log) + { + this.log = log; + } + + public async Task GiveRewards(GiveRewardsCommand rewards) + { + await Task.CompletedTask; + + log.Log(JsonConvert.SerializeObject(rewards, Formatting.None)); + } + } +} diff --git a/Tools/BiblioTech/Program.cs b/Tools/BiblioTech/Program.cs index f289d9b..6ec7dae 100644 --- a/Tools/BiblioTech/Program.cs +++ b/Tools/BiblioTech/Program.cs @@ -41,25 +41,15 @@ namespace BiblioTech public async Task MainAsync(string[] args) { Log.Log("Starting Codex Discord Bot..."); - client = new DiscordSocketClient(); - client.Log += ClientLog; - - var notifyCommand = new NotifyCommand(); - var associateCommand = new UserAssociateCommand(notifyCommand); - var sprCommand = new SprCommand(); - var handler = new CommandHandler(client, - new GetBalanceCommand(associateCommand), - new MintCommand(associateCommand), - sprCommand, - associateCommand, - notifyCommand, - new AdminCommand(sprCommand), - new MarketCommand() - ); - - await client.LoginAsync(TokenType.Bot, Config.ApplicationToken); - await client.StartAsync(); - AdminChecker = new AdminChecker(); + if (Config.DebugNoDiscord) + { + Log.Log("Debug option is set. Discord connection disabled!"); + RoleDriver = new LoggingRoleDriver(Log); + } + else + { + await StartDiscordBot(); + } var builder = WebApplication.CreateBuilder(args); builder.WebHost.ConfigureKestrel((context, options) => @@ -75,6 +65,29 @@ namespace BiblioTech await Task.Delay(-1); } + private async Task StartDiscordBot() + { + client = new DiscordSocketClient(); + client.Log += ClientLog; + + var notifyCommand = new NotifyCommand(); + var associateCommand = new UserAssociateCommand(notifyCommand); + var sprCommand = new SprCommand(); + var handler = new CommandHandler(client, + new GetBalanceCommand(associateCommand), + new MintCommand(associateCommand), + sprCommand, + associateCommand, + notifyCommand, + new AdminCommand(sprCommand), + new MarketCommand() + ); + + await client.LoginAsync(TokenType.Bot, Config.ApplicationToken); + await client.StartAsync(); + AdminChecker = new AdminChecker(); + } + private static void PrintHelp() { Log.Log("BiblioTech - Codex Discord Bot");