Example #1
0
        private static async Task LoadEmoticons(UserModel user, LockedDictionary <string, LockedDictionary <string, EmoticonImage> > storage)
        {
            List <EmoticonPackModel> userPacks = (await ChannelSession.Connection.GetEmoticons(ChannelSession.Channel, user)).ToList();

            foreach (EmoticonPackModel userPack in userPacks)
            {
                if (!storage.ContainsKey(userPack.channelId.ToString()))
                {
                    storage.Add(userPack.channelId.ToString(), new LockedDictionary <string, EmoticonImage>());
                }

                foreach (KeyValuePair <string, EmoticonGroupModel> emoticon in userPack.emoticons)
                {
                    storage[userPack.channelId.ToString()][emoticon.Key] = new EmoticonImage
                    {
                        Name   = emoticon.Key,
                        Uri    = userPack.url,
                        X      = emoticon.Value.x,
                        Y      = emoticon.Value.y,
                        Width  = emoticon.Value.width,
                        Height = emoticon.Value.height,
                    };
                }
            }
        }
Example #2
0
 public InteractiveClientWrapper()
 {
     this.Scenes          = new List <InteractiveConnectedSceneModel>();
     this.Controls        = new Dictionary <string, InteractiveControlModel>();
     this.ControlCommands = new Dictionary <string, InteractiveConnectedControlCommand>();
     this.Participants    = new LockedDictionary <string, InteractiveParticipantModel>();
 }
Example #3
0
        internal DiscordClientBase(RestDiscordClient restClient, DiscordClientBaseConfiguration configuration)
        {
            if (restClient == null)
            {
                throw new ArgumentNullException(nameof(restClient));
            }

            if (!restClient.HasAuthorization)
            {
                throw new ArgumentException("Clients without authorization are not supported.", nameof(restClient));
            }

            RestClient  = restClient;
            State       = new DiscordClientState(this, configuration.MessageCache.GetValueOrDefault(() => new DefaultMessageCache(100)));
            Logger      = configuration.Logger.GetValueOrDefault() ?? restClient.Logger;
            Serializer  = configuration.Serializer.GetValueOrDefault() ?? restClient.Serializer;
            _extensions = new LockedDictionary <Type, DiscordClientExtension>();

            _ready                 = new AsynchronousEvent <ReadyEventArgs>();
            _channelCreated        = new AsynchronousEvent <ChannelCreatedEventArgs>();
            _channelUpdated        = new AsynchronousEvent <ChannelUpdatedEventArgs>();
            _channelDeleted        = new AsynchronousEvent <ChannelDeletedEventArgs>();
            _channelPinsUpdated    = new AsynchronousEvent <ChannelPinsUpdatedEventArgs>();
            _guildAvailable        = new AsynchronousEvent <GuildAvailableEventArgs>();
            _guildUnavailable      = new AsynchronousEvent <GuildUnavailableEventArgs>();
            _joinedGuild           = new AsynchronousEvent <JoinedGuildEventArgs>();
            _guildUpdated          = new AsynchronousEvent <GuildUpdatedEventArgs>();
            _leftGuild             = new AsynchronousEvent <LeftGuildEventArgs>();
            _roleCreated           = new AsynchronousEvent <RoleCreatedEventArgs>();
            _roleUpdated           = new AsynchronousEvent <RoleUpdatedEventArgs>();
            _roleDeleted           = new AsynchronousEvent <RoleDeletedEventArgs>();
            _inviteCreated         = new AsynchronousEvent <InviteCreatedEventArgs>();
            _inviteDeleted         = new AsynchronousEvent <InviteDeletedEventArgs>();
            _memberBanned          = new AsynchronousEvent <MemberBannedEventArgs>();
            _memberUnbanned        = new AsynchronousEvent <MemberUnbannedEventArgs>();
            _guildEmojisUpdated    = new AsynchronousEvent <GuildEmojisUpdatedEventArgs>();
            _memberJoined          = new AsynchronousEvent <MemberJoinedEventArgs>();
            _memberLeft            = new AsynchronousEvent <MemberLeftEventArgs>();
            _memberUpdated         = new AsynchronousEvent <MemberUpdatedEventArgs>();
            _messageReceived       = new AsynchronousEvent <MessageReceivedEventArgs>();
            _messageDeleted        = new AsynchronousEvent <MessageDeletedEventArgs>();
            _messagesBulkDeleted   = new AsynchronousEvent <MessagesBulkDeletedEventArgs>();
            _messageUpdated        = new AsynchronousEvent <MessageUpdatedEventArgs>();
            _reactionAdded         = new AsynchronousEvent <ReactionAddedEventArgs>();
            _reactionRemoved       = new AsynchronousEvent <ReactionRemovedEventArgs>();
            _reactionsCleared      = new AsynchronousEvent <ReactionsClearedEventArgs>();
            _emojiReactionsCleared = new AsynchronousEvent <EmojiReactionsClearedEventArgs>();
            _presenceUpdated       = new AsynchronousEvent <PresenceUpdatedEventArgs>();
            _typingStarted         = new AsynchronousEvent <TypingStartedEventArgs>();
            _userUpdated           = new AsynchronousEvent <UserUpdatedEventArgs>();
            _voiceStateUpdated     = new AsynchronousEvent <VoiceStateUpdatedEventArgs>();
            _voiceServerUpdated    = new AsynchronousEvent <VoiceServerUpdatedEventArgs>();
            _webhooksUpdated       = new AsynchronousEvent <WebhooksUpdatedEventArgs>();

            if (this is IDiscordSharder sharder)
            {
                sharder._shardReady = new AsynchronousEvent <ShardReadyEventArgs>();
            }
        }
