improved joke recognition

This commit is contained in:
2021-07-13 11:02:06 -05:00
parent 5db45c6927
commit 4e62232248

View File

@@ -28,29 +28,36 @@ class RoboPage(discord.Client):
async def handle_message(self, message):
if message.author != self.user:
for joke in self.jokes:
if (match := joke.regex.search(message.content)):
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{match.group(0)}')
await joke.respond(message, self, match)
if (scan_res := joke.scan(message)):
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
await joke.respond(message, self, scan_res)
class Joke:
@property
def regex(self) -> re.Pattern:
raise NotImplementedError
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
def scan(self, message: discord.Message):
if (match := self.regex.search(message.content)):
return match
async def respond(self, message: discord.Message, client: discord.Client, scan_res):
raise NotImplementedError
class CumJoke(Joke):
@property
def regex(self) -> re.Pattern:
return re.compile('|'.join([
words = [
'come',
'coming',
'came',
'cum',
'cumming',
'cummed'
]), re.IGNORECASE)
]
return re.compile(f"(?<!\w)({'|'.join(words)})", re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
if not match.group(0).startswith('be'):
@@ -63,14 +70,16 @@ class BlackJoke(Joke):
return re.compile('black (\w+)', re.IGNORECASE)
async def respond(self, message: discord.Message, client: discord.Client, match: re.Match):
msg = await message.reply(unblack(message.content))
await msg.add_reaction(discord.utils.get(client.emojis, name='kaylon'))
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( |\-)(\w)', re.IGNORECASE)
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)