public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                StickerSet.ToBytes(),
                Covers.ToBytes()));
 }
        public async Task Index_and_Find_TwoStickers_SameKeyword()
        {
            // Setup
            var stickerSetIndexer = new StickerSetIndexer(new Mock <ILogger>().Object);
            var stickers          = new StickerSet("Default stickers", new Sticker[] {
                new Sticker("sticker 1", new Uri("https://microsoft.com"), new string[] { "key" }),
                new Sticker("sticker 2", new Uri("https://microsoft.com"), new string[] { "key" })
            });

            // Action
            await stickerSetIndexer.IndexStickerSetAsync(stickers);

            // Verify
            // no matching stickers.
            var indexedStickers = await stickerSetIndexer.FindStickersByQuery("not found");

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(0, indexedStickers.Count());

            // matches both keywords.
            indexedStickers = await stickerSetIndexer.FindStickersByQuery("key");

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(2, indexedStickers.Count());
            Assert.AreEqual("sticker 1", indexedStickers.ElementAt(0).Name);
            Assert.AreEqual("sticker 2", indexedStickers.ElementAt(1).Name);
        }
Esempio n. 3
0
        public async Task Should_Throw_StickerSetNotModifiedException()
        {
            StickerSet testStickerSet = await BotClient.GetStickerSetAsync(_classFixture.TestStickerSetName);

            Sticker stickerToRemove = testStickerSet.Stickers[0];

            StickerSetNotModifiedException exception = await Assert.ThrowsAsync <StickerSetNotModifiedException>(
                async() =>
            {
                //foreach (Sticker sticker in testStickerSet.Stickers)
                //{
                //    await BotClient.DeleteStickerFromSetAsync(sticker.FileId);
                //}

                //foreach (Sticker sticker in testStickerSet.Stickers)
                //{
                //    await BotClient.DeleteStickerFromSetAsync(sticker.FileId);
                //}

                await BotClient.DeleteStickerFromSetAsync(stickerToRemove.FileId);
                await BotClient.DeleteStickerFromSetAsync(stickerToRemove.FileId);
            }
                );

            Assert.Equal(400, exception.ErrorCode);
            Assert.Contains("STICKERSET_NOT_MODIFIED", exception.Message);
        }
        /// <inheritdoc />
        public Task IndexStickerSetAsync(StickerSet stickerSet, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var scope = this.logger.BeginScope($"{nameof(StickerSetIndexer)}.{nameof(this.IndexStickerSetAsync)}"))
            {
                if (stickerSet == null)
                {
                    throw new ArgumentNullException(nameof(stickerSet));
                }

                this.allStickers.AddRange(stickerSet);

                foreach (var sticker in stickerSet)
                {
                    foreach (var keyword in sticker.Keywords)
                    {
                        var indexedKeyword = keyword.ToLowerInvariant().Trim();
                        if (!this.stickerKeywordMap.TryGetValue(indexedKeyword, out var indexedStickers))
                        {
                            indexedStickers = new List <Sticker>();
                            this.stickerKeywordMap.Add(indexedKeyword, indexedStickers);
                        }

                        indexedStickers.Add(sticker);
                    }
                }

                return(Task.CompletedTask);
            }
        }
Esempio n. 5
0
        public async Task Should_Answer_Inline_Query_With_Cached_Sticker()
        {
            await _fixture.SendTestInstructionsAsync(
                "Staring the inline query with this message...",
                startInlineQuery : true
                );

            Update iqUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            StickerSet stickerSet = await BotClient.GetStickerSetAsync("EvilMinds");

            const string resultId = "sticker_result";

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultCachedSticker(id: resultId, stickerFileId: stickerSet.Stickers[0].FileId)
            };

            await BotClient.AnswerInlineQueryAsync(
                inlineQueryId : iqUpdate.InlineQuery.Id,
                results : results,
                cacheTime : 0
                );

            (Update messageUpdate, Update chosenResultUpdate) =
                await _fixture.UpdateReceiver.GetInlineQueryResultUpdates(MessageType.Sticker);

            Update resultUpdate = chosenResultUpdate;

            Assert.Equal(MessageType.Sticker, messageUpdate.Message.Type);
            Assert.Equal(resultId, resultUpdate.ChosenInlineResult.ResultId);
            Assert.Equal(iqUpdate.InlineQuery.Query, resultUpdate.ChosenInlineResult.Query);
        }
