split up handling messages into multiple sub-functions
This commit is contained in:
@@ -59,16 +59,17 @@ class Kwaylon(Client):
|
|||||||
|
|
||||||
async def handle_message(self, message: Message):
|
async def handle_message(self, message: Message):
|
||||||
if message.author != self.user:
|
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:
|
for mention in message.mentions:
|
||||||
if mention.id == self.user.id and 'read' in message.content:
|
if mention.id == self.user.id and 'read' in message.content:
|
||||||
if (m := re.search('(\d+) days', message.content)):
|
days = get_days(message.content) or self.days
|
||||||
days = int(m.group(1))
|
|
||||||
else:
|
|
||||||
days = self.days
|
|
||||||
|
|
||||||
await self.data.scan_messages(client=self, limit=self.limit, days=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)):
|
if (most_match := self.most_regex.match(message.content)):
|
||||||
emoji_ref = most_match.group('emoji')
|
emoji_ref = most_match.group('emoji')
|
||||||
emoji_name = get_emoji_name(emoji_ref)
|
emoji_name = get_emoji_name(emoji_ref)
|
||||||
@@ -90,18 +91,21 @@ class Kwaylon(Client):
|
|||||||
if (board := await self.leaderboard(df)) is not None:
|
if (board := await self.leaderboard(df)) is not None:
|
||||||
res += board
|
res += board
|
||||||
await message.reply(res)
|
await message.reply(res)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
most = df.sort_values('count').iloc[-1]
|
most = df.sort_values('count').iloc[-1]
|
||||||
msg = await self.fetch_message(most)
|
msg = await self.fetch_message(most)
|
||||||
await message.reply(f'{msg.jump_url}')
|
await message.reply(f'{msg.jump_url}')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
await message.reply(f"NObody (in the past {days} days)...gah, leave me alone!")
|
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:
|
for joke in self.jokes:
|
||||||
if (joke_match := joke.scan(message)) is not None:
|
if (joke_match := joke.scan(message)):
|
||||||
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {m.group()}')
|
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {joke_match.group()}')
|
||||||
await joke.respond(message, self, joke_match)
|
await joke.respond(message, self, joke_match)
|
||||||
|
|
||||||
async def leaderboard(self, df: pd.DataFrame) -> str:
|
async def leaderboard(self, df: pd.DataFrame) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user