Example #1
0
        private void PresenceUpdateEvents(JObject message)
        {
            DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
            var user = ServersList.Find(x => x.members.Find(y => y.user.id == message["d"]["id"].ToString()) != null).members.Find(x => x.user.id == message["d"]["id"].ToString());

            dpuea.game_id = message["d"]["game_id"].ToString() == null ? "null" : message["d"]["game_id"].ToString();
            if (message["d"]["status"].ToString() == "online")
            {
                dpuea.status = DiscordUserStatus.ONLINE;
            }
            else if (message["d"]["status"].ToString() == "idle")
            {
                dpuea.status = DiscordUserStatus.IDLE;
            }
            else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
            {
                dpuea.status = DiscordUserStatus.OFFLINE;
            }
            if (PresenceUpdated != null)
            {
                PresenceUpdated(this, dpuea);
            }
        }
        private void PresenceUpdateEvents(JObject message)
        {
            DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
            dpuea.RawJson = message;
            var pserver = ServersList.Find(x => x.members.Find(y => y.ID == message["d"]["id"].ToString()) != null);
            if (pserver != null)
            {
                var user = pserver.members.Find(x => x.ID == message["d"]["id"].ToString());
                dpuea.user = user;

                string game = message["d"]["game"].ToString();
                if (message["d"]["game"].IsNullOrEmpty())
                    dpuea.game = "";
                else
                    dpuea.game = message["d"]["game"]["name"].ToString();

                if (message["d"]["status"].ToString() == "online")
                    dpuea.status = DiscordUserStatus.ONLINE;
                else if (message["d"]["status"].ToString() == "idle")
                    dpuea.status = DiscordUserStatus.IDLE;
                else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
                    dpuea.status = DiscordUserStatus.OFFLINE;
                if (PresenceUpdated != null)
                    PresenceUpdated(this, dpuea);
            }
        }
Example #3
0
        private void PresenceUpdateEvents(JObject message)
        {
            DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
            dpuea.RawJson = message;

            if (!message["d"]["guild_id"].IsNullOrEmpty())
            {
                var server = ServersList.Find(x => x.ID == message["d"]["guild_id"].ToString());
                if (server != null)
                {
                    var user = server.GetMemberByKey(message["d"]["user"]["id"].ToString().Trim());
                    if (user != null)
                    {
                        //If usernames change.
                        if (!message["d"]["user"]["username"].IsNullOrEmpty())
                            user.Username = message["d"]["user"]["username"].ToString();

                        //If avatar changes.
                        if (!message["d"]["user"]["avatar"].IsNullOrEmpty())
                            user.Avatar = message["d"]["user"]["avatar"].ToString();

                        if (message["d"]["nick"].ToString() == null)
                            user.Nickname = null;
                        else
                            user.Nickname = message["d"]["nick"].ToString();

                        //Actual presence update
                        user.SetPresence(message["d"]["status"].ToString());

                        //Updating games.
                        string game = message["d"]["game"].ToString();
                        if (message["d"]["game"].IsNullOrEmpty()) //null means not playing
                        {
                            dpuea.Game = "";
                            user.CurrentGame = null;
                        }
                        else
                        {
                            if (message["d"]["game"]["name"].IsNullOrEmpty())
                                if (message["d"]["game"]["game"].IsNullOrEmpty())
                                    dpuea.Game = "";
                                else
                                    dpuea.Game = message["d"]["game"]["game"].ToString();
                            else
                                dpuea.Game = message["d"]["game"]["name"].ToString();
                            user.CurrentGame = dpuea.Game;

                            if (message["d"]["game"]["type"] != null && message["d"]["game"]["type"].ToObject<int>() == 1)
                            {
                                user.Streaming = true;
                                if (message["d"]["game"]["url"].ToString() != null)
                                    user.StreamURL = message["d"]["game"]["url"].ToString();
                            }
                        }
                        dpuea.User = user;

                        if (message["d"]["status"].ToString() == "online")
                            dpuea.Status = DiscordUserStatus.ONLINE;
                        else if (message["d"]["status"].ToString() == "idle")
                            dpuea.Status = DiscordUserStatus.IDLE;
                        else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
                            dpuea.Status = DiscordUserStatus.OFFLINE;
                        if (PresenceUpdated != null)
                            PresenceUpdated(this, dpuea);
                    }
                    else
                    {
                        if (!message["d"]["guild_id"].IsNullOrEmpty()) //if this is null or empty, that means this pertains to friends list
                        {
                            if (!message["d"]["user"]["username"].IsNullOrEmpty() && !message["d"]["user"]["id"].IsNullOrEmpty())
                            {
                                DebugLogger.Log($"User {message["d"]["user"]["username"]} ({message["d"]["user"]["id"].ToString()}) doesn't exist in server {server.Name} ({server.ID}) no problemo. Creating/adding", MessageLevel.Debug);
                                DiscordMember memeber = JsonConvert.DeserializeObject<DiscordMember>(message["d"]["user"].ToString());
                                memeber.parentclient = this;
                                memeber.SetPresence(message["d"]["status"].ToString());
                                memeber.Parent = ServersList.Find(x => x.ID == message["d"]["guild_id"].ToString());

                                if (message["d"]["game"].IsNullOrEmpty())
                                {
                                    dpuea.Game = "";
                                    memeber.CurrentGame = null;
                                }
                                else
                                {
                                    dpuea.Game = message["d"]["game"]["name"].ToString();
                                    memeber.CurrentGame = dpuea.Game;
                                    if (message["d"]["game"]["type"].ToObject<int>() == 1)
                                    {
                                        user.Streaming = true;
                                        if (message["d"]["game"]["url"].ToString() != null)
                                            user.StreamURL = message["d"]["game"]["url"].ToString();
                                    }
                                }

                                if (message["d"]["status"].ToString() == "online")
                                    dpuea.Status = DiscordUserStatus.ONLINE;
                                else if (message["d"]["status"].ToString() == "idle")
                                    dpuea.Status = DiscordUserStatus.IDLE;
                                else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
                                    dpuea.Status = DiscordUserStatus.OFFLINE;

                                memeber.Parent.AddMember(memeber);
                            }
                        }
                    }
                }
            }
        }
