private bool TestHelpMessage(ISummonable middleware, IChatServiceConnection chatServiceConnection, ChatMessageModel message) { // expect exactly 1 instance of the action verb var helpMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?help\\s*"); // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware Regex testRegex = new Regex(helpMatchPattern, RegexOptions.IgnoreCase); Match match = testRegex.Match(message.Body); return(match.Success); }
/// <summary> /// Add the specified ISummonable entity to the player's inventory /// </summary> /// <param name="item">ISummonable entity to add to the player's inventory</param> public void AddItem(ISummonable item) { bool found = false; ISummonable flag = item; foreach (var occupiedInventorySlot in _inventory) { if (occupiedInventorySlot.Key is Weapon && item is Weapon) { var inventoryItem = (Weapon)occupiedInventorySlot.Key; var giftedItem = (Weapon)item; if (inventoryItem.Name == giftedItem.Name) { found = true; flag = inventoryItem; } } if (occupiedInventorySlot.Key is Character && item is Character) { var inventoryItem = (Character)occupiedInventorySlot.Key; var giftedItem = (Character)item; if (inventoryItem.Name == giftedItem.Name) { found = true; flag = inventoryItem; } } } if (found && flag != item) { _inventory[flag]++; } else { _inventory.Add(item, 1); } }
private string ProcessSummonMessage(ISummonable middleware, IChatServiceConnection chatServiceConnection, ChatMessageModel message) { // expect exactly 1 instance of the action verb var verbMatchPattern = string.Concat(middleware.GetSummonVerb(), "{1}\\s?("); // match for message format "<bot mention> <verb> *rest of message*" and return *rest of message* to middleware var testPattern = string.Concat(verbMatchPattern, middleware.MentionRegex, ")"); Regex testRegex = new Regex(testPattern, RegexOptions.IgnoreCase); Match match = testRegex.Match(message.Body); if (!match.Success) { return(null); } var strippedMessageMatchGroup = match.Groups[1]; return(strippedMessageMatchGroup.Value == null ? string.Empty : strippedMessageMatchGroup.Value); }
/// <summary> /// Get static Summon Verb value for ISummonable object /// </summary> public static string GetSummonVerb(this ISummonable o) { return(o.GetType().GetSummonVerb()); }