public async Task <Result <FeedbackMessage> > DeleteWarningAsync(long warningID) { var getWarning = await _warnings.GetWarningAsync(_context.GuildID.Value, warningID); if (!getWarning.IsSuccess) { return(Result <FeedbackMessage> .FromError(getWarning)); } var warning = getWarning.Entity; // This has to be done before the warning is actually deleted - otherwise, the lazy loader is removed and // navigation properties can't be evaluated var notifyResult = await _logging.NotifyUserWarningRemovedAsync(warning, _context.User.ID); if (!notifyResult.IsSuccess) { return(Result <FeedbackMessage> .FromError(notifyResult)); } var deleteWarning = await _warnings.DeleteWarningAsync(warning); return(deleteWarning.IsSuccess ? new FeedbackMessage("Warning deleted.", _feedback.Theme.Secondary) : Result <FeedbackMessage> .FromError(deleteWarning)); }
public async Task DeleteWarningAsync(long warningID) { var getWarning = await _warnings.GetWarningAsync(this.Context.Guild, warningID); if (!getWarning.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getWarning.ErrorReason); return; } var warning = getWarning.Entity; var deleteWarning = await _warnings.DeleteWarningAsync(warning); if (!deleteWarning.IsSuccess) { await _feedback.SendErrorAsync(this.Context, deleteWarning.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, "Warning deleted."); var rescinder = await this.Context.Guild.GetUserAsync(this.Context.User.Id); await _logging.NotifyUserWarningRemoved(warning, rescinder); }
public async Task <RuntimeResult> DeleteWarningAsync(long warningID) { var getWarning = await _warnings.GetWarningAsync(this.Context.Guild, warningID); if (!getWarning.IsSuccess) { return(getWarning.ToRuntimeResult()); } var warning = getWarning.Entity; // This has to be done before the warning is actually deleted - otherwise, the lazy loader is removed and // navigation properties can't be evaluated var rescinder = await this.Context.Guild.GetUserAsync(this.Context.User.Id); var notifyResult = await _logging.NotifyUserWarningRemovedAsync(warning, rescinder); if (!notifyResult.IsSuccess) { return(notifyResult.ToRuntimeResult()); } var deleteWarning = await _warnings.DeleteWarningAsync(warning); if (!deleteWarning.IsSuccess) { return(deleteWarning.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Warning deleted.")); }
public async Task DeleteWarningAsync(long warningID) { var getWarning = await _warnings.GetWarningAsync(this.Context.Guild, warningID); if (!getWarning.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getWarning.ErrorReason); return; } var warning = getWarning.Entity; // This has to be done before the warning is actually deleted - otherwise, the lazy loader is removed and // navigation properties can't be evaluated var rescinder = await this.Context.Guild.GetUserAsync(this.Context.User.Id); await _logging.NotifyUserWarningRemoved(warning, rescinder); var deleteWarning = await _warnings.DeleteWarningAsync(warning); if (!deleteWarning.IsSuccess) { await _feedback.SendErrorAsync(this.Context, deleteWarning.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, "Warning deleted."); }
/// <inheritdoc/> protected override async Task OnTickAsync(CancellationToken ct) { if (this.Client.ConnectionState != ConnectionState.Connected) { // Give the client some time to start up await Task.Delay(TimeSpan.FromSeconds(5), ct); return; } var now = DateTime.UtcNow; foreach (var guild in this.Client.Guilds) { var warnings = _warnings.GetWarnings(guild).Where(w => w.IsTemporary); foreach (var warning in warnings) { if (warning.ExpiresOn <= now) { await _warnings.DeleteWarningAsync(warning); } } if (!guild.GetUser(this.Client.CurrentUser.Id).GuildPermissions.BanMembers) { // No point in trying to rescind bans if the bot doesn't have ban perms continue; } var bans = _bans.GetBans(guild).Where(b => b.IsTemporary); foreach (var ban in bans) { if (ban.ExpiresOn <= now) { await _bans.DeleteBanAsync(ban); await guild.RemoveBanAsync((ulong)ban.User.DiscordID); } } } await Task.Delay(TimeSpan.FromHours(1), ct); }
private async Task <OperationResult> RescindWarningIfExpiredAsync ( ChannelLoggingService loggingService, WarningService warnings, SocketGuild guild, UserWarning warning, CancellationToken ct ) { if (ct.IsCancellationRequested) { return(OperationResult.FromError("Operation was cancelled.")); } if (!(warning.ExpiresOn <= DateTime.UtcNow)) { // No rescinding is needed, so we'll just bail out return(OperationResult.FromSuccess()); } var rescinder = guild.GetUser(this.Client.CurrentUser.Id); var notifyResult = await loggingService.NotifyUserWarningRemovedAsync(warning, rescinder); if (!notifyResult.IsSuccess) { return(OperationResult.FromError(notifyResult)); } var deleteResult = await warnings.DeleteWarningAsync(warning, ct); if (!deleteResult.IsSuccess) { return(OperationResult.FromError(deleteResult)); } return(OperationResult.FromSuccess()); }