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