Beispiel #1
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);
        }
 public MemberUpdatedEventArgs(
     CachedMember oldMember,
     IMember newMember)
 {
     OldMember = oldMember;
     NewMember = newMember;
 }
Beispiel #3
0
        public static CachedMember GetOrAddMember(this IGatewayDispatcher dispatcher, Snowflake guildId, MemberJsonModel memberModel)
        {
            if (!memberModel.User.HasValue)
            {
                return(null);
            }

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

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

            if (dispatcher.Client.CacheProvider.TryGetMembers(guildId, out var cache))
            {
                if (cache.TryGetValue(memberModel.User.Value.Id, out var member))
                {
                    member.Update(memberModel);
                    return(member);
                }

                member = new CachedMember(sharedUser, guildId, memberModel);
                cache.Add(memberModel.User.Value.Id, member);
                return(member);
            }

            return(null);
        }
Beispiel #4
0
 public InteractionReceivedEventArgs(
     IInteraction interaction,
     CachedMember member)
 {
     Interaction = interaction;
     Member      = member;
 }
Beispiel #5
0
 public CachedUserMessage(IGatewayClient client, CachedMember author, MessageJsonModel model)
     : base(client, author, model)
 {
     WebhookId      = model.WebhookId.GetValueOrNullable();
     IsTextToSpeech = model.Tts;
     Nonce          = model.Nonce;
 }
 public MessageReceivedEventArgs(
     IGatewayMessage message,
     CachedTextChannel channel,
     CachedMember member)
 {
     Message = message;
     Channel = channel;
     Member  = member;
 }
Beispiel #7
0
 public TypingStartedEventArgs(
     Snowflake?guildId,
     Snowflake channelId,
     Snowflake userId,
     DateTimeOffset startedAt,
     CachedMember member)
 {
     GuildId   = guildId;
     ChannelId = channelId;
     UserId    = userId;
     StartedAt = startedAt;
     Member    = member;
 }
Beispiel #8
0
        protected CachedMessage(IGatewayClient client, CachedMember author, MessageJsonModel model)
            : base(client, model.Id)
        {
            ChannelId = model.ChannelId;
            GuildId   = model.GuildId.GetValueOrNullable();
            if (author != null)
            {
                _cachedAuthor = author;
            }
            else
            {
                if (model.Member.HasValue)
                {
                    model.Member.Value.User = model.Author;
                    _transientAuthor        = new TransientMember(Client, GuildId.Value, model.Member.Value);
                }
                else
                {
                    _transientAuthor = new TransientUser(Client, model.Author);
                }
            }

            Update(model);
        }