Esempio n. 6
0
        public virtual void Update(StickerSet set, bool reset = false)
        {
            _set = set;

            for (int i = 0; i < set.Stickers.Count; i++)
            {
                if (i < Stickers.Count)
                {
                    if (Stickers[i] is MoreStickerViewModel)
                    {
                        Stickers[i] = new StickerViewModel(_protoService, set.Stickers[i]);
                    }
                    else
                    {
                        Stickers[i].Update(set.Stickers[i]);
                    }
                }
                else
                {
                    Stickers.Add(new StickerViewModel(_protoService, set.Stickers[i]));
                }
            }

            if (reset)
            {
                Stickers.Reset();
            }
        }
        private async Task DeleteStickersAsync()
        {
            StickerSet testStickerSet = await BotClient.GetStickerSetAsync(TestStickerSetName);

            foreach (Sticker sticker in testStickerSet.Stickers)
            {
                await BotClient.DeleteStickerFromSetAsync(sticker.FileId);
            }
        }
Esempio n. 8
0
        public async Task Should_Change_Sticker_Position_In_Set()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldSetStickerPositionInSet);

            StickerSet testStickerSet = await BotClient.GetStickerSetAsync(_classFixture.TestStickerSet.Name);

            Sticker tuxSticker = testStickerSet.Stickers[1];

            await BotClient.SetStickerPositionInSetAsync(
                sticker : tuxSticker.FileId,
                position : 0
                );
        }
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            Message msg             = context.Update.Message;
            Sticker incomingSticker = msg.Sticker;

            StickerSet evilMindsSet = await context.Bot.Client.GetStickerSetAsync("EvilMinds");

            Sticker similarEvilMindSticker = evilMindsSet.Stickers.FirstOrDefault(sticker => incomingSticker.Emoji.Contains(sticker.Emoji));

            Sticker replySticker = similarEvilMindSticker ?? evilMindsSet.Stickers.First();

            await context.Bot.Client.SendStickerAsync(msg.Chat, replySticker.FileId, replyToMessageId : msg.MessageId);
        }
Esempio n. 10
0
        public void Update(StickerSet set, bool reset = false)
        {
            _set = set;

            for (int i = 0; i < set.Stickers.Count && i < Stickers.Count; i++)
            {
                Stickers[i].Update(set.Stickers[i]);
            }

            if (reset)
            {
                Stickers.Reset();
            }
        }
        public static string SelectRandomFromSet(StickerSet stickerSet)
        {
            var fileName = stickerSet switch
            {
                StickerSet.Yoba => Path.Combine("Stickers", "Yoba", "YobaUrls.txt"),
                StickerSet.Frog => Path.Combine("Stickers", "Frog", "FrogUrls.txt"),
                _ => string.Empty
            };

            var urls = File.ReadAllLines(fileName).ToArray();

            return(urls[new Random().Next(urls.Length)]);
        }
    }
Esempio n. 12
0
        public async Task Should_Throw_StickerSetNotModifiedException()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldStickerSetNotModifiedException);

            StickerSet testStickerSet = await BotClient.GetStickerSetAsync(_classFixture.TestStickerSet.Name);

            BadRequestException exception = await Assert.ThrowsAnyAsync <BadRequestException>(() =>
                                                                                              BotClient.DeleteStickerFromSetAsync(
                                                                                                  sticker: testStickerSet.Stickers.Single().FileId
                                                                                                  )
                                                                                              );

            Assert.IsType <StickerSetNotModifiedException>(exception);
        }
        public void Update(long chatId, StickerSet set, bool reset = true)
        {
            _info.Id = set.Id;
            ChatId   = chatId;

            if (reset)
            {
                Stickers = new MvxObservableCollection <StickerViewModel>(set.Stickers.Select(x => new StickerViewModel(_protoService, _aggregator, x)));
            }
            else
            {
                Stickers.ReplaceWith(set.Stickers.Select(x => new StickerViewModel(_protoService, _aggregator, x)));
            }
        }
