コード例 #1
0
        public ReadyHandler()
        {
            PendingGuilds = new SynchronizedDictionary <ShardId, ISynchronizedDictionary <Snowflake, bool> >();
            InitialReadys = new SynchronizedDictionary <ShardId, Tcs>();

            _delays = new SynchronizedDictionary <ShardId, DelayToken>();
        }
コード例 #2
0
        public static CachedMember GetOrAddMember(this IGatewayDispatcher dispatcher,
                                                  ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, ISynchronizedDictionary <Snowflake, CachedMember> memberCache,
                                                  Snowflake guildId, MemberJsonModel memberModel)
        {
            if (!memberModel.User.HasValue)
            {
                return(null);
            }

            var sharedUser = dispatcher.GetOrAddSharedUser(userCache, memberModel.User.Value);

            if (sharedUser == null)
            {
                return(null);
            }

            if (memberCache.TryGetValue(memberModel.User.Value.Id, out var member))
            {
                member.Update(memberModel);
                return(member);
            }

            member = new CachedMember(sharedUser, guildId, memberModel);
            memberCache.Add(memberModel.User.Value.Id, member);
            return(member);
        }
コード例 #3
0
            public Bucket(int degreeOfParallelism)
            {
                _degreeOfParallelism = degreeOfParallelism;
                _tokens = Channel.CreateUnbounded <Token>();
                _tasks  = new SynchronizedDictionary <DiscordCommandContext, Task>(degreeOfParallelism);

                _ = RunAsync();
            }
コード例 #4
0
 public static CachedSharedUser GetOrAddSharedUser(this IGatewayDispatcher dispatcher,
                                                   ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, UserJsonModel model)
 {
     return(userCache.GetOrAdd(model.Id, static (_, tuple) =>
     {
         var(client, model) = tuple;
         return new CachedSharedUser(client, model);
     }, (dispatcher.Client, model)));
 }
コード例 #5
0
ファイル: ContractResolver.cs プロジェクト: Pyhoma69/Disqord
 public ContractResolver(DefaultJsonSerializer serializer)
 {
     _serializer          = serializer;
     _stringEnumConverter = new StringEnumConverter();
     _streamConverter     = new StreamConverter(serializer);
     _jsonTokenConverter  = new JsonTokenConverter();
     _snowflakeConverter  = new SnowflakeConverter();
     _optionalConverters  = new SynchronizedDictionary <Type, OptionalConverter>();
 }
コード例 #6
0
        public DefaultGatewayChunker(
            IOptions <DefaultGatewayChunkerConfiguration> options,
            ILogger <DefaultGatewayChunker> logger)
        {
            Logger = logger;

            _operations = new SynchronizedDictionary <string, ChunkOperation>();

            _binder = new Binder <IGatewayClient>(this);
        }
コード例 #7
0
        /// <summary>
        ///     Instantiates a new <see cref="DefaultCommandQueue"/>.
        /// </summary>
        /// <param name="options"> The options instance. </param>
        public DefaultCommandQueue(
            IOptions <DefaultCommandQueueConfiguration> options)
        {
            var configuration = options.Value;

            DegreeOfParallelism = configuration.DegreeOfParallelism;

            _guildBuckets = new SynchronizedDictionary <Snowflake, Bucket>();

            _binder = new Binder <DiscordBotBase>(this);
        }
コード例 #8
0
        public static IMember GetOrAddMemberTransient(this IGatewayDispatcher dispatcher,
                                                      ISynchronizedDictionary <Snowflake, CachedSharedUser> userCache, ISynchronizedDictionary <Snowflake, CachedMember> memberCache,
                                                      Snowflake guildId, MemberJsonModel memberModel)
        {
            if (!memberModel.User.HasValue)
            {
                return(null);
            }

            var member = dispatcher.GetOrAddMember(userCache, memberCache, guildId, memberModel);

            return(member ?? new TransientMember(dispatcher.Client, guildId, memberModel) as IMember);
        }
コード例 #9
0
        /// <inheritdoc/>
        public bool TryGetCache <TEntity>(out ISynchronizedDictionary <Snowflake, TEntity> cache)
        {
            lock (this)
            {
                if (_caches.TryGetValue(typeof(TEntity), out var boxedCache))
                {
                    cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache;
                    return(true);
                }

                cache = default;
                return(false);
            }
        }
