public void PopPendingGuild(ShardId shardId, Snowflake guildId) { if (PendingGuilds.TryGetValue(shardId, out var guilds) && guilds.TryRemove(guildId, out _)) { if (guilds.Count == 0 && _delays.TryGetValue(shardId, out var delay)) { // Received all pending guilds, complete the delay. PendingGuilds.Remove(shardId); delay.Tcs.Complete(); } } }
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); }
/// <summary> /// This performs a deep search for the specified key. /// That is, it first looks in the top-level dictionary, /// then in each of the parents (from newest to oldest), /// Note that defaults are NOT searched! /// If you need to check for a default, use "TryGetDefault()" instead. /// If a "shallow" search is required, call "Shallow().TryGetValue()" instead. /// </summary> /// <remarks>If the search is successful, the key is added to both the Accessed and Gotten lists.</remarks> /// <param name="key">The key that will be searched.</param> /// <param name="value">The out value of the entry if one is found.</param> /// <returns>A boolean indicating if the specified key and associated value were found.</returns> public bool TryGetValue(TKey key, out TValue value) { lock (_syncRoot) { // finding it at the top-level means that we are done if (_localEntries.TryGetValue(key, out value)) { return(true); } // check each parent from newest to oldest for (var x = Parents.Count - 1; x >= 0; x--) { if (Parents[x].TryGetValue(key, out value)) { return(true); } } return(false); } }
internal async ValueTask OnButtonAsync(ButtonEventArgs e) { if (!TriggersOnRemoval && !e.WasAdded) { return; } if (!_buttons.TryGetValue(e.Emoji, out var button)) { return; } try { if (!await CheckReactionAsync(e).ConfigureAwait(false)) { return; } } catch (Exception ex) { Interactivity.Logger.LogError(ex, "An exception occurred in a reaction check for menu {0}.", GetType()); return; } if (_timeoutTimer != null) { // When a button is triggered we refresh the menu timeout. _timeoutTimer.Change(_timeout, Timeout.InfiniteTimeSpan); } try { await button.Callback(e).ConfigureAwait(false); } catch (Exception ex) { Interactivity.Logger.LogError(ex, "An exception occurred in a button callback for menu {0}.", GetType()); } }