Make errorhandler and languagehandler async, await all database actions
This commit is contained in:
parent
926a632641
commit
95618b1f8b
46 changed files with 181 additions and 137 deletions
|
@ -35,7 +35,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
||||
public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage)
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.WelcomeMessage = welcomeMessage;
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -52,7 +52,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
var m = await channel.SendMessageAsync("verifying...");
|
||||
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.ModChannel = channel.Id.AsLong();
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -65,7 +65,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context, "That channel doesn't seem to be valid");
|
||||
await _errorHandler.HandleCommandException(e, Context, "That channel doesn't seem to be valid");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
try
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
var modChannel = await GetModChannel(guild.ModChannel.AsUlong());
|
||||
if (modChannel == null) return;
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
try
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
var modChannel = await GetModChannel(guild.ModChannel.AsUlong());
|
||||
if (modChannel == null) return;
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,15 +124,15 @@ namespace Geekbot.net.Commands.Admin
|
|||
try
|
||||
{
|
||||
var language = languageRaw.ToUpper();
|
||||
var success = _translation.SetLanguage(Context.Guild.Id, language);
|
||||
var success = await _translation.SetLanguage(Context.Guild.Id, language);
|
||||
if (success)
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.Language = language;
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var trans = _translation.GetDict(Context);
|
||||
var trans = await _translation.GetDict(Context);
|
||||
await ReplyAsync(trans["NewLanguageSet"]);
|
||||
return;
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
try
|
||||
{
|
||||
var language = languageRaw.ToLower();
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.WikiLang = language;
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -162,7 +162,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
try
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.Ping = !guild.Ping;
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -180,7 +180,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
{
|
||||
try
|
||||
{
|
||||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
var guild = await GetGuildSettings(Context.Guild.Id);
|
||||
guild.Hui = !guild.Hui;
|
||||
_database.GuildSettings.Update(guild);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -198,11 +198,11 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private GuildSettingsModel GetGuildSettings(ulong guildId)
|
||||
private async Task<GuildSettingsModel> GetGuildSettings(ulong guildId)
|
||||
{
|
||||
var guild = _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildId.AsLong()));
|
||||
if (guild != null) return guild;
|
||||
|
@ -212,12 +212,12 @@ namespace Geekbot.net.Commands.Admin
|
|||
GuildId = guildId.AsLong(),
|
||||
Hui = false,
|
||||
Ping = false,
|
||||
Language = "en",
|
||||
Language = "EN",
|
||||
ShowDelete = false,
|
||||
ShowLeave = false,
|
||||
WikiLang = "en"
|
||||
});
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
return _database.GuildSettings.FirstOrDefault(g => g.GuildId.Equals(guildId.AsLong()));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
$"I don't have enough permissions do that");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,14 +52,14 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
|
||||
await ReplyAsync("starting migration");
|
||||
_globalSettings.SetKey("MigrationStatus", "Running");
|
||||
await _globalSettings.SetKey("MigrationStatus", "Running");
|
||||
var redisMigration = new RedisMigration(_database, _redis, _logger, _client);
|
||||
await redisMigration.Migrate();
|
||||
_globalSettings.SetKey("MigrationStatus", "Done");
|
||||
await _globalSettings.SetKey("MigrationStatus", "Done");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
|
||||
await ReplyAsync("done");
|
||||
|
@ -69,7 +69,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
[Summary("Set the youtube api key")]
|
||||
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
||||
{
|
||||
_globalSettings.SetKey("YoutubeKey", key);
|
||||
await _globalSettings.SetKey("YoutubeKey", key);
|
||||
await ReplyAsync("Apikey has been set");
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
[Summary("Set the game that the bot is playing")]
|
||||
public async Task SetGame([Remainder] [Summary("Game")] string key)
|
||||
{
|
||||
_globalSettings.SetKey("Game", key);
|
||||
await _globalSettings.SetKey("Game", key);
|
||||
await _client.SetGameAsync(key);
|
||||
_logger.Information(LogSource.Geekbot, $"Changed game to {key}");
|
||||
await ReplyAsync($"Now Playing {key}");
|
||||
|
@ -109,14 +109,14 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
"Couldn't complete User Repository, see console for more info");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("error", RunMode = RunMode.Async)]
|
||||
[Summary("Throw an error un purpose")]
|
||||
public void PurposefulError()
|
||||
public async Task PurposefulError()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -124,7 +124,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,11 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
_errorHandler.HandleHttpException(e, Context);
|
||||
await _errorHandler.HandleHttpException(e, Context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace Geekbot.net.Commands.Audio
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
_audioUtils.Cleanup(Context.Guild.Id);
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ namespace Geekbot.net.Commands.Audio
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
_audioUtils.Cleanup(Context.Guild.Id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Geekbot.net.Commands.Games
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Geekbot.net.Commands.Games
|
|||
var number = new Random().Next(1, 100);
|
||||
var guess = 1000;
|
||||
int.TryParse(stuff, out guess);
|
||||
var transDict = _translation.GetDict(Context);
|
||||
var transDict = await _translation.GetDict(Context);
|
||||
if (guess <= 100 && guess > 0)
|
||||
{
|
||||
var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious", Context.Message.Author.Id);
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Geekbot.net.Commands.Integrations.Google
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace Geekbot.net.Commands.Integrations
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace Geekbot.net.Commands.Integrations
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Geekbot.net.Commands.Integrations
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.Integrations
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Randomness.Cat
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Geekbot.net.Commands.Randomness.Chuck
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Geekbot.net.Commands.Randomness.Dad
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Randomness.Dog
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ namespace Geekbot.net.Commands.Randomness
|
|||
|
||||
await ReplyAsync($"{Context.User.Username} slapped {user.Username} with a {things[new Random().Next(things.Count - 1)]}");
|
||||
|
||||
UpdateRecieved(user.Id);
|
||||
UpdateGiven(Context.User.Id);
|
||||
await UpdateRecieved(user.Id);
|
||||
await UpdateGiven(Context.User.Id);
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -91,21 +91,21 @@ namespace Geekbot.net.Commands.Randomness
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdateGiven(ulong userId)
|
||||
private async Task UpdateGiven(ulong userId)
|
||||
{
|
||||
var user = GetUser(userId);
|
||||
var user = await GetUser(userId);
|
||||
user.Given++;
|
||||
_database.Slaps.Update(user);
|
||||
}
|
||||
|
||||
private void UpdateRecieved(ulong userId)
|
||||
private async Task UpdateRecieved(ulong userId)
|
||||
{
|
||||
var user = GetUser(userId);
|
||||
var user = await GetUser(userId);
|
||||
user.Recieved++;
|
||||
_database.Slaps.Update(user);
|
||||
}
|
||||
|
||||
private SlapsModel GetUser(ulong userId)
|
||||
private async Task<SlapsModel> GetUser(ulong userId)
|
||||
{
|
||||
var user = _database.Slaps.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
|
@ -121,7 +121,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
Recieved = 0,
|
||||
Given = 0
|
||||
});
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
return _database.Slaps.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userId.AsLong()));
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.User
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace Geekbot.net.Commands.User
|
|||
{
|
||||
try
|
||||
{
|
||||
var transDict = _translation.GetDict(Context);
|
||||
var actor = GetUser(Context.User.Id);
|
||||
var transDict = await _translation.GetDict(Context);
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username));
|
||||
|
@ -43,7 +43,7 @@ namespace Geekbot.net.Commands.User
|
|||
}
|
||||
else
|
||||
{
|
||||
var target = GetUser(user.Id);
|
||||
var target = await GetUser(user.Id);
|
||||
target.Karma = target.Karma + 1;
|
||||
SetUser(target);
|
||||
|
||||
|
@ -77,8 +77,8 @@ namespace Geekbot.net.Commands.User
|
|||
{
|
||||
try
|
||||
{
|
||||
var transDict = _translation.GetDict(Context);
|
||||
var actor = GetUser(Context.User.Id);
|
||||
var transDict = await _translation.GetDict(Context);
|
||||
var actor = await GetUser(Context.User.Id);
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
await ReplyAsync(string.Format(transDict["CannotChangeOwn"], Context.User.Username));
|
||||
|
@ -90,7 +90,7 @@ namespace Geekbot.net.Commands.User
|
|||
}
|
||||
else
|
||||
{
|
||||
var target = GetUser(user.Id);
|
||||
var target = await GetUser(user.Id);
|
||||
target.Karma = target.Karma - 1;
|
||||
SetUser(target);
|
||||
|
||||
|
@ -129,19 +129,18 @@ namespace Geekbot.net.Commands.User
|
|||
return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds";
|
||||
}
|
||||
|
||||
private KarmaModel GetUser(ulong userId)
|
||||
private async Task<KarmaModel> GetUser(ulong userId)
|
||||
{
|
||||
var user = _database.Karma.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? CreateNewRow(userId);
|
||||
var user = _database.Karma.FirstOrDefault(u =>u.GuildId.Equals(Context.Guild.Id.AsLong()) && u.UserId.Equals(userId.AsLong())) ?? await CreateNewRow(userId);
|
||||
return user;
|
||||
}
|
||||
|
||||
private bool SetUser(KarmaModel user)
|
||||
private void SetUser(KarmaModel user)
|
||||
{
|
||||
_database.Karma.Update(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
private KarmaModel CreateNewRow(ulong userId)
|
||||
private async Task<KarmaModel> CreateNewRow(ulong userId)
|
||||
{
|
||||
var user = new KarmaModel()
|
||||
{
|
||||
|
@ -151,7 +150,7 @@ namespace Geekbot.net.Commands.User
|
|||
TimeOut = DateTimeOffset.MinValue
|
||||
};
|
||||
var newUser = _database.Karma.Add(user).Entity;
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,15 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
return;
|
||||
}
|
||||
|
||||
int guildMessages = 0;
|
||||
if (type == RankType.messages)
|
||||
{
|
||||
guildMessages = _database.Messages
|
||||
.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.Select(e => e.MessageCount)
|
||||
.Sum();
|
||||
}
|
||||
|
||||
var highscoreUsers = new Dictionary<RankUserDto, int>();
|
||||
var failedToRetrieveUser = false;
|
||||
foreach (var user in list)
|
||||
|
@ -112,7 +121,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
}
|
||||
|
||||
if (failedToRetrieveUser) replyBuilder.AppendLine(":warning: Couldn't get all userdata\n");
|
||||
replyBuilder.AppendLine($":bar_chart: **{type} Highscore for {Context.Guild.Name}**");
|
||||
replyBuilder.AppendLine($":bar_chart: **{type.ToString().CapitalizeFirst()} Highscore for {Context.Guild.Name}**");
|
||||
var highscorePlace = 1;
|
||||
foreach (var user in highscoreUsers)
|
||||
{
|
||||
|
@ -123,8 +132,10 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
replyBuilder.Append(user.Key.Username != null
|
||||
? $"**{user.Key.Username}#{user.Key.Discriminator}**"
|
||||
: $"**{user.Key.Id}**");
|
||||
|
||||
replyBuilder.Append($" - {user.Value} {type}\n");
|
||||
|
||||
replyBuilder.Append(type == RankType.messages
|
||||
? $" - {user.Value} {type} - {Math.Round((double) (100 * user.Value) / guildMessages, digits: 2)}%\n"
|
||||
: $" - {user.Value} {type}\n");
|
||||
|
||||
highscorePlace++;
|
||||
}
|
||||
|
@ -133,12 +144,17 @@ namespace Geekbot.net.Commands.User.Ranking
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<ulong, int> GetMessageList(int amount)
|
||||
{
|
||||
// return _database.Messages
|
||||
// .Where(k => k.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
// .OrderByDescending(o => o.MessageCount)
|
||||
// .Take(amount)
|
||||
// .ToDictionary(key => key.UserId.AsUlong(), key => key.MessageCount);
|
||||
return _redis.Db
|
||||
.HashGetAll($"{Context.Guild.Id}:Messages").ToDictionary().Take(amount + 1)
|
||||
.Where(user => !user.Key.Equals(0))
|
||||
|
|
|
@ -39,11 +39,18 @@ namespace Geekbot.net.Commands.User
|
|||
var age = Math.Floor((DateTime.Now - createdAt).TotalDays);
|
||||
var joinedDayAgo = Math.Floor((DateTime.Now - joinedAt).TotalDays);
|
||||
|
||||
var messages = (int) _redis.Db.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.ToString());
|
||||
var guildMessages = (int) _redis.Db.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
||||
var messages = _database.Messages.FirstOrDefault(e =>
|
||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) &&
|
||||
e.UserId.Equals(userInfo.Id.AsLong()))?.MessageCount;
|
||||
|
||||
var guildMessages = _database.Messages
|
||||
.Where(e => e.GuildId.Equals(Context.Guild.Id.AsLong()))
|
||||
.Select(e => e.MessageCount)
|
||||
.Sum();
|
||||
|
||||
var level = _levelCalc.GetLevel(messages);
|
||||
|
||||
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||
var percent = Math.Round((double) (100 * messages) / guildMessages, digits: 2);
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace Geekbot.net.Commands.Utils.Changelog
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ namespace Geekbot.net.Commands.Utils
|
|||
{
|
||||
try
|
||||
{
|
||||
var transDict = _translation.GetDict(Context);
|
||||
var transDict = await _translation.GetDict(Context);
|
||||
var choicesArray = choices.Split(';');
|
||||
var choice = new Random().Next(choicesArray.Length);
|
||||
await ReplyAsync(string.Format(transDict["Choice"], choicesArray[choice]));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ namespace Geekbot.net.Commands.Utils
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context, "Whoops, seems like the quote was to edgy to return");
|
||||
await _errorHandler.HandleCommandException(e, Context, "Whoops, seems like the quote was to edgy to return");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
"I counldn't find a quote from that user :disappointed:");
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
"I couldn't find a message with that id :disappointed:");
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
"I counldn't find a quote from that user :disappointed:");
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context,
|
||||
await _errorHandler.HandleCommandException(e, Context,
|
||||
"I couldn't find a message with that id :disappointed:");
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context, "I couldn't find a quote with that id :disappointed:");
|
||||
await _errorHandler.HandleCommandException(e, Context, "I couldn't find a quote with that id :disappointed:");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue