From 9717591224cec828ffd9116fe4d93d305dad1246 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 16 May 2024 11:54:31 +0200 Subject: [PATCH 1/4] Updates bot config to use ids instead of names --- Framework/ArgsUniform/ArgsUniform.cs | 8 +++----- Tools/BiblioTech/Configuration.cs | 20 ++++++++++---------- Tools/BiblioTech/Program.cs | 2 ++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Framework/ArgsUniform/ArgsUniform.cs b/Framework/ArgsUniform/ArgsUniform.cs index d987aa71..e8f0277c 100644 --- a/Framework/ArgsUniform/ArgsUniform.cs +++ b/Framework/ArgsUniform/ArgsUniform.cs @@ -42,7 +42,7 @@ namespace ArgsUniform { printAppInfo(); PrintHelp(); - throw new Exception(); + Environment.Exit(0); } var result = Activator.CreateInstance(); @@ -55,9 +55,7 @@ namespace ArgsUniform { if (!UniformAssign(result, attr, uniformProperty) && attr.Required) { - { - missingRequired.Add(uniformProperty); - } + missingRequired.Add(uniformProperty); } } } @@ -75,7 +73,7 @@ namespace ArgsUniform } PrintHelp(); - throw new ArgumentException("Unable to assemble all required arguments"); + Environment.Exit(1); } if (printResult) diff --git a/Tools/BiblioTech/Configuration.cs b/Tools/BiblioTech/Configuration.cs index 37e1cc33..73e143e8 100644 --- a/Tools/BiblioTech/Configuration.cs +++ b/Tools/BiblioTech/Configuration.cs @@ -7,23 +7,23 @@ namespace BiblioTech [Uniform("token", "t", "TOKEN", true, "Discord Application Token")] public string ApplicationToken { get; set; } = string.Empty; - [Uniform("server-name", "sn", "SERVERNAME", true, "Name of the Discord server")] - public string ServerName { get; set; } = string.Empty; + [Uniform("server-id", "sn", "SERVERID", true, "ID of the Discord server")] + public ulong ServerId { get; set; } [Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")] public string DataPath { get; set; } = "datapath"; - [Uniform("admin-role", "a", "ADMINROLE", true, "Name of the Discord server admin role")] - public string AdminRoleName { get; set; } = string.Empty; + [Uniform("admin-role-id", "a", "ADMINROLEID", true, "ID of the Discord server admin role")] + public ulong AdminRoleId { get; set; } - [Uniform("admin-channel-name", "ac", "ADMINCHANNELNAME", true, "Name of the Discord server channel where admin commands are allowed.")] - public string AdminChannelName { get; set; } = "admin-channel"; + [Uniform("admin-channel-id", "ac", "ADMINCHANNELID", true, "ID of the Discord server channel where admin commands are allowed.")] + public ulong AdminChannelId{ get; set; } - [Uniform("rewards-channel-name", "rc", "REWARDSCHANNELNAME", false, "Name of the Discord server channel where participation rewards will be announced.")] - public string RewardsChannelName { get; set; } = ""; + [Uniform("rewards-channel-id", "rc", "REWARDSCHANNELID", false, "ID of the Discord server channel where participation rewards will be announced.")] + public ulong RewardsChannelId { get; set; } - [Uniform("chain-events-channel-name", "cc", "CHAINEVENTSCHANNELNAME", false, "Name of the Discord server channel where chain events will be posted.")] - public string ChainEventsChannelName { get; set; } = ""; + [Uniform("chain-events-channel-id", "cc", "CHAINEVENTSCHANNELID", false, "ID of the Discord server channel where chain events will be posted.")] + public ulong ChainEventsChannelID { get; set; } [Uniform("reward-api-port", "rp", "REWARDAPIPORT", false, "TCP listen port for the reward API.")] public int RewardApiPort { get; set; } = 31080; diff --git a/Tools/BiblioTech/Program.cs b/Tools/BiblioTech/Program.cs index a604812a..f289d9b8 100644 --- a/Tools/BiblioTech/Program.cs +++ b/Tools/BiblioTech/Program.cs @@ -21,6 +21,8 @@ namespace BiblioTech public static Task Main(string[] args) { + Log = new ConsoleLog(); + var uniformArgs = new ArgsUniform(PrintHelp, args); Config = uniformArgs.Parse(); From b3771cce3245dc9571f43d33650d7473d752e79e Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 16 May 2024 12:14:03 +0200 Subject: [PATCH 2/4] Extract assigner from argsUniform --- Framework/ArgsUniform/ArgsUniform.cs | 134 +------------------------ Framework/ArgsUniform/Assigner.cs | 142 +++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 130 deletions(-) create mode 100644 Framework/ArgsUniform/Assigner.cs diff --git a/Framework/ArgsUniform/ArgsUniform.cs b/Framework/ArgsUniform/ArgsUniform.cs index e8f0277c..8804c25f 100644 --- a/Framework/ArgsUniform/ArgsUniform.cs +++ b/Framework/ArgsUniform/ArgsUniform.cs @@ -4,9 +4,8 @@ namespace ArgsUniform { public class ArgsUniform { + private readonly Assigner assigner; private readonly Action printAppInfo; - private readonly object? defaultsProvider; - private readonly IEnv.IEnv env; private readonly string[] args; private const int cliStart = 8; private const int shortStart = 38; @@ -31,9 +30,9 @@ namespace ArgsUniform public ArgsUniform(Action printAppInfo, object defaultsProvider, IEnv.IEnv env, params string[] args) { this.printAppInfo = printAppInfo; - this.defaultsProvider = defaultsProvider; - this.env = env; this.args = args; + + assigner = new Assigner(env, args, defaultsProvider); } public T Parse(bool printResult = false) @@ -53,7 +52,7 @@ namespace ArgsUniform var attr = uniformProperty.GetCustomAttribute(); if (attr != null) { - if (!UniformAssign(result, attr, uniformProperty) && attr.Required) + if (!assigner.UniformAssign(result, attr, uniformProperty) && attr.Required) { missingRequired.Add(uniformProperty); } @@ -124,130 +123,5 @@ namespace ArgsUniform Console.CursorLeft = descStart; Console.Write(desc + Environment.NewLine); } - - private object GetDefaultValue(Type t) - { - if (t.IsValueType) return Activator.CreateInstance(t)!; - return null!; - } - - private bool UniformAssign(T result, UniformAttribute attr, PropertyInfo uniformProperty) - { - if (AssignFromArgsIfAble(result, attr, uniformProperty)) return true; - if (AssignFromEnvVarIfAble(result, attr, uniformProperty)) return true; - if (AssignFromDefaultsIfAble(result, uniformProperty)) return true; - return false; - } - - private bool AssignFromDefaultsIfAble(T result, PropertyInfo uniformProperty) - { - var currentValue = uniformProperty.GetValue(result); - var isEmptryString = (currentValue as string) == string.Empty; - if (currentValue != GetDefaultValue(uniformProperty.PropertyType) && !isEmptryString) return true; - - if (defaultsProvider == null) return false; - - var defaultProperty = defaultsProvider.GetType().GetProperties().SingleOrDefault(p => p.Name == uniformProperty.Name); - if (defaultProperty == null) return false; - - var value = defaultProperty.GetValue(defaultsProvider); - if (value != null) - { - return Assign(result, uniformProperty, value); - } - return false; - } - - private bool AssignFromEnvVarIfAble(T result, UniformAttribute attr, PropertyInfo uniformProperty) - { - var e = env.GetEnvVarOrDefault(attr.EnvVar, string.Empty); - if (!string.IsNullOrEmpty(e)) - { - return Assign(result, uniformProperty, e); - } - return false; - } - - private bool AssignFromArgsIfAble(T result, UniformAttribute attr, PropertyInfo uniformProperty) - { - var fromArg = GetFromArgs(attr.Arg); - if (fromArg != null) - { - return Assign(result, uniformProperty, fromArg); - } - var fromShort = GetFromArgs(attr.ArgShort); - if (fromShort != null) - { - return Assign(result, uniformProperty, fromShort); - } - return false; - } - - private bool Assign(T result, PropertyInfo uniformProperty, object value) - { - if (uniformProperty.PropertyType == value.GetType()) - { - uniformProperty.SetValue(result, value); - return true; - } - else - { - if (uniformProperty.PropertyType == typeof(string) || uniformProperty.PropertyType == typeof(int)) - { - uniformProperty.SetValue(result, Convert.ChangeType(value, uniformProperty.PropertyType)); - return true; - } - else - { - if (uniformProperty.PropertyType == typeof(int?)) return AssignOptionalInt(result, uniformProperty, value); - if (uniformProperty.PropertyType.IsEnum) return AssignEnum(result, uniformProperty, value); - if (uniformProperty.PropertyType == typeof(bool)) return AssignBool(result, uniformProperty, value); - - throw new NotSupportedException(); - } - } - } - - private static bool AssignEnum(T result, PropertyInfo uniformProperty, object value) - { - var s = value.ToString(); - if (Enum.TryParse(uniformProperty.PropertyType, s, out var e)) - { - uniformProperty.SetValue(result, e); - return true; - } - return false; - } - - private static bool AssignOptionalInt(T result, PropertyInfo uniformProperty, object value) - { - if (int.TryParse(value.ToString(), out int i)) - { - uniformProperty.SetValue(result, i); - return true; - } - return false; - } - - private static bool AssignBool(T result, PropertyInfo uniformProperty, object value) - { - var s = value.ToString(); - if (s == "1" || (s != null && s.ToLowerInvariant() == "true")) - { - uniformProperty.SetValue(result, true); - } - return true; - } - - private string? GetFromArgs(string key) - { - var argKey = $"--{key}="; - var arg = args.FirstOrDefault(a => a.StartsWith(argKey)); - if (arg != null) - { - return arg.Substring(argKey.Length); - } - return null; - } } } diff --git a/Framework/ArgsUniform/Assigner.cs b/Framework/ArgsUniform/Assigner.cs new file mode 100644 index 00000000..b25c68bf --- /dev/null +++ b/Framework/ArgsUniform/Assigner.cs @@ -0,0 +1,142 @@ +using System.Reflection; + +namespace ArgsUniform +{ + public class Assigner + { + private readonly IEnv.IEnv env; + private readonly string[] args; + private readonly object? defaultsProvider; + + public Assigner(IEnv.IEnv env, string[] args, object? defaultsProvider) + { + this.env = env; + this.args = args; + this.defaultsProvider = defaultsProvider; + } + + public bool UniformAssign(T result, UniformAttribute attr, PropertyInfo uniformProperty) + { + if (AssignFromArgsIfAble(result, attr, uniformProperty)) return true; + if (AssignFromEnvVarIfAble(result, attr, uniformProperty)) return true; + if (AssignFromDefaultsIfAble(result, uniformProperty)) return true; + return false; + } + + private bool AssignFromDefaultsIfAble(T result, PropertyInfo uniformProperty) + { + var currentValue = uniformProperty.GetValue(result); + var isEmptryString = (currentValue as string) == string.Empty; + if (currentValue != GetDefaultValueForType(uniformProperty.PropertyType) && !isEmptryString) return true; + if (defaultsProvider == null) return false; + + var defaultProperty = defaultsProvider.GetType().GetProperties().SingleOrDefault(p => p.Name == uniformProperty.Name); + if (defaultProperty == null) return false; + + var value = defaultProperty.GetValue(defaultsProvider); + if (value != null) + { + return Assign(result, uniformProperty, value); + } + return false; + } + + private bool AssignFromEnvVarIfAble(T result, UniformAttribute attr, PropertyInfo uniformProperty) + { + var e = env.GetEnvVarOrDefault(attr.EnvVar, string.Empty); + if (!string.IsNullOrEmpty(e)) + { + return Assign(result, uniformProperty, e); + } + return false; + } + + private bool AssignFromArgsIfAble(T result, UniformAttribute attr, PropertyInfo uniformProperty) + { + var fromArg = GetFromArgs(attr.Arg); + if (fromArg != null) + { + return Assign(result, uniformProperty, fromArg); + } + var fromShort = GetFromArgs(attr.ArgShort); + if (fromShort != null) + { + return Assign(result, uniformProperty, fromShort); + } + return false; + } + + private bool Assign(T result, PropertyInfo uniformProperty, object value) + { + if (uniformProperty.PropertyType == value.GetType()) + { + uniformProperty.SetValue(result, value); + return true; + } + else + { + if (uniformProperty.PropertyType == typeof(string) || uniformProperty.PropertyType == typeof(int)) + { + uniformProperty.SetValue(result, Convert.ChangeType(value, uniformProperty.PropertyType)); + return true; + } + else + { + if (uniformProperty.PropertyType == typeof(int?)) return AssignOptionalInt(result, uniformProperty, value); + if (uniformProperty.PropertyType.IsEnum) return AssignEnum(result, uniformProperty, value); + if (uniformProperty.PropertyType == typeof(bool)) return AssignBool(result, uniformProperty, value); + + throw new NotSupportedException(); + } + } + } + + private static bool AssignEnum(T result, PropertyInfo uniformProperty, object value) + { + var s = value.ToString(); + if (Enum.TryParse(uniformProperty.PropertyType, s, out var e)) + { + uniformProperty.SetValue(result, e); + return true; + } + return false; + } + + private static bool AssignOptionalInt(T result, PropertyInfo uniformProperty, object value) + { + if (int.TryParse(value.ToString(), out int i)) + { + uniformProperty.SetValue(result, i); + return true; + } + return false; + } + + private static bool AssignBool(T result, PropertyInfo uniformProperty, object value) + { + var s = value.ToString(); + if (s == "1" || (s != null && s.ToLowerInvariant() == "true")) + { + uniformProperty.SetValue(result, true); + } + return true; + } + + private string? GetFromArgs(string key) + { + var argKey = $"--{key}="; + var arg = args.FirstOrDefault(a => a.StartsWith(argKey)); + if (arg != null) + { + return arg.Substring(argKey.Length); + } + return null; + } + + private static object GetDefaultValueForType(Type t) + { + if (t.IsValueType) return Activator.CreateInstance(t)!; + return null!; + } + } +} From 7d9dcb263d044faa237404f59067d094e6b4e50c Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 16 May 2024 14:05:58 +0200 Subject: [PATCH 3/4] Prints default ArgsUniform values. Applies discord IDs instead of names. --- Framework/ArgsUniform/ArgsUniform.cs | 49 ++++++++++++++------------ Framework/ArgsUniform/Assigner.cs | 40 +++++++++++++++------ Tools/BiblioTech/AdminChecker.cs | 4 +-- Tools/BiblioTech/CommandHandler.cs | 2 +- Tools/BiblioTech/Configuration.cs | 10 +++--- Tools/BiblioTech/Rewards/RoleDriver.cs | 16 ++++----- 6 files changed, 71 insertions(+), 50 deletions(-) diff --git a/Framework/ArgsUniform/ArgsUniform.cs b/Framework/ArgsUniform/ArgsUniform.cs index 8804c25f..68bf8f27 100644 --- a/Framework/ArgsUniform/ArgsUniform.cs +++ b/Framework/ArgsUniform/ArgsUniform.cs @@ -61,7 +61,7 @@ namespace ArgsUniform if (missingRequired.Any()) { - PrintResults(result, uniformProperties); + PrintResults(printResult,result, uniformProperties); Print(""); foreach (var missing in missingRequired) { @@ -75,34 +75,36 @@ namespace ArgsUniform Environment.Exit(1); } - if (printResult) - { - PrintResults(result, uniformProperties); - } + PrintResults(printResult, result, uniformProperties); return result; } - private void PrintResults(T result, PropertyInfo[] uniformProperties) - { - Print(""); - foreach (var p in uniformProperties) - { - Print($"\t{p.Name} = {p.GetValue(result)}"); - } - Print(""); - } - public void PrintHelp() { Print(""); - PrintAligned("CLI option:", "(short)", "Environment variable:", "Description"); - var attrs = typeof(T).GetProperties().Where(m => m.GetCustomAttributes(typeof(UniformAttribute), false).Length == 1).Select(p => p.GetCustomAttribute()).Where(a => a != null).ToArray(); - foreach (var attr in attrs) + PrintAligned("CLI option:", "(short)", "Environment variable:", "Description", "(default)"); + var props = typeof(T).GetProperties().Where(m => m.GetCustomAttributes(typeof(UniformAttribute), false).Length == 1).ToArray(); + foreach (var prop in props) { - var a = attr!; - var optional = !a.Required ? " *" : ""; - PrintAligned($"--{a.Arg}=...", $"({a.ArgShort})", a.EnvVar, a.Description + optional); + var a = prop.GetCustomAttribute(); + if (a != null) + { + var optional = !a.Required ? " (optional)" : ""; + var def = assigner.DescribeDefaultFor(prop); + PrintAligned($"--{a.Arg}=...", $"({a.ArgShort})", a.EnvVar, a.Description + optional, $"({def})"); + } + } + Print(""); + } + + private void PrintResults(bool printResult, T result, PropertyInfo[] uniformProperties) + { + if (!printResult) return; + Print(""); + foreach (var p in uniformProperties) + { + Print($"\t{p.Name} = {p.GetValue(result)}"); } Print(""); } @@ -112,7 +114,7 @@ namespace ArgsUniform Console.WriteLine(msg); } - private void PrintAligned(string cli, string s, string env, string desc) + private void PrintAligned(string cli, string s, string env, string desc, string def) { Console.CursorLeft = cliStart; Console.Write(cli); @@ -121,7 +123,8 @@ namespace ArgsUniform Console.CursorLeft = envStart; Console.Write(env); Console.CursorLeft = descStart; - Console.Write(desc + Environment.NewLine); + Console.Write(desc + " "); + Console.Write(def + Environment.NewLine); } } } diff --git a/Framework/ArgsUniform/Assigner.cs b/Framework/ArgsUniform/Assigner.cs index b25c68bf..d1e2e81e 100644 --- a/Framework/ArgsUniform/Assigner.cs +++ b/Framework/ArgsUniform/Assigner.cs @@ -23,20 +23,38 @@ namespace ArgsUniform return false; } + public string DescribeDefaultFor(PropertyInfo property) + { + var obj = Activator.CreateInstance(); + var defaultValue = GetDefaultValue(obj, property); + if (defaultValue == null) return ""; + if (defaultValue is string str) + { + return "\"" + str + "\""; + } + return defaultValue.ToString() ?? string.Empty; + } + + private object? GetDefaultValue(T result, PropertyInfo uniformProperty) + { + // Get value from object's static initializer if it's there. + var currentValue = uniformProperty.GetValue(result); + if (currentValue != null) return currentValue; + + // Get value from defaults-provider object if it's there. + if (defaultsProvider == null) return null; + var defaultProperty = defaultsProvider.GetType().GetProperties().SingleOrDefault(p => p.Name == uniformProperty.Name); + if (defaultProperty == null) return null; + return defaultProperty.GetValue(defaultsProvider); + } + private bool AssignFromDefaultsIfAble(T result, PropertyInfo uniformProperty) { - var currentValue = uniformProperty.GetValue(result); - var isEmptryString = (currentValue as string) == string.Empty; - if (currentValue != GetDefaultValueForType(uniformProperty.PropertyType) && !isEmptryString) return true; - if (defaultsProvider == null) return false; - - var defaultProperty = defaultsProvider.GetType().GetProperties().SingleOrDefault(p => p.Name == uniformProperty.Name); - if (defaultProperty == null) return false; - - var value = defaultProperty.GetValue(defaultsProvider); - if (value != null) + var defaultValue = GetDefaultValue(result, uniformProperty); + var isEmptryString = (defaultValue as string) == string.Empty; + if (defaultValue != null && defaultValue != GetDefaultValueForType(uniformProperty.PropertyType) && !isEmptryString) { - return Assign(result, uniformProperty, value); + return Assign(result, uniformProperty, defaultValue); } return false; } diff --git a/Tools/BiblioTech/AdminChecker.cs b/Tools/BiblioTech/AdminChecker.cs index e1c82cda..def2870b 100644 --- a/Tools/BiblioTech/AdminChecker.cs +++ b/Tools/BiblioTech/AdminChecker.cs @@ -24,7 +24,7 @@ namespace BiblioTech public bool IsAdminChannel(IChannel channel) { - return channel.Name == Program.Config.AdminChannelName; + return channel.Id == Program.Config.AdminChannelId; } public ISocketMessageChannel GetAdminChannel() @@ -45,7 +45,7 @@ namespace BiblioTech private void UpdateAdminIds() { lastUpdate = DateTime.UtcNow; - var adminRole = guild.Roles.Single(r => r.Name == Program.Config.AdminRoleName); + var adminRole = guild.Roles.Single(r => r.Id == Program.Config.AdminRoleId); adminIds = adminRole.Members.Select(m => m.Id).ToArray(); } } diff --git a/Tools/BiblioTech/CommandHandler.cs b/Tools/BiblioTech/CommandHandler.cs index 79071773..c7263c5b 100644 --- a/Tools/BiblioTech/CommandHandler.cs +++ b/Tools/BiblioTech/CommandHandler.cs @@ -22,7 +22,7 @@ namespace BiblioTech private async Task Client_Ready() { - var guild = client.Guilds.Single(g => g.Name == Program.Config.ServerName); + var guild = client.Guilds.Single(g => g.Id == Program.Config.ServerId); Program.AdminChecker.SetGuild(guild); Program.Log.Log($"Initializing for guild: '{guild.Name}'"); diff --git a/Tools/BiblioTech/Configuration.cs b/Tools/BiblioTech/Configuration.cs index 73e143e8..9164cf7b 100644 --- a/Tools/BiblioTech/Configuration.cs +++ b/Tools/BiblioTech/Configuration.cs @@ -10,7 +10,7 @@ namespace BiblioTech [Uniform("server-id", "sn", "SERVERID", true, "ID of the Discord server")] public ulong ServerId { get; set; } - [Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")] + [Uniform("datapath", "dp", "DATAPATH", true, "Root path where all data files will be saved.")] public string DataPath { get; set; } = "datapath"; [Uniform("admin-role-id", "a", "ADMINROLEID", true, "ID of the Discord server admin role")] @@ -23,15 +23,15 @@ namespace BiblioTech public ulong RewardsChannelId { get; set; } [Uniform("chain-events-channel-id", "cc", "CHAINEVENTSCHANNELID", false, "ID of the Discord server channel where chain events will be posted.")] - public ulong ChainEventsChannelID { get; set; } + public ulong ChainEventsChannelId { get; set; } - [Uniform("reward-api-port", "rp", "REWARDAPIPORT", false, "TCP listen port for the reward API.")] + [Uniform("reward-api-port", "rp", "REWARDAPIPORT", true, "TCP listen port for the reward API.")] public int RewardApiPort { get; set; } = 31080; - [Uniform("send-eth", "se", "SENDETH", false, "Amount of Eth send by the mint command. Default: 10.")] + [Uniform("send-eth", "se", "SENDETH", true, "Amount of Eth send by the mint command.")] public int SendEth { get; set; } = 10; - [Uniform("mint-tt", "mt", "MINTTT", false, "Amount of TestTokens minted by the mint command. Default: 1073741824")] + [Uniform("mint-tt", "mt", "MINTTT", true, "Amount of TestTokens minted by the mint command.")] public int MintTT { get; set; } = 1073741824; public string EndpointsPath diff --git a/Tools/BiblioTech/Rewards/RoleDriver.cs b/Tools/BiblioTech/Rewards/RoleDriver.cs index 6695af32..f0ea48f7 100644 --- a/Tools/BiblioTech/Rewards/RoleDriver.cs +++ b/Tools/BiblioTech/Rewards/RoleDriver.cs @@ -16,8 +16,8 @@ namespace BiblioTech.Rewards { this.client = client; - rewardsChannel = GetChannel(Program.Config.RewardsChannelName); - eventsChannel = GetChannel(Program.Config.ChainEventsChannelName); + rewardsChannel = GetChannel(Program.Config.RewardsChannelId); + eventsChannel = GetChannel(Program.Config.ChainEventsChannelId); } public async Task GiveRewards(GiveRewardsCommand rewards) @@ -45,10 +45,10 @@ namespace BiblioTech.Rewards await context.ProcessGiveRewardsCommand(LookUpUsers(rewards)); } - private SocketTextChannel? GetChannel(string name) + private SocketTextChannel? GetChannel(ulong id) { - if (string.IsNullOrEmpty(name)) return null; - return GetGuild().TextChannels.SingleOrDefault(c => c.Name == name); + if (id == 0) return null; + return GetGuild().TextChannels.SingleOrDefault(c => c.Id == id); } private async Task ProcessChainEvents(string[] eventsOverview) @@ -147,11 +147,11 @@ namespace BiblioTech.Rewards private SocketGuild GetGuild() { - var guild = client.Guilds.SingleOrDefault(g => g.Name == Program.Config.ServerName); + var guild = client.Guilds.SingleOrDefault(g => g.Id == Program.Config.ServerId); if (guild == null) { - throw new Exception($"Unable to find guild by name: '{Program.Config.ServerName}'. " + - $"Known guilds: [{string.Join(",", client.Guilds.Select(g => g.Name))}]"); + throw new Exception($"Unable to find guild by id: '{Program.Config.ServerId}'. " + + $"Known guilds: [{string.Join(",", client.Guilds.Select(g => g.Name + " (" + g.Id + ")"))}]"); } return guild; } From 8847de116d91447f836d489debe419c717ff7944 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 16 May 2024 14:07:14 +0200 Subject: [PATCH 4/4] cleanup rewarder bot config --- Tools/TestNetRewarder/Configuration.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tools/TestNetRewarder/Configuration.cs b/Tools/TestNetRewarder/Configuration.cs index c180648f..c88a0aa8 100644 --- a/Tools/TestNetRewarder/Configuration.cs +++ b/Tools/TestNetRewarder/Configuration.cs @@ -4,16 +4,16 @@ namespace TestNetRewarder { public class Configuration { - [Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")] + [Uniform("datapath", "dp", "DATAPATH", true, "Root path where all data files will be saved.")] public string DataPath { get; set; } = "datapath"; [Uniform("discordbot-host", "dh", "DISCORDBOTHOST", true, "http address of the discord bot.")] public string DiscordHost { get; set; } = "host"; - [Uniform("discordbot-port", "dp", "DISCORDBOTPORT", true, "port number of the discord bot reward API. (31080 by default)")] + [Uniform("discordbot-port", "dp", "DISCORDBOTPORT", true, "port number of the discord bot reward API.")] public int DiscordPort { get; set; } = 31080; - [Uniform("interval-minutes", "im", "INTERVALMINUTES", false, "time in minutes between reward updates. (default 15)")] + [Uniform("interval-minutes", "im", "INTERVALMINUTES", true, "time in minutes between reward updates.")] public int IntervalMinutes { get; set; } = 15; [Uniform("check-history", "ch", "CHECKHISTORY", true, "Unix epoc timestamp of a moment in history on which processing begins. Required for hosting rewards. Should be 'launch of the testnet'.")] @@ -22,7 +22,7 @@ namespace TestNetRewarder [Uniform("market-insights", "mi", "MARKETINSIGHTS", false, "Semi-colon separated integers. Each represents a multiple of intervals, for which a market insights average will be generated.")] public string MarketInsights { get; set; } = "1;96"; - [Uniform("events-overview", "eo", "EVENTSOVERVIEW", false, "When greater than zero, chain event summary will be generated. (default 1)")] + [Uniform("events-overview", "eo", "EVENTSOVERVIEW", false, "When greater than zero, chain event summary will be generated.")] public int CreateChainEventsOverview { get; set; } = 1; public string LogPath