various minor tweaks
This commit is contained in:
@@ -93,8 +93,7 @@ class MsgData:
|
||||
if len(msg.reactions) > 0:
|
||||
new = reaction_df(msg)
|
||||
async with self.lock:
|
||||
# self.reactions = self.reactions.join(new, how='outer')
|
||||
self.reactions = pd.concat([self.reactions, new])
|
||||
self.reactions = self.reactions.append(new)
|
||||
LOGGER.info(str(new.droplevel(level=0, axis=0).loc[:, 'count']))
|
||||
|
||||
if msg.id not in self.msgs.index:
|
||||
|
||||
@@ -5,7 +5,7 @@ from .base import Joke, GifJoke
|
||||
def collect_jokes():
|
||||
for name in dir(jokes):
|
||||
try:
|
||||
if issubclass((j := getattr(jokes, name)), Joke):
|
||||
yield j
|
||||
if issubclass((joke := getattr(jokes, name)), Joke):
|
||||
yield joke()
|
||||
except TypeError as e:
|
||||
continue
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import Union
|
||||
from pathlib import Path
|
||||
|
||||
import discord
|
||||
import pandas as pd
|
||||
from discord import RawReactionActionEvent, RawReactionClearEmojiEvent
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
from . import data, jokes
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
LIL_STINKY_ID = 704043422276780072
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Kwaylon(discord.Client):
|
||||
db_path: str = '../messages.db'
|
||||
db_path: Path = Path('../messages.db')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, limit: int = 5000, days: int = 30, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.limit, self.days = limit, days
|
||||
self.jokes = list(jokes.collect_jokes())
|
||||
|
||||
self.most_regex = re.compile(
|
||||
@@ -36,13 +35,7 @@ class Kwaylon(discord.Client):
|
||||
channel: discord.TextChannel = discord.utils.get(self.get_all_channels(), name='robotics-facility')
|
||||
await channel.send(f"I'm aliiiiiive {discord.utils.get(self.emojis, name='kaylon')}")
|
||||
|
||||
self.data: data.MsgData = await data.MsgData.create(
|
||||
client=self,
|
||||
limit=5000,
|
||||
days=30,
|
||||
# limit=100,
|
||||
# days=14,
|
||||
)
|
||||
self.data: data.MsgData = await data.MsgData.create(client=self, limit=self.limit, days=self.days)
|
||||
self.data.to_sql(self.db_path)
|
||||
LOGGER.info(f'{self.data.msgs.shape[0]} messages total')
|
||||
# await alive()
|
||||
@@ -74,7 +67,7 @@ class Kwaylon(discord.Client):
|
||||
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {m.group()}')
|
||||
await joke.respond(message, self, m)
|
||||
|
||||
async def handle_raw_reaction(self, payload: Union[RawReactionActionEvent, RawReactionClearEmojiEvent]):
|
||||
async def handle_raw_reaction(self, payload: RawReactionActionEvent):
|
||||
LOGGER.info(payload)
|
||||
guild = await self.fetch_guild(payload.guild_id)
|
||||
channel = await guild.fetch_channel(payload.channel_id)
|
||||
@@ -116,14 +109,14 @@ class Kwaylon(discord.Client):
|
||||
msg += '\n' + await self.worst_offsenses(user=user, days=days, top=3, emoji_str=match.group('emoji'))
|
||||
return msg
|
||||
|
||||
async def worst_offsenses(self, user: discord.User, days: int, top: int, emoji_str: str) -> str:
|
||||
cdf = self.data.emoji_messages(get_emoji_name(emoji_str), days=days)
|
||||
cdf = cdf[cdf['user id'] == user.id].sort_values('count', ascending=False).iloc[:top]
|
||||
async def worst_offsenses(self, user: discord.User, emoji_str: str, days: int = None, top: int = 3) -> str:
|
||||
df: pd.DataFrame = self.data.emoji_messages(get_emoji_name(emoji_str), days=days)
|
||||
df: pd.DataFrame = df[df['user id'] == user.id].sort_values('count', ascending=False).iloc[:top]
|
||||
|
||||
if cdf.shape[0] > 0:
|
||||
if df.shape[0] > 0:
|
||||
res = f'Top {top} {emoji_str}\n'
|
||||
res += f'\n'.join(
|
||||
f'{emoji_str}x{row["count"]:.0f}\n{row["link"]}' for idx, row in cdf.iterrows())
|
||||
f'{emoji_str}x{row["count"]:.0f}\n{row["link"]}' for idx, row in df.iterrows())
|
||||
else:
|
||||
res = f'No {emoji_str} for {user} in the past {days} days'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user