internal SocketVoiceState(SocketVoiceChannel voiceChannel, DateTimeOffset?requestToSpeak, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream)
        {
            VoiceChannel            = voiceChannel;
            VoiceSessionId          = sessionId;
            RequestToSpeakTimestamp = requestToSpeak;

            Flags voiceStates = Flags.Normal;

            if (isSelfMuted)
            {
                voiceStates |= Flags.SelfMuted;
            }
            if (isSelfDeafened)
            {
                voiceStates |= Flags.SelfDeafened;
            }
            if (isMuted)
            {
                voiceStates |= Flags.Muted;
            }
            if (isDeafened)
            {
                voiceStates |= Flags.Deafened;
            }
            if (isSuppressed)
            {
                voiceStates |= Flags.Suppressed;
            }
            if (isStream)
            {
                voiceStates |= Flags.SelfStream;
            }
            _voiceStates = voiceStates;
        }
Esempio n. 2
0
        internal new static SocketVoiceChannel Create(SocketGuild guild, ClientState state, Model model)
        {
            var entity = new SocketVoiceChannel(guild.Discord, model.Id, guild);

            entity.Update(state, model);
            return(entity);
        }
Esempio n. 3
0
        internal SocketVoiceState(SocketVoiceChannel voiceChannel, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isMuted, bool isDeafened, bool isSuppressed, bool isStream)
        {
            VoiceChannel   = voiceChannel;
            VoiceSessionId = sessionId;

            Flags voiceStates = Flags.Normal;

            if (isSelfMuted)
            {
                voiceStates |= Flags.SelfMuted;
            }
            if (isSelfDeafened)
            {
                voiceStates |= Flags.SelfDeafened;
            }
            if (isMuted)
            {
                voiceStates |= Flags.Muted;
            }
            if (isDeafened)
            {
                voiceStates |= Flags.Deafened;
            }
            if (isSuppressed)
            {
                voiceStates |= Flags.Suppressed;
            }
            if (isStream)
            {
                voiceStates |= Flags.SelfStream;
            }
            _voiceStates = voiceStates;
        }
        //Voice States
        internal SocketVoiceState AddOrUpdateVoiceState(ClientState state, VoiceStateModel model)
        {
            SocketVoiceChannel voiceChannel = state.GetChannel(model.ChannelId.Value) as SocketVoiceChannel;
            SocketVoiceState   voiceState   = SocketVoiceState.Create(voiceChannel, model);

            _voiceStates[model.UserId] = voiceState;
            return(voiceState);
        }
 internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, Model model)
 {
     return(model.Type switch
     {
         ChannelType.News => SocketNewsChannel.Create(guild, state, model),
         ChannelType.Text => SocketTextChannel.Create(guild, state, model),
         ChannelType.Voice => SocketVoiceChannel.Create(guild, state, model),
         ChannelType.Category => SocketCategoryChannel.Create(guild, state, model),
         ChannelType.PrivateThread or ChannelType.PublicThread or ChannelType.NewsThread => SocketThreadChannel.Create(guild, state, model),
         ChannelType.Stage => SocketStageChannel.Create(guild, state, model),
         _ => new SocketGuildChannel(guild.Discord, model.Id, guild),
     });
Esempio n. 6
0
        internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(SocketTextChannel.Create(guild, state, model));

            case ChannelType.Voice:
                return(SocketVoiceChannel.Create(guild, state, model));

            default:
                throw new InvalidOperationException("Unknown guild channel type");
            }
        }
        internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.Text:
                return(SocketTextChannel.Create(guild, state, model));

            case ChannelType.Voice:
                return(SocketVoiceChannel.Create(guild, state, model));

            default:
                // TODO: Proper implementation for channel categories
                return(new SocketGuildChannel(guild.Discord, model.Id, guild));
            }
        }
Esempio n. 8
0
        internal static SocketGuildChannel Create(SocketGuild guild, ClientState state, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.News:
                return(SocketNewsChannel.Create(guild, state, model));

            case ChannelType.Text:
                return(SocketTextChannel.Create(guild, state, model));

            case ChannelType.Voice:
                return(SocketVoiceChannel.Create(guild, state, model));

            case ChannelType.Category:
                return(SocketCategoryChannel.Create(guild, state, model));

            default:
                return(new SocketGuildChannel(guild.Discord, model.Id, guild));
            }
        }
