Пример #1
0
        private async void T_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (!users.All(x => CurrentVcUsers.Any(y => x.id == y.Id.ToString())) || users.Count != CurrentVcUsers.Count || CurrentVcUsers.All(x => users.Any(y => y.id == x.Id.ToString())))
            {
                // find all users who left
                var leftUsers = users.Where(x => !CurrentVcUsers.Any(y => y.Id.ToString() == x.id));
                foreach (var user in leftUsers.ToArray())
                {
                    if (user == null)
                    {
                        return;
                    }

                    if (user.GetUser().IsMuted)
                    {
                        await user.GetUser().ModifyAsync(x => x.Mute = false);
                    }

                    user.Remove();
                    users.Remove(user);
                }

                var joinedUsers = CurrentVcUsers.Where(x => !users.Any(y => y.id == x.Id.ToString()));

                foreach (var guildUser in joinedUsers)
                {
                    var user = new EventVcUser(client.GetGuild(Global.SwissGuildId).GetUser(guildUser.Id), guildUser.VoiceState.Value);
                    users.Add(user);
                }
            }
        }
Пример #2
0
        private async Task HandleVoiceStateUpdate(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3)
        {
            if (arg2.VoiceChannel == null && arg3.VoiceChannel != null && arg3.VoiceChannel.Id == 627906629047943238 ||
                arg2.VoiceChannel != null && arg3.VoiceChannel != null && arg2.VoiceChannel.Id != arg3.VoiceChannel.Id && arg3.VoiceChannel.Id == 627906629047943238)
            {
                // User joined the vc
                var user = new EventVcUser(client.GetGuild(Global.SwissGuildId).GetUser(arg1.Id), arg3);
                users.Add(user);
                return;
            }
            else if (arg2.VoiceChannel != null && arg2.VoiceChannel.Id == 627906629047943238 && arg3.VoiceChannel == null ||
                     arg2.VoiceChannel != null && arg2.VoiceChannel.Id == 627906629047943238 && arg3.VoiceChannel.Id != 627906629047943238)
            {
                // Remove
                var user = users.FirstOrDefault(x => x.id == arg1.Id.ToString());

                if (arg2.IsMuted)
                {
                    await client.GetGuild(Global.SwissGuildId).GetUser(arg1.Id).ModifyAsync(x => x.Mute = false);
                }

                if (user == null)
                {
                    return;
                }

                user.Remove();
                users.Remove(user);
            }
            else if (arg3.VoiceChannel != null && arg3.VoiceChannel.Id == 627906629047943238)
            {
                if (
                    arg3.IsSelfDeafened != arg2.IsSelfDeafened ||
                    arg3.IsSelfMuted != arg2.IsSelfMuted ||
                    arg3.IsMuted != arg2.IsMuted ||
                    arg3.IsDeafened != arg2.IsDeafened
                    )
                {
                    var user = users.FirstOrDefault(x => x.id == arg1.Id.ToString());

                    if (user == null)
                    {
                        return;
                    }

                    user.UpdateVoiceState(arg3);
                }
            }
        }