예제 #1
0
 internal Channel(JsonChannel restChannel, QuarrelClient context) :
     base(context)
 {
     Id   = restChannel.Id;
     Name = restChannel.Name;
     Type = restChannel.Type;
 }
예제 #2
0
        internal DirectChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, settings, context)
        {
            Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients));

            RecipientId = restChannel.Recipients[0].Id;
        }
예제 #3
0
        internal override JsonChannel ToJsonChannel()
        {
            JsonChannel restChannel = base.ToJsonChannel();

            restChannel.Position = Position;
            restChannel.GuildId  = GuildId;
            return(restChannel);
        }
예제 #4
0
        internal override void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel)
        {
            base.PrivateUpdateFromJsonChannel(jsonChannel);

            if (jsonChannel.Recipients is not null)
            {
                Context.Users.AddUser(jsonChannel.Recipients[0]);
            }
        }
예제 #5
0
        internal override JsonChannel ToJsonChannel()
        {
            JsonChannel restChannel = base.ToJsonChannel();

            restChannel.OwnerId    = OwnerId;
            restChannel.RTCRegion  = RTCRegion;
            restChannel.Recipients = Recipients.Select(x => x.ToRestUser()).ToArray();
            return(restChannel);
        }
예제 #6
0
        internal PrivateChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, context)
        {
            LastMessageId = restChannel.LastMessageId;
            RTCRegion     = restChannel.RTCRegion;

            IsMuted = settings?.Muted ?? false;

            _users = new HashSet <ulong>();
        }
예제 #7
0
        private void OnChannelCreated(JsonChannel arg)
        {
            var channel = Channels.AddChannel(arg);

            if (channel is null)
            {
                return;
            }

            ChannelCreated?.Invoke(this, channel);
        }
예제 #8
0
        private void OnChannelDeleted(JsonChannel arg)
        {
            Channel?channel = Channels.RemoveChannel(arg.Id);

            if (channel is null)
            {
                return;
            }

            ChannelDeleted?.Invoke(this, channel);
        }
예제 #9
0
        internal GroupChannel(JsonChannel restChannel, ChannelSettings?settings, QuarrelClient context) :
            base(restChannel, settings, context)
        {
            Guard.IsNotNull(restChannel.OwnerId, nameof(restChannel.OwnerId));
            Guard.IsNotNull(restChannel.Recipients, nameof(restChannel.Recipients));

            OwnerId = restChannel.OwnerId.Value;

            Recipients = restChannel.Recipients.Select(x => new User(x, context)).ToArray();
            Icon       = restChannel.Icon;
        }
예제 #10
0
        internal override void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel)
        {
            Position = jsonChannel.Position ?? Position;
            GuildId  = jsonChannel.GuildId ?? GuildId;

            if (jsonChannel.PermissionOverwrites is not null)
            {
                PermissionOverwrites = CreateOverwrites(jsonChannel.PermissionOverwrites);
            }

            base.PrivateUpdateFromJsonChannel(jsonChannel);
        }
예제 #11
0
        internal override JsonChannel ToJsonChannel()
        {
            JsonChannel restChannel = base.ToJsonChannel();
            var         recipient   = Context.Users.GetUser(RecipientId)?.ToRestUser();

            if (recipient is not null)
            {
                restChannel.Recipients = new[] { recipient };
            }

            return(restChannel);
        }
예제 #12
0
        internal GuildChannel(JsonChannel restChannel, ulong?guildId, QuarrelClient context) :
            base(restChannel, context)
        {
            guildId = restChannel.GuildId ?? guildId;
            Guard.IsNotNull(restChannel.Position, nameof(restChannel.Position));
            Guard.IsNotNull(guildId, nameof(guildId));

            Position = restChannel.Position.Value;
            GuildId  = guildId.Value;

            if (restChannel.PermissionOverwrites is not null)
            {
                PermissionOverwrites = CreateOverwrites(restChannel.PermissionOverwrites);
            }
        }
        /// <summary>
        /// Tries adding new channel into channels' concurrent dictionary
        /// </summary>
        /// <param name="webSocket">This goes inside a new channel</param>
        public void AddConnection(WebSocket webSocket, string uri)
        {
            //TODO: IF XML way is added, then implement a factory pattern to make both XML channel or Json channel.
            var channel = new JsonChannel();

            _channels.TryAdd(uri, channel);
            channel.Closed += (s, e) => {
                _channels.TryRemove(uri, out var _);
                ChannelClosed?.Invoke(this, EventArgs.Empty);
            };

            channel.Attach(webSocket);
            MessageDispatcher.Bind(channel);
            ChannelAccepted?.Invoke(this, EventArgs.Empty);
        }
