Esempio n. 1
0
        private void UserUpdateEvents(JObject message)
        {
            DiscordUserUpdateEventArgs e = new DiscordUserUpdateEventArgs();
            e.RawJson = message;
            DiscordMember newMember = new DiscordMember
            {
                user = new DiscordUser
                {
                    username = message["d"]["username"].ToString(),
                    id = message["d"]["id"].ToString(),
                    verified = message["d"]["verified"].ToObject<bool>(),
                    email = message["d"]["email"].ToString(),
                    avatar = message["d"]["avatar"].ToString(),
                    discriminator = message["d"]["discriminator"].ToString()
                }
            };

            DiscordMember oldMember = new DiscordMember();
            //Update members
            foreach(var server in ServersList)
            {
                for(int i = 0; i < server.members.Count; i++)
                {
                    if(server.members[i].user.id == newMember.user.id)
                    {
                        server.members[i] = newMember;
                        
                        oldMember = server.members[i];
                        
                    }
                }
            }
            e.NewMember = newMember;
            e.OriginalMember = oldMember;
            if (UserUpdate != null)
                UserUpdate(this, e);
        }
Esempio n. 2
0
        private void UserUpdateEvents(JObject message)
        {
            DiscordUserUpdateEventArgs e = new DiscordUserUpdateEventArgs();
            e.RawJson = message;
            DiscordMember newMember = JsonConvert.DeserializeObject<DiscordMember>(message["d"].ToString());
            newMember.parentclient = this;

            DiscordMember oldMember = new DiscordMember(this);
            //Update members
            foreach (var server in ServersList)
            {
                for (int i = 0; i < server.members.Count; i++)
                {
                    if (server.members[i].ID == newMember.ID)
                    {
                        server.members[i] = newMember;
                        oldMember = server.members[i];
                    }
                }
            }

            newMember.Parent = oldMember.Parent;

            if (!message["roles"].IsNullOrEmpty())
            {
                JArray rawRoles = JArray.Parse(message["roles"].ToString());
                if (rawRoles.Count > 0)
                {
                    foreach (var role in rawRoles.Children())
                    {
                        newMember.Roles.Add(newMember.Parent.roles.Find(x => x.id == role.Value<string>()));
                    }
                }
                else
                {
                    newMember.Roles.Add(newMember.Parent.roles.Find(x => x.name == "@everyone"));
                }
            }
            
            e.NewMember = newMember;
            e.OriginalMember = oldMember;
            if (UserUpdate != null)
                UserUpdate(this, e);
        }
Esempio n. 3
0
        private void UserUpdateEvents(JObject message)
        {
            DiscordUserUpdateEventArgs e = new DiscordUserUpdateEventArgs();
            e.RawJson = message;
            DiscordMember newMember = JsonConvert.DeserializeObject<DiscordMember>(message["d"].ToString());
            newMember.parentclient = this;

            DiscordMember oldMember = new DiscordMember(this);
            oldMember.parentclient = this;
            //Update members
            foreach (var server in ServersList)
            {
                foreach (var member in server.Members)
                {
                    if (member.Value.ID == newMember.ID)
                    {
                        oldMember = member.Value;
                        server.AddMember(newMember);
                        break;
                    }
                }
            }

            newMember.Parent = oldMember.Parent;

            if (!message["roles"].IsNullOrEmpty())
            {
                JArray rawRoles = JArray.Parse(message["roles"].ToString());
                if (rawRoles.Count > 0)
                {
                    foreach (var role in rawRoles.Children())
                    {
                        newMember.Roles.Add(newMember.Parent.Roles.Find(x => x.ID == role.ToString()));
                    }
                }
                else
                {
                    newMember.Roles.Add(newMember.Parent.Roles.Find(x => x.Name == "@everyone"));
                }
            }

            e.NewMember = newMember;
            e.OriginalMember = oldMember;
            UserUpdate?.Invoke(this, e);
        }