Files
kwaylon/jokes.py

163 lines
4.8 KiB
Python

import re
import discord
import nltk
import stockquotes
# TODO implement new jokes
# - j'accuse
# - egos
# - money is no option
# - we're young, hot, and rich
# - last name page when ordering
# - mcnulty shot and beer
# - white trash karate backflips
# - buc-ees
# - arbys
# - grease 2
# - Sweet Transvestite
# - Hopkins County Stew Contest
# - yesterday tacos
# - strip club
class Joke:
@property
def regex(self) -> re.Pattern:
raise NotImplementedError
def scan(self, message: discord.Message) -> re.Match:
return self.regex.search(message.content)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
raise NotImplementedError
class CumJoke(Joke):
@property
def regex(self) -> re.Pattern:
words = [
'come',
'coming',
'came',
'cum',
'cumming',
'cummed'
]
return re.compile(f"(?<!\w)({'|'.join(words)})(?!\w)", re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
if not match.group(0).startswith('be'):
await message.add_reaction(discord.utils.get(client.emojis, name='kaylon'))
class BlackJoke(Joke):
@property
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):
res = unblack(message.content)
if res is not None:
msg = await message.reply(res)
await msg.add_reaction(discord.utils.get(client.emojis, name='kaylon'))
class AssJoke(Joke):
@property
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):
res = assify(message.content)
if res is not None:
await message.reply(f'{res} {discord.utils.get(client.emojis, name="kaylon")}')
class DominosJoke(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 GifJoke(Joke):
url: str
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
await message.channel.send(self.url)
class BeansJoke(GifJoke):
url = 'https://c.tenor.com/TjX1yORoln0AAAAM/this-is-beans-beans.gif'
@property
def regex(self) -> re.Pattern:
return re.compile('beans', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
await message.reply('Somebody help! I\'ve got beans in my motherboard!\n')
await super().respond(message, client, match)
class NotLikeThisJoke(GifJoke):
url = 'https://tenor.com/view/not-like-this-the-matrix-panic-neo-angry-gif-5216157'
@property
def regex(self) -> re.Pattern:
return re.compile('not like this', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
await message.reply(self.url)
class ChiliJoke(GifJoke):
url = 'https://tenor.com/view/office-gif-20038284'
@property
def regex(self) -> re.Pattern:
return re.compile('chil(i|ly)', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
await message.reply(self.url)
pattern = 'NP: {<DT>?<JJ>*<NN>}'
cp = nltk.RegexpParser(pattern)
def token_list(s):
return nltk.chunk.tree2conlltags(
cp.parse(
nltk.pos_tag(
nltk.word_tokenize(s)
)))
def assify(s):
tag_list = token_list(s)
for i, (text, tag, iob) in enumerate(tag_list):
if text[-3:].lower() == 'ass':
try:
next_tag = tag_list[i + 1][1]
if next_tag == 'NN' or next_tag == 'NNS':
return f'ass-{tag_list[i + 1][0]}'
except IndexError as e:
return
def unblack(s):
tag_list = token_list(s)
for i, (text, tag, iob) in enumerate(tag_list):
if text.lower() == 'black':
if tag.startswith('JJ') or tag.startswith('NN'):
for text, tag, iob in tag_list[i + 1:]:
if tag.startswith('NN'):
return f'Or as I would say, {text.lower()}'