示例#1
0
        /// <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();
         }
     }));
 }
示例#3
0
 public static bool TryDeleteAsync(this IDeletable deletable, RequestOptions options = null)
 {
     try
     {
         deletable.DeleteAsync(options);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#4
0
        public static async Task <bool> TryDeleteAsync(this IDeletable deletable, RequestOptions options = null)
        {
            try
            {
                await deletable.DeleteAsync(options).ConfigureAwait(false);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#5
0
        /// <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);
            }
        }
示例#6
0
        /// <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);
            }
        }
示例#7
0
 public static Task DeleteAfterTimeSpan(this IDeletable message, TimeSpan timeSpan)
 {
     return(Task.Delay(timeSpan).ContinueWith(async _ => await message.DeleteAsync()));
 }
示例#8
0
            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
 });