Exemple #1
0
 public async Task Delete()
 {
     if (Client.Config.UseMessageQueue)
         Client.MessageQueue.QueueDelete(this);
     else
     {
         var request = new DeleteMessageRequest(Channel.Id, Id);
         try { await Client.ClientAPI.Send(request).ConfigureAwait(false); }
         catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
     }
 }
Exemple #2
0
        private Task RunDeleteQueue(CancellationToken cancelToken)
        {
            return Task.Run(async () =>
            {
                try
                {
                    while (!cancelToken.IsCancellationRequested)
                    {
                        Message msg;
                        while (_pendingDeletes.TryPeek(out msg) && msg.State != MessageState.Queued)
                        {
                            if (_pendingDeletes.TryDequeue(out msg))
                            {
                                DecrementCount();
                                if (msg.State == MessageState.Normal)
                                {
                                    try
                                    {
                                        var request = new DeleteMessageRequest(msg.Channel.Id, msg.Id);
                                        await _rest.Send(request).ConfigureAwait(false);
                                    }
                                    catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } //Ignore
                                    catch (Exception ex) { _logger.Error($"Failed to delete message {msg.Path}", ex); }
                                }
                            }
                        }

                        await Task.Delay(Discord.DiscordConfig.MessageQueueInterval).ConfigureAwait(false);
                    }
                }
                catch (OperationCanceledException) { }
            });
        }
 internal async Task Delete(Message msg)
 {                
     if (msg.State == MessageState.Normal)
     {
         try
         {
             var request = new DeleteMessageRequest(msg.Channel.Id, msg.Id);
             await _client.ClientAPI.Send(request).ConfigureAwait(false);
         }
         catch (Exception ex) { msg.State = MessageState.Failed; _logger.Error("Failed to delete message", ex); }
     }
 }