示例#1
0
        public async Task <Opcode.Channel> DeleteChannel(ulong channelId)
        {
            HttpResponseMessage response = await this._client.DeleteAsync(string.Format("channels/{0}", channelId));

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                Opcode.Channel channel = JsonConvert.DeserializeObject <Opcode.Channel>(json);
                return(channel);
            }

            throw new Exception();
        }
示例#2
0
        public async Task <Opcode.Channel> CreateGuildChannel(ulong guildId, string channelName,
                                                              Opcode.Channel.ChannelType?channelType = null,
                                                              string topic                  = null, uint?bitrate  = null, uint?userlimit = null,
                                                              uint?rateLimitPerUser         = null, uint?position = null,
                                                              Opcode.Overwrite[] overwrites = null, Snowflake parentId = null, bool?nsfw = null)
        {
            if (channelName.Length < 2 || channelName.Length > 100)
            {
                throw new ArgumentOutOfRangeException();
            }

            Dictionary <string, object> jsonParams = new Dictionary <string, object>();

            jsonParams.Add("name", channelName);

            if (channelType != null)
            {
                jsonParams.Add("type", (uint)channelType);

                if (channelType == Opcode.Channel.ChannelType.GuildVoice)
                {
                    if (bitrate != null)
                    {
                        jsonParams.Add("bitrate", bitrate);
                    }
                    if (userlimit != null)
                    {
                        jsonParams.Add("user_limit", userlimit);
                    }
                }
            }

            if (topic != null)
            {
                jsonParams.Add("topic", topic);
            }
            if (rateLimitPerUser != null)
            {
                jsonParams.Add("rate_limit_per_user", rateLimitPerUser);
            }
            if (position != null)
            {
                jsonParams.Add("position", position);
            }
            if (overwrites != null)
            {
                jsonParams.Add("permission_overwrites", overwrites);
            }
            if (parentId != null)
            {
                jsonParams.Add("parent_id", parentId.Id.ToString());
            }
            if (nsfw != null)
            {
                jsonParams.Add("nsfw", nsfw.ToString());
            }

            StringContent parameters = new StringContent(JsonConvert.SerializeObject(jsonParams), Encoding.UTF8, "application/json");

            HttpResponseMessage response = await this._client.PostAsync(string.Format("guilds/{0}/channels", guildId), parameters);

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                Opcode.Channel channel = JsonConvert.DeserializeObject <Opcode.Channel>(json);
                return(channel);
            }

            throw new NotImplementedException();
        }
示例#3
0
        private void OpcodeDispatch(Payload payload)
        {
            switch (payload.Opcode)
            {
            case 0:     // Dispatch
                this._last_sequence_number = (int)payload.SequenceNumber;
                //this.messageLog.Write(payload.Data.ToString());
                //this.messageLog.FlushAsync().Wait();
                switch (payload.EventName)
                {
                case "CHANNEL_CREATE":
                    if (this.OnChannelCreate != null)
                    {
                        Opcode.Channel channel = JsonConvert.DeserializeObject <Opcode.Channel>(payload.Data.ToString());
                        this.OnChannelCreate(channel);
                    }
                    break;

                case "CHANNEL_UPDATE":
                    if (this.OnChannelUpdate != null)
                    {
                        Opcode.Channel channel = JsonConvert.DeserializeObject <Opcode.Channel>(payload.Data.ToString());
                        OnChannelUpdate(channel);
                    }
                    break;

                case "CHANNEL_DELETE":
                    if (this.OnChannelDelete != null)
                    {
                        Opcode.Channel channel = JsonConvert.DeserializeObject <Opcode.Channel>(payload.Data.ToString());
                        this.OnChannelDelete(channel);
                    }
                    break;

                case "CHANNEL_PINS_UPDATE":
                    break;

                case "GUILD_CREATE":
                    break;

                case "GUILD_UPDATE":
                    break;

                case "GUILD_DELETE":
                    break;

                case "GUILD_BAN_ADD":
                    break;

                case "GUILD_BAN_REMOVE":
                    break;

                case "GUILD_EMOJIS_UPDATE":
                    break;

                case "GUILD_INTEGRATIONS_UPDATE":
                    break;

                case "GUILD_MEMBER_ADD":
                    break;

                case "GUILD_MEMBER_REMOVE":
                    break;

                case "GUILD_MEMBER_UPDATE":
                    break;

                case "GUILD_MEMBERS_CHUNK":
                    break;

                case "GUILD_ROLE_CREATE":
                    break;

                case "GUILD_ROLE_UPDATE":
                    break;

                case "GUILD_ROLE_DELETE":
                    break;

                case "READY":
                    Opcode.Ready ready = JsonConvert.DeserializeObject <Opcode.Ready>(payload.Data.ToString());
                    this._me         = ready.User;
                    this._session_id = ready.SessionId;
                    if (this.OnReady != null)
                    {
                        OnReady(ready);
                    }
                    break;

                case "PRESENCE_UPDATE":
                    if (this.OnPresenceUpdate != null)
                    {
                        Opcode.PresenceUpdate presence = JsonConvert.DeserializeObject <Opcode.PresenceUpdate>(payload.Data.ToString());
                        OnPresenceUpdate(presence);
                    }
                    break;

                case "TYPING_START":
                    //Opcode.TypingStart typing = JsonConvert.DeserializeObject<Opcode.TypingStart>(payload.Data.ToString());
                    //OnTypingStart(typing);
                    break;

                case "MESSAGE_CREATE":
                    if (this.OnMessageCreate != null)
                    {
                        Opcode.Message message = JsonConvert.DeserializeObject <Opcode.Message>(payload.Data.ToString());
                        OnMessageCreate(message);
                    }
                    break;

                default:
                    Console.WriteLine(payload.EventName);
                    break;
                }
                break;

            case 7:     // Reconnect
                break;

            case 9:     // Invalid session
                break;

            case 10:     //Hello
                Opcode.Hello hello = JsonConvert.DeserializeObject <Opcode.Hello>(payload.Data.ToString());
                this._timer           = new System.Timers.Timer(hello.HeartbeatInterval);
                this._timer.AutoReset = true;
                this._timer.Elapsed  += (source, e) => this.HeartBeat();
                this._timer.Enabled   = true;
                break;

            case 11:     // Heartbeat acknowledge
                break;

            default:
                //Console.WriteLine(JsonConvert.SerializeObject(payload));
                break;
            }
        }
示例#4
0
 public async Task <Opcode.Message[]> GetPinnedMessages(Opcode.Channel channel)
 {
     return(await this.GetPinnedMessages(channel.Id.Id));
 }
示例#5
0
 public async Task TriggerTypingIndicator(Opcode.Channel channel)
 {
     await this.TriggerTypingIndicator(channel.Id.Id);
 }