Esempio n. 14
0
        public async Task Should_Remove_All_Stickers_From_Set_Except_1()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldRemoveStickersFromSet);

            StickerSet testStickerSet = await BotClient.GetStickerSetAsync(_classFixture.TestStickerSet.Name);

            Sticker[] stickersToRemove = testStickerSet.Stickers.SkipLast(1).ToArray();
            foreach (Sticker sticker in stickersToRemove)
            {
                await Task.Delay(3_000); // ToDo: Bot API delays in updating changes to sticker sets

                await BotClient.DeleteStickerFromSetAsync(sticker : sticker.FileId);
            }
        }
        public async Task Index_and_Find_TwoStickers_Pagination()
        {
            // Setup
            var stickerSetIndexer = new StickerSetIndexer(new Mock <ILogger>().Object);
            var stickers          = new StickerSet("Default stickers", new Sticker[] {
                new Sticker("sticker 1", new Uri("https://microsoft.com"), new string[] { "key1" }),
                new Sticker("sticker 2", new Uri("https://microsoft.com"), new string[] { "key2" })
            });

            // Action
            await stickerSetIndexer.IndexStickerSetAsync(stickers);

            // Verify
            // first sticker.
            var indexedStickers = await stickerSetIndexer.FindStickersByQuery(null, 0, 1);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(1, indexedStickers.Count());
            Assert.AreEqual("sticker 1", indexedStickers.ElementAt(0).Name);

            // second sticker.
            indexedStickers = await stickerSetIndexer.FindStickersByQuery(null, 1, 1);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(1, indexedStickers.Count());
            Assert.AreEqual("sticker 2", indexedStickers.ElementAt(0).Name);

            // both stickers.
            indexedStickers = await stickerSetIndexer.FindStickersByQuery(null, 0, 2);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(2, indexedStickers.Count());
            Assert.AreEqual("sticker 1", indexedStickers.ElementAt(0).Name);
            Assert.AreEqual("sticker 2", indexedStickers.ElementAt(1).Name);

            // more requested than available 1.
            indexedStickers = await stickerSetIndexer.FindStickersByQuery(null, 0, 5);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(2, indexedStickers.Count());
            Assert.AreEqual("sticker 1", indexedStickers.ElementAt(0).Name);
            Assert.AreEqual("sticker 2", indexedStickers.ElementAt(1).Name);

            // more requested than available 2.
            indexedStickers = await stickerSetIndexer.FindStickersByQuery(null, 5, 2);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(0, indexedStickers.Count());
        }
        public async Task Index_and_Find_EmptyStickerSet()
        {
            // Setup
            var stickerSetIndexer = new StickerSetIndexer(new Mock <ILogger>().Object);
            var stickers          = new StickerSet("Default stickers", Enumerable.Empty <Sticker>());

            // Action
            await stickerSetIndexer.IndexStickerSetAsync(stickers);

            // Verify
            var indexedStickers = await stickerSetIndexer.FindStickersByQuery(null);

            Assert.IsNotNull(indexedStickers);
            Assert.AreEqual(0, indexedStickers.Count());
        }
Esempio n. 17
0
        public async Task Should_Get_Sticker_Set_With_Masks()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldGetStickerSetWithMasks);

            const string setName    = "masks2";
            const string setTitle   = "Masks II: Face Lift";
            StickerSet   stickerSet = await BotClient.GetStickerSetAsync(
                name : setName
                );

            Assert.Equal(setName, stickerSet.Name);
            Assert.Equal(setTitle, stickerSet.Title);
            Assert.True(stickerSet.ContainsMasks);
            Assert.True(20 < stickerSet.Stickers.Length);
        }
Esempio n. 18
0
        public async Task Should_Get_Sticker_Set()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldGetStickerSet);

            const string setName    = "EvilMinds";
            StickerSet   stickerSet = await _fixture.BotClient.GetStickerSetAsync(setName);

            Assert.Equal(setName, stickerSet.Name);
            Assert.Equal("Evil Minds", stickerSet.Title);
            Assert.False(stickerSet.ContainsMasks);
            Assert.NotEmpty(stickerSet.Stickers);
            Assert.True(20 < stickerSet.Stickers.Count);
            // ToDo: Add more asserts

            // ToDo: Assign sticker set to this class's fixture
        }
Esempio n. 19
0
        public StickerSet CreateStickerSet(string stickerSetTitle, string stickerSetName, long?albumId = null)
        {
            var stickerSet = new StickerSet
            {
                VkAlbumId   = albumId,
                Name        = stickerSetName,
                Title       = stickerSetTitle,
                CreatedDate = DateTime.Now
            };

            stickerSet = _context.Add(stickerSet).Entity;

            _context.SaveChangesAsync();

            return(stickerSet);
        }
