split up handling messages into multiple sub-functions

This commit is contained in:
jsl12
2022-01-28 00:23:46 -06:00
parent 63c4edc088
commit 7a6ccf1721

View File

@@ -59,16 +59,17 @@ class Kwaylon(Client):
async def handle_message(self, message: Message):
if message.author != self.user:
await self.read_command(message)
await self.respond_to_joke(message)
await self.respond_to_emoji(message)
async def read_command(self, message: Message):
for mention in message.mentions:
if mention.id == self.user.id and 'read' in message.content:
if (m := re.search('(\d+) days', message.content)):
days = int(m.group(1))
else:
days = self.days
days = get_days(message.content) or self.days
await self.data.scan_messages(client=self, limit=self.limit, days=days)
return
async def respond_to_emoji(self, message: Message):
if (most_match := self.most_regex.match(message.content)):
emoji_ref = most_match.group('emoji')
emoji_name = get_emoji_name(emoji_ref)
@@ -90,18 +91,21 @@ class Kwaylon(Client):
if (board := await self.leaderboard(df)) is not None:
res += board
await message.reply(res)
else:
most = df.sort_values('count').iloc[-1]
msg = await self.fetch_message(most)
await message.reply(f'{msg.jump_url}')
else:
await message.reply(f"NObody (in the past {days} days)...gah, leave me alone!")
LOGGER.info(f'Done')
return
LOGGER.info(f'Done')
async def respond_to_joke(self, message: Message):
for joke in self.jokes:
if (joke_match := joke.scan(message)) is not None:
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {m.group()}')
if (joke_match := joke.scan(message)):
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {joke_match.group()}')
await joke.respond(message, self, joke_match)
async def leaderboard(self, df: pd.DataFrame) -> str: