diff --git a/Dockerfile b/Dockerfile
index ddfdea9..022bca3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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 ./ ./
diff --git a/kwaylon/jokes/helpers.py b/kwaylon/jokes/helpers.py
index 5e46008..82b216c 100644
--- a/kwaylon/jokes/helpers.py
+++ b/kwaylon/jokes/helpers.py
@@ -1,9 +1,17 @@
import nltk
+import requests
+from bs4 import BeautifulSoup
pattern = 'NP: {
?*}'
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(
diff --git a/kwaylon/jokes/jokes.py b/kwaylon/jokes/jokes.py
index 3feccbb..dd03bdc 100644
--- a/kwaylon/jokes/jokes.py
+++ b/kwaylon/jokes/jokes.py
@@ -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"(? 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\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)
diff --git a/main.py b/main.py
index 9edeed6..93fea5e 100644
--- a/main.py
+++ b/main.py
@@ -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):