- 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;
}
// todo pubsub via IPubSub
private void HandleStatusChanges()
{
_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
/// that means no guilds are subscribed to that stream anymore
/// </summary>
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;
}
/// <summary>

View File

@@ -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<ulong, ConcurrentHashSet<ulong>> _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<bool> _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<ulong>();
_excludedChannels = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>();
_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)

View File

@@ -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";

View File

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