diff --git a/CHANGELOG.md b/CHANGELOG.md index 58820d7d6..dd8f203be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o +## [5.1.12] - 03.10.2024 + +### Added + +- Added support for `seq` for logging. If you fill in seq url and apiKey in creds.yml, bot will sends logs to it + +### Fixed + +- Fixed another bug in `.greet` / `.bye` system, which caused it to show wrong message on a wrong server occasionally + ## [5.1.11] - 03.10.2024 ### Added diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 6f89bd3ce..37bcbee65 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -25,7 +25,7 @@ public sealed class Bot : IBot public bool IsReady { get; private set; } public int ShardId { get; set; } - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly CommandService _commandService; private readonly DbService _db; @@ -42,6 +42,9 @@ public sealed class Bot : IBot _credsProvider = new BotCredsProvider(totalShards, credPath); _creds = _credsProvider.GetCreds(); + LogSetup.SetupLogger(shardId, _creds); + Log.Information("Pid: {ProcessId}", Environment.ProcessId); + _db = new NadekoDbService(_credsProvider); var messageCacheSize = @@ -115,7 +118,7 @@ public sealed class Bot : IBot // svcs.Components.Remove(); // svcs.Components.Add(); - svcs.AddSingleton(_ => _credsProvider.GetCreds()); + svcs.AddSingleton(_ => _credsProvider.GetCreds()); svcs.AddSingleton(_db); svcs.AddSingleton(_credsProvider); svcs.AddSingleton(Client); diff --git a/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs b/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs index efa869778..541a0ea10 100644 --- a/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs +++ b/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs @@ -208,11 +208,11 @@ public class GreetService : INService, IReadyExecutor return Task.CompletedTask; } - private TypedKey GreetSettingsKey(GreetType type) - => new($"greet_settings:{type}"); + private TypedKey GreetSettingsKey(ulong gid, GreetType type) + => new($"greet_settings:{gid}:{type}"); public async Task GetGreetSettingsAsync(ulong gid, GreetType type) - => await _cache.GetOrAddAsync(GreetSettingsKey(type), + => await _cache.GetOrAddAsync(GreetSettingsKey(gid, type), () => InternalGetGreetSettingsAsync(gid, type), TimeSpan.FromSeconds(3)); diff --git a/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs b/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs index e26c30b64..e89c79ff7 100644 --- a/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs @@ -13,7 +13,7 @@ public sealed class ReactionRolesService : IReadyExecutor, INService, IReactionR { private readonly DbService _db; private readonly DiscordSocketClient _client; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private ConcurrentDictionary> _cache; private readonly object _cacheLock = new(); @@ -24,7 +24,7 @@ public sealed class ReactionRolesService : IReadyExecutor, INService, IReactionR DiscordSocketClient client, IPatronageService ps, DbService db, - IBotCredentials creds) + IBotCreds creds) { _db = db; _client = client; diff --git a/src/NadekoBot/Modules/Administration/Role/StickyRolesService.cs b/src/NadekoBot/Modules/Administration/Role/StickyRolesService.cs index aa12fc451..ceef11717 100644 --- a/src/NadekoBot/Modules/Administration/Role/StickyRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Role/StickyRolesService.cs @@ -9,13 +9,13 @@ namespace NadekoBot.Modules.Administration; public sealed class StickyRolesService : INService, IReadyExecutor { private readonly DiscordSocketClient _client; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DbService _db; private HashSet _stickyRoles = new(); public StickyRolesService( DiscordSocketClient client, - IBotCredentials creds, + IBotCreds creds, DbService db) { _client = client; diff --git a/src/NadekoBot/Modules/Administration/Self/SelfService.cs b/src/NadekoBot/Modules/Administration/Self/SelfService.cs index b2fa1143b..0a7214494 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfService.cs @@ -15,7 +15,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService private readonly IBotStrings _strings; private readonly DiscordSocketClient _client; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private ImmutableDictionary ownerChannels = new Dictionary().ToImmutableDictionary(); @@ -36,7 +36,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService CommandHandler cmdHandler, DbService db, IBotStrings strings, - IBotCredentials creds, + IBotCreds creds, IHttpClientFactory factory, BotConfigService bss, IPubSub pubSub, diff --git a/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs b/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs index 308da6d73..c2c5a9555 100644 --- a/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs +++ b/src/NadekoBot/Modules/Expressions/NadekoExpressions.cs @@ -12,10 +12,10 @@ public partial class NadekoExpressions : NadekoModule All } - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IHttpClientFactory _clientFactory; - public NadekoExpressions(IBotCredentials creds, IHttpClientFactory clientFactory) + public NadekoExpressions(IBotCreds creds, IHttpClientFactory clientFactory) { _creds = creds; _clientFactory = clientFactory; diff --git a/src/NadekoBot/Modules/Gambling/VoteRewardService.cs b/src/NadekoBot/Modules/Gambling/VoteRewardService.cs index 1a92cefdb..b3e9b8515 100644 --- a/src/NadekoBot/Modules/Gambling/VoteRewardService.cs +++ b/src/NadekoBot/Modules/Gambling/VoteRewardService.cs @@ -14,13 +14,13 @@ public class VoteModel public class VoteRewardService : INService, IReadyExecutor { private readonly DiscordSocketClient _client; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly ICurrencyService _currencyService; private readonly GamblingConfigService _gamb; public VoteRewardService( DiscordSocketClient client, - IBotCredentials creds, + IBotCreds creds, ICurrencyService currencyService, GamblingConfigService gamb) { diff --git a/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs index dc11e32f9..87e871fe6 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/WaifuService.cs @@ -15,7 +15,7 @@ public class WaifuService : INService, IReadyExecutor private readonly ICurrencyService _cs; private readonly IBotCache _cache; private readonly GamblingConfigService _gss; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DiscordSocketClient _client; public WaifuService( @@ -23,7 +23,7 @@ public class WaifuService : INService, IReadyExecutor ICurrencyService cs, IBotCache cache, GamblingConfigService gss, - IBotCredentials creds, + IBotCreds creds, DiscordSocketClient client) { _db = db; diff --git a/src/NadekoBot/Modules/Games/ChatterBot/ChatterBotService.cs b/src/NadekoBot/Modules/Games/ChatterBot/ChatterBotService.cs index 02791d157..223bd097c 100644 --- a/src/NadekoBot/Modules/Games/ChatterBot/ChatterBotService.cs +++ b/src/NadekoBot/Modules/Games/ChatterBot/ChatterBotService.cs @@ -19,7 +19,7 @@ public class ChatterBotService : IExecOnMessage private readonly DiscordSocketClient _client; private readonly IPermissionChecker _perms; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IHttpClientFactory _httpFactory; private readonly GamesConfigService _gcs; private readonly IMessageSenderService _sender; @@ -32,7 +32,7 @@ public class ChatterBotService : IExecOnMessage IBot bot, IPatronageService ps, IHttpClientFactory factory, - IBotCredentials creds, + IBotCreds creds, GamesConfigService gcs, IMessageSenderService sender, DbService db) diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index b594c914b..ad3443ef9 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -12,9 +12,9 @@ public sealed partial class Music { private static readonly SemaphoreSlim _playlistLock = new(1, 1); private readonly DbService _db; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; - public PlaylistCommands(DbService db, IBotCredentials creds) + public PlaylistCommands(DbService db, IBotCreds creds) { _db = db; _creds = creds; diff --git a/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs b/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs index 4f86459fe..33bcd09b7 100644 --- a/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs +++ b/src/NadekoBot/Modules/Searches/Crypto/CryptoService.cs @@ -16,11 +16,11 @@ public class CryptoService : INService { private readonly IBotCache _cache; private readonly IHttpClientFactory _httpFactory; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly SemaphoreSlim _getCryptoLock = new(1, 1); - public CryptoService(IBotCache cache, IHttpClientFactory httpFactory, IBotCredentials creds) + public CryptoService(IBotCache cache, IHttpClientFactory httpFactory, IBotCreds creds) { _cache = cache; _httpFactory = httpFactory; diff --git a/src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs b/src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs index 91555a544..21cc83247 100644 --- a/src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs +++ b/src/NadekoBot/Modules/Searches/Osu/OsuCommands.cs @@ -9,10 +9,10 @@ public partial class Searches [Group] public partial class OsuCommands : NadekoModule { - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IHttpClientFactory _httpFactory; - public OsuCommands(IBotCredentials creds, IHttpClientFactory factory) + public OsuCommands(IBotCreds creds, IHttpClientFactory factory) { _creds = creds; _httpFactory = factory; diff --git a/src/NadekoBot/Modules/Searches/Osu/OsuService.cs b/src/NadekoBot/Modules/Searches/Osu/OsuService.cs index 5f1b8bc6a..49fb5cec9 100644 --- a/src/NadekoBot/Modules/Searches/Osu/OsuService.cs +++ b/src/NadekoBot/Modules/Searches/Osu/OsuService.cs @@ -7,9 +7,9 @@ namespace NadekoBot.Modules.Searches; public sealed class OsuService : INService { private readonly IHttpClientFactory _httpFactory; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; - public OsuService(IHttpClientFactory httpFactory, IBotCredentials creds) + public OsuService(IHttpClientFactory httpFactory, IBotCreds creds) { _httpFactory = httpFactory; _creds = creds; diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 581537932..369496acf 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -13,14 +13,14 @@ namespace NadekoBot.Modules.Searches; public partial class Searches : NadekoModule { - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IGoogleApiService _google; private readonly IHttpClientFactory _httpFactory; private readonly IMemoryCache _cache; private readonly ITimezoneService _tzSvc; public Searches( - IBotCredentials creds, + IBotCreds creds, IGoogleApiService google, IHttpClientFactory factory, IMemoryCache cache, diff --git a/src/NadekoBot/Modules/Utility/Giveaway/GiveawayService.cs b/src/NadekoBot/Modules/Utility/Giveaway/GiveawayService.cs index 2de27ec9e..6c34fc476 100644 --- a/src/NadekoBot/Modules/Utility/Giveaway/GiveawayService.cs +++ b/src/NadekoBot/Modules/Utility/Giveaway/GiveawayService.cs @@ -11,7 +11,7 @@ public sealed class GiveawayService : INService, IReadyExecutor public static string GiveawayEmoji = "🎉"; private readonly DbService _db; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DiscordSocketClient _client; private readonly IMessageSenderService _sender; private readonly IBotStrings _strings; @@ -20,7 +20,7 @@ public sealed class GiveawayService : INService, IReadyExecutor private SortedSet _giveawayCache = new SortedSet(); private readonly NadekoRandom _rng; - public GiveawayService(DbService db, IBotCredentials creds, DiscordSocketClient client, + public GiveawayService(DbService db, IBotCreds creds, DiscordSocketClient client, IMessageSenderService sender, IBotStrings strings, ILocalization localization, IMemoryCache cache) { _db = db; diff --git a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs index 4f395c6cf..c6f84951a 100644 --- a/src/NadekoBot/Modules/Utility/Remind/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Remind/RemindService.cs @@ -17,14 +17,14 @@ public class RemindService : INService, IReadyExecutor, IRemindService private readonly DiscordSocketClient _client; private readonly DbService _db; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IMessageSenderService _sender; private readonly CultureInfo _culture; public RemindService( DiscordSocketClient client, DbService db, - IBotCredentials creds, + IBotCreds creds, IMessageSenderService sender) { _client = client; diff --git a/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs index 7c96650dd..3b1b3a2bc 100644 --- a/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Repeater/RepeaterService.cs @@ -12,7 +12,7 @@ public sealed class RepeaterService : IReadyExecutor, INService private readonly DbService _db; private readonly IReplacementService _repSvc; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DiscordSocketClient _client; private readonly LinkedList _repeaterQueue; private readonly ConcurrentHashSet _noRedundant; @@ -25,7 +25,7 @@ public sealed class RepeaterService : IReadyExecutor, INService DiscordSocketClient client, DbService db, IReplacementService repSvc, - IBotCredentials creds, + IBotCreds creds, IMessageSenderService sender) { _db = db; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 39370c332..5d7a9d56b 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -34,7 +34,7 @@ public partial class Utility : NadekoModule private readonly DiscordSocketClient _client; private readonly ICoordinator _coord; private readonly IStatsService _stats; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DownloadTracker _tracker; private readonly IHttpClientFactory _httpFactory; private readonly VerboseErrorsService _veService; @@ -45,7 +45,7 @@ public partial class Utility : NadekoModule DiscordSocketClient client, ICoordinator coord, IStatsService stats, - IBotCredentials creds, + IBotCreds creds, DownloadTracker tracker, IHttpClientFactory httpFactory, VerboseErrorsService veService, diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index b11371fac..81b7d2654 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -25,7 +25,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand private readonly IImageCache _images; private readonly IBotStrings _strings; private readonly FontProvider _fonts; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly ICurrencyService _cs; private readonly IHttpClientFactory _httpFactory; private readonly XpConfigService _xpConfig; @@ -55,7 +55,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand IImageCache images, IBotCache c, FontProvider fonts, - IBotCredentials creds, + IBotCreds creds, ICurrencyService cs, IHttpClientFactory http, XpConfigService xpConfig, diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 466544eb7..8a539eab2 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -4,7 +4,7 @@ enable true en - 5.1.11 + 5.1.12 $(MSBuildProjectDirectory) diff --git a/src/NadekoBot/Program.cs b/src/NadekoBot/Program.cs index 53b8fcde5..88c7c8d2f 100644 --- a/src/NadekoBot/Program.cs +++ b/src/NadekoBot/Program.cs @@ -1,5 +1,3 @@ -var pid = Environment.ProcessId; - var shardId = 0; int? totalShards = null; // 0 to read from creds.yml if (args.Length > 0 && args[0] != "run") @@ -22,7 +20,5 @@ if (args.Length > 0 && args[0] != "run") } } -LogSetup.SetupLogger(shardId); -Log.Information("Pid: {ProcessId}", pid); await new Bot(shardId, totalShards, Environment.GetEnvironmentVariable("NadekoBot__creds")).RunAndBlockAsync(); \ No newline at end of file diff --git a/src/NadekoBot/_common/Abstractions/Helpers/LogSetup.cs b/src/NadekoBot/_common/Abstractions/Helpers/LogSetup.cs index 32f104d6e..8baf750ce 100644 --- a/src/NadekoBot/_common/Abstractions/Helpers/LogSetup.cs +++ b/src/NadekoBot/_common/Abstractions/Helpers/LogSetup.cs @@ -6,9 +6,9 @@ namespace Nadeko.Common; public static class LogSetup { - public static void SetupLogger(object source) + public static void SetupLogger(object source, IBotCreds creds) { - Log.Logger = new LoggerConfiguration().MinimumLevel.Override("Microsoft", LogEventLevel.Information) + var config = new LoggerConfiguration().MinimumLevel.Override("Microsoft", LogEventLevel.Information) .MinimumLevel.Override("System", LogEventLevel.Information) .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) .Enrich.FromLogContext() @@ -16,8 +16,13 @@ public static class LogSetup theme: GetTheme(), outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] | #{LogSource} | {Message:lj}{NewLine}{Exception}") - .Enrich.WithProperty("LogSource", source) - .CreateLogger(); + .Enrich.WithProperty("LogSource", source); + + if (!string.IsNullOrWhiteSpace(creds.Seq.Url)) + config = config.WriteTo.Seq(creds.Seq.Url, apiKey: creds.Seq.ApiKey); + + Log.Logger = config + .CreateLogger(); Console.OutputEncoding = Encoding.UTF8; } diff --git a/src/NadekoBot/_common/Abstractions/creds/IBotCredentials.cs b/src/NadekoBot/_common/Abstractions/creds/IBotCreds.cs similarity index 97% rename from src/NadekoBot/_common/Abstractions/creds/IBotCredentials.cs rename to src/NadekoBot/_common/Abstractions/creds/IBotCreds.cs index 8236dfc98..5178cbb74 100644 --- a/src/NadekoBot/_common/Abstractions/creds/IBotCredentials.cs +++ b/src/NadekoBot/_common/Abstractions/creds/IBotCreds.cs @@ -1,7 +1,7 @@ #nullable disable namespace NadekoBot; -public interface IBotCredentials +public interface IBotCreds { string Token { get; } string NadekoAiToken { get; } @@ -30,6 +30,7 @@ public interface IBotCredentials GoogleApiConfig Google { get; set; } BotCacheImplemenation BotCache { get; set; } Creds.GrpcApiConfig GrpcApi { get; set; } + SeqConfig Seq { get; set; } } public interface IVotesSettings diff --git a/src/NadekoBot/_common/Abstractions/creds/IBotCredsProvider.cs b/src/NadekoBot/_common/Abstractions/creds/IBotCredsProvider.cs index 97568583d..7f4c2bd0a 100644 --- a/src/NadekoBot/_common/Abstractions/creds/IBotCredsProvider.cs +++ b/src/NadekoBot/_common/Abstractions/creds/IBotCredsProvider.cs @@ -3,6 +3,6 @@ public interface IBotCredsProvider { public void Reload(); - public IBotCredentials GetCreds(); - public void ModifyCredsFile(Action func); + public IBotCreds GetCreds(); + public void ModifyCredsFile(Action func); } \ No newline at end of file diff --git a/src/NadekoBot/_common/Configs/BotConfig.cs b/src/NadekoBot/_common/Configs/BotConfig.cs index 36d87bc9e..ce747548d 100644 --- a/src/NadekoBot/_common/Configs/BotConfig.cs +++ b/src/NadekoBot/_common/Configs/BotConfig.cs @@ -29,7 +29,7 @@ public sealed partial class BotConfig : ICloneable public CultureInfo DefaultLocale { get; set; } [Comment(""" - Style in which executed commands will show up in the console. + Style in which executed commands will show up in the logs. Allowed values: Simple, Normal, None """)] public ConsoleOutputType ConsoleOutputType { get; set; } diff --git a/src/NadekoBot/_common/Creds.cs b/src/NadekoBot/_common/Creds.cs index 9850aa0d0..3d68c263b 100644 --- a/src/NadekoBot/_common/Creds.cs +++ b/src/NadekoBot/_common/Creds.cs @@ -3,10 +3,10 @@ using NadekoBot.Common.Yml; namespace NadekoBot.Common; -public sealed class Creds : IBotCredentials +public sealed class Creds : IBotCreds { [Comment("""DO NOT CHANGE""")] - public int Version { get; set; } = 10; + public int Version { get; set; } = 11; [Comment("""Bot token. Do not share with anyone ever -> https://discordapp.com/developers/applications/""")] public string Token { get; set; } @@ -163,6 +163,11 @@ public sealed class Creds : IBotCredentials """)] public GrpcApiConfig GrpcApi { get; set; } + [Comment(""" + Url to + """)] + public SeqConfig Seq { get; set; } + public Creds() { Token = string.Empty; @@ -188,7 +193,8 @@ public sealed class Creds : IBotCredentials RestartCommand = new RestartConfig(); Google = new GoogleApiConfig(); - GrpcApi = new GrpcApiConfig(); + GrpcApi = new(); + Seq = new(); } public class DbOptions @@ -293,6 +299,12 @@ public sealed class Creds : IBotCredentials } } +public sealed class SeqConfig +{ + public string Url { get; init; } + public string ApiKey { get; init; } +} + public class GoogleApiConfig : IGoogleApiConfig { public string SearchId { get; init; } diff --git a/src/NadekoBot/_common/Impl/BotCredsProvider.cs b/src/NadekoBot/_common/Impl/BotCredsProvider.cs index a4cd337a3..b291aab25 100644 --- a/src/NadekoBot/_common/Impl/BotCredsProvider.cs +++ b/src/NadekoBot/_common/Impl/BotCredsProvider.cs @@ -119,7 +119,7 @@ public sealed class BotCredsProvider : IBotCredsProvider } } - public void ModifyCredsFile(Action func) + public void ModifyCredsFile(Action func) { var ymlData = File.ReadAllText(CREDS_FILE_NAME); var creds = Yaml.Deserializer.Deserialize(ymlData); @@ -137,18 +137,18 @@ public sealed class BotCredsProvider : IBotCredsProvider var creds = Yaml.Deserializer.Deserialize(File.ReadAllText(CREDS_FILE_NAME)); if (creds.Version <= 5) { - creds.BotCache = BotCacheImplemenation.Redis; + creds.BotCache = BotCacheImplemenation.Memory; } - if (creds.Version <= 9) + if (creds.Version < 11) { - creds.Version = 10; + creds.Version = 11; File.WriteAllText(CREDS_FILE_NAME, Yaml.Serializer.Serialize(creds)); } } } - public IBotCredentials GetCreds() + public IBotCreds GetCreds() { lock (_reloadLock) { diff --git a/src/NadekoBot/_common/Impl/PubSub/RedisPubSub.cs b/src/NadekoBot/_common/Impl/PubSub/RedisPubSub.cs index 8635ec027..97901d814 100644 --- a/src/NadekoBot/_common/Impl/PubSub/RedisPubSub.cs +++ b/src/NadekoBot/_common/Impl/PubSub/RedisPubSub.cs @@ -4,11 +4,11 @@ namespace NadekoBot.Common; public sealed class RedisPubSub : IPubSub { - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly ConnectionMultiplexer _multi; private readonly ISeria _serializer; - public RedisPubSub(ConnectionMultiplexer multi, ISeria serializer, IBotCredentials creds) + public RedisPubSub(ConnectionMultiplexer multi, ISeria serializer, IBotCreds creds) { _multi = multi; _serializer = serializer; diff --git a/src/NadekoBot/_common/Impl/RedisBotStringsProvider.cs b/src/NadekoBot/_common/Impl/RedisBotStringsProvider.cs index d86f1421c..4af92a5f6 100644 --- a/src/NadekoBot/_common/Impl/RedisBotStringsProvider.cs +++ b/src/NadekoBot/_common/Impl/RedisBotStringsProvider.cs @@ -15,13 +15,13 @@ public class RedisBotStringsProvider : IBotStringsProvider private readonly ConnectionMultiplexer _redis; private readonly IStringsSource _source; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; public RedisBotStringsProvider( ConnectionMultiplexer redis, DiscordSocketClient discordClient, IStringsSource source, - IBotCredentials creds) + IBotCreds creds) { _redis = redis; _source = source; diff --git a/src/NadekoBot/_common/Impl/RemoteGrpcCoordinator.cs b/src/NadekoBot/_common/Impl/RemoteGrpcCoordinator.cs index 62df7afd6..ed395dac4 100644 --- a/src/NadekoBot/_common/Impl/RemoteGrpcCoordinator.cs +++ b/src/NadekoBot/_common/Impl/RemoteGrpcCoordinator.cs @@ -11,7 +11,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor private readonly Coordinator.Coordinator.CoordinatorClient _coordClient; private readonly DiscordSocketClient _client; - public RemoteGrpcCoordinator(IBotCredentials creds, DiscordSocketClient client) + public RemoteGrpcCoordinator(IBotCreds creds, DiscordSocketClient client) { var coordUrl = string.IsNullOrWhiteSpace(creds.CoordinatorUrl) ? "http://localhost:3442" : creds.CoordinatorUrl; diff --git a/src/NadekoBot/_common/ServiceCollectionExtensions.cs b/src/NadekoBot/_common/ServiceCollectionExtensions.cs index 046888f27..a63f55af3 100644 --- a/src/NadekoBot/_common/ServiceCollectionExtensions.cs +++ b/src/NadekoBot/_common/ServiceCollectionExtensions.cs @@ -61,7 +61,7 @@ public static class ServiceCollectionExtensions return svcs; } - public static IContainer AddCache(this IContainer cont, IBotCredentials creds) + public static IContainer AddCache(this IContainer cont, IBotCreds creds) { if (creds.BotCache == BotCacheImplemenation.Redis) { diff --git a/src/NadekoBot/_common/Services/Impl/BlacklistService.cs b/src/NadekoBot/_common/Services/Impl/BlacklistService.cs index d77fea96b..315b7dd47 100644 --- a/src/NadekoBot/_common/Services/Impl/BlacklistService.cs +++ b/src/NadekoBot/_common/Services/Impl/BlacklistService.cs @@ -14,12 +14,12 @@ public sealed class BlacklistService : IExecOnMessage private readonly DbService _db; private readonly IPubSub _pubSub; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private IReadOnlyList blacklist; private readonly TypedKey _blPubKey = new("blacklist.reload"); - public BlacklistService(DbService db, IPubSub pubSub, IBotCredentials creds) + public BlacklistService(DbService db, IPubSub pubSub, IBotCreds creds) { _db = db; _pubSub = pubSub; diff --git a/src/NadekoBot/_common/Services/Impl/SingleProcessCoordinator.cs b/src/NadekoBot/_common/Services/Impl/SingleProcessCoordinator.cs index 8c43de83a..5ae4c3994 100644 --- a/src/NadekoBot/_common/Services/Impl/SingleProcessCoordinator.cs +++ b/src/NadekoBot/_common/Services/Impl/SingleProcessCoordinator.cs @@ -5,10 +5,10 @@ namespace NadekoBot.Services; public class SingleProcessCoordinator : ICoordinator { - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DiscordSocketClient _client; - public SingleProcessCoordinator(IBotCredentials creds, DiscordSocketClient client) + public SingleProcessCoordinator(IBotCreds creds, DiscordSocketClient client) { _creds = creds; _client = client; diff --git a/src/NadekoBot/_common/Services/Impl/StatsService.cs b/src/NadekoBot/_common/Services/Impl/StatsService.cs index 476f715b8..03deab65e 100644 --- a/src/NadekoBot/_common/Services/Impl/StatsService.cs +++ b/src/NadekoBot/_common/Services/Impl/StatsService.cs @@ -29,7 +29,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService private readonly Process _currentProcess = Process.GetCurrentProcess(); private readonly DiscordSocketClient _client; - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly DateTime _started; private long textChannels; @@ -42,7 +42,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService public StatsService( DiscordSocketClient client, CommandHandler cmdHandler, - IBotCredentials creds, + IBotCreds creds, IHttpClientFactory factory) { _client = client; diff --git a/src/NadekoBot/_common/_Extensions/BotCredentialsExtensions.cs b/src/NadekoBot/_common/_Extensions/BotCredentialsExtensions.cs index 14b65c1d6..07f39df2f 100644 --- a/src/NadekoBot/_common/_Extensions/BotCredentialsExtensions.cs +++ b/src/NadekoBot/_common/_Extensions/BotCredentialsExtensions.cs @@ -2,9 +2,9 @@ namespace NadekoBot.Extensions; public static class BotCredentialsExtensions { - public static bool IsOwner(this IBotCredentials creds, IUser user) + public static bool IsOwner(this IBotCreds creds, IUser user) => creds.IsOwner(user.Id); - public static bool IsOwner(this IBotCredentials creds, ulong userId) + public static bool IsOwner(this IBotCreds creds, ulong userId) => creds.OwnerIds.Contains(userId); } \ No newline at end of file diff --git a/src/NadekoBot/_common/_Extensions/Extensions.cs b/src/NadekoBot/_common/_Extensions/Extensions.cs index 6e0d2273b..122721675 100644 --- a/src/NadekoBot/_common/_Extensions/Extensions.cs +++ b/src/NadekoBot/_common/_Extensions/Extensions.cs @@ -103,7 +103,7 @@ public static class Extensions /// /// First 10 characters of teh bot token. /// - public static string RedisKey(this IBotCredentials bc) + public static string RedisKey(this IBotCreds bc) => bc.Token[..10]; public static bool IsAuthor(this IMessage msg, IDiscordClient client)