public Character(int _characterId) { characterId = _characterId; nameVar = "char" + _characterId.ToString() + "name"; hairColorVar = "char" + _characterId.ToString() + "haircolor"; actionVar = "char" + _characterId.ToString() + "action"; actionItemVar = "char" + _characterId.ToString() + "actionitem"; RantProgram setName = RantProgram.CompileString(@"[vs:" + nameVar + ";<name>]"); RantProgram setHairColor = RantProgram.CompileString(@"[vs:" + hairColorVar + ";<adj-color>]"); RantProgram setAction = RantProgram.CompileString(@"[vs:" + actionVar + ";<verb>]"); RantProgram setActionItem = RantProgram.CompileString(@"[vs:" + actionItemVar + ";<noun>]"); rantEngine.Do(setName); rantEngine.Do(setHairColor); rantEngine.Do(setAction); rantEngine.Do(setActionItem); RantProgram getName = RantProgram.CompileString("[v:" + nameVar + "]"); RantProgram getHairColor = RantProgram.CompileString("[v:" + hairColorVar + "]"); RantProgram getAction = RantProgram.CompileString("[v:" + actionVar + "]"); RantProgram getActionItem = RantProgram.CompileString("[v:" + actionItemVar + "]"); name = rantEngine.Do(getName).Main; hairColor = rantEngine.Do(getHairColor).Main; action = rantEngine.Do(getAction).Main; actionItem = rantEngine.Do(getActionItem).Main; }
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); }
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); }
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)); }
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); }
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); } }
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(); }
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); }
public void SaveLoadRun() { var package = new RantPackage { ID = "TestPackage", Description = "This is a test.", Title = "Test Package?!", Version = new RantPackageVersion(1, 1, 0) }; package.AddResource(RantDictionaryTable.FromStream("nouns", File.Open("Tables/nouns.table", FileMode.Open))); package.AddResource(RantProgram.CompileString("TestProgram", @"[case:title]<noun-food-fruit-yellow> [rs:5;,\s]{[rn]}")); package.Save("TestPackage.rantpkg"); package = RantPackage.Load("TestPackage.rantpkg"); rant.LoadPackage(package); Assert.AreEqual("Banana 1, 2, 3, 4, 5", rant.DoName("TestProgram").Main); Assert.AreEqual("TestPackage", package.ID); Assert.AreEqual("This is a test.", package.Description); Assert.AreEqual("Test Package?!", package.Title); Assert.AreEqual("1.1.0", package.Version.ToString()); }
public void MissingQueryClassFilter() { RantProgram.CompileString(@"<noun->"); }
public void MissingQuerySubtype() { RantProgram.CompileString(@"<noun.>"); }
public void InvalidQuerySubtype() { RantProgram.CompileString(@"<noun.???>"); }
public void InvalidQueryTableName(string name) { RantProgram.CompileString($"<{name}>"); }
public void UnterminatedQuery() { RantProgram.CompileString(@"<noun"); }
public void UnterminatedFunctionCall() { RantProgram.CompileString(@"[rep:10"); }
public async Task MakeRant([Remainder] string cmd) { var pgm = RantProgram.CompileString(cmd); await ReplyAsync(rant.Do(pgm).Main); }
public void UnterminatedQueryComplement() { RantProgram.CompileString(@"<verb.ing [the <noun>>"); }
public void TooManyCarrierOperators() { RantProgram.CompileString(@"<noun::!A::@B>"); }
public void MissingReplacerArgument() { RantProgram.CompileString(@"[`\s*`:this is a test]"); }
public void ExtraOpeningBracket() { RantProgram.CompileString(@"[[rep:10]"); }
public void UnterminatedBlock() { RantProgram.CompileString(@"{"); }
public void BadNameArgsSeparator() { RantProgram.CompileString(@"[numfmt;verbal-en]"); }
public void BadParameterNames() { RantProgram.CompileString(@"[$[epic_fail:good_param;bad=param]:NO]"); }
public void MissingQuantifierComma() { RantProgram.CompileString(@"\123a"); }
public void EmptyTag() { RantProgram.CompileString(@"[]"); }
public void UnexpectedTagTerminator() { RantProgram.CompileString(@"]"); }
public void UnexpectedQueryTerminator() { RantProgram.CompileString(@">"); }
public void UnexpectedBlockTerminator() { RantProgram.CompileString(@"}"); }
public void ParameterMismatch(string pattern) { RantProgram.CompileString(pattern); }