예제 #1
0
        public void OneArg()
        {
            var args = new RantProgramArgs
            {
                ["foo"] = "Bar"
            };

            Assert.AreEqual("FooBar", rant.Do(@"Foo[in:foo]", 0, 0, args).Main);
        }
예제 #2
0
파일: Channels.cs 프로젝트: thygrrr/rant3
        public void Public()
        {
            var output = rant.Do(@"Hello [chan:foo;public;World]");

            Assert.AreEqual("Hello World", output.Main);
            Assert.AreEqual("World", output["foo"]);
        }
예제 #3
0
        public void SerializeAndExecute(string pattern)
        {
            var ms     = new MemoryStream();
            var pgmSer = RantProgram.CompileString(pattern);

            pgmSer.SaveToStream(ms);
            ms.Seek(0, SeekOrigin.Begin);
            var pgmDeser    = RantProgram.LoadStream("Test", ms);
            var resultSer   = rant.Do(pgmSer, seed: 0).Main;
            var resultDeser = rant.Do(pgmDeser, seed: 0).Main;

            Console.WriteLine($"Before: '{resultSer}'");
            Console.WriteLine($"After: '{resultDeser}'");
            Assert.AreEqual(resultSer, resultDeser);
        }
예제 #4
0
        public void StringSplit()
        {
            var rant   = new RantEngine();
            var result = rant.Do("[split:a;,;\"a,b,c,d\"][v:a]").Main;

            Assert.AreEqual("(a, b, c, d)", result);
        }
예제 #5
0
        public void VariableExists()
        {
            var rant = new RantEngine();

            rant.Do("[vn:testvar;123]");
            Assert.IsNotNull(rant["testvar"]);
        }
예제 #6
0
        public void Loop()
        {
            var rant   = new RantEngine();
            var result = rant.Do("[vn:a;10][while:[gt:[v:a];0];[vsub:a;1]a]").Main;

            Assert.AreEqual(result, "aaaaaaaaaa");
        }
예제 #7
0
        public void RandomNumbers()
        {
            var output = rant.Do(@"[r:10][s:\s]{[n:1;100]}").Main.Split(' ');

            Assert.AreEqual(10, output.Length);
            int i;

            foreach (var numberString in output)
            {
                Assert.True(int.TryParse(numberString, out i));
                Assert.True(i >= 1 && i <= 100);
            }
        }
예제 #8
0
        public void VariableSwap()
        {
            var rant = new RantEngine();

            rant.Do("[vn:a;3][vn:b;5][swap:a;b]");
            Assert.AreEqual(rant["a"].Value, 5);
            Assert.AreEqual(rant["b"].Value, 3);
        }
예제 #9
0
        public void VariableScope()
        {
            var rant = new RantEngine();

            rant.Do("{[vn:a;100]}[vn:b;150]");
            Assert.IsNull(rant["a"]);
            Assert.IsNotNull(rant["b"]);
        }
예제 #10
0
        public void StringGlobal()
        {
            var rant = new RantEngine {
                ["myString"] = new RantObject("Hello world")
            };

            Assert.AreEqual("Hello world", rant.Do(@"[@myString]").Main);
        }
예제 #11
0
 protected override IEnumerable<IDocument> Execute(object content, IDocument input, IExecutionContext context)
 {
     string output;
     if(_seed.HasValue)
     {
         output = _engine.Do(content.ToString(), _seed.Value);
         if (_incrementSeed)
         {
             _seed++;
         }
     }
     else
     {
         output = _engine.Do(content.ToString());
     }
     return new[] {Execute(output, input, context)};
 }
예제 #12
0
        public void IntegerGlobal()
        {
            var rant = new RantEngine {
                ["myInt"] = new RantObject(123)
            };

            Assert.AreEqual("123", rant.Do(@"[@myInt]").Main);
        }