コード例 #10
0
        public InteractivityExtension(
            IOptions <InteractivityExtensionConfiguration> options,
            ILogger <InteractivityExtension> logger)
            : base(logger)
        {
            var configuration = options.Value;

            DefaultMessageTimeout  = configuration.DefaultMessageTimeout;
            DefaultReactionTimeout = configuration.DefaultReactionTimeout;
            DefaultMenuTimeout     = configuration.DefaultMenuTimeout;

            _messageWaiters  = new SynchronizedDictionary <Snowflake, LinkedList <Waiter <MessageReceivedEventArgs> > >();
            _reactionWaiters = new SynchronizedDictionary <Snowflake, LinkedList <Waiter <ReactionAddedEventArgs> > >();
            _menus           = new SynchronizedDictionary <Snowflake, MenuBase>();
        }
コード例 #11
0
            static void UncacheThread(ISynchronizedDictionary <Snowflake, CachedGuildChannel> channelCache, Dictionary <Snowflake, IReadOnlyList <CachedThreadChannel> > uncachedThreads, KeyValuePair <Snowflake, List <ChannelJsonModel> > kvp, CachedThreadChannel cachedThreadChannel)
            {
                channelCache.Remove(cachedThreadChannel.Id);
                List <CachedThreadChannel> list;

                if (uncachedThreads.TryGetValue(kvp.Key, out var boxedList))
                {
                    list = boxedList as List <CachedThreadChannel>;
                }
                else
                {
                    uncachedThreads.Add(kvp.Key, list = new List <CachedThreadChannel>());
                }
                list.Add(cachedThreadChannel);
            }
コード例 #12
0
        public bool TryGetCache <TEntity>(Snowflake parentId, out ISynchronizedDictionary <Snowflake, TEntity> cache, bool lookupOnly = false)
            where TEntity : CachedSnowflakeEntity
        {
            lock (this)
            {
                if (!_nestedCaches.TryGetValue(typeof(TEntity), out var nestedCache))
                {
                    cache = default;
                    return(false);
                }

                if (nestedCache.TryGetValue(parentId, out var boxedCache))
                {
                    cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache;
                    return(true);
                }

                if (!lookupOnly && _supportedNestedTypes.Contains(typeof(TEntity)))
                {
                    if (typeof(TEntity) == typeof(CachedUserMessage))
                    {
                        var messageCache = new MessageDictionary(MessagesPerChannel).Synchronized();
                        cache = (ISynchronizedDictionary <Snowflake, TEntity>)messageCache;
                    }
                    else if (typeof(TEntity) == typeof(CachedMember))
                    {
                        var memberCache = new MemberDictionary(this).Synchronized();
                        cache = (ISynchronizedDictionary <Snowflake, TEntity>)memberCache;
                    }
                    else
                    {
                        cache = new SynchronizedDictionary <Snowflake, TEntity>();
                    }

                    nestedCache.Add(parentId, cache);
                    return(true);
                }

                cache = default;
                return(false);
            }
        }
コード例 #13
0
        /// <inheritdoc/>
        public bool TryRemoveCache <TEntity>(Snowflake parentId, out ISynchronizedDictionary <Snowflake, TEntity> cache)
        {
            lock (this)
            {
                if (!_nestedCaches.TryGetValue(typeof(TEntity), out var nestedCache))
                {
                    cache = default;
                    return(false);
                }

                if (nestedCache.TryRemove(parentId, out var boxedCache))
                {
                    cache = (ISynchronizedDictionary <Snowflake, TEntity>)boxedCache;
                    return(true);
                }

                cache = default;
                return(false);
            }
        }