Example #4
0
 internal CachedMessage(ICachedMessageChannel channel, CachedUser author, MessageModel model) : base(channel.Client, model.Id)
 {
     Channel    = channel;
     Author     = author;
     _reactions = new LockedDictionary <IEmoji, ReactionData>(model.Reactions.HasValue
         ? model.Reactions.Value?.Length ?? 0
         : 0);
 }
Example #5
0
 public ContractResolver(DefaultJsonSerializer serializer)
 {
     _serializer           = serializer;
     _stringEnumConverter  = new StringEnumConverter();
     _streamConverter      = new StreamConverter(serializer);
     _jsonElementConverter = new JsonElementConverter();
     _snowflakeConverter   = new SnowflakeConverter();
     _optionalConverters   = new LockedDictionary <Type, OptionalConverter>();
 }
Example #6
0
        internal CachedGroupChannel(DiscordClientBase client, ChannelModel model) : base(client, model)
        {
            _recipients = new LockedDictionary <Snowflake, CachedUser>(model.Recipients.Value.Length);
            for (var i = 0; i < model.Recipients.Value.Length; i++)
            {
                var recipient = model.Recipients.Value[i];
                _recipients.TryAdd(recipient.Id, client.State.GetOrAddSharedUser(recipient));
            }

            Update(model);
        }
Example #7
0
        internal CachedCurrentUser(CachedSharedUser user, UserModel model, int relationshipCount, int noteCount) : base(user)
        {
            SharedUser = user;

            if (!Client.IsBot)
            {
                _relationships = new LockedDictionary <Snowflake, CachedRelationship>(relationshipCount);
                _notes         = new LockedDictionary <Snowflake, string>(noteCount);
            }

            Update(model);
        }
Example #8
0
        public DiscordClientState(DiscordClientBase client, MessageCache messageCache)
        {
            _client       = client;
            _messageCache = messageCache ?? DummyMessageCache.Instance;

            _guilds          = new LockedDictionary <Snowflake, CachedGuild>();
            _users           = new LockedDictionary <Snowflake, CachedSharedUser>();
            _privateChannels = new LockedDictionary <Snowflake, CachedPrivateChannel>();

            Guilds          = new ReadOnlyDictionary <Snowflake, CachedGuild>(_guilds);
            Users           = new ReadOnlyUpcastingDictionary <Snowflake, CachedSharedUser, CachedUser>(_users);
            PrivateChannels = new ReadOnlyDictionary <Snowflake, CachedPrivateChannel>(_privateChannels);
            DmChannels      = new ReadOnlyOfTypeDictionary <Snowflake, CachedPrivateChannel, CachedDmChannel>(_privateChannels);
            GroupChannels   = new ReadOnlyOfTypeDictionary <Snowflake, CachedPrivateChannel, CachedGroupChannel>(_privateChannels);
        }
        public void UpdateLockedModel(string key)
        {
            Thread.CurrentThread.Join(200);

            lock (_lock)
            {
                if (LockedDictionary.ContainsKey(key))
                {
                    LockedDictionary[key].Count++;
                }
                else
                {
                    LockedDictionary.Add(key, new DataCountModel {
                        Count = 1
                    });
                }
            }
        }
