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.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Lib.Converters;
|
using Geekbot.net.Lib.Converters;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Geekbot.net.Lib.Logger;
|
|
||||||
using Geekbot.net.Lib.UserRepository;
|
using Geekbot.net.Lib.UserRepository;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
@ -19,21 +17,17 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
{
|
{
|
||||||
private readonly IEmojiConverter _emojiConverter;
|
private readonly IEmojiConverter _emojiConverter;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IGeekbotLogger _logger;
|
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly DiscordSocketClient _client;
|
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
|
|
||||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IGeekbotLogger logger, IUserRepository userRepository,
|
public Rank(DatabaseContext database, IErrorHandler errorHandler, IUserRepository userRepository,
|
||||||
IEmojiConverter emojiConverter, DiscordSocketClient client, IDatabase redis)
|
IEmojiConverter emojiConverter, IDatabase redis)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_logger = logger;
|
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_emojiConverter = emojiConverter;
|
_emojiConverter = emojiConverter;
|
||||||
_client = client;
|
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,42 +138,28 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
|
|
||||||
private Dictionary<ulong, int> GetMessageList(int amount)
|
private Dictionary<ulong, int> GetMessageList(int amount)
|
||||||
{
|
{
|
||||||
|
return _redis
|
||||||
var data = _redis.HashGetAll($"{Context.Guild.Id}:Messages").ToDictionary().Take(amount + 1);
|
.HashGetAll($"{Context.Guild.Id}:Messages").ToDictionary().Take(amount + 1)
|
||||||
|
.Where(user => !user.Key.Equals(0))
|
||||||
return data.Where(user => !user.Key.Equals(0)).ToDictionary(user => ulong.Parse(user.Key), user => int.Parse(user.Value));
|
.ToDictionary(user => ulong.Parse(user.Key), user => int.Parse(user.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<ulong, int> GetKarmaList(int amount)
|
private Dictionary<ulong, int> GetKarmaList(int amount)
|
||||||
{
|
{
|
||||||
var data = _database.Karma
|
return _database.Karma
|
||||||
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||||
.OrderByDescending(o => o.Karma)
|
.OrderByDescending(o => o.Karma)
|
||||||
.Take(amount);
|
.Take(amount)
|
||||||
|
.ToDictionary(key => key.UserId.AsUlong(), key => key.Karma);
|
||||||
var dict = new Dictionary<ulong, int>();
|
|
||||||
foreach (var user in data)
|
|
||||||
{
|
|
||||||
dict.Add(user.UserId.AsUlong(), user.Karma);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<ulong, int> GetRollsList(int amount)
|
private Dictionary<ulong, int> GetRollsList(int amount)
|
||||||
{
|
{
|
||||||
var data = _database.Rolls
|
return _database.Rolls
|
||||||
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||||
.OrderByDescending(o => o.Rolls)
|
.OrderByDescending(o => o.Rolls)
|
||||||
.Take(amount);
|
.Take(amount)
|
||||||
|
.ToDictionary(key => key.UserId.AsUlong(), key => key.Rolls);
|
||||||
var dict = new Dictionary<ulong, int>();
|
|
||||||
foreach (var user in data)
|
|
||||||
{
|
|
||||||
dict.Add(user.UserId.AsUlong(), user.Rolls);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -230,6 +230,62 @@ namespace Geekbot.net.Database
|
||||||
}
|
}
|
||||||
#endregion
|
#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
|
#region Users
|
||||||
/**
|
/**
|
||||||
* Users
|
* Users
|
||||||
|
|
Loading…
Reference in a new issue