Port !stats, !role, !wiki and !slap, fix messages in rank, add roleselfservicemodel to db
This commit is contained in:
parent
a1b5bd1955
commit
08015c6102
8 changed files with 141 additions and 74 deletions
|
@ -6,12 +6,12 @@ using System.Threading.Tasks;
|
|||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib;
|
||||
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;
|
||||
|
||||
namespace Geekbot.net.Commands.User.Ranking
|
||||
{
|
||||
|
@ -23,9 +23,10 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
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)
|
||||
IEmojiConverter emojiConverter, DiscordSocketClient client, IDatabase redis)
|
||||
{
|
||||
_database = database;
|
||||
_errorHandler = errorHandler;
|
||||
|
@ -33,6 +34,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
_userRepository = userRepository;
|
||||
_emojiConverter = emojiConverter;
|
||||
_client = client;
|
||||
_redis = redis;
|
||||
}
|
||||
|
||||
[Command("rank", RunMode = RunMode.Async)]
|
||||
|
@ -74,8 +76,8 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
list = GetRollsList(amount);
|
||||
break;
|
||||
default:
|
||||
list = new Dictionary<ulong, int>();
|
||||
break;
|
||||
await ReplyAsync("Valid types are '`messages`' '`karma`', '`rolls`'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!list.Any())
|
||||
|
@ -142,18 +144,10 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
|
||||
private Dictionary<ulong, int> GetMessageList(int amount)
|
||||
{
|
||||
var data = _database.Messages
|
||||
.Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.OrderByDescending(o => o.MessageCount)
|
||||
.Take(amount);
|
||||
|
||||
var dict = new Dictionary<ulong, int>();
|
||||
foreach (var user in data)
|
||||
{
|
||||
dict.Add(user.UserId.AsUlong(), user.MessageCount);
|
||||
}
|
||||
|
||||
return dict;
|
||||
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));
|
||||
}
|
||||
|
||||
private Dictionary<ulong, int> GetKarmaList(int amount)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Database;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Extensions;
|
||||
using Geekbot.net.Lib.Levels;
|
||||
using StackExchange.Redis;
|
||||
|
||||
|
@ -14,10 +16,12 @@ namespace Geekbot.net.Commands.User
|
|||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly ILevelCalc _levelCalc;
|
||||
private readonly IDatabase _redis;
|
||||
private readonly DatabaseContext _database;
|
||||
|
||||
public Stats(IDatabase redis, IErrorHandler errorHandler, ILevelCalc levelCalc)
|
||||
public Stats(IDatabase redis, DatabaseContext database, IErrorHandler errorHandler, ILevelCalc levelCalc)
|
||||
{
|
||||
_redis = redis;
|
||||
_database = database;
|
||||
_errorHandler = errorHandler;
|
||||
_levelCalc = levelCalc;
|
||||
}
|
||||
|
@ -47,20 +51,23 @@ namespace Geekbot.net.Commands.User
|
|||
.WithName(userInfo.Username));
|
||||
eb.WithColor(new Color(221, 255, 119));
|
||||
|
||||
var karma = _redis.HashGet($"{Context.Guild.Id}:Karma", userInfo.Id.ToString());
|
||||
var correctRolls = _redis.HashGet($"{Context.Guild.Id}:Rolls", userInfo.Id.ToString());
|
||||
var karma = _database.Karma.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userInfo.Id.AsLong()));
|
||||
var correctRolls = _database.Rolls.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userInfo.Id.AsLong()));
|
||||
|
||||
eb.AddInlineField("Discordian Since",
|
||||
$"{createdAt.Day}.{createdAt.Month}.{createdAt.Year} ({age} days)")
|
||||
.AddInlineField("Joined Server",
|
||||
$"{joinedAt.Day}.{joinedAt.Month}.{joinedAt.Year} ({joinedDayAgo} days)")
|
||||
.AddInlineField("Karma", karma.ToString() ?? "0")
|
||||
.AddInlineField("Karma", karma?.Karma ?? 0)
|
||||
.AddInlineField("Level", level)
|
||||
.AddInlineField("Messages Sent", messages)
|
||||
.AddInlineField("Server Total", $"{percent}%");
|
||||
|
||||
if (!correctRolls.IsNullOrEmpty)
|
||||
eb.AddInlineField("Guessed Rolls", correctRolls);
|
||||
if (correctRolls != null) eb.AddInlineField("Guessed Rolls", correctRolls.Rolls);
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue