responsive error handling
This commit is contained in:
25
robopage.py
25
robopage.py
@@ -25,8 +25,8 @@ class RoboPage(discord.Client):
|
||||
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
||||
self.jokes = list(attrs)
|
||||
self.lock = Lock()
|
||||
self.emoji_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
|
||||
re.IGNORECASE)
|
||||
self.most_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
|
||||
re.IGNORECASE)
|
||||
self.leaderboard_regex = re.compile('^most (?P<emoji>\w+) leaderboard$', re.IGNORECASE)
|
||||
|
||||
def run(self):
|
||||
@@ -39,8 +39,8 @@ class RoboPage(discord.Client):
|
||||
|
||||
self.data: msg.MsgData = await msg.MsgData.create(
|
||||
client=self,
|
||||
# limit=3000,
|
||||
limit=20,
|
||||
limit=3000,
|
||||
# limit=20,
|
||||
days=14,
|
||||
)
|
||||
self.data.to_sql('messages.db')
|
||||
@@ -51,23 +51,26 @@ class RoboPage(discord.Client):
|
||||
await self.data.add_msg(message)
|
||||
|
||||
if message.author != self.user:
|
||||
try:
|
||||
if (m := self.leaderboard_regex.match(message.content)) is not None:
|
||||
if (m := self.leaderboard_regex.match(message.content)) is not None:
|
||||
try:
|
||||
await message.reply(self.data.emoji_leaderboard(emoji_name=m.group('emoji'), days=14))
|
||||
except KeyError as e:
|
||||
await message.reply(f"I couldn't find any {m.group('emoji')} reactions. Leave me alone!")
|
||||
|
||||
elif (m := self.emoji_regex.match(message.content)) is not None:
|
||||
days = m.group('days') or 14
|
||||
elif (m := self.most_regex.match(message.content)) is not None:
|
||||
days = m.group('days') or 14
|
||||
try:
|
||||
await message.reply(
|
||||
await self.data.biggest_single(client=self, emoji=m.group('emoji'), days=int(days))
|
||||
)
|
||||
except IndexError as e:
|
||||
await message.reply('NObody')
|
||||
|
||||
else:
|
||||
for joke in self.jokes:
|
||||
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)
|
||||
except Exception as e:
|
||||
# await message.reply('oops')
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user