public async Task <bool> SuspendAsync(ulong user, ulong suspender, string reason, Duplicate duplicate = null) { if (GetUserSuspension(user) != null) { // if user is already suspended, return feedback to user return(false); } // if there is no suspension, add one to the database using (SmeuContext database = smeuBaseFactory.GetSmeuBase()) { Suspension suspension = new Suspension { User = user, Date = DateTime.UtcNow, Suspender = suspender, Reason = reason }; database.Suspensions.Add(suspension); if (duplicate != null) { // if a duplicate was given, update the duplicate to reflect the suspension duplicate.Suspension = suspension; database.Duplicates.Update(duplicate); } await database.SaveChangesAsync().ConfigureAwait(false); } return(true); }
public async Task GetSuspensions() { using (var typing = Context.Channel.EnterTypingState()) { using (SmeuContext database = smeuBaseFactory.GetSmeuBase()) { // get all suspensions var dbresult = from s in database.Suspensions where s.Revoker == null select s; // if nobody is suspended, notify the user about that if (dbresult.Count() == 0) { await ReplyAsync("Er is op dit moment helemaal niemand af!"); } else { // present the suspensions in an embed EmbedBuilder eb = new EmbedBuilder() .WithTitle("Deze mensen zijn **af**:") .WithColor(Color.DarkRed); foreach (Suspension suspension in dbresult) { eb.AddField(client.GetUser(suspension.User).Username, suspension); } await ReplyAsync(embed : eb.Build()); } } } }
private async Task AddPendingSmeuToChat() { // get the smeu channel and add all the un-assigned smeu to it if (!(client.GetChannel(settings.SmeuChannelId) is IMessageChannel smeuChannel)) { await logger.LogAsync(new LogMessage(LogSeverity.Warning, "RestoreService", $"Could not restore pending smeu, because something went wrong while acquiring the smeu text channel")).ConfigureAwait(false); return; } using (SmeuContext database = smeuBaseFactory.GetSmeuBase()) { // get all unassigned smeu from the chat var dbresult = from s in database.Submissions where s.MessageId == 0 select s; await logger.LogAsync(new LogMessage(LogSeverity.Info, "RestoreService", $"Found {dbresult.Count()} smeu to restore.")).ConfigureAwait(false); foreach (Submission submission in dbresult) { // send all unassigned smeu to the chat and update the database IUserMessage msg = await smeuChannel.SendMessageAsync(submission.Smeu).ConfigureAwait(false); submission.MessageId = msg.Id; } database.Submissions.UpdateRange(dbresult); await database.SaveChangesAsync().ConfigureAwait(false); await logger.LogAsync(new LogMessage(LogSeverity.Info, "RestoreService", "All smeu are restored")).ConfigureAwait(false); } }
public async Task RestoreAsync() { await logger.LogAsync(new LogMessage(LogSeverity.Info, "RestoreService", "Start database migration")); try { using (SmeuContext context = smeuBaseFactory.GetSmeuBase()) { context.Database.Migrate(); } } catch (Exception e) { await logger.LogAsync(new LogMessage(LogSeverity.Critical, "RestoreService", "Attempted to migrate the database, but failed.", e)); Environment.Exit(-1); } await logger.LogAsync(new LogMessage(LogSeverity.Info, "RestoreService", "Database migrated")); }