reworked update_reaction and emoji calculation. Should work with unicode emojis now
This commit is contained in:
33
robopage.py
33
robopage.py
@@ -1,9 +1,8 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import discord
|
||||
from discord import RawReactionActionEvent, RawReactionClearEmojiEvent
|
||||
from dotenv import load_dotenv
|
||||
@@ -28,16 +27,13 @@ class RoboPage(discord.Client):
|
||||
self.jokes = list(attrs)
|
||||
self.most_regex = re.compile(
|
||||
"^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
|
||||
re.IGNORECASE
|
||||
re.IGNORECASE & re.UNICODE,
|
||||
)
|
||||
self.leaderboard_regex = re.compile(
|
||||
'^most (?P<emoji>\w+)(?=(?:.+)?leaderboard)(?:.+(?P<days>\d+) days)?',
|
||||
re.IGNORECASE
|
||||
'^most (?P<emoji>.+)(?=(?:.+)?leaderboard)(?:.+(?P<days>\d+) days)?',
|
||||
re.IGNORECASE & re.UNICODE
|
||||
)
|
||||
|
||||
with Path('gifs.json').open('r') as file:
|
||||
self.gifs = json.load(file)
|
||||
|
||||
def run(self):
|
||||
return super().run(os.getenv('DISCORD_TOKEN'))
|
||||
|
||||
@@ -48,9 +44,10 @@ class RoboPage(discord.Client):
|
||||
|
||||
self.data: data.MsgData = await data.MsgData.create(
|
||||
client=self,
|
||||
# limit=5000,
|
||||
limit=20,
|
||||
# days=30,
|
||||
limit=5000,
|
||||
days=30,
|
||||
# limit=500,
|
||||
# days=3,
|
||||
)
|
||||
self.data.to_sql('messages.db')
|
||||
LOGGER.info(f'{self.data.msgs.shape[0]} messages total')
|
||||
@@ -62,11 +59,11 @@ class RoboPage(discord.Client):
|
||||
await self.data.add_msg(message)
|
||||
|
||||
if (m := self.leaderboard_regex.match(message.content)) is not None:
|
||||
days = int(m.group('days')) or 14
|
||||
emoji = m.group('emoji').lower()
|
||||
days = m.group('days') or 14
|
||||
emoji = m.group('emoji').lower().strip()
|
||||
try:
|
||||
await message.reply(
|
||||
await self.data.emoji_leaderboard(client=self, emoji_name=emoji, days=days)
|
||||
await self.data.emoji_leaderboard(client=self, emoji_name=emoji, days=int(days))
|
||||
)
|
||||
except KeyError as e:
|
||||
LOGGER.exception(e)
|
||||
@@ -74,14 +71,16 @@ class RoboPage(discord.Client):
|
||||
return
|
||||
|
||||
elif (m := self.most_regex.match(message.content)) is not None:
|
||||
days = int(m.group('days')) or 14
|
||||
emoji = m.group('emoji').lower()
|
||||
days = m.group('days') or 14
|
||||
emoji = m.group('emoji').lower().strip()
|
||||
try:
|
||||
await message.reply(
|
||||
await self.data.biggest_single(client=self, emoji=emoji, days=days))
|
||||
await self.data.biggest_single(client=self, emoji=emoji, days=int(days)))
|
||||
except IndexError as e:
|
||||
await message.reply('NObody')
|
||||
return
|
||||
else:
|
||||
LOGGER.warning(f'No self.data attribute')
|
||||
|
||||
for joke in self.jokes:
|
||||
if (scan_res := joke.scan(message)):
|
||||
|
||||
Reference in New Issue
Block a user