Make errorhandler and languagehandler async, await all database actions

This commit is contained in:
runebaas 2018-06-13 22:18:57 +02:00
parent 926a632641
commit 95618b1f8b
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
46 changed files with 181 additions and 137 deletions

View file

@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Randomness.Cat
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.Randomness
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}

View file

@ -44,7 +44,7 @@ namespace Geekbot.net.Commands.Randomness.Chuck
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -44,7 +44,7 @@ namespace Geekbot.net.Commands.Randomness.Dad
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Randomness.Dog
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -50,7 +50,7 @@ namespace Geekbot.net.Commands.Randomness
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -31,7 +31,7 @@ namespace Geekbot.net.Commands.Randomness
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}
}

View file

@ -59,7 +59,7 @@ namespace Geekbot.net.Commands.Randomness
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
await _errorHandler.HandleCommandException(e, Context);
}
}

View file

@ -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()));