Example #10
0
        internal CachedGuild(DiscordClientBase client, WebSocketGuildModel model) : base(client, model.Id)
        {
            _roles    = new LockedDictionary <Snowflake, CachedRole>(model.Roles.Value.Length);
            _emojis   = new LockedDictionary <Snowflake, CachedGuildEmoji>(model.Emojis.Value.Length);
            _channels = new LockedDictionary <Snowflake, CachedGuildChannel>(model.Channels.Length);
            _members  = new LockedDictionary <Snowflake, CachedMember>(model.MemberCount);

            Update(model);
            if (client.IsBot && IsLarge)
            {
                ChunksExpected = (int)Math.Ceiling(model.MemberCount / 1000.0);
                ChunkTcs       = new TaskCompletionSource <bool>();
            }
            else if (!client.IsBot)
            {
                SyncTcs = new TaskCompletionSource <bool>();
            }
        }
Example #11
0
        public static EmoticonImage GetEmoticonForMessage(ChatMessageDataModel message)
        {
            if (message.type.Equals("emoticon", StringComparison.InvariantCultureIgnoreCase))
            {
                LockedDictionary <string, LockedDictionary <string, EmoticonImage> > emoticons = null;
                switch (message.source.ToLower())
                {
                case "external":
                    emoticons = externalEmoticons;
                    break;

                case "builtin":
                    emoticons = builtinEmoticons;
                    break;
                }

                if (emoticons != null && emoticons.ContainsKey(message.pack) && emoticons[message.pack].ContainsKey(message.text))
                {
                    return(emoticons[message.pack][message.text]);
                }
            }
            return(null);
        }
Example #12
0
 public UserDataViewModel()
 {
     this.CurrencyAmounts = new LockedDictionary <UserCurrencyViewModel, UserCurrencyDataViewModel>();
 }
Example #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LockedDictionary{TKey, TValue}.Enumerator"/> <see langword="struct"/>
 ///     with the provided <see cref="LockedDictionary{TKey, TValue}"/>.
 /// </summary>
 /// <param name="dictionary">
 ///     The source dictionary.
 /// </param>
 public Enumerator(LockedDictionary <TKey, TValue> dictionary)
 {
     _enumerator = dictionary._dictionary.GetEnumerator();
 }
Example #14
0
        private static IEnumerable <EmoticonImage> FindMatchingEmoticons(string text, LockedDictionary <string, LockedDictionary <string, EmoticonImage> > storage)
        {
            List <EmoticonImage> matchedImages = new List <EmoticonImage>();

            if (text.Length == 1 && char.IsLetterOrDigit(text[0]))
            {
                // Short circuit for very short searches that start with letters or digits
                return(matchedImages);
            }

            // User specific emoticons
            foreach (var kvp in storage)
            {
                var values = kvp.Value.ToDictionary();
                matchedImages.AddRange(values.Where(v => v.Key.StartsWith(text, StringComparison.InvariantCultureIgnoreCase)).Select(v => v.Value));
            }

            // Builtin emoticons (added last to put them at the end)
            foreach (var kvp in builtinEmoticons)
            {
                var values = kvp.Value.ToDictionary();
                matchedImages.AddRange(values.Where(v => v.Key.StartsWith(text, StringComparison.InvariantCultureIgnoreCase)).Select(v => v.Value));
            }

            return(matchedImages.Distinct());
        }
Example #15
0
 private static void Entities_OnCloseAll()
 {
     MyAPIGateway.Entities.OnCloseAll -= Entities_OnCloseAll;
     lock_constructing = null;
     DefinitionType = null;
 }
Example #16
0
 /// <summary>
 ///     Instiantiates a new <see cref="DefaultMessageCache"/> with the specified capacity.
 /// </summary>
 /// <param name="capacity"> The capacity of each channel's circular cache. </param>
 public DefaultMessageCache(int capacity)
 {
     Capacity = capacity;
     _caches  = new LockedDictionary <Snowflake, CircularBuffer <CachedUserMessage> >();
 }
 public UniqueNumberStatisticDataTracker(string name, string iconName, Func <StatisticDataTrackerBase, Task> updateFunction)
     : base(name, iconName, updateFunction)
 {
     this.UniqueData = new LockedDictionary <string, double>();
 }