small tweaks to jokes to standardize things a bit, added TODO list of jokes to implement
This commit is contained in:
35
jokes.py
35
jokes.py
@@ -4,17 +4,32 @@ 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):
|
||||
if (match := self.regex.search(message.content)):
|
||||
return match
|
||||
def scan(self, message: discord.Message) -> re.Match:
|
||||
return self.regex.search(message.content)
|
||||
|
||||
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
|
||||
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@@ -75,7 +90,7 @@ class DominosJoke(Joke):
|
||||
class GifJoke(Joke):
|
||||
url: str
|
||||
|
||||
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
|
||||
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
|
||||
await message.channel.send(self.url)
|
||||
|
||||
|
||||
@@ -86,9 +101,9 @@ class BeansJoke(GifJoke):
|
||||
def regex(self) -> re.Pattern:
|
||||
return re.compile('beans', re.IGNORECASE)
|
||||
|
||||
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
|
||||
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, scan_res)
|
||||
await super().respond(message, client, match)
|
||||
|
||||
|
||||
class NotLikeThisJoke(GifJoke):
|
||||
@@ -98,7 +113,7 @@ class NotLikeThisJoke(GifJoke):
|
||||
def regex(self) -> re.Pattern:
|
||||
return re.compile('not like this', re.IGNORECASE)
|
||||
|
||||
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
|
||||
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
|
||||
await message.reply(self.url)
|
||||
|
||||
|
||||
@@ -107,9 +122,9 @@ class ChiliJoke(GifJoke):
|
||||
|
||||
@property
|
||||
def regex(self) -> re.Pattern:
|
||||
return re.compile('chil(i|ly)')
|
||||
return re.compile('chil(i|ly)', re.IGNORECASE)
|
||||
|
||||
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
|
||||
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
|
||||
await message.reply(self.url)
|
||||
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ class RoboPage(discord.Client):
|
||||
LOGGER.warning(f'No self.data attribute')
|
||||
|
||||
for joke in self.jokes:
|
||||
if (scan_res := joke.scan(message)):
|
||||
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {scan_res.group()}')
|
||||
await joke.respond(message, self, scan_res)
|
||||
if (m := joke.scan(message)) is not None:
|
||||
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {m.group()}')
|
||||
await joke.respond(message, self, m)
|
||||
|
||||
async def handle_raw_reaction(self, payload: Union[RawReactionActionEvent, RawReactionClearEmojiEvent]):
|
||||
LOGGER.info(payload)
|
||||
|
||||
Reference in New Issue
Block a user