Esempio n. 20
0
        public async Task Should_Get_Sticker_Set()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldGetStickerSet);

            const string setName    = "EvilMinds";
            const string setTitle   = "Evil Minds";
            StickerSet   stickerSet = await BotClient.GetStickerSetAsync(
                name : setName
                );

            Assert.Equal(setName, stickerSet.Name);
            Assert.Equal(setTitle, stickerSet.Title);
            Assert.False(stickerSet.ContainsMasks);
            Assert.NotEmpty(stickerSet.Stickers);
            Assert.True(20 < stickerSet.Stickers.Length);

            _classFixture.EvilMindsStickerSet = stickerSet;
        }
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            IsLoading = true;

            if (parameter is long setId)
            {
                var response = await ProtoService.SendAsync(new GetStickerSet(setId));

                if (response is StickerSet stickerSet)
                {
                    IsLoading = false;

                    StickerSet = stickerSet;
                    Items.ReplaceWith(stickerSet.Stickers);
                }
                else
                {
                    StickerSet = new StickerSet {
                        Title = "Sticker pack not found."
                    };
                    Items.Clear();
                }
            }
            else if (parameter is string name)
            {
                var response = await ProtoService.SendAsync(new SearchStickerSet(name));

                if (response is StickerSet stickerSet)
                {
                    IsLoading = false;

                    StickerSet = stickerSet;
                    Items.ReplaceWith(stickerSet.Stickers);
                }
                else
                {
                    StickerSet = new StickerSet {
                        Title = "Sticker pack not found."
                    };
                    Items.Clear();
                }
            }
        }
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);

            Message msg             = context.Update.Message;
            Sticker incomingSticker = msg.Sticker;

            var chat = await _telegramService.GetChat();

            var        stickerSetName = chat.StickerSetName ?? "EvilMinds";
            StickerSet evilMindsSet   = await context.Bot.Client.GetStickerSetAsync(stickerSetName, cancellationToken);

            Sticker similarEvilMindSticker = evilMindsSet.Stickers.FirstOrDefault(
                sticker => incomingSticker.Emoji.Contains(sticker.Emoji)
                );

            Sticker replySticker = similarEvilMindSticker ?? evilMindsSet.Stickers.First();

            await context.Bot.Client.SendStickerAsync(
                msg.Chat,
                replySticker.FileId,
                replyToMessageId : msg.MessageId, cancellationToken : cancellationToken);
        }
Esempio n. 23
0
        public async Task Should_Answer_Inline_Query_With_Cached_Sticker()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithCachedSticker,
                                                         startInlineQuery : true);

            Update iqUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            StickerSet stickerSet = await BotClient.GetStickerSetAsync("EvilMinds");

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultCachedSticker(
                    id: "sticker_result",
                    stickerFileId: stickerSet.Stickers[0].FileId
                    )
            };

            await BotClient.AnswerInlineQueryAsync(
                inlineQueryId : iqUpdate.InlineQuery.Id,
                results : results,
                cacheTime : 0
                );
        }
Esempio n. 24
0
 public Task <ContentDialogResult> ShowAsync(StickerSet parameter, ItemClickEventHandler callback)
 {
     return(ShowAsync(parameter.Id, callback));
 }
Esempio n. 25
0
 public Task <ContentDialogResult> ShowAsync(StickerSet parameter)
 {
     return(ShowAsync(parameter, null));
 }
 public StickerSetViewModel(IProtoService protoService, IEventAggregator aggregator, StickerSetInfo info, StickerSet set)
     : this(protoService, aggregator, info)
 {
     IsLoaded = true;
     Update(set);
 }
 public SupergroupStickerSetViewModel(IProtoService protoService, IEventAggregator aggregator, StickerSetInfo info, StickerSet set)
     : base(protoService, aggregator, info, set)
 {
 }
Esempio n. 28
0
 public StickerSetViewModel(StickerSetInfo info, StickerSet set)
     : this(info)
 {
     IsLoaded = true;
     Update(set);
 }
Esempio n. 29
0
 public IAsyncOperation <ContentDialogBaseResult> ShowAsync(StickerSet parameter, ItemClickEventHandler callback)
 {
     return(ShowAsync(parameter.Id, callback));
 }
Esempio n. 30
0
 public override string ToString()
 {
     return(string.Format("{0} Id={1}", GetType().Name, Id) + (StickerSet != null ? StickerSet.ToString() : string.Empty));
 }