make database saves async
This commit is contained in:
parent
8c107de92e
commit
e0d6a97dca
7 changed files with 26 additions and 28 deletions
|
@ -39,7 +39,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.WelcomeMessage = welcomeMessage;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
|
||||
await ReplyAsync($"Welcome message has been changed\r\nHere is an example of how it would look:\r\n{formatedMessage}");
|
||||
|
@ -56,7 +56,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.ModChannel = channel.Id.AsLong();
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine("Successfully saved mod channel, you can now do the following");
|
||||
|
@ -82,7 +82,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
|
||||
guild.ShowLeave = !guild.ShowLeave;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await modChannel.SendMessageAsync(guild.ShowLeave
|
||||
? "Saved - now sending messages here when someone leaves"
|
||||
: "Saved - stopping sending messages here when someone leaves"
|
||||
|
@ -106,7 +106,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
|
||||
guild.ShowDelete = !guild.ShowDelete;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await modChannel.SendMessageAsync(guild.ShowDelete
|
||||
? "Saved - now sending messages here when someone deletes a message"
|
||||
: "Saved - stopping sending messages here when someone deletes a message"
|
||||
|
@ -131,7 +131,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.Language = language;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var trans = _translation.GetDict(Context);
|
||||
await ReplyAsync(trans["NewLanguageSet"]);
|
||||
|
@ -157,7 +157,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.WikiLang = language;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
await ReplyAsync($"Now using the {language} wikipedia");
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.Ping = !guild.Ping;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync(guild.Ping ? "i will reply to ping now" : "No more pongs...");
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -194,7 +194,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
var guild = GetGuildSettings(Context.Guild.Id);
|
||||
guild.Hui = !guild.Hui;
|
||||
_database.GuildSettings.Update(guild);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync(guild.Hui ? "i will reply to hui now" : "No more hui's...");
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
RoleId = role.Id.AsLong(),
|
||||
WhiteListName = roleName
|
||||
});
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"Added {role.Name} to the whitelist");
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -146,7 +146,7 @@ namespace Geekbot.net.Commands.Admin
|
|||
if (roleFromDb != null)
|
||||
{
|
||||
_database.RoleSelfService.Remove(roleFromDb);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
await ReplyAsync($"Removed {roleName} from the whitelist");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
SecondUserId = userKeys.Item2,
|
||||
Strength = shippingRate
|
||||
});
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
|
||||
UpdateRecieved(user.Id);
|
||||
UpdateGiven(Context.User.Id);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Geekbot.net.Commands.User
|
|||
actor.TimeOut = DateTimeOffset.Now;
|
||||
SetUser(actor);
|
||||
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
|
@ -98,7 +98,7 @@ namespace Geekbot.net.Commands.User
|
|||
actor.TimeOut = DateTimeOffset.Now;
|
||||
SetUser(actor);
|
||||
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
|
||||
var quote = CreateQuoteObject(lastMessage);
|
||||
_database.Quotes.Add(quote);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var embed = QuoteBuilder(quote);
|
||||
await ReplyAsync("**Quote Added**", false, embed.Build());
|
||||
|
@ -107,7 +107,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
|
||||
var quote = CreateQuoteObject(message);
|
||||
_database.Quotes.Add(quote);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
var embed = QuoteBuilder(quote);
|
||||
await ReplyAsync("**Quote Added**", false, embed.Build());
|
||||
|
@ -169,7 +169,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
if (quote != null)
|
||||
{
|
||||
_database.Quotes.Remove(quote);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
var embed = QuoteBuilder(quote);
|
||||
await ReplyAsync($"**Removed #{id}**", false, embed.Build());
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Geekbot.net.Database
|
|||
_client = client;
|
||||
}
|
||||
|
||||
public Task Migrate()
|
||||
public async Task Migrate()
|
||||
{
|
||||
_logger.Information(LogSource.Geekbot, "Starting migration process");
|
||||
foreach (var guild in _client.Guilds)
|
||||
|
@ -49,7 +49,7 @@ namespace Geekbot.net.Database
|
|||
var qd = JsonConvert.DeserializeObject<QuoteObjectDto>(q);
|
||||
var quote = CreateQuoteObject(guild.Id, qd);
|
||||
_database.Quotes.Add(quote);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ namespace Geekbot.net.Database
|
|||
TimeOut = DateTimeOffset.MinValue
|
||||
};
|
||||
_database.Karma.Add(user);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ namespace Geekbot.net.Database
|
|||
Rolls = int.Parse(q.Value)
|
||||
};
|
||||
_database.Rolls.Add(user);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ namespace Geekbot.net.Database
|
|||
Recieved= int.Parse(gotten[int.Parse(q.Name)].Value)
|
||||
};
|
||||
_database.Slaps.Add(user);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ namespace Geekbot.net.Database
|
|||
MessageCount= int.Parse(q.Value)
|
||||
};
|
||||
_database.Messages.Add(user);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ namespace Geekbot.net.Database
|
|||
Strength = int.Parse(q.Value)
|
||||
};
|
||||
_database.Ships.Add(user);
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
done.Add(q.Name);
|
||||
}
|
||||
catch
|
||||
|
@ -309,7 +309,7 @@ namespace Geekbot.net.Database
|
|||
Joined = user.CreatedAt,
|
||||
UsedNames = names
|
||||
}, model => model.UserId.Equals(user.Id.AsLong()));
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -333,14 +333,12 @@ namespace Geekbot.net.Database
|
|||
Name = guild.Name,
|
||||
Owner = guild.Owner.Id.AsLong()
|
||||
});
|
||||
_database.SaveChanges();
|
||||
await _database.SaveChangesAsync();
|
||||
|
||||
#endregion
|
||||
_logger.Information(LogSource.Geekbot, $"Finished Migration for {guild.Name}");
|
||||
}
|
||||
_logger.Information(LogSource.Geekbot, "Finished migration process");
|
||||
|
||||
return Task.CompletedTask;;
|
||||
}
|
||||
|
||||
private QuoteModel CreateQuoteObject(ulong guild, QuoteObjectDto quote)
|
||||
|
|
Loading…
Reference in a new issue