public ProducerResponse Process(IMessage message, bool addressed) { Match match; if (addressed) { match = Regex.Match(message.Text, "say \"(.+)\""); if (match.Success) { return (new ProducerResponse( variableHandler.Substitute(match.Groups[1].Value, message), false)); } } match = Regex.Match(message.Text, @"^say (\S)([^.?!]+)[.?!]*$"); if (match.Success) { return (new ProducerResponse( match.Groups[1].Value.ToUpper() + match.Groups[2].Value + "!", false)); } return(null); }
public ProducerResponse Process(IMessage message, bool addressed) { var match = Regex.Match(message.Text, @"^([a-z]\w*)\s+([a-z]\w*)\s+([a-z]\w*)$", RegexOptions.IgnoreCase); if (match.Success) { var words = new[] { match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value }; var expandedAcronym = String.Join(" ", words); var tlaChance = int.Parse(Config.Get("PercentChanceOfNewTLA", "5")); var shouldCreateNewAcronym = StaticRandom.Next(0, 100) < tlaChance; if (shouldCreateNewAcronym) { var acronym = new String(words.Select(s => s.First()).ToArray()).ToUpperInvariant(); if (!tlaDataStore.Put(acronym, expandedAcronym)) { return(null); } // grab a random band name reply factoid and :shipit: var bandNameFactoidStr = factoidDataStore.GetRandomValue("band name reply")?.Value ?? DefaultBandNameReply; var bandNameFactoid = FactoidUtilities.GetVerbAndResponseFromPartialFactoid(bandNameFactoidStr); // GHETTO ALERT var coercedResponse = Regex.Replace(bandNameFactoid.Response, @"\$(?:band|tla)", expandedAcronym, RegexOptions.IgnoreCase); return(new ProducerResponse(variableHandler.Substitute(coercedResponse, message), false)); } } return(null); }
private ProducerResponse ProcessFactoid(string messageText, IMessage message) { var seenAliases = new HashSet <string>(); while (true) { var randomReply = dataStore.GetRandomValue(messageText); if (randomReply == null) { return(null); } var factoid = FactoidUtilities.GetVerbAndResponseFromPartialFactoid(randomReply.Value); factoid.Trigger = randomReply.Key; var factoidResponse = variableHandler.Substitute(factoid.Response, message); LastFactoid = String.Format("(#{3}) {0} <{1}> {2}", factoid.Trigger, factoid.Verb, factoid.Response, randomReply.Id); if (IsAddressedToBot(message.To ?? message.Who, factoid.Response) && ShouldFuckShitUp()) { var factoidResponseBytes = Encoding.UTF8.GetBytes(factoidResponse); factoidResponse = Encoding.UTF7.GetString(factoidResponseBytes); } switch (factoid.Verb) { case "reply": return(new ProducerResponse(factoidResponse, false)); case "action": return(new ProducerResponse(factoidResponse, true)); case "alias": if (!seenAliases.Add(messageText)) { return(new ProducerResponse(String.Format("Sorry {0}, but this factoid resolves to a circular reference.", message.Who), false)); } messageText = factoid.Response; continue; default: return(new ProducerResponse(String.Format("{0} {1} {2}", message.Text, factoid.Verb, factoid.Response), false)); } } }
public ProducerResponse Process(IMessage message, bool addressed) { var botName = Config.Get("Name", "gambot"); var match = Regex.Match(message.Text, String.Format(@"^(?:I give|gives) (?:(.+) to {0}|{0} (.+))$", botName), RegexOptions.IgnoreCase); if (!match.Success) { return(null); } var itemName = String.IsNullOrEmpty(match.Groups[1].Value) ? match.Groups[2].Value : match.Groups[1].Value; if (itemName.EndsWith("?")) { return(null); } var inventoryLimit = Int32.Parse(Config.Get("InventoryLimit", "10")); var allItems = GetInventory(); var currentInventorySize = allItems.Count(); // we dont have a .GetCount lololo if (allItems.Contains(itemName)) { var randomDuplicateAddReply = factoidDataStore.GetRandomValue("duplicate item")?.Value ?? "<reply> I already have $item."; var duplicateFactoid = FactoidUtilities.GetVerbAndResponseFromPartialFactoid(randomDuplicateAddReply); return (new ProducerResponse( variableHandler.Substitute( duplicateFactoid.Response, message, Replace.VarWith("item", itemName)), false)); } if (currentInventorySize >= inventoryLimit) { var randomItemToDrop = RemoveRandomItem(); if (randomItemToDrop == null) { return(null); } AddItem(itemName); var randomDropItemReply = factoidDataStore.GetRandomValue("drops item")?.Value ?? "<reply> I take $newitem and drop $giveitem."; var dropItemFactoid = FactoidUtilities.GetVerbAndResponseFromPartialFactoid(randomDropItemReply); return(new ProducerResponse(variableHandler.Substitute(dropItemFactoid.Response, message, Replace.VarWith("giveitem", randomItemToDrop), Replace.VarWith("newitem", itemName)), true)); } else { AddItem(itemName); var randomSuccessfulAddReply = factoidDataStore.GetRandomValue("takes item")?.Value ?? "<reply> I now have $item."; var successfulFactoid = FactoidUtilities.GetVerbAndResponseFromPartialFactoid( randomSuccessfulAddReply); return(new ProducerResponse(variableHandler.Substitute(successfulFactoid.Response, message, Replace.VarWith("item", itemName)), false)); } return(null); }