public CoreMessage Patch(MessageUpdatePayload value) { Content = value.Content; Embeds = value.Embeds.ToArray(); EditedTimestamp = value.EditedTimestamp; return this; }
public Message Patch([NotNull] MessageUpdatePayload value) { Content = value.Content; Embeds = value.Embeds.ToArray(); EditedTimestamp = value.EditedTimestamp; return(this); }
public static Message From(IClient client, [NotNull] MessageUpdatePayload message) { return(new Message(client, ulong.Parse(message.Id), MessageType.DEFAULT, null, ulong.Parse(message.ChannelId), null, message.GuildId == null ? (ulong?)null : ulong.Parse(message.GuildId), message.Member == null ? null : GuildMember.From(client, message.Member, message.Author), null, message.WebhookId == null ? (ulong?)null : ulong.Parse(message.WebhookId), User.From(client, message.Author), ulong.Parse(message.Author.Id), message.Content, message.Embeds.ToArray(), message.Attachments.ToArray(), message.Timestamp ?? DateTime.MinValue, message.EditedTimestamp, null)); }
private async Task RunAsync(MessageUpdatePayload messageUpdate) { var previousMessage = await Client.Cache.Messages.GetAsync(messageUpdate.Id); var message = previousMessage == null ? CoreMessage.From(Client, messageUpdate) : previousMessage.Clone().Patch(messageUpdate); await message.CacheAsync(); await Client.EventHandler.OnMessageUpdateAsync(previousMessage, message); }
private async Task RunAsync([NotNull] MessageUpdatePayload messageUpdate) { // Instantiate CoreMessage for usage everywhere var previousMessage = await Client.Cache.Messages.GetAsync(messageUpdate.Id, messageUpdate.ChannelId); var message = previousMessage == null ? Message.From(Client, messageUpdate) : previousMessage.Clone().Patch(messageUpdate); await message.CacheAsync(); // Handle the message await Client.EventHandler.OnMessageUpdateAsync(previousMessage, message); }
private static Message GenerateMessage(MessageUpdatePayload messageUpdate, CachedMessage?previousMessage) { return(new Message { Id = messageUpdate.Id, Author = messageUpdate.Author, Member = messageUpdate.Member, Content = messageUpdate.Content, Embeds = messageUpdate.Embeds, Attachments = messageUpdate.Attachments, Type = messageUpdate.Type ?? MessageType.DEFAULT, Timestamp = messageUpdate.Timestamp ?? previousMessage?.Timestamp ?? DateTime.MinValue, ChannelId = messageUpdate.ChannelId, GuildId = messageUpdate.GuildId, EditedTimestamp = messageUpdate.EditedTimestamp, WebhookId = messageUpdate.WebhookId }); }
private async Task RunAsync(MessageUpdatePayload messageUpdate) { try { // TODO(kyranet): Pull message.Author from Redis or fetch, Discord sometimes doesn't give it. var previousMessage = await Client.Cache.Messages.GetAsync(messageUpdate.Id); var message = GenerateMessage(messageUpdate, previousMessage); await Client.Cache.Messages.SetAsync(new CachedMessage(message)); RunMonitors(message); } catch (Exception exception) { Console.Error.WriteLine($"Error! {exception.Message}: ${exception.StackTrace}"); } }
internal async Task <DiscordMessage> EditDiscordMessageAsync(ulong channel_id, ulong message_id, string content, DiscordEmbed embed) { if (embed == null && content == null) { throw new ArgumentNullException("Cannot send empty message"); } var obj = new MessageUpdatePayload() { Content = content, Embed = embed }; var msg = new HttpRequestMessage(new HttpMethod("PATCH"), new Uri($"{_baseAddress}/channels/{channel_id}/messages/{message_id}")) { Content = new StringContent(JsonConvert.SerializeObject(obj)) }; var response = await _httpClient.SendRequestAsync(msg, RequestType.Other, CancellationToken).ConfigureAwait(false); var rescont = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <DiscordMessage>(rescont)); } else { if (!string.IsNullOrWhiteSpace(response.Headers.RetryAfter?.ToString())) { return(JsonConvert.DeserializeObject <DiscordMessage>(await RetryAsync(int.Parse(response.Headers.RetryAfter.ToString()), msg).ConfigureAwait(false))); } else { throw new Exception($"Returned Message: {rescont}"); } } }
private void Run(MessageUpdatePayload message) { Task.Run(() => RunAsync(message)); }