Ejemplo n.º 1
0
        public BottomBenchmark()
        {
            _encode_data = BenchmarkData.ENCODE_INPUT[N];
            _decode_data = BenchmarkData.DECODE_INPUT[N];

            Bottomify.EncodeByte(0); // preload cache
        }
 public void TestByteEncode()
 {
     Assert.AreEqual(
         "💖💖,,,,👉👈",
         Bottomify.EncodeByte((byte)'h')
         );
     Assert.AreEqual(
         "❤️👉👈",
         Bottomify.EncodeByte((byte)'\0')
         );
 }
 public void TestStringEncode()
 {
     Assert.AreEqual(
         "💖✨✨✨,,,,👉👈💖💖,👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈",
         Bottomify.EncodeString("Test")
         );
     Assert.AreEqual(
         "💖✨✨✨,,,,👉👈💖💖,👉👈❤️👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈",
         Bottomify.EncodeString("Te\0st")
         );
 }
 public void TestIsEncoded()
 {
     Assert.AreEqual(
         true,
         Bottomify.IsEncoded("💖✨✨✨,,,,\u200B💖💖,\u200B💖💖✨🥺\u200B💖💖✨🥺,\u200B")
         );
     Assert.AreEqual(
         false,
         Bottomify.IsEncoded("Hello")
         );
 }
 public void TestUnicodeStringEncode()
 {
     Assert.AreEqual(
         "🫂✨✨✨✨👉👈💖💖💖🥺,,,,👉👈💖💖💖✨🥺👉👈💖💖💖✨✨✨🥺,👉👈",
         Bottomify.EncodeString("🥺")
         );
     Assert.AreEqual(
         "🫂✨✨🥺,,👉👈💖💖✨✨🥺,,,,👉👈💖💖✨✨✨✨👉👈🫂✨✨🥺,,👉👈" +
         "💖💖✨✨✨👉👈💖💖✨✨✨✨🥺,,👉👈🫂✨✨🥺,,👉👈💖💖✨✨🥺,,,,👉👈" +
         "💖💖💖✨✨🥺,👉👈🫂✨✨🥺,,👉👈💖💖✨✨✨👉👈💖💖✨✨✨✨👉👈",
         Bottomify.EncodeString("がんばれ")
         );
 }
 public void TestStringDecode()
 {
     Assert.AreEqual(
         "Test",
         Bottomify.DecodeString("💖✨✨✨,,,,\u200B💖💖,\u200B💖💖✨🥺\u200B💖💖✨🥺,\u200B")
         );
     Assert.AreEqual(
         "Test",
         Bottomify.DecodeString("💖✨✨✨,,,,👉👈💖💖,👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈")
         );
     Assert.AreEqual(
         "Te\0st",
         Bottomify.DecodeString("💖✨✨✨,,,,👉👈💖💖,👉👈❤️👉👈💖💖✨🥺👉👈💖💖✨🥺,👉👈")
         );
 }
 public void TestIsCharacterValueGroup()
 {
     Assert.AreEqual(
         true,
         Bottomify.IsCharacterValueGroup("💖💖,,,,👉👈")
         );
     Assert.AreEqual(
         false,
         Bottomify.IsCharacterValueGroup("💖✨✨✨,,,,\u200B💖💖,\u200B💖💖✨🥺\u200B💖💖✨🥺,\u200B")
         );
     Assert.AreEqual(
         true,
         Bottomify.IsCharacterValueGroup("hello")
         );
 }
 public void TestCharacterValueGroupDecode()
 {
     Assert.AreEqual(
         (byte)'h',
         Bottomify.DecodeCharacterValueGroup("💖💖,,,,👉👈")
         );
     Assert.AreEqual(
         (byte)'a',
         Bottomify.DecodeCharacterValueGroup("💖✨✨✨✨,,,,,,,👉👈")
         );
     Assert.AreEqual(
         (byte)'\0',
         Bottomify.DecodeCharacterValueGroup("❤️👉👈")
         );
 }
Ejemplo n.º 9
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());
    }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public string Decode() => Bottomify.DecodeString(_decode_data);
Ejemplo n.º 12
0
 public string Encode() => Bottomify.EncodeString(_encode_data);
Ejemplo n.º 13
0
        static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            RootCommand rootCommand = new RootCommand
            {
                new Option <bool>(
                    new string[] { "-b", "--bottomify" },
                    description: "Translate text to bottom"),
                new Option <bool>(
                    new string[] { "-r", "--regress" },
                    description: "Translate bottom to human-readable text (futile)"),
                new Option <FileInfo>(
                    new string[] { "-i", "--input" },
                    description: "Input file [default: stdin]"),
                new Option <FileInfo>(
                    new string[] { "-o", "--output" },
                    description: "Output file [default: stdout]"),
                new Argument <string>(
                    "text",
                    getDefaultValue: () => null
                    )
            };

            rootCommand.Name        = "bottom";
            rootCommand.Description = "Fantastic (maybe) CLI for translating between bottom and human-readable text";

            rootCommand.Handler = CommandHandler.Create <bool, bool, FileInfo, FileInfo, string>((bottomify, regress, input, output, text) =>
            {
                if (!(bottomify || regress))
                {
                    rootCommand.InvokeAsync("--help");
                    return;
                }

                if (bottomify && regress)
                {
                    Console.Error.WriteLine("Both encoding options set, only set one.");
                    return;
                }

                if (input is null && text is null)
                {
                    Console.Error.WriteLine("Either input text or the --input options must be provided.");
                    return;
                }

                if (!(input is null))
                {
                    if (!input.Exists)
                    {
                        Console.Error.WriteLine($"Input file \"{input.FullName}\" does not exist.");
                        return;
                    }
                    using StreamReader sr = input.OpenText();
                    text = sr.ReadToEnd();
                }

                string result;
                if (bottomify)
                {
                    result = Bottomify.EncodeString(text);
                }
                else
                {
                    result = Bottomify.DecodeString(text);
                }

                if (!(output is null))
                {
                    using StreamWriter sw = output.CreateText();
                    sw.Write(result);
                }