diff --git a/.gitignore b/.gitignore index 28387ed..d2c1341 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ config.json* *.exe [fF]ryatog vendor/* +.idea/ diff --git a/card.go b/card.go index bb55ca2..e906733 100644 --- a/card.go +++ b/card.go @@ -439,10 +439,6 @@ func fetchScryfallCardByFuzzyName(input string, isLang bool) (Card, error) { } if !isLang && card.Lang != "en" { log.Debug("Got back a foreign card when it wasn't requested, let's try again") - coercedName, err := HandleForeignCardOverlapCases(input) - if err == nil && coercedName != "" { - card.Name = coercedName - } return fetchScryfallCardByFuzzyName(card.Name, false) } if IsDumbCard(card) { @@ -454,15 +450,6 @@ func fetchScryfallCardByFuzzyName(input string, isLang bool) (Card, error) { return card, fmt.Errorf("Card not found by Scryfall") } -func HandleForeignCardOverlapCases(input string) (string, error) { - log.Debug("Handling foreign card overlap", "Card", input) - if uroRegex.MatchString(input) { - log.Debug("\tThey probably wanted Uro, Titan of Nature's Wrath") - return "Uro, Titan of Nature's Wrath", nil - } - return "", nil -} - func IsDumbCard(card Card) bool { releaseTime, err := time.Parse("2006-01-02", card.ReleasedAt) if err != nil { diff --git a/card_test.go b/card_test.go index c0330ab..4a531c7 100644 --- a/card_test.go +++ b/card_test.go @@ -523,26 +523,6 @@ func TestSearchResultHandling(t *testing.T) { } } -func TestCoerceRealNamesFromForeignHiccups(t *testing.T) { - tables := []struct { - input string - output string - }{ - {"Uro,", "Uro, Titan of Nature's Wrath"}, - {"Uro", "Uro, Titan of Nature's Wrath"}, - {"uro", "Uro, Titan of Nature's Wrath"}, - } - for _, table := range tables { - got, err := HandleForeignCardOverlapCases(table.input) - if err != nil { - t.Errorf("Something broke: %s", err) - } - if got != table.output { - t.Errorf("Incorrect output -- got %s -- want %s", got, table.output) - } - } -} - func TestIsDumbCard(t *testing.T) { tables := []struct { jsonFile string diff --git a/utils.go b/utils.go index 230ce5f..62196cb 100644 --- a/utils.go +++ b/utils.go @@ -22,18 +22,18 @@ var ( //Stuff pared from main.go botCommandRegex = regexp.MustCompile(`[!&]([^=!&?[)][^!&?[)]+)\.\s|[!&]([^=!&?[)][^!&?[)]+)|\[\[(.*?)\]\]`) - singleQuotedWord = regexp.MustCompile(`^(?:\"|\')\w+(?:\"|\')$`) - nonTextRegex = regexp.MustCompile(`^[^\w]+$`) - wordEndingInBang = regexp.MustCompile(`!(?:"|') |(?:\n)+`) - wordStartingWithBang = regexp.MustCompile(`\s+!(?: *)\S+`) + singleQuotedWord = regexp.MustCompile(`^(?:"\w+"|'\w+')$`) + nonTextRegex = regexp.MustCompile(`^\W+$`) + wordEndingInBang = regexp.MustCompile(`!["'] |\n+`) + wordStartingWithBang = regexp.MustCompile(`\s+! *\S+`) - diceRegex = regexp.MustCompile(`(?:roll)?(?:\s*)(.*?)(?:d(\d+)([+-]\d+)?)`) + diceRegex = regexp.MustCompile(`^(?:roll )?\s*(.*?)d(\d+)([+-]\d+)?`) - cardMetadataRegex = regexp.MustCompile(`(?i)^(?:ruling(?:s?)|reminder|flavo(?:u?)r)(?: )`) + cardMetadataRegex = regexp.MustCompile(`(?i)^(?:rulings?|reminder|flavou?r) `) gathererRulingRegex = regexp.MustCompile(`^(?:(?P\d+) ?(?P.+)|(?P.*?) ?(?P\d+).*?|(?P.+))`) - seeRuleRegexp = regexp.MustCompile(`rule (\d+\.{0,1}\d*\w?)`) + seeRuleRegexp = regexp.MustCompile(`rule (\d+\.?\d*\w?)`) noPunctuationRegex = regexp.MustCompile(`\W$`) @@ -42,19 +42,16 @@ var ( ruleRegexp = regexp.MustCompile(ruleRegexpLiteral) ruleExampleRegexp = regexp.MustCompile(`(\d+) ` + ruleRegexpLiteral + `|` + ruleRegexpLiteral + ` (\d+)` + `|` + ruleRegexpLiteral) - greetingRegexp = regexp.MustCompile(`(?i)^h(ello|i)( *)(\!|\.|\?)*( *)$`) + greetingRegexp = regexp.MustCompile(`(?i)^h(ello|i) *[!.?]* *$`) //Stuff pared from card.go reminderRegexp = regexp.MustCompile(`\((.*?)\)`) nonAlphaRegex = regexp.MustCompile(`\W+`) - emojiRegex = regexp.MustCompile(`{\d+}|{[A-Z]}|{\d\/[A-Z]}|{[A-Z]\/[A-Z]}`) + emojiRegex = regexp.MustCompile(`{\d+}|{[A-Z]}|{\d/[A-Z]}|{[A-Z]/[A-Z]}`) // Super rudimentary policy regex to parse e.g '4.8' into 4-8 for link generation policyRegex = regexp.MustCompile(`[^0-9]+`) - // We PROBABLY want Uro, not Aurochs - uroRegex = regexp.MustCompile(`^[Uu]ro,?$`) - // Metrics totalLines = expvar.NewInt("bot_totalLines") ircLines = expvar.NewInt("bot_ircLines")