Esempio n. 9
0
        public VoiceState(SocketVoiceChannel voiceChannel, string sessionId, bool isSelfMuted, bool isSelfDeafened, bool isSuppressed)
        {
            VoiceChannel   = voiceChannel;
            VoiceSessionId = sessionId;

            Flags voiceStates = Flags.None;

            if (isSelfMuted)
            {
                voiceStates |= Flags.SelfMuted;
            }
            if (isSelfDeafened)
            {
                voiceStates |= Flags.SelfDeafened;
            }
            if (isSuppressed)
            {
                voiceStates |= Flags.Suppressed;
            }
            _voiceStates = voiceStates;
        }
Esempio n. 10
0
 internal static SocketVoiceState Create(SocketVoiceChannel voiceChannel, Model model)
 {
     return(new SocketVoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream));
 }
Esempio n. 11
0
 /// <summary>
 /// Constructs a new <see cref="SocketVoiceChannelAbstraction"/> around an existing <see cref="WebSocket.SocketVoiceChannel"/>.
 /// </summary>
 /// <param name="socketVoiceChannel">The value to use for <see cref="WebSocket.SocketVoiceChannel"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketVoiceChannel"/>.</exception>
 public SocketVoiceChannelAbstraction(SocketVoiceChannel socketVoiceChannel)
     : base(socketVoiceChannel)
 {
 }
Esempio n. 12
0
 /// <inheritdoc />
 public Task SyncPermissionsAsync(RequestOptions options = null)
 => SocketVoiceChannel.SyncPermissionsAsync(options);
Esempio n. 13
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <VoiceChannelProperties> func, RequestOptions options = null)
 => SocketVoiceChannel.ModifyAsync(func, options);
Esempio n. 14
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IInviteMetadata> > GetInvitesAsync(RequestOptions options = null)
 => (await SocketVoiceChannel.GetInvitesAsync(options))
 .Select(InviteMetadataAbstractionExtensions.Abstract)
 .ToArray();
Esempio n. 15
0
 /// <inheritdoc />
 public Task DisconnectAsync()
 => SocketVoiceChannel.DisconnectAsync();
Esempio n. 16
0
 /// <inheritdoc />
 public async Task <IInviteMetadata> CreateInviteAsync(int?maxAge = 86400, int?maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
 => (await SocketVoiceChannel.CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options))
 .Abstract();
Esempio n. 17
0
 /// <inheritdoc />
 public Task <IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false)
 => SocketVoiceChannel.ConnectAsync(selfDeaf, selfMute, external);
Esempio n. 18
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);*/
        }
Esempio n. 19
0
 internal static SocketVoiceState Create(SocketVoiceChannel voiceChannel, Model model)
 {
     return(new SocketVoiceState(voiceChannel, model.RequestToSpeakTimestamp.IsSpecified ? model.RequestToSpeakTimestamp.Value : null, model.SessionId, model.SelfMute, model.SelfDeaf, model.Mute, model.Deaf, model.Suppress, model.SelfStream, model.SelfVideo));
 }
Esempio n. 20
0
 public VoiceState(SocketVoiceChannel voiceChannel, Model model)
     : this(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Suppress)
 {
 }
Esempio n. 21
0
 /// <summary>
 /// Converts an existing <see cref="SocketVoiceChannel"/> to an abstracted <see cref="ISocketVoiceChannel"/> value.
 /// </summary>
 /// <param name="socketVoiceChannel">The existing <see cref="SocketVoiceChannel"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketVoiceChannel"/>.</exception>
 /// <returns>An <see cref="ISocketVoiceChannel"/> that abstracts <paramref name="socketVoiceChannel"/>.</returns>
 public static ISocketVoiceChannel Abstract(this SocketVoiceChannel socketVoiceChannel)
 => new SocketVoiceChannelAbstraction(socketVoiceChannel);