- xp template reload now uses new pubsub

- multiplexer.GetSubscriber().subscribe is no longer used in any service
- fixed some build warnings
This commit is contained in:
Kwoth
2021-07-03 00:57:47 +02:00
parent 941d393971
commit e681978f83
5 changed files with 31 additions and 14 deletions

View File

@@ -386,7 +386,6 @@ namespace NadekoBot.Modules.Administration.Services
return isToAll; return isToAll;
} }
// todo pubsub via IPubSub
private void HandleStatusChanges() private void HandleStatusChanges()
{ {
_pubSub.Sub(_activitySetKey, async data => _pubSub.Sub(_activitySetKey, async data =>

View File

@@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Searches.Services
/// When counter reaches 0, stream is removed from tracking because /// When counter reaches 0, stream is removed from tracking because
/// that means no guilds are subscribed to that stream anymore /// that means no guilds are subscribed to that stream anymore
/// </summary> /// </summary>
private async ValueTask HandleFollowStream(FollowStreamPubData info) private ValueTask HandleFollowStream(FollowStreamPubData info)
{ {
_streamTracker.CacheAddData(info.Key, null, replace: false); _streamTracker.CacheAddData(info.Key, null, replace: false);
lock (_shardLock) lock (_shardLock)
@@ -201,6 +201,8 @@ namespace NadekoBot.Modules.Searches.Services
}; };
} }
} }
return default;
} }
/// <summary> /// <summary>

View File

@@ -47,7 +47,8 @@ namespace NadekoBot.Modules.Xp.Services
private readonly Task updateXpTask; private readonly Task updateXpTask;
private readonly IHttpClientFactory _httpFactory; private readonly IHttpClientFactory _httpFactory;
private readonly XpConfigService _xpConfig; private readonly XpConfigService _xpConfig;
private readonly IPubSub _pubSub;
public const int XP_REQUIRED_LVL_1 = 36; public const int XP_REQUIRED_LVL_1 = 36;
private readonly ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> _excludedRoles; private readonly ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>> _excludedRoles;
@@ -61,9 +62,21 @@ namespace NadekoBot.Modules.Xp.Services
private XpTemplate _template; private XpTemplate _template;
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
public XpService(DiscordSocketClient client, CommandHandler cmd, Bot bot, DbService db, private readonly TypedKey<bool> _xpTemplateReloadKey;
IBotStrings strings, IDataCache cache, FontProvider fonts, IBotCredentials creds,
ICurrencyService cs, IHttpClientFactory http, XpConfigService xpConfig) 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; _db = db;
_cmd = cmd; _cmd = cmd;
@@ -75,17 +88,21 @@ namespace NadekoBot.Modules.Xp.Services
_cs = cs; _cs = cs;
_httpFactory = http; _httpFactory = http;
_xpConfig = xpConfig; _xpConfig = xpConfig;
_pubSub = pubSub;
_excludedServers = new ConcurrentHashSet<ulong>(); _excludedServers = new ConcurrentHashSet<ulong>();
_excludedChannels = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(); _excludedChannels = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>();
_client = client; _client = client;
_xpTemplateReloadKey = new("xp.template.reload");
InternalReloadXpTemplate(); InternalReloadXpTemplate();
if (client.ShardId == 0) if (client.ShardId == 0)
{ {
var sub = _cache.Redis.GetSubscriber(); _pubSub.Sub(_xpTemplateReloadKey, _ =>
sub.Subscribe(_creds.RedisKey() + "_reload_xp_template", {
(ch, val) => InternalReloadXpTemplate()); InternalReloadXpTemplate();
return default;
});
} }
//load settings //load settings
@@ -303,8 +320,7 @@ namespace NadekoBot.Modules.Xp.Services
public void ReloadXpTemplate() public void ReloadXpTemplate()
{ {
var sub = _cache.Redis.GetSubscriber(); _pubSub.Pub(_xpTemplateReloadKey, true);
sub.Publish(_creds.RedisKey() + "_reload_xp_template", "");
} }
public void SetCurrencyReward(ulong guildId, int level, int amount) public void SetCurrencyReward(ulong guildId, int level, int amount)

View File

@@ -3,14 +3,13 @@ using Microsoft.Extensions.Configuration;
using System.IO; using System.IO;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using NadekoBot.Common; using NadekoBot.Common;
using NadekoBot.Common;
using NadekoBot.Common.Yml; using NadekoBot.Common.Yml;
using Serilog; using Serilog;
namespace NadekoBot.Services namespace NadekoBot.Services
{ {
// todo check why is memory usage so unstable // todo check why is memory usage so unstable
public class BotCredsProvider public sealed class BotCredsProvider
{ {
private readonly int? _totalShards; private readonly int? _totalShards;
private const string _credsFileName = "creds.yml"; private const string _credsFileName = "creds.yml";

View File

@@ -30,8 +30,9 @@ namespace NadekoBot.Services
return AnsiConsoleTheme.Code; return AnsiConsoleTheme.Code;
#if DEBUG #if DEBUG
return AnsiConsoleTheme.Code; return AnsiConsoleTheme.Code;
#endif #else
return ConsoleTheme.None; return ConsoleTheme.None;
#endif
} }
} }
} }