responsive error handling
This commit is contained in:
2
msg.py
2
msg.py
@@ -164,7 +164,7 @@ async def message_gen(client: discord.Client, limit=20, days: int = 90, **kwargs
|
|||||||
channels = filter(lambda c: isinstance(c, discord.TextChannel), channels)
|
channels = filter(lambda c: isinstance(c, discord.TextChannel), channels)
|
||||||
channels = filter(lambda c: c.category.name != 'Archive', channels)
|
channels = filter(lambda c: c.category.name != 'Archive', channels)
|
||||||
channels = sorted(channels, key=lambda c: (c.category.name, c.name))
|
channels = sorted(channels, key=lambda c: (c.category.name, c.name))
|
||||||
for channel in channels[:5]:
|
for channel in channels:
|
||||||
LOGGER.info(f'{channel.category.name} #{channel.name}')
|
LOGGER.info(f'{channel.category.name} #{channel.name}')
|
||||||
if 'after' not in kwargs:
|
if 'after' not in kwargs:
|
||||||
kwargs['after'] = (datetime.today() - timedelta(days=days))
|
kwargs['after'] = (datetime.today() - timedelta(days=days))
|
||||||
|
|||||||
19
robopage.py
19
robopage.py
@@ -25,7 +25,7 @@ class RoboPage(discord.Client):
|
|||||||
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
||||||
self.jokes = list(attrs)
|
self.jokes = list(attrs)
|
||||||
self.lock = Lock()
|
self.lock = Lock()
|
||||||
self.emoji_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
|
self.most_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
self.leaderboard_regex = re.compile('^most (?P<emoji>\w+) leaderboard$', re.IGNORECASE)
|
self.leaderboard_regex = re.compile('^most (?P<emoji>\w+) leaderboard$', re.IGNORECASE)
|
||||||
|
|
||||||
@@ -39,8 +39,8 @@ class RoboPage(discord.Client):
|
|||||||
|
|
||||||
self.data: msg.MsgData = await msg.MsgData.create(
|
self.data: msg.MsgData = await msg.MsgData.create(
|
||||||
client=self,
|
client=self,
|
||||||
# limit=3000,
|
limit=3000,
|
||||||
limit=20,
|
# limit=20,
|
||||||
days=14,
|
days=14,
|
||||||
)
|
)
|
||||||
self.data.to_sql('messages.db')
|
self.data.to_sql('messages.db')
|
||||||
@@ -51,23 +51,26 @@ class RoboPage(discord.Client):
|
|||||||
await self.data.add_msg(message)
|
await self.data.add_msg(message)
|
||||||
|
|
||||||
if message.author != self.user:
|
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))
|
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:
|
elif (m := self.most_regex.match(message.content)) is not None:
|
||||||
days = m.group('days') or 14
|
days = m.group('days') or 14
|
||||||
|
try:
|
||||||
await message.reply(
|
await message.reply(
|
||||||
await self.data.biggest_single(client=self, emoji=m.group('emoji'), days=int(days))
|
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:
|
for joke in self.jokes:
|
||||||
if (scan_res := joke.scan(message)):
|
if (scan_res := joke.scan(message)):
|
||||||
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
|
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
|
||||||
await joke.respond(message, self, scan_res)
|
await joke.respond(message, self, scan_res)
|
||||||
except Exception as e:
|
|
||||||
# await message.reply('oops')
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user