Exemplo n.º 1
0
        private bool API_SendChannelMessage(Plugin owner, string channel, KeyValuePair <string, bool>[] message_parts, string embed_color = null, Func <int, string, bool> callback = null, Dictionary <string, string> headers = null, string type = "plain")
        {
            List <GameMessagePart> parts = new List <GameMessagePart>();

            foreach (KeyValuePair <string, bool> part in message_parts)
            {
                parts.Add(
                    new GameMessagePart
                {
                    Content = part.Key,
                    Escape  = part.Value
                }
                    );
            }

            GameMessage sm = new GameMessage
            {
                MessageParts = parts.ToArray()
            };

            if (embed_color != null)
            {
                if (!KnownChannelList.CanStyleTo(channel))
                {
                    Puts(string.Format(lang.GetMessage("discord.channel_cannot_style", this), channel));
                    return(false);
                }
                sm.Type       = 1;
                sm.EmbedStyle = new GameMessageEmbedStyle
                {
                    Color = embed_color
                };
            }
            else
            {
                if (!KnownChannelList.CanSendTo(channel))
                {
                    Puts(string.Format(lang.GetMessage("discord.channel_cannot_send", this), channel));
                    return(false);
                }
            }

            if (channel[0] == '#')
            {
                channel = channel.Substring(1);
            }

            if (callback == null)
            {
                callback = (int code, string response) => (code == 200);
            }

            string body = JsonConvert.SerializeObject(sm);

            return(Request(new ApiRequest(RequestMethod.POST, $"{ApiMessageBaseURI}/{channel}", body, owner), callback));
        }