Adds no-discord debug option to discord bot.
This commit is contained in:
parent
ad2181db0b
commit
22cf82b99b
|
@ -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.");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue