mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-13 18:58:27 -04:00
Applied codestyle to all .cs files
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#nullable disable
|
||||
using System.Web;
|
||||
using StackExchange.Redis;
|
||||
using System.Web;
|
||||
|
||||
namespace NadekoBot.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Uses <see cref="IStringsSource"/> to load strings into redis hash (only on Shard 0)
|
||||
/// and retrieves them from redis via <see cref="GetText"/>
|
||||
/// Uses <see cref="IStringsSource" /> to load strings into redis hash (only on Shard 0)
|
||||
/// and retrieves them from redis via <see cref="GetText" />
|
||||
/// </summary>
|
||||
public class RedisBotStringsProvider : IBotStringsProvider
|
||||
{
|
||||
@@ -14,14 +14,17 @@ public class RedisBotStringsProvider : IBotStringsProvider
|
||||
private readonly IStringsSource _source;
|
||||
private readonly IBotCredentials _creds;
|
||||
|
||||
public RedisBotStringsProvider(ConnectionMultiplexer redis, DiscordSocketClient discordClient,
|
||||
IStringsSource source, IBotCredentials creds)
|
||||
public RedisBotStringsProvider(
|
||||
ConnectionMultiplexer redis,
|
||||
DiscordSocketClient discordClient,
|
||||
IStringsSource source,
|
||||
IBotCredentials creds)
|
||||
{
|
||||
_redis = redis;
|
||||
_source = source;
|
||||
_creds = creds;
|
||||
|
||||
if(discordClient.ShardId == 0)
|
||||
if (discordClient.ShardId == 0)
|
||||
Reload();
|
||||
}
|
||||
|
||||
@@ -33,20 +36,18 @@ public class RedisBotStringsProvider : IBotStringsProvider
|
||||
|
||||
public CommandStrings GetCommandStrings(string localeName, string commandName)
|
||||
{
|
||||
string argsStr = _redis.GetDatabase().HashGet($"{_creds.RedisKey()}:commands:{localeName}", $"{commandName}::args");
|
||||
string argsStr = _redis.GetDatabase()
|
||||
.HashGet($"{_creds.RedisKey()}:commands:{localeName}", $"{commandName}::args");
|
||||
if (argsStr == default)
|
||||
return null;
|
||||
|
||||
var descStr = _redis.GetDatabase().HashGet($"{_creds.RedisKey()}:commands:{localeName}", $"{commandName}::desc");
|
||||
|
||||
var descStr = _redis.GetDatabase()
|
||||
.HashGet($"{_creds.RedisKey()}:commands:{localeName}", $"{commandName}::desc");
|
||||
if (descStr == default)
|
||||
return null;
|
||||
|
||||
|
||||
var args = Array.ConvertAll(argsStr.Split('&'), HttpUtility.UrlDecode);
|
||||
return new()
|
||||
{
|
||||
Args = args,
|
||||
Desc = descStr
|
||||
};
|
||||
return new() { Args = args, Desc = descStr };
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
@@ -54,23 +55,20 @@ public class RedisBotStringsProvider : IBotStringsProvider
|
||||
var redisDb = _redis.GetDatabase();
|
||||
foreach (var (localeName, localeStrings) in _source.GetResponseStrings())
|
||||
{
|
||||
var hashFields = localeStrings
|
||||
.Select(x => new HashEntry(x.Key, x.Value))
|
||||
.ToArray();
|
||||
var hashFields = localeStrings.Select(x => new HashEntry(x.Key, x.Value)).ToArray();
|
||||
|
||||
redisDb.HashSet($"{_creds.RedisKey()}:responses:{localeName}", hashFields);
|
||||
}
|
||||
|
||||
|
||||
foreach (var (localeName, localeStrings) in _source.GetCommandStrings())
|
||||
{
|
||||
var hashFields = localeStrings
|
||||
.Select(x => new HashEntry($"{x.Key}::args",
|
||||
string.Join('&', Array.ConvertAll(x.Value.Args, HttpUtility.UrlEncode))))
|
||||
.Concat(localeStrings
|
||||
.Select(x => new HashEntry($"{x.Key}::desc", x.Value.Desc)))
|
||||
.ToArray();
|
||||
.Select(x => new HashEntry($"{x.Key}::args",
|
||||
string.Join('&', Array.ConvertAll(x.Value.Args, HttpUtility.UrlEncode))))
|
||||
.Concat(localeStrings.Select(x => new HashEntry($"{x.Key}::desc", x.Value.Desc)))
|
||||
.ToArray();
|
||||
|
||||
redisDb.HashSet($"{_creds.RedisKey()}:commands:{localeName}", hashFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user