From e681978f836544bb5dbc157a30b4b4a4fbf6d7be Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 3 Jul 2021 00:57:47 +0200 Subject: [PATCH] - xp template reload now uses new pubsub - multiplexer.GetSubscriber().subscribe is no longer used in any service - fixed some build warnings --- .../Administration/Services/SelfService.cs | 1 - .../Services/StreamNotificationService.cs | 4 ++- .../Modules/Xp/Services/XpService.cs | 34 ++++++++++++++----- .../Services/Impl/BotCredsProvider.cs | 3 +- src/NadekoBot/Services/LogSetup.cs | 3 +- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index 98dc81e98..d8f1273cb 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -386,7 +386,6 @@ namespace NadekoBot.Modules.Administration.Services return isToAll; } - // todo pubsub via IPubSub private void HandleStatusChanges() { _pubSub.Sub(_activitySetKey, async data => diff --git a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs index b5f61b6c8..caf79a044 100644 --- a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs @@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Searches.Services /// When counter reaches 0, stream is removed from tracking because /// that means no guilds are subscribed to that stream anymore /// - private async ValueTask HandleFollowStream(FollowStreamPubData info) + private ValueTask HandleFollowStream(FollowStreamPubData info) { _streamTracker.CacheAddData(info.Key, null, replace: false); lock (_shardLock) @@ -201,6 +201,8 @@ namespace NadekoBot.Modules.Searches.Services }; } } + + return default; } /// diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index a465e03cf..662e42213 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -47,7 +47,8 @@ namespace NadekoBot.Modules.Xp.Services private readonly Task updateXpTask; private readonly IHttpClientFactory _httpFactory; private readonly XpConfigService _xpConfig; - + private readonly IPubSub _pubSub; + public const int XP_REQUIRED_LVL_1 = 36; private readonly ConcurrentDictionary> _excludedRoles; @@ -61,9 +62,21 @@ namespace NadekoBot.Modules.Xp.Services private XpTemplate _template; private readonly DiscordSocketClient _client; - public XpService(DiscordSocketClient client, CommandHandler cmd, Bot bot, DbService db, - IBotStrings strings, IDataCache cache, FontProvider fonts, IBotCredentials creds, - ICurrencyService cs, IHttpClientFactory http, XpConfigService xpConfig) + private readonly TypedKey _xpTemplateReloadKey; + + public XpService( + DiscordSocketClient client, + CommandHandler cmd, + Bot bot, + DbService db, + IBotStrings strings, + IDataCache cache, + FontProvider fonts, + IBotCredentials creds, + ICurrencyService cs, + IHttpClientFactory http, + XpConfigService xpConfig, + IPubSub pubSub) { _db = db; _cmd = cmd; @@ -75,17 +88,21 @@ namespace NadekoBot.Modules.Xp.Services _cs = cs; _httpFactory = http; _xpConfig = xpConfig; + _pubSub = pubSub; _excludedServers = new ConcurrentHashSet(); _excludedChannels = new ConcurrentDictionary>(); _client = client; + _xpTemplateReloadKey = new("xp.template.reload"); InternalReloadXpTemplate(); if (client.ShardId == 0) { - var sub = _cache.Redis.GetSubscriber(); - sub.Subscribe(_creds.RedisKey() + "_reload_xp_template", - (ch, val) => InternalReloadXpTemplate()); + _pubSub.Sub(_xpTemplateReloadKey, _ => + { + InternalReloadXpTemplate(); + return default; + }); } //load settings @@ -303,8 +320,7 @@ namespace NadekoBot.Modules.Xp.Services public void ReloadXpTemplate() { - var sub = _cache.Redis.GetSubscriber(); - sub.Publish(_creds.RedisKey() + "_reload_xp_template", ""); + _pubSub.Pub(_xpTemplateReloadKey, true); } public void SetCurrencyReward(ulong guildId, int level, int amount) diff --git a/src/NadekoBot/Services/Impl/BotCredsProvider.cs b/src/NadekoBot/Services/Impl/BotCredsProvider.cs index 24bd7091d..da98a2789 100644 --- a/src/NadekoBot/Services/Impl/BotCredsProvider.cs +++ b/src/NadekoBot/Services/Impl/BotCredsProvider.cs @@ -3,14 +3,13 @@ using Microsoft.Extensions.Configuration; using System.IO; using Microsoft.Extensions.Primitives; using NadekoBot.Common; -using NadekoBot.Common; using NadekoBot.Common.Yml; using Serilog; namespace NadekoBot.Services { // todo check why is memory usage so unstable - public class BotCredsProvider + public sealed class BotCredsProvider { private readonly int? _totalShards; private const string _credsFileName = "creds.yml"; diff --git a/src/NadekoBot/Services/LogSetup.cs b/src/NadekoBot/Services/LogSetup.cs index 3a32de07c..11c2cf6c6 100644 --- a/src/NadekoBot/Services/LogSetup.cs +++ b/src/NadekoBot/Services/LogSetup.cs @@ -30,8 +30,9 @@ namespace NadekoBot.Services return AnsiConsoleTheme.Code; #if DEBUG return AnsiConsoleTheme.Code; -#endif +#else return ConsoleTheme.None; +#endif } } }