Example #1
0
        public async Task <Message> SendAsync(SendableMessage data)
        {
            // Cache the string values
            var id      = Id.ToString();
            var channel = ChannelId.ToString();

            // Retrieve the previous message
            var previous = await Client.Cache.EditableMessages.GetAsync(id, channel);

            Message response;

            // If a previous message exists...
            if (previous != null)
            {
                // Then we check whether or not it's editable (has no attachments), and we're not sending attachments
                if (Attachments.Length == 0 && data.File == null)
                {
                    // We update the message and return.
                    response = From(Client, await Client.Rest.Channels[channel]
                                    .Messages[previous.OwnMessageId.ToString()]
                                    .PatchAsync <Spectacles.NET.Types.Message>(data));
                    response.GuildId = GuildId;
                    return(response);
                }

                // Otherwise we delete the previous message and do a fallback.
                await Client.Rest.Channels[channel].Messages[previous.OwnMessageId.ToString()].DeleteAsync();
            }

            // Send a message to Discord, receive a Message back.
            response = From(Client,
                            await Client.Rest.Channels[channel].Messages.PostAsync <Spectacles.NET.Types.Message>(data));
            response.GuildId = GuildId;

            // Store the message into Redis for later processing.
            await Client.Cache.EditableMessages.SetAsync(
                new EditableMessage(Client, Id, response.Id), channel);

            // Return the response.
            return(response);
        }
Example #2
0
 public static async Task <Message> EditAsync(this Message message, Client client, SendableMessage data)
 {
     return(await client.Rest.Channels[message.ChannelId].Messages[message.Id].PatchAsync <Message>(data));
 }
Example #3
0
        public static async Task <Message> SendAsync(this Message message, Client client, SendableMessage data)
        {
            // Retrieve the previous message
            var previous = await client.Cache.EditableMessages.GetAsync(message.Id, message.ChannelId);

            // If a previous message exists...
            if (previous != null)
            {
                // Then we check whether or not it's editable (has no attachments), and we're not sending attachments
                if (message.Attachments.Count == 0 && data.File == null)
                // We update the message and return.
                {
                    return(await client.Rest.Channels[message.ChannelId].Messages[previous.OwnMessageId]
                           .PatchAsync <Message>(data));
                }

                // Otherwise we delete the previous message and do a fallback.
                await client.Rest.Channels[message.ChannelId].Messages[previous.OwnMessageId].DeleteAsync();
            }

            // Send a message to Discord, receive a Message back.
            var response = await client.Rest.Channels[message.ChannelId].Messages.PostAsync <Message>(data);

            // Store the message into Redis for later processing.
            await client.Cache.EditableMessages.SetAsync(
                new CachedEditableMessage(message.Id, response.Id), message.ChannelId);

            // Return the response.
            return(response);
        }
Example #4
0
 public async Task <Message> EditAsync(SendableMessage data)
 {
     return(From(Client, await Client.Rest.Channels[ChannelId.ToString()].Messages[Id.ToString()]
                 .PatchAsync <Spectacles.NET.Types.Message>(data)));
 }
Example #5
0
 /// <summary>
 /// Sends the specified message.
 /// </summary>
 public void Send(SendableMessage message)
 {
     message.Send(writer, this);
 }
Example #6
0
 /// <summary>
 /// Sends the specified message.
 /// </summary>
 public void Send(SendableMessage message)
 {
     message.Send(writer, this);
 }
Example #7
0
		public async Task<CoreMessage> EditAsync(SendableMessage data)
		{
			return From(Client, await Client.Rest.Channels[ChannelId.ToString()].Messages[Id.ToString()]
				.PatchAsync<Message>(data));
		}