Ejemplo n.º 1
0
        public async Task <Message> EditMessage(string channelId, string messageId, MessageEdit edit)
        {
            if (edit.Content == null && !edit.Embed.HasValue)
            {
                throw new Exception("Expecting MessageEdit to have either content or embed");
            }

            var body = new Dictionary <string, string>();

            if (edit.Content != null)
            {
                body.Add("content", edit.Content);
            }

            if (edit.Embed.HasValue)
            {
                body.Add("embed", JsonConvert.SerializeObject(edit.Embed.Value));
            }

            var response = await ClientToolbox.PatchAsync(DiscordAPI.Message(channelId, messageId), body);

            if (response != null && response.IsSuccessStatusCode)
            {
                Message message = this.client.CreateStructure <Message>(await response.Content.ReadAsStringAsync());

                // TODO: Should be by reference, Client object may be large
                // Inject client
                return(this.InjectClient(ref message));
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static async Task <bool> DeleteGuildEmoji(string guildId, string emojiId)
        {
            // TODO: DiscordAPI.Emoji
            var response = await ClientToolbox.DeleteAsync(DiscordAPI.Message(channelId, messageId));

            return(response.StatusCode == System.Net.HttpStatusCode.NoContent);
        }
Ejemplo n.º 3
0
 public Client()
 {
     this.manager = new ClientManager(this);
     this.guilds  = new Dictionary <string, Guild>();
     this.users   = new Dictionary <string, User>();;
     this.toolbox = new ClientToolbox(this);
 }
Ejemplo n.º 4
0
        public async Task <StructureType> FetchInjectableStructure <StructureType>(string url) where StructureType : ClientInjectable
        {
            var response = await ClientToolbox.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                StructureType result = this.client.CreateStructure <StructureType>(await response.Content.ReadAsStringAsync());

                return(result);
            }

            return(default(StructureType));
        }
Ejemplo n.º 5
0
        public static async Task <StructureType> FetchStructure <StructureType>(string url)
        {
            var response = await ClientToolbox.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                StructureType result = JsonConvert.DeserializeObject <StructureType>(await response.Content.ReadAsStringAsync());

                return(result);
            }

            return(default(StructureType));
        }
Ejemplo n.º 6
0
        // TODO: Return the message
        /// <summary>
        /// Create a message in the specified channel
        /// </summary>
        /// <param name="channelId">The channel in which to send the message</param>
        /// <param name="content">The message's content</param>
        public async Task <Message> CreateMessage(string channelId, string content)
        {
            var response = await ClientToolbox.PostAsync(DiscordAPI.ChannelMessages(channelId), new Dictionary <string, string>() {
                { "content", content }
            });

            if (response.IsSuccessStatusCode)
            {
                Message message = this.client.CreateStructure <Message>(await response.Content.ReadAsStringAsync());

                // TODO: Should be by reference, Client object may be large
                // Inject client
                return(this.InjectClient(ref message));
            }

            return(null);
        }
Ejemplo n.º 7
0
        public static async Task <bool> DeleteOwnReaction(string channelId, string messageId, SimpleEmoji emoji)
        {
            var response = await ClientToolbox.DeleteAsync(DiscordAPI.MessageReaction(channelId, messageId, emoji.ToString()));

            return(response.StatusCode == System.Net.HttpStatusCode.NoContent);
        }
Ejemplo n.º 8
0
        public static async Task <bool> DeleteMessage(string channelId, string messageId)
        {
            var response = await ClientToolbox.DeleteAsync(DiscordAPI.Message(channelId, messageId));

            return(response.StatusCode == System.Net.HttpStatusCode.NoContent);
        }
Ejemplo n.º 9
0
 public Task <ChannelType> GetChannel <ChannelType>(string channelId) where ChannelType : Channel
 {
     // TODO: Need to inject client
     return(ClientToolbox.FetchStructure <ChannelType>(DiscordAPI.Channel(channelId)));
 }