dominos joke working again

This commit is contained in:
jsl12
2022-01-24 11:55:10 -06:00
parent 2181e71e44
commit 145ba88042
4 changed files with 33 additions and 24 deletions

View File

@@ -3,13 +3,14 @@ FROM python:latest
RUN python -m pip install --upgrade pip
RUN pip install pandas
# RUN pip install discord.py
RUN pip install nltk
RUN python -m nltk.downloader -d /usr/local/share/nltk_data all
RUN pip install python-dotenv
RUN pip install nextcord
RUN pip install beautifulsoup4 requests lxml
WORKDIR /usr/src/app
COPY ./ ./

View File

@@ -1,9 +1,17 @@
import nltk
import requests
from bs4 import BeautifulSoup
pattern = 'NP: {<DT>?<JJ>*<NN>}'
cp = nltk.RegexpParser(pattern)
def get_stock_price(symbol: str):
soup = BeautifulSoup(requests.get(f'https://finance.yahoo.com/quote/{symbol}').content, 'lxml')
tag = soup.select_one(f'fin-streamer[data-symbol="{symbol}"]')
return float(tag['value'])
def token_list(s):
return nltk.chunk.tree2conlltags(
cp.parse(

View File

@@ -1,11 +1,12 @@
import logging
import re
import nextcord as discord
from nextcord import Client, Message
from nextcord import utils
from . import base, helpers
# import stockquotes
LOGGER = logging.getLogger(__name__)
# TODO implement new jokes
@@ -38,9 +39,9 @@ class CumJoke(base.Joke):
]
return re.compile(f"(?<!\w)({'|'.join(words)})(?!\w)", re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
async def respond(self, message: Message, client: Client, match: re.Match):
if not match.group(0).startswith('be'):
await message.add_reaction(discord.utils.get(client.emojis, name='kaylon'))
await message.add_reaction(utils.get(client.emojis, name='kaylon'))
class BlackJoke(base.Joke):
@@ -48,11 +49,11 @@ class BlackJoke(base.Joke):
def regex(self) -> re.Pattern:
return re.compile('black (\w+)', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
async def respond(self, message: Message, client: Client, match: re.Match):
res = helpers.unblack(message.content)
if res is not None:
msg = await message.reply(res)
await msg.add_reaction(discord.utils.get(client.emojis, name='kaylon'))
await msg.add_reaction(utils.get(client.emojis, name='kaylon'))
class AssJoke(base.Joke):
@@ -60,24 +61,22 @@ class AssJoke(base.Joke):
def regex(self) -> re.Pattern:
return re.compile('[ \-]ass[ \-](?P<target>\w+)', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
async def respond(self, message: Message, client: Client, match: re.Match):
res = helpers.assify(message.content)
if res is not None:
await message.reply(f'{res} {discord.utils.get(client.emojis, name="kaylon")}')
await message.reply(f'{res} {utils.get(client.emojis, name="kaylon")}')
# DominosJoke isn't working because stockquotes is fucked
# class DominosJoke(base.Joke):
# @property
# def regex(self) -> re.Pattern:
# return re.compile('domino\'?s', re.IGNORECASE)
#
# async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
# cp = stockquotes.Stock('DPZ').current_price
# msg = f'You know, my friend Ben has made about ${cp - 16:.0f} on Domino\'s stock. He basically owns it now'
# if (e := discord.utils.get(client.emojis, name="pizza")):
# await message.add_reaction(e)
# await message.reply(msg)
class DominosJoke(base.Joke):
@property
def regex(self) -> re.Pattern:
return re.compile('domino\'?s', re.IGNORECASE)
async def respond(self, message: Message, client: Client, match: re.Match):
cp = helpers.get_stock_price('DPZ')
msg = f'You know, my friend Nick has made about ${cp - 16:.0f} on Domino\'s stock. He basically owns it now'
await message.add_reaction('\U0001F355')
await message.reply(msg)
class BeansJoke(base.GifJoke):
@@ -87,7 +86,7 @@ class BeansJoke(base.GifJoke):
def regex(self) -> re.Pattern:
return re.compile('beans', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
async def respond(self, message: Message, client: Client, match: re.Match):
await message.reply('Somebody help! I\'ve got beans in my motherboard!\n')
await message.channel.send(self.url)

View File

@@ -17,7 +17,8 @@ if __name__ == '__main__':
@client.event
async def on_ready():
await client.handle_ready()
# await client.data.scan_messages(client=client, days=10)
# await client.data.scan_messages(client=client, limit=50)
@client.event
async def on_message(message: discord.Message):