fixed buggy GoodBot response

This commit is contained in:
jsl12
2022-02-03 12:00:55 -06:00
parent fcbaef50ef
commit 40a27885d6
2 changed files with 9 additions and 2 deletions

View File

@@ -5,6 +5,12 @@ from bs4 import BeautifulSoup
pattern = 'NP: {<DT>?<JJ>*<NN>}' pattern = 'NP: {<DT>?<JJ>*<NN>}'
cp = nltk.RegexpParser(pattern) cp = nltk.RegexpParser(pattern)
WORDS = set(w.lower() for w in nltk.corpus.words.words())
def valid_word(word: str):
return word.strip().lower() in WORDS
def get_stock_price(symbol: str): def get_stock_price(symbol: str):
soup = BeautifulSoup(requests.get(f'https://finance.yahoo.com/quote/{symbol}').content, 'lxml') soup = BeautifulSoup(requests.get(f'https://finance.yahoo.com/quote/{symbol}').content, 'lxml')

View File

@@ -153,7 +153,8 @@ class Jaccuse(base.Joke):
class GoodBot(base.Joke): class GoodBot(base.Joke):
@property @property
def regex(self) -> re.Pattern: def regex(self) -> re.Pattern:
return re.compile('(\w+) bot', re.IGNORECASE) return re.compile('(\w+) bot$', re.IGNORECASE)
async def respond(self, message: Message, client: Client, match: re.Match): async def respond(self, message: Message, client: Client, match: re.Match):
if helpers.valid_word(match.group(1)):
await message.add_reaction(utils.get(client.emojis, name='kaylon')) await message.add_reaction(utils.get(client.emojis, name='kaylon'))