コード例 #1
0
ファイル: Message.cs プロジェクト: ElAfroNinja/Discord.Net
 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) { }
     }
 }
コード例 #2
0
ファイル: MessageQueue.cs プロジェクト: Kwoth/Discord.Net
        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) { }
            });
        }
コード例 #3
0
 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); }
     }
 }