예제 #14
0
 internal static Channel?FromJsonChannel(
     JsonChannel jsonChannel,
     QuarrelClient context,
     ulong?guildId            = null,
     ChannelSettings?settings = null)
 {
     return(jsonChannel.Type switch
     {
         ChannelType.GuildText => new GuildTextChannel(jsonChannel, guildId, settings, context),
         ChannelType.News => new GuildTextChannel(jsonChannel, guildId, settings, context),
         ChannelType.DirectMessage => new DirectChannel(jsonChannel, settings, context),
         ChannelType.GuildVoice => new VoiceChannel(jsonChannel, guildId, settings, context),
         ChannelType.StageVoice => new VoiceChannel(jsonChannel, guildId, settings, context),
         ChannelType.GroupDM => new GroupChannel(jsonChannel, settings, context),
         ChannelType.Category => new CategoryChannel(jsonChannel, guildId, context),
         _ => null,
     });
예제 #15
0
        internal VoiceChannel(JsonChannel restChannel,
                              ulong?guildId,
                              ChannelSettings?settings,
                              QuarrelClient context) :
            base(restChannel, guildId, context)
        {
            Guard.IsNotNull(restChannel.Bitrate, nameof(restChannel.Bitrate));

            Bitrate    = restChannel.Bitrate.Value;
            UserLimit  = restChannel.UserLimit;
            RTCRegion  = restChannel.RTCRegion;
            CategoryId = restChannel.CategoryId;

            IsMuted = settings?.Muted ?? false;

            _users = new HashSet <ulong>();
        }
예제 #16
0
        internal GuildTextChannel(
            JsonChannel restChannel,
            ulong?guildId,
            ChannelSettings?settings,
            QuarrelClient context) :
            base(restChannel, guildId, context)
        {
            Guard.IsNotNull(restChannel.SlowModeDelay, nameof(restChannel.SlowModeDelay));

            Topic         = restChannel.Topic;
            IsNSFW        = restChannel.IsNSFW;
            SlowModeDelay = restChannel.SlowModeDelay.Value;
            LastMessageId = restChannel.LastMessageId;
            CategoryId    = restChannel.CategoryId;

            IsMuted = settings?.Muted ?? false;
        }
예제 #17
0
 internal void UpdateFromJsonChannel(JsonChannel jsonChannel)
 {
     Guard.IsEqualTo(Id, jsonChannel.Id, nameof(Id));
     PrivateUpdateFromJsonChannel(jsonChannel);
 }
예제 #18
0
 internal virtual void PrivateUpdateFromJsonChannel(JsonChannel jsonChannel)
 {
     Name = jsonChannel.Name ?? Name;
     Type = jsonChannel.Type;
 }
예제 #19
0
 private void OnChannelUpdated(JsonChannel arg)
 {
     Channels.UpdateChannel(arg, out Channel channel);
     ChannelUpdated?.Invoke(this, channel);
 }
예제 #20
0
 internal CategoryChannel(JsonChannel restChannel, ulong?guildId, QuarrelClient context) :
     base(restChannel, guildId, context)
 {
 }
예제 #21
0
 private AnnounceChannelData(JsonChannel channel, bool isEnabled)
 {
     Channel = channel;
     IsEnabled = isEnabled;
 }
예제 #22
0
 private AnnounceChannelData(JsonChannel channel, bool isEnabled)
 {
     Channel   = channel;
     IsEnabled = isEnabled;
 }