コード例 #14
0
        /// <summary>
        /// This constructor will copy the entries from another instance.
        /// Tracking information will also be copied depending on the values
        /// of the 'copyAccessedTracking' and 'copyGottenTracking' arguments.
        /// </summary>
        /// <param name="other">The instance that will be copied to create this new instance.</param>
        /// <param name="copyAccessedTracking">A boolean indicating whether or not to copy 'Accessed' tracking information.</param>
        /// <param name="copyGottenTracking">A boolean indicating whether or not to copy 'Gotten' tracking information.</param>
        public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other, bool copyAccessedTracking, bool copyGottenTracking)
            : this()
        {
            if (other == null)
            {
                throw new ArgumentNullException("other", "The argument must not be null.");
            }

            lock (_syncRoot) // just in case there are static operations
            {
                _innerDict = new Dictionary <TKey, TValue>(other);
                if (copyAccessedTracking)
                {
                    _trackAccessed = other.TrackAccessed;
                    _accessed      = other.Accessed == null ? null : new List <TKey>(other.Accessed);
                }
                if (copyGottenTracking)
                {
                    _trackGotten = other.TrackGotten;
                    _gotten      = other.Gotten == null ? null : new List <TKey>(other.Gotten);
                }
            }
        }
コード例 #15
0
 /// <summary>
 /// This constructor will copy the entries from another instance.
 /// Tracking information (Accessed and Gotten) will also be copied
 /// depending on the value of the 'copyTracking' argument.
 /// </summary>
 /// <param name="other">>The instance that will be copied to create this new instance.</param>
 /// <param name="copyTracking">A boolean indicating whether or not to copy all tracking information.</param>
 public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other, bool copyTracking)
     : this(copyTracking, copyTracking)
 {
 }
コード例 #16
0
 static DefaultGatewayRateLimiter()
 {
     _sharedBuckets = new SynchronizedDictionary <Snowflake, ISynchronizedDictionary <GatewayPayloadOperation, Bucket> >(1);
 }
コード例 #17
0
 /// <summary>
 ///     Attempts to get the users cache from this cache provider.
 /// </summary>
 /// <param name="cacheProvider"> The cache provider to retrieve the cache from. </param>
 /// <param name="cache"> The given cache. </param>
 /// <returns>
 ///     <see langword="true"/> if the cache exists.
 /// </returns>
 public static bool TryGetUsers(this IGatewayCacheProvider cacheProvider, out ISynchronizedDictionary <Snowflake, CachedSharedUser> cache)
 => cacheProvider.TryGetCache(out cache);
コード例 #18
0
 /// <summary>
 /// This constructor will copy the entries from another instance.
 /// All tracking information (Accessed and Gotten) will also be copied.
 /// </summary>
 /// <param name="other">The instance that will be copied to create this new instance.</param>
 public SynchronizedDictionary(ISynchronizedDictionary <TKey, TValue> other)
     : this(other, true, true)
 {
 }
コード例 #19
0
 /// <inheritdoc cref="TryGetUsers"/>
 /// <summary>
 ///     Attempts to get the stages cache from this cache provider.
 /// </summary>
 public static bool TryGetStages(this IGatewayCacheProvider cacheProvider, Snowflake guildId, out ISynchronizedDictionary <Snowflake, CachedStage> cache, bool lookupOnly = false)
 => cacheProvider.TryGetCache(guildId, out cache, lookupOnly);
コード例 #20
0
 /// <inheritdoc cref="TryGetUsers"/>
 /// <summary>
 ///     Attempts to get the guilds cache from this cache provider.
 /// </summary>
 public static bool TryGetGuilds(this IGatewayCacheProvider cacheProvider, out ISynchronizedDictionary <Snowflake, CachedGuild> cache)
 => cacheProvider.TryGetCache(out cache);
コード例 #21
0
ファイル: MenuBase.cs プロジェクト: Pyhoma69/Disqord
 /// <summary>
 ///     Instantiates a new <see cref="MenuBase"/>.
 /// </summary>
 protected MenuBase()
 {
     _tcs     = new Tcs();
     _buttons = GetButtons(this);
 }
コード例 #22
0
 /// <inheritdoc cref="TryGetUsers"/>
 /// <summary>
 ///     Attempts to get the messages cache from this cache provider.
 /// </summary>
 public static bool TryGetMessages(this IGatewayCacheProvider cacheProvider, Snowflake channelId, out ISynchronizedDictionary <Snowflake, CachedUserMessage> cache, bool lookupOnly = false)
 => cacheProvider.TryGetCache(channelId, out cache, lookupOnly);
コード例 #23
0
 static MenuBase()
 {
     _typeCache = new SynchronizedDictionary <Type, KeyValuePair <IEmoji, MethodInfo>[]>();
 }