From 487c7865cb5c53423af75b3155d1d6595a0a42c9 Mon Sep 17 00:00:00 2001 From: Toastie Date: Sat, 5 Oct 2024 11:44:44 +1300 Subject: [PATCH] Fixed greet/bye messages showing wrong message in the wrong server sometimes Fixed the check for updates service Version upped to 5.1.12. Updated CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ src/EllieBot/Bot.cs | 7 +++++-- src/EllieBot/EllieBot.csproj | 2 +- .../Administration/GreetBye/GreetService.cs | 6 +++--- .../Role/ReactionRolesService.cs | 4 ++-- .../Administration/Role/StickyRolesService.cs | 4 ++-- .../Self/CheckForUpdatesService.cs | 2 +- .../Modules/Administration/Self/SelfService.cs | 4 ++-- .../Modules/Expressions/EllieExpressions.cs | 4 ++-- .../Modules/Gambling/VoteRewardService.cs | 4 ++-- .../Modules/Gambling/Waifus/WaifuService.cs | 4 ++-- .../Games/ChatterBot/ChatterBotService.cs | 4 ++-- src/EllieBot/Modules/Music/PlaylistCommands.cs | 4 ++-- .../Modules/Searches/Crypto/CryptoService.cs | 4 ++-- .../Modules/Searches/Osu/OsuCommands.cs | 4 ++-- .../Modules/Searches/Osu/OsuService.cs | 4 ++-- src/EllieBot/Modules/Searches/Searches.cs | 4 ++-- .../Utility/Giveaway/GiveawayService.cs | 4 ++-- .../Modules/Utility/Remind/RemindService.cs | 4 ++-- .../Utility/Repeater/RepeaterService.cs | 4 ++-- src/EllieBot/Modules/Utility/Utility.cs | 4 ++-- src/EllieBot/Modules/Xp/XpService.cs | 4 ++-- src/EllieBot/Program.cs | 6 +----- .../_common/Abstractions/Helpers/LogSetup.cs | 13 +++++++++---- .../creds/{IBotCredentials.cs => IBotCreds.cs} | 3 ++- .../Abstractions/creds/IBotCredsProvider.cs | 4 ++-- src/EllieBot/_common/Configs/BotConfig.cs | 2 +- src/EllieBot/_common/Creds.cs | 18 +++++++++++++++--- src/EllieBot/_common/Impl/BotCredsProvider.cs | 4 ++-- .../_common/Impl/PubSub/RedisPubSub.cs | 4 ++-- .../_common/Impl/RedisBotStringsProvider.cs | 4 ++-- .../_common/Impl/RemoteGrpcCoordinator.cs | 2 +- .../_common/ServiceCollectionExtensions.cs | 2 +- .../_common/Services/Impl/BlacklistService.cs | 4 ++-- .../Services/Impl/SingleProcessCoordinator.cs | 4 ++-- .../_common/Services/Impl/StatsService.cs | 4 ++-- .../_Extensions/BotCredentialsExtensions.cs | 4 ++-- src/EllieBot/_common/_Extensions/Extensions.cs | 2 +- 38 files changed, 101 insertions(+), 74 deletions(-) rename src/EllieBot/_common/Abstractions/creds/{IBotCredentials.cs => IBotCreds.cs} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1abbf..11a1e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.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/EllieBot/Bot.cs b/src/EllieBot/Bot.cs index af69cee..a98ebcd 100644 --- a/src/EllieBot/Bot.cs +++ b/src/EllieBot/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 EllieDbService(_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/EllieBot/EllieBot.csproj b/src/EllieBot/EllieBot.csproj index 6c88f77..3a496b0 100644 --- a/src/EllieBot/EllieBot.csproj +++ b/src/EllieBot/EllieBot.csproj @@ -4,7 +4,7 @@ enable true en - 5.1.11 + 5.1.12 $(MSBuildProjectDirectory) diff --git a/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs b/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs index b89b8cd..a6ea2d4 100644 --- a/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs +++ b/src/EllieBot/Modules/Administration/GreetBye/GreetService.cs @@ -208,11 +208,11 @@ public class GreetService : IEService, 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/EllieBot/Modules/Administration/Role/ReactionRolesService.cs b/src/EllieBot/Modules/Administration/Role/ReactionRolesService.cs index caa3e19..f8550ed 100644 --- a/src/EllieBot/Modules/Administration/Role/ReactionRolesService.cs +++ b/src/EllieBot/Modules/Administration/Role/ReactionRolesService.cs @@ -13,7 +13,7 @@ public sealed class ReactionRolesService : IReadyExecutor, IEService, 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, IEService, IReactionR DiscordSocketClient client, IPatronageService ps, DbService db, - IBotCredentials creds) + IBotCreds creds) { _db = db; _client = client; diff --git a/src/EllieBot/Modules/Administration/Role/StickyRolesService.cs b/src/EllieBot/Modules/Administration/Role/StickyRolesService.cs index ede5b63..5147daf 100644 --- a/src/EllieBot/Modules/Administration/Role/StickyRolesService.cs +++ b/src/EllieBot/Modules/Administration/Role/StickyRolesService.cs @@ -9,13 +9,13 @@ namespace EllieBot.Modules.Administration; public sealed class StickyRolesService : IEService, 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/EllieBot/Modules/Administration/Self/CheckForUpdatesService.cs b/src/EllieBot/Modules/Administration/Self/CheckForUpdatesService.cs index 4b782dd..66cac5b 100644 --- a/src/EllieBot/Modules/Administration/Self/CheckForUpdatesService.cs +++ b/src/EllieBot/Modules/Administration/Self/CheckForUpdatesService.cs @@ -19,7 +19,7 @@ public sealed class CheckForUpdatesService : IEService, IReadyExecutor private readonly IMessageSenderService _sender; - private const string RELEASES_URL = "https://toastielab.dev/Emotions-stuff/elliebot/releases"; + private const string RELEASES_URL = "https://toastielab.dev/api/v1/repos/Emotions-stuff/elliebot/releases"; public CheckForUpdatesService( BotConfigService bcs, diff --git a/src/EllieBot/Modules/Administration/Self/SelfService.cs b/src/EllieBot/Modules/Administration/Self/SelfService.cs index bbed3f7..0707005 100644 --- a/src/EllieBot/Modules/Administration/Self/SelfService.cs +++ b/src/EllieBot/Modules/Administration/Self/SelfService.cs @@ -15,7 +15,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, IEService 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, IEService CommandHandler cmdHandler, DbService db, IBotStrings strings, - IBotCredentials creds, + IBotCreds creds, IHttpClientFactory factory, BotConfigService bss, IPubSub pubSub, diff --git a/src/EllieBot/Modules/Expressions/EllieExpressions.cs b/src/EllieBot/Modules/Expressions/EllieExpressions.cs index ddb3624..a90b52a 100644 --- a/src/EllieBot/Modules/Expressions/EllieExpressions.cs +++ b/src/EllieBot/Modules/Expressions/EllieExpressions.cs @@ -11,10 +11,10 @@ public partial class EllieExpressions : EllieModule All } - private readonly IBotCredentials _creds; + private readonly IBotCreds _creds; private readonly IHttpClientFactory _clientFactory; - public EllieExpressions(IBotCredentials creds, IHttpClientFactory clientFactory) + public EllieExpressions(IBotCreds creds, IHttpClientFactory clientFactory) { _creds = creds; _clientFactory = clientFactory; diff --git a/src/EllieBot/Modules/Gambling/VoteRewardService.cs b/src/EllieBot/Modules/Gambling/VoteRewardService.cs index 62d861b..6886102 100644 --- a/src/EllieBot/Modules/Gambling/VoteRewardService.cs +++ b/src/EllieBot/Modules/Gambling/VoteRewardService.cs @@ -14,13 +14,13 @@ public class VoteModel public class VoteRewardService : IEService, 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/EllieBot/Modules/Gambling/Waifus/WaifuService.cs b/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs index 9bbce79..58a27fb 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs @@ -15,7 +15,7 @@ public class WaifuService : IEService, 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 : IEService, IReadyExecutor ICurrencyService cs, IBotCache cache, GamblingConfigService gss, - IBotCredentials creds, + IBotCreds creds, DiscordSocketClient client) { _db = db; diff --git a/src/EllieBot/Modules/Games/ChatterBot/ChatterBotService.cs b/src/EllieBot/Modules/Games/ChatterBot/ChatterBotService.cs index b1ca50c..b18b75b 100644 --- a/src/EllieBot/Modules/Games/ChatterBot/ChatterBotService.cs +++ b/src/EllieBot/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/EllieBot/Modules/Music/PlaylistCommands.cs b/src/EllieBot/Modules/Music/PlaylistCommands.cs index d64e931..68a651d 100644 --- a/src/EllieBot/Modules/Music/PlaylistCommands.cs +++ b/src/EllieBot/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/EllieBot/Modules/Searches/Crypto/CryptoService.cs b/src/EllieBot/Modules/Searches/Crypto/CryptoService.cs index 0ffd422..8bfeb8d 100644 --- a/src/EllieBot/Modules/Searches/Crypto/CryptoService.cs +++ b/src/EllieBot/Modules/Searches/Crypto/CryptoService.cs @@ -16,11 +16,11 @@ public class CryptoService : IEService { 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/EllieBot/Modules/Searches/Osu/OsuCommands.cs b/src/EllieBot/Modules/Searches/Osu/OsuCommands.cs index f122c33..81f354a 100644 --- a/src/EllieBot/Modules/Searches/Osu/OsuCommands.cs +++ b/src/EllieBot/Modules/Searches/Osu/OsuCommands.cs @@ -9,10 +9,10 @@ public partial class Searches [Group] public partial class OsuCommands : EllieModule { - 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/EllieBot/Modules/Searches/Osu/OsuService.cs b/src/EllieBot/Modules/Searches/Osu/OsuService.cs index 18327c9..9bdb319 100644 --- a/src/EllieBot/Modules/Searches/Osu/OsuService.cs +++ b/src/EllieBot/Modules/Searches/Osu/OsuService.cs @@ -7,9 +7,9 @@ namespace EllieBot.Modules.Searches; public sealed class OsuService : IEService { 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/EllieBot/Modules/Searches/Searches.cs b/src/EllieBot/Modules/Searches/Searches.cs index 70e2556..ac7e60a 100644 --- a/src/EllieBot/Modules/Searches/Searches.cs +++ b/src/EllieBot/Modules/Searches/Searches.cs @@ -13,14 +13,14 @@ namespace EllieBot.Modules.Searches; public partial class Searches : EllieModule { - 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/EllieBot/Modules/Utility/Giveaway/GiveawayService.cs b/src/EllieBot/Modules/Utility/Giveaway/GiveawayService.cs index 200c88a..0a0cf51 100644 --- a/src/EllieBot/Modules/Utility/Giveaway/GiveawayService.cs +++ b/src/EllieBot/Modules/Utility/Giveaway/GiveawayService.cs @@ -11,7 +11,7 @@ public sealed class GiveawayService : IEService, 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 : IEService, IReadyExecutor private SortedSet _giveawayCache = new SortedSet(); private readonly EllieRandom _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/EllieBot/Modules/Utility/Remind/RemindService.cs b/src/EllieBot/Modules/Utility/Remind/RemindService.cs index 29913c0..69025f4 100644 --- a/src/EllieBot/Modules/Utility/Remind/RemindService.cs +++ b/src/EllieBot/Modules/Utility/Remind/RemindService.cs @@ -17,14 +17,14 @@ public class RemindService : IEService, 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/EllieBot/Modules/Utility/Repeater/RepeaterService.cs b/src/EllieBot/Modules/Utility/Repeater/RepeaterService.cs index 8d513cb..7aa9b76 100644 --- a/src/EllieBot/Modules/Utility/Repeater/RepeaterService.cs +++ b/src/EllieBot/Modules/Utility/Repeater/RepeaterService.cs @@ -12,7 +12,7 @@ public sealed class RepeaterService : IReadyExecutor, IEService 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, IEService DiscordSocketClient client, DbService db, IReplacementService repSvc, - IBotCredentials creds, + IBotCreds creds, IMessageSenderService sender) { _db = db; diff --git a/src/EllieBot/Modules/Utility/Utility.cs b/src/EllieBot/Modules/Utility/Utility.cs index 89fee19..8463d36 100644 --- a/src/EllieBot/Modules/Utility/Utility.cs +++ b/src/EllieBot/Modules/Utility/Utility.cs @@ -34,7 +34,7 @@ public partial class Utility : EllieModule 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 : EllieModule DiscordSocketClient client, ICoordinator coord, IStatsService stats, - IBotCredentials creds, + IBotCreds creds, DownloadTracker tracker, IHttpClientFactory httpFactory, VerboseErrorsService veService, diff --git a/src/EllieBot/Modules/Xp/XpService.cs b/src/EllieBot/Modules/Xp/XpService.cs index 98ae74f..b4cc0b5 100644 --- a/src/EllieBot/Modules/Xp/XpService.cs +++ b/src/EllieBot/Modules/Xp/XpService.cs @@ -25,7 +25,7 @@ public class XpService : IEService, 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 : IEService, IReadyExecutor, IExecNoCommand IImageCache images, IBotCache c, FontProvider fonts, - IBotCredentials creds, + IBotCreds creds, ICurrencyService cs, IHttpClientFactory http, XpConfigService xpConfig, diff --git a/src/EllieBot/Program.cs b/src/EllieBot/Program.cs index 2c5b5a9..5a74a96 100644 --- a/src/EllieBot/Program.cs +++ b/src/EllieBot/Program.cs @@ -1,6 +1,4 @@ -var pid = Environment.ProcessId; - -var shardId = 0; +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("EllieBot__creds")).RunAndBlockAsync(); \ No newline at end of file diff --git a/src/EllieBot/_common/Abstractions/Helpers/LogSetup.cs b/src/EllieBot/_common/Abstractions/Helpers/LogSetup.cs index 8983740..3d4edec 100644 --- a/src/EllieBot/_common/Abstractions/Helpers/LogSetup.cs +++ b/src/EllieBot/_common/Abstractions/Helpers/LogSetup.cs @@ -6,9 +6,9 @@ namespace Ellie.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/EllieBot/_common/Abstractions/creds/IBotCredentials.cs b/src/EllieBot/_common/Abstractions/creds/IBotCreds.cs similarity index 97% rename from src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs rename to src/EllieBot/_common/Abstractions/creds/IBotCreds.cs index 7f98972..83d19b2 100644 --- a/src/EllieBot/_common/Abstractions/creds/IBotCredentials.cs +++ b/src/EllieBot/_common/Abstractions/creds/IBotCreds.cs @@ -1,7 +1,7 @@ #nullable disable namespace EllieBot; -public interface IBotCredentials +public interface IBotCreds { string Token { get; } string EllieAiToken { 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/EllieBot/_common/Abstractions/creds/IBotCredsProvider.cs b/src/EllieBot/_common/Abstractions/creds/IBotCredsProvider.cs index ecc90f0..bb39339 100644 --- a/src/EllieBot/_common/Abstractions/creds/IBotCredsProvider.cs +++ b/src/EllieBot/_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/EllieBot/_common/Configs/BotConfig.cs b/src/EllieBot/_common/Configs/BotConfig.cs index df6bc1a..1f691ed 100644 --- a/src/EllieBot/_common/Configs/BotConfig.cs +++ b/src/EllieBot/_common/Configs/BotConfig.cs @@ -28,7 +28,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/EllieBot/_common/Creds.cs b/src/EllieBot/_common/Creds.cs index d9139c9..169cf24 100644 --- a/src/EllieBot/_common/Creds.cs +++ b/src/EllieBot/_common/Creds.cs @@ -3,10 +3,10 @@ using EllieBot.Common.Yml; namespace EllieBot.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; } @@ -164,6 +164,11 @@ public sealed class Creds : IBotCredentials """)] public GrpcApiConfig GrpcApi { get; set; } + [Comment(""" + Url to + """)] + public SeqConfig Seq { get; set; } + public Creds() { Token = string.Empty; @@ -189,7 +194,8 @@ public sealed class Creds : IBotCredentials RestartCommand = new RestartConfig(); Google = new GoogleApiConfig(); - GrpcApi = new GrpcApiConfig(); + GrpcApi = new(); + Seq = new(); } public class DbOptions @@ -294,6 +300,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/EllieBot/_common/Impl/BotCredsProvider.cs b/src/EllieBot/_common/Impl/BotCredsProvider.cs index 5d9a83d..fa05f8f 100644 --- a/src/EllieBot/_common/Impl/BotCredsProvider.cs +++ b/src/EllieBot/_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); @@ -148,7 +148,7 @@ public sealed class BotCredsProvider : IBotCredsProvider } } - public IBotCredentials GetCreds() + public IBotCreds GetCreds() { lock (_reloadLock) { diff --git a/src/EllieBot/_common/Impl/PubSub/RedisPubSub.cs b/src/EllieBot/_common/Impl/PubSub/RedisPubSub.cs index fd4a36c..6a20888 100644 --- a/src/EllieBot/_common/Impl/PubSub/RedisPubSub.cs +++ b/src/EllieBot/_common/Impl/PubSub/RedisPubSub.cs @@ -4,11 +4,11 @@ namespace EllieBot.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/EllieBot/_common/Impl/RedisBotStringsProvider.cs b/src/EllieBot/_common/Impl/RedisBotStringsProvider.cs index c0bef49..504fff6 100644 --- a/src/EllieBot/_common/Impl/RedisBotStringsProvider.cs +++ b/src/EllieBot/_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/EllieBot/_common/Impl/RemoteGrpcCoordinator.cs b/src/EllieBot/_common/Impl/RemoteGrpcCoordinator.cs index 1fb2867..cd1ad8f 100644 --- a/src/EllieBot/_common/Impl/RemoteGrpcCoordinator.cs +++ b/src/EllieBot/_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/EllieBot/_common/ServiceCollectionExtensions.cs b/src/EllieBot/_common/ServiceCollectionExtensions.cs index c5539af..2326ebb 100644 --- a/src/EllieBot/_common/ServiceCollectionExtensions.cs +++ b/src/EllieBot/_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/EllieBot/_common/Services/Impl/BlacklistService.cs b/src/EllieBot/_common/Services/Impl/BlacklistService.cs index ac01491..01ad347 100644 --- a/src/EllieBot/_common/Services/Impl/BlacklistService.cs +++ b/src/EllieBot/_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/EllieBot/_common/Services/Impl/SingleProcessCoordinator.cs b/src/EllieBot/_common/Services/Impl/SingleProcessCoordinator.cs index 0784fc7..ffa5323 100644 --- a/src/EllieBot/_common/Services/Impl/SingleProcessCoordinator.cs +++ b/src/EllieBot/_common/Services/Impl/SingleProcessCoordinator.cs @@ -5,10 +5,10 @@ namespace EllieBot.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/EllieBot/_common/Services/Impl/StatsService.cs b/src/EllieBot/_common/Services/Impl/StatsService.cs index 363f8a5..a35df44 100644 --- a/src/EllieBot/_common/Services/Impl/StatsService.cs +++ b/src/EllieBot/_common/Services/Impl/StatsService.cs @@ -29,7 +29,7 @@ public sealed class StatsService : IStatsService, IReadyExecutor, IEService 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, IEService public StatsService( DiscordSocketClient client, CommandHandler cmdHandler, - IBotCredentials creds, + IBotCreds creds, IHttpClientFactory factory) { _client = client; diff --git a/src/EllieBot/_common/_Extensions/BotCredentialsExtensions.cs b/src/EllieBot/_common/_Extensions/BotCredentialsExtensions.cs index 890bab3..0166335 100644 --- a/src/EllieBot/_common/_Extensions/BotCredentialsExtensions.cs +++ b/src/EllieBot/_common/_Extensions/BotCredentialsExtensions.cs @@ -2,9 +2,9 @@ namespace EllieBot.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/EllieBot/_common/_Extensions/Extensions.cs b/src/EllieBot/_common/_Extensions/Extensions.cs index dca195d..5a21861 100644 --- a/src/EllieBot/_common/_Extensions/Extensions.cs +++ b/src/EllieBot/_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)