Example #4
0
 private void PresenceUpdateEvents(JObject message)
 {
     DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
     var user = ServersList.Find(x => x.members.Find(y => y.user.id == message["d"]["id"].ToString()) != null).members.Find(x => x.user.id == message["d"]["id"].ToString());
     dpuea.game_id = message["d"]["game_id"].ToString() == null ? "null" : message["d"]["game_id"].ToString();
     if (message["d"]["status"].ToString() == "online")
         dpuea.status = DiscordUserStatus.ONLINE;
     else if (message["d"]["status"].ToString() == "idle")
         dpuea.status = DiscordUserStatus.IDLE;
     else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
         dpuea.status = DiscordUserStatus.OFFLINE;
     if (PresenceUpdated != null)
         PresenceUpdated(this, dpuea);
 }
Example #5
0
        private void PresenceUpdateEvents(JObject message)
        {
            DiscordPresenceUpdateEventArgs dpuea = new DiscordPresenceUpdateEventArgs();
            dpuea.RawJson = message;
            //var pserver = ServersList.Find(x => x.members.Find(y => y.ID == message["d"]["id"].ToString()) != null);
            foreach(var server in ServersList)
            {
                var user = server.members.Find(x => x.ID == message["d"]["id"].ToString());
                if(user != null)
                {
                    //If usernames change.
                    if (!message["d"]["username"].IsNullOrEmpty())
                        user.Username = message["d"]["username"].ToString();

                    //If avatar changes.
                    if (!message["d"]["avatar"].IsNullOrEmpty())
                        user.Avatar = message["d"]["avatar"].ToString();

                    //Actual presence update
                    user.SetPresence(message["d"]["status"].ToString());

                    //Updating games.
                    string game = message["d"]["game"].ToString();
                    if (message["d"]["game"].IsNullOrEmpty())
                    {
                        dpuea.game = "";
                        user.CurrentGame = null;
                    }
                    else
                    {
                        dpuea.game = message["d"]["game"]["name"].ToString();
                        user.CurrentGame = dpuea.game;
                    }
                    dpuea.user = user;

                    if (message["d"]["status"].ToString() == "online")
                        dpuea.status = DiscordUserStatus.ONLINE;
                    else if (message["d"]["status"].ToString() == "idle")
                        dpuea.status = DiscordUserStatus.IDLE;
                    else if (message["d"]["status"].ToString() == null || message["d"]["status"].ToString() == "offline")
                        dpuea.status = DiscordUserStatus.OFFLINE;
                    if (PresenceUpdated != null)
                        PresenceUpdated(this, dpuea);
                }
                else
                {
                    DebugLogger.Log($"User doesn't exist in server, no problemo.", MessageLevel.Debug);
                }
            }
        }