예제 #13
0
        public void ListFilter()
        {
            var rant   = new RantEngine();
            var result = rant.Do(@"
				[vl:test][laddn:test;1][laddn:test;2][laddn:test;3][laddn:test;4]
				[lfilter:test;a;[gt:[v:a];2]][v:test]"                ).Main;

            Assert.AreEqual("(3, 4)", result);
        }
예제 #14
0
        public void ShowRoom()
        {
            RantProgram program = RantProgram.CompileString(@"You <descriptor-room_arrived>");
            RantOutput  output  = rantEngine.Do(program);

            string roomArrive = output.ToString();

            Console.WriteLine(Environment.NewLine + roomArrive + " " + this.description);
        }
예제 #15
0
        public void ListMap()
        {
            var rant   = new RantEngine();
            var result = rant.Do(@"
				[vl:test][laddn:test;1][laddn:test;2][laddn:test;3][laddn:test;4]
				[lmap:test;a;[v:a][v:a]][v:test]"                ).Main;

            Assert.AreEqual("(11, 22, 33, 44)", result);
        }
예제 #16
0
        static async void OnMessage(object sender, MessageEventArgs eventArgs)
        {
            var messageText = eventArgs.Message.Text;

            _rant["tense"] = new RantObject(messageText);
            var program = RantProgram.CompileString("Прости, я пока что не понимаю, что ты [if: [eq:[v: tense];present];<verb.present>;<verb.simple_past>]!");
            var message = _rant.Do(program);
            await _client.SendTextMessageAsync(eventArgs.Message.Chat, message);
        }
예제 #17
0
 public void ListGlobal()
 {
     var list = new List<RantObject>
     {
         new RantObject("A"),
         new RantObject("B"),
         new RantObject("C"),
         new RantObject("D")
     };
     var rant = new RantEngine {["myList"] = new RantObject(list) };
     Assert.AreEqual("A, B, C, D", rant.Do(@"[@ myList.join("", "") ]").Main);
 }
예제 #18
0
        public string ExecuteRant(string rawMessage, bool gender, bool botGender)
        {
            _rant["gender"] = gender == Const.Gender.Male
                ? new RantObject("male")
                : new RantObject("female");

            _rant["botGender"] = botGender == Const.Gender.Male
                            ? new RantObject("male")
                            : new RantObject("female");

            var rantProgram = RantProgram.CompileString(rawMessage);

            return(_rant.Do(rantProgram));
        }
예제 #19
0
        public void ListGlobal()
        {
            var list = new List <RantObject>
            {
                new RantObject("A"),
                new RantObject("B"),
                new RantObject("C"),
                new RantObject("D")
            };
            var rant = new RantEngine {
                ["myList"] = new RantObject(list)
            };

            Assert.AreEqual("A, B, C, D", rant.Do(@"[@ myList.join("", "") ]").Main);
        }
예제 #20
0
        public void SendBotChatMessage(Player p, LocalizedString message, RantProgramArgs args)
        {
            if (!Game.Settings.ChatEnabled || message == null)
            {
                return;
            }
            int seed = _rng.Next();
            var cfg  = Game.Settings.BotConfig;

            async void send(ClientConnectionBase connection, Random rng)
            {
                await Task.Delay(rng.Next(1500, 3000));

                RantProgram pgm;

                try
                {
                    pgm = RantProgram.CompileString(message[connection.ClientLanguage]);
                    var output = _rant.Do(pgm, seed: seed, charLimit: 0, timeout: -1, args: args).Main.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var msg in output)
                    {
                        int delay = rng.Next(cfg.MinTypingDelay, cfg.MaxTypingDelay + 1)
                                    + msg.Length * rng.Next(cfg.MinTypingInterval, cfg.MaxTypingInterval + 1);
                        await Task.Delay(delay);

                        connection.SendChatMessage(p, msg);
                        Console.WriteLine($"{p} says: \"{msg}\"");
                    }
                }
                catch (RantCompilerException ex)
                {
                    Console.WriteLine($"Rant compiler error: {ex}");
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Rant failure: {ex}");
                    return;
                }
            }

            foreach (var connection in _connections.ToArray())
            {
                var rng = new Random(seed);
                send(connection, rng);
            }
        }
예제 #21
0
        static void Main(string[] args)
        {
            int    repetition = 10;
            string text;

            var rant = new RantEngine();

            rant.LoadPackage("build/AlinhamentoZuado-0.0.1.rantpkg");

            var program = RantProgram.CompileFile("alinhamentoZuado.rant");

            for (int i = 0; i < repetition; i++)
            {
                text = rant.Do(program);
                Console.WriteLine(text);
            }
        }
예제 #22
0
파일: Map.cs 프로젝트: newellewen/rantGame
        private static List <Room> GetRooms(int roomCount)
        {
            RantProgram program = RantProgram.CompileString(@"<adj> <noun-indoor>");
            RantOutput  output  = null;
            List <Room> rooms   = new List <Room>();

            for (int i = 0; i < roomCount; i++)
            {
                output = rantEngine.Do(program);
                Room newRoom = new Room();
                newRoom.roomId      = i + 1;
                newRoom.name        = output.ToString();
                newRoom.description = output.ToString();
                rooms.Add(newRoom);
            }
            return(rooms);
        }
        static void Main(string[] args)
        {
            var rant = new RantEngine();

            rant.LoadPackage("Rantionary-3.0.20.rantpkg");
            rant.Dictionary.IncludeHiddenClass("nsfw");

            Console.WriteLine("Press <Enter> to create a list of 1000 groups");
            Console.ReadKey(true);
            Console.Clear();

            var pgm    = RantProgram.CompileString(@"[rs:1000;\n]{<adj> <adj> <noun.pl>}");
            var output = rant.Do(pgm);

            Console.WriteLine(output.Main);



            Console.ReadLine();
        }
예제 #24
0
        public void generate_product_reviews()
        {
            var reviews = new[]
            {
                "this $product is <adj>.",
                "I tried to <verb-violent> it but got <noun-food> all over it.",
                "i use it <timeadv-frequency> when i'm in my <noun-place-indoor>.",
                "My <noun-living-animal> loves to play with it.",
                "[vl:ending][ladd:ending;!;!!;!!!;.]The box this comes in is [num:3;5] <unit-length> by [num:5;6] <unit-length> and weights [num:10;20] <unit-weight>[lrand:ending]",
                "This $product works <advattr> well. It <adv> improves my <activity> by a lot.",
                "I saw one of these in <country> and I bought one.",
                "one of my hobbies is <hobby::=A>. and when i'm <hobby.pred::=A> this works great.",
                "It only works when I'm <country>.",
                "My neighbor <name-female> has one of these. She works as a <noun-living-job> and she says it looks <adj-appearance>.",
                "My co-worker <name-male> has one of these. He says it looks <adj-appearance>.",
                "heard about this on <musicgenre> radio, decided to give it a try.",
                "[vl:ending][ladd:ending;!;!!;!!!;.]talk about <noun-uc-emotion>[lrand:ending]"
            };

            var singles = new[]
            {
                "This $product, does exactly what it's suppose to do.",
                "SoCal cockroaches are unwelcome, crafty, and tenacious. This $product keeps them away.",
                "works okay.",
                "I saw this on TV and wanted to give it a try.",
                "This is a really good $product."
            };

            var genReviews = reviews
                             .Select(rant => RantProgram.CompileString(rant))
                             .SelectMany(pgm =>
            {
                return(Enumerable.Range(1, 25)
                       .Select(_ => rant.Do(pgm, rng).Main));
            })
                             .Concat(singles)
                             .Distinct()
                             .ToList();

            Inject("en", "rant", "review", genReviews);
        }
예제 #25
0
        public void StringBuildingWhileLoop()
        {
            var output = rant.Do(@"
[@
    (function() 
    {
        var parts = (""this"", ""is"", ""a"", ""test"");
        var i = 0;
        var buffer = """";
        while(i < parts.length)
        {
            if (i > 0) buffer ~= "" "";
            buffer ~= parts[i];
            i++;
        }
        return buffer;
    })();
]");

            Assert.AreEqual("this is a test", output.Main);
        }
예제 #26
0
파일: Targets.cs 프로젝트: thygrrr/rant3
 public void SingleTargetOnce()
 {
     Assert.AreEqual("The quick brown fox jumps over the lazy dog.",
                     rant.Do(@"The quick brown [t:a] jumps over the lazy dog.[send:a;fox]").Main);
 }
예제 #27
0
 public void Basic()
 {
     Assert.IsNotNull(rant.Do("<noun>"));
 }
예제 #28
0
 public void BasicOperators(int a, int b, string op, string result)
 {
     Assert.AreEqual(result, rant.Do($"[@ {a} {op} {b} ]").Main);
 }
예제 #29
0
 public void IntegerGlobal()
 {
     var rant = new RantEngine { ["myInt"] = new RantObject(123) };
     Assert.AreEqual("123", rant.Do(@"[@myInt]").Main);
 }
예제 #30
0
 public void Uppercase()
 {
     Assert.AreEqual(rant.Do(@"[caps:upper]hello world").Main, "HELLO WORLD");
 }
예제 #31
0
 public void ConvertToString()
 {
     Assert.AreEqual("5", rant.Do("[@ Convert.toString(5); ]").Main);
 }
예제 #32
0
 public void OutputPrint()
 {
     Assert.AreEqual("test string", rant.Do("[@ Output.print(\"test string\") ]").Main);
 }
예제 #33
0
 public void StringGlobal()
 {
     var rant = new RantEngine {["myString"] = new RantObject("Hello world") };
     Assert.AreEqual("Hello world", rant.Do(@"[@myString]").Main);
 }