Example #1
0
        //Voice States
        internal async Task <SocketVoiceState> AddOrUpdateVoiceStateAsync(ClientState state, VoiceStateModel model)
        {
            var voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel;
            var before       = GetVoiceState(model.UserId) ?? SocketVoiceState.Default;
            var after        = SocketVoiceState.Create(voiceChannel, model);

            _voiceStates[model.UserId] = after;

            if (_audioClient != null && before.VoiceChannel?.Id != after.VoiceChannel?.Id)
            {
                if (model.UserId == CurrentUser.Id)
                {
                    if (after.VoiceChannel != null && _audioClient.ChannelId != after.VoiceChannel?.Id)
                    {
                        _audioClient.ChannelId = after.VoiceChannel.Id;
                        await RepopulateAudioStreamsAsync().ConfigureAwait(false);
                    }
                }
                else
                {
                    await _audioClient.RemoveInputStreamAsync(model.UserId).ConfigureAwait(false); //User changed channels, end their stream

                    if (CurrentUser.VoiceChannel != null && after.VoiceChannel?.Id == CurrentUser.VoiceChannel?.Id)
                    {
                        await _audioClient.CreateInputStreamAsync(model.UserId).ConfigureAwait(false);
                    }
                }
            }

            return(after);
        }
Example #2
0
        //Voice States
        internal SocketVoiceState AddOrUpdateVoiceState(ClientState state, VoiceStateModel model)
        {
            var voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel;
            var voiceState   = SocketVoiceState.Create(voiceChannel, model);

            _voiceStates[model.UserId] = voiceState;
            return(voiceState);
        }
        async Task Client_UserVoiceStateUpdated(Discord.WebSocket.SocketUser arg1, Discord.WebSocket.SocketVoiceState arg2, Discord.WebSocket.SocketVoiceState arg3)
        {
            if (arg1.IsBot)
            {
                return;
            }
            if (TTTGame.IsTTTVoice(arg2.VoiceChannel) || TTTGame.IsTTTVoice(arg3.VoiceChannel))
            {
                return;
            }
            var thread = new Thread(handle);

            thread.Start(new passing()
            {
                arg1 = arg1,
                arg2 = arg2,
                arg3 = arg3
            });
        }
Example #4
0
        internal void Update(ClientState state, ExtendedModel model)
        {
            IsAvailable = !(model.Unavailable ?? false);
            if (!IsAvailable)
            {
                if (_channels == null)
                {
                    _channels = new ConcurrentHashSet <ulong>();
                }
                if (_members == null)
                {
                    _members = new ConcurrentDictionary <ulong, SocketGuildUser>();
                }
                if (_roles == null)
                {
                    _roles = new ConcurrentDictionary <ulong, SocketRole>();
                }

                /*if (Emojis == null)
                 *  _emojis = ImmutableArray.Create<Emoji>();
                 * if (Features == null)
                 *  _features = ImmutableArray.Create<string>();*/
                _syncPromise       = new TaskCompletionSource <bool>();
                _downloaderPromise = new TaskCompletionSource <bool>();
                return;
            }

            Update(state, model as Model);

            var channels = new ConcurrentHashSet <ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Channels.Length * 1.05));

            {
                for (int i = 0; i < model.Channels.Length; i++)
                {
                    var channel = SocketGuildChannel.Create(this, state, model.Channels[i]);
                    state.AddChannel(channel);
                    channels.TryAdd(channel.Id);
                }
            }
            _channels = channels;

            var members = new ConcurrentDictionary <ulong, SocketGuildUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05));

            {
                for (int i = 0; i < model.Members.Length; i++)
                {
                    var member = SocketGuildUser.Create(this, state, model.Members[i]);
                    members.TryAdd(member.Id, member);
                }
                DownloadedMemberCount = members.Count;

                for (int i = 0; i < model.Presences.Length; i++)
                {
                    if (members.TryGetValue(model.Presences[i].User.Id, out SocketGuildUser member))
                    {
                        member.Update(state, model.Presences[i], true);
                    }
                }
            }
            _members    = members;
            MemberCount = model.MemberCount;

            var voiceStates = new ConcurrentDictionary <ulong, SocketVoiceState>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.VoiceStates.Length * 1.05));

            {
                for (int i = 0; i < model.VoiceStates.Length; i++)
                {
                    SocketVoiceChannel channel = null;
                    if (model.VoiceStates[i].ChannelId.HasValue)
                    {
                        channel = state.GetChannel(model.VoiceStates[i].ChannelId.Value) as SocketVoiceChannel;
                    }
                    var voiceState = SocketVoiceState.Create(channel, model.VoiceStates[i]);
                    voiceStates.TryAdd(model.VoiceStates[i].UserId, voiceState);
                }
            }
            _voiceStates = voiceStates;

            _syncPromise       = new TaskCompletionSource <bool>();
            _downloaderPromise = new TaskCompletionSource <bool>();
            var _ = _syncPromise.TrySetResultAsync(true);

            /*if (!model.Large)
             *  _ = _downloaderPromise.TrySetResultAsync(true);*/
        }
Example #5
0
 /// <summary>
 /// Converts an existing <see cref="SocketVoiceState"/> to an abstracted <see cref="ISocketVoiceState"/> value.
 /// </summary>
 /// <param name="socketVoiceState">The existing <see cref="SocketVoiceState"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketVoiceState"/>.</exception>
 /// <returns>An <see cref="ISocketVoiceState"/> that abstracts <paramref name="socketVoiceState"/>.</returns>
 public static ISocketVoiceState Abstract(this SocketVoiceState socketVoiceState)
 => new SocketVoiceStateAbstraction(socketVoiceState);
Example #6
0
 /// <summary>
 /// Constructs a new <see cref="SocketVoiceStateAbstraction"/> around an existing <see cref="SocketVoiceState"/>.
 /// </summary>
 /// <param name="socketVoiceState">The value to use for <see cref="SocketVoiceState"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketVoiceState"/>.</exception>
 public SocketVoiceStateAbstraction(SocketVoiceState socketVoiceState)
 {
     _socketVoiceState = socketVoiceState;
 }