コード例 #1
0
    public override async Task <Status> Handle(DefaultFallbackAction action, CancellationToken cancellationToken)
    {
        if (!string.IsNullOrWhiteSpace(action.Message.Text) && Bottomify.IsEncoded(action.Message.Text))
        {
            await NavigatorContext.GetTelegramClient().SendTextMessageAsync(NavigatorContext.GetTelegramChat() !,
                                                                            $"`Fellow humans I have decoded these words of wisdom:` \n_{Bottomify.DecodeString(action.Message.Text)}_",
                                                                            ParseMode.Markdown,
                                                                            cancellationToken: cancellationToken);
        }

        if (RandomProvider.GetThreadRandom().Next(0, 600) < 598)
        {
            return(Success());
        }

        var sentence = string.Empty;

        var odds = RandomProvider.GetThreadRandom().Next(0, 20);

        if (odds >= 0 && odds < 5)
        {
            sentence = await _lipsumService.GetBacon(cancellationToken : cancellationToken);
        }
        else if (odds >= 5 && odds < 10)
        {
            sentence = await _lipsumService.GetMetaphorSentence(cancellationToken : cancellationToken);
        }
        else if (action.Message.Text?.Split(' ').Length > 3)
        {
            sentence = MockFilter.Apply(action.Message.Text);
        }

        if (!string.IsNullOrWhiteSpace(sentence))
        {
            await NavigatorContext.GetTelegramClient().SendTextMessageAsync(NavigatorContext.GetTelegramChat() !, sentence, ParseMode.Markdown,
                                                                            replyToMessageId: action.Message.MessageId, cancellationToken: cancellationToken);
        }

        return(Success());
    }
コード例 #2
0
        public override async Task <Unit> Handle(DefaultFallbackAction request, CancellationToken cancellationToken)
        {
            if (!string.IsNullOrWhiteSpace(Ctx.GetMessageOrDefault()?.Text) && Bottomify.IsEncoded(Ctx.GetMessage().Text))
            {
                await Ctx.Client.SendTextMessageAsync(Ctx.GetTelegramChat(),
                                                      $"`Fellow humans I have decoded these words of wisdom:` \n_{Bottomify.DecodeString(Ctx.GetMessage().Text)}_",
                                                      ParseMode.Markdown,
                                                      cancellationToken : cancellationToken);
            }

            if (RandomProvider.GetThreadRandom().Next(0, 600) < 598)
            {
                return(Unit.Value);
            }

            var sentence = string.Empty;

            var odds = RandomProvider.GetThreadRandom().Next(0, 20);

            if (odds >= 0 && odds < 5)
            {
                sentence = await LipsumService.GetBacon(cancellationToken : cancellationToken);
            }
            else if (odds >= 5 && odds < 10)
            {
                sentence = await LipsumService.GetMetaphorSentence(cancellationToken : cancellationToken);
            }
            else if (Ctx.GetMessageOrDefault()?.Text.Split(' ').Length > 3)
            {
                sentence = MockFilter.Apply(Ctx.GetMessage().Text);
            }

            if (!string.IsNullOrWhiteSpace(sentence))
            {
                await Ctx.Client.SendTextMessageAsync(Ctx.GetTelegramChat(), sentence, ParseMode.Markdown,
                                                      replyToMessageId : request.MessageId, cancellationToken : cancellationToken);
            }

            return(Unit.Value);
        }
コード例 #3
0
        public void TestAcceptorFilterChain()
        {
            Int32 port = 1024;
            IoFilter mockFilter = new MockFilter();
            IoHandler mockHandler = new MockHandler();

            acceptor.FilterChain.AddLast("mock", mockFilter);
            acceptor.Handler = mockHandler;
            acceptor.Bind(new IPEndPoint(IPAddress.Loopback, port));

            try
            {
                IConnectFuture future = connector.Connect(new IPEndPoint(IPAddress.Loopback, port));
                future.Await();

                IWriteFuture writeFuture = future.Session.Write(IoBuffer.Allocate(16).PutInt32(0).Flip());
                writeFuture.Await();
                Assert.IsTrue(writeFuture.Written);

                future.Session.Close(true);

                for (int i = 0; i < 30; i++)
                {
                    if (result.Length == 2)
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }

                Assert.AreEqual("FH", result);
            }
            finally
            {
                acceptor.Unbind();
            }
        }
コード例 #4
0
ファイル: DatagramConfigTest.cs プロジェクト: xlg210/Mina.NET
        public void TestAcceptorFilterChain()
        {
            Int32     port        = 1024;
            IoFilter  mockFilter  = new MockFilter();
            IoHandler mockHandler = new MockHandler();

            acceptor.FilterChain.AddLast("mock", mockFilter);
            acceptor.Handler = mockHandler;
            acceptor.Bind(new IPEndPoint(IPAddress.Loopback, port));

            try
            {
                IConnectFuture future = connector.Connect(new IPEndPoint(IPAddress.Loopback, port));
                future.Await();

                IWriteFuture writeFuture = future.Session.Write(IoBuffer.Allocate(16).PutInt32(0).Flip());
                writeFuture.Await();
                Assert.IsTrue(writeFuture.Written);

                future.Session.Close(true);

                for (int i = 0; i < 30; i++)
                {
                    if (result.Length == 2)
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }

                Assert.AreEqual("FH", result);
            }
            finally
            {
                acceptor.Unbind();
            }
        }
コード例 #5
0
ファイル: CustomSocket.cs プロジェクト: DmitryRyder/spa
 public CustomSocket()
 {
     _filter = new MockFilter();
 }