protected override async Task ProcessReceivedPacket(string packetJSON) { try { DiscordWebSocketPacket packet = SerializerHelper.DeserializeFromString <DiscordWebSocketPacket>(packetJSON); this.lastSequenceNumber = packet.Sequence; switch (packet.OPCodeType) { case DiscordWebSocketPacketTypeEnum.Other: if (packet.IsReadyPacket) { this.BotUser = new DiscordUser((JObject)packet.Data["user"]); this.sessionID = packet.Data["session_id"].ToString(); this.IsReady = true; } break; case DiscordWebSocketPacketTypeEnum.Heartbeat: break; case DiscordWebSocketPacketTypeEnum.Hello: this.heartbeatTime = (int)packet.Data["heartbeat_interval"]; JObject data = new JObject(); data["token"] = this.botToken; data["large_threshold"] = 100; JObject propertiesObj = new JObject(); propertiesObj["$device"] = "Mix It Up"; data["properties"] = propertiesObj; DiscordWebSocketPacket identifyPacket = new DiscordWebSocketPacket() { OPCodeType = DiscordWebSocketPacketTypeEnum.Identify, Data = data }; await this.Send(identifyPacket); break; case DiscordWebSocketPacketTypeEnum.HeartbeatAck: break; default: break; } } catch (Exception ex) { Logger.Log(ex); } }
public async Task Send(DiscordWebSocketPacket packet) { packet.Sequence = this.lastSequenceNumber; await this.Send(SerializerHelper.SerializeToString(packet)); }