Add Guild Settings to redis migration
This commit is contained in:
parent
08015c6102
commit
4a11ce6207
2 changed files with 68 additions and 32 deletions
|
@ -4,12 +4,10 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib.Converters;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Extensions;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using Geekbot.net.Lib.UserRepository;
|
||||
using StackExchange.Redis;
|
||||
|
||||
|
@ -19,21 +17,17 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
{
|
||||
private readonly IEmojiConverter _emojiConverter;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IDatabase _redis;
|
||||
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IGeekbotLogger logger, IUserRepository userRepository,
|
||||
IEmojiConverter emojiConverter, DiscordSocketClient client, IDatabase redis)
|
||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IUserRepository userRepository,
|
||||
IEmojiConverter emojiConverter, IDatabase redis)
|
||||
{
|
||||
_database = database;
|
||||
_errorHandler = errorHandler;
|
||||
_logger = logger;
|
||||
_userRepository = userRepository;
|
||||
_emojiConverter = emojiConverter;
|
||||
_client = client;
|
||||
_redis = redis;
|
||||
}
|
||||
|
||||
|
@ -144,42 +138,28 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
|
||||
private Dictionary<ulong, int> GetMessageList(int amount)
|
||||
{
|
||||
|
||||
var data = _redis.HashGetAll($"{Context.Guild.Id}:Messages").ToDictionary().Take(amount + 1);
|
||||
|
||||
return data.Where(user => !user.Key.Equals(0)).ToDictionary(user => ulong.Parse(user.Key), user => int.Parse(user.Value));
|
||||
return _redis
|
||||
.HashGetAll($"{Context.Guild.Id}:Messages").ToDictionary().Take(amount + 1)
|
||||
.Where(user => !user.Key.Equals(0))
|
||||
.ToDictionary(user => ulong.Parse(user.Key), user => int.Parse(user.Value));
|
||||
}
|
||||
|
||||
private Dictionary<ulong, int> GetKarmaList(int amount)
|
||||
{
|
||||
var data = _database.Karma
|
||||
return _database.Karma
|
||||
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.OrderByDescending(o => o.Karma)
|
||||
.Take(amount);
|
||||
|
||||
var dict = new Dictionary<ulong, int>();
|
||||
foreach (var user in data)
|
||||
{
|
||||
dict.Add(user.UserId.AsUlong(), user.Karma);
|
||||
}
|
||||
|
||||
return dict;
|
||||
.Take(amount)
|
||||
.ToDictionary(key => key.UserId.AsUlong(), key => key.Karma);
|
||||
}
|
||||
|
||||
private Dictionary<ulong, int> GetRollsList(int amount)
|
||||
{
|
||||
var data = _database.Rolls
|
||||
return _database.Rolls
|
||||
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.OrderByDescending(o => o.Rolls)
|
||||
.Take(amount);
|
||||
|
||||
var dict = new Dictionary<ulong, int>();
|
||||
foreach (var user in data)
|
||||
{
|
||||
dict.Add(user.UserId.AsUlong(), user.Rolls);
|
||||
}
|
||||
|
||||
return dict;
|
||||
.Take(amount)
|
||||
.ToDictionary(key => key.UserId.AsUlong(), key => key.Rolls);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -230,6 +230,62 @@ namespace Geekbot.net.Database
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region GuildSettings
|
||||
/**
|
||||
* Users
|
||||
*/
|
||||
try
|
||||
{
|
||||
var data = _redis.HashGetAll($"{guild.Id}:Settings");
|
||||
var settings = new GuildSettingsModel()
|
||||
{
|
||||
GuildId = guild.Id.AsLong(),
|
||||
Hui = true
|
||||
};
|
||||
foreach (var setting in data)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (setting.Name)
|
||||
{
|
||||
case "ShowLeave":
|
||||
settings.ShowLeave = setting.Value.ToString() == "1";
|
||||
break;
|
||||
case "WikiDel":
|
||||
settings.ShowDelete = setting.Value.ToString() == "1";
|
||||
break;
|
||||
case "WikiLang":
|
||||
settings.WikiLang = setting.Value.ToString();
|
||||
break;
|
||||
case "Language":
|
||||
settings.Language = setting.Value.ToString();
|
||||
break;
|
||||
case "WelcomeMsg":
|
||||
settings.WelcomeMessage = setting.Value.ToString();
|
||||
break;
|
||||
case "ping":
|
||||
settings.Ping = bool.Parse(setting.Value.ToString());
|
||||
break;
|
||||
case "ModChannel":
|
||||
settings.ModChannel = long.Parse(setting.Value);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_logger.Warning(LogSource.Geekbot, $"Setting failed: {setting.Name} - {guild.Id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_logger.Warning(LogSource.Geekbot, "Settings migration failed");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Users
|
||||
/**
|
||||
* Users
|
||||
|
|
Loading…
Reference in a new issue