/// <summary> /// Removes <see cref="IMessage" /> after a timeout /// </summary> /// <param name="message">Message to remove</param> /// <param name="timeout">Timeout to remove message</param> /// <returns></returns> private static async Task RemoveAfterTimeout(this IDeletable message, int timeout = 10000) { await Task.Delay(timeout); await message.DeleteAsync(new RequestOptions { RetryMode = RetryMode.RetryRatelimit }); await Task.CompletedTask; }
public static Task DeleteAfterTimeSpan(this IDeletable message, TimeSpan timeSpan) { return(Task.Delay(timeSpan).ContinueWith(async _ => { if (message != null) { await message?.DeleteAsync(); } })); }
public static bool TryDeleteAsync(this IDeletable deletable, RequestOptions options = null) { try { deletable.DeleteAsync(options); return(true); } catch { return(false); } }
public static async Task <bool> TryDeleteAsync(this IDeletable deletable, RequestOptions options = null) { try { await deletable.DeleteAsync(options).ConfigureAwait(false); return(true); } catch { return(false); } }
/// <inheritdoc /> public async Task UnConfigureGuildAsync(IGuild guild) { var config = await ModerationConfigRepository.ReadAsync(guild.Id); if (config != null) { IDeletable muteRole = guild.Roles.FirstOrDefault(x => x.Id == config.MuteRoleId); if (muteRole != null) { await muteRole.DeleteAsync(); } await ModerationConfigRepository.DeleteAsync(config.GuildId); } }
/// <inheritdoc /> public async Task UnConfigureGuildAsync(IGuild guild) { foreach (var mapping in await ModerationMuteRoleMappingRepository .SearchBriefsAsync(new ModerationMuteRoleMappingSearchCriteria() { GuildId = guild.Id, IsDeleted = false, })) { IDeletable muteRole = guild.Roles.FirstOrDefault(x => x.Id == mapping.MuteRoleId); if (muteRole != null) { await muteRole.DeleteAsync(); } await ModerationMuteRoleMappingRepository.TryDeleteAsync(mapping.Id, DiscordClient.CurrentUser.Id); } }
public static Task DeleteAfterTimeSpan(this IDeletable message, TimeSpan timeSpan) { return(Task.Delay(timeSpan).ContinueWith(async _ => await message.DeleteAsync())); }
public async Task <Result> Execute(SocketUserMessage e, IDeletable deletable) { await deletable.DeleteAsync(); return(new Result(null, "Succesfully deleted the given object.")); }
// deleting public static Task DeleteAsync(this IDeletable entity, CancellationToken cancellationToken) => entity.DeleteAsync(new RequestOptions { CancelToken = cancellationToken });