disabled reaction stuff and removed a lot of it

This commit is contained in:
John Lancaster
2023-05-26 00:15:09 -05:00
parent e8ac0e1f58
commit 3e4af3f816

View File

@@ -1,72 +1,56 @@
import asyncio
import logging
import re
import sqlite3
from pathlib import Path
from typing import List
import pandas as pd
# from nextcord import Client, Message, TextChannel
# from nextcord import RawReactionActionEvent, Emoji
# from nextcord import utils
from discord import Client, Message, TextChannel
from discord import RawReactionActionEvent, Emoji
from discord import utils
from discord import (Client, Emoji, Guild, Message, RawReactionActionEvent,
TextChannel, utils)
from . import jokes
from .reactions import ReactionData
FD_GUILD_ID = 689603977884860519
LIL_STINKY_ID = 704043422276780072
ROBOTICS_FACILITY_ID = 689974023156924455
DEV_ROBOTICS_FACILITY_ID = 690404397175406642
LOGGER = logging.getLogger(__name__)
_log = logging.getLogger(__name__)
class Kwaylon(Client):
def __init__(self, limit: int = 5000, days: int = 30, db_path: Path = None, *args, **kwargs):
super().__init__(*args, **kwargs)
if db_path is None:
self.db_path = Path(__file__).parents[2] / 'data' / 'messages.db'
else:
self.db_path = db_path
self.limit, self.days = limit, days
self.jokes = list(jokes.collect_jokes())
self.lock = asyncio.Lock()
self.most_regex = re.compile('^most\s*(?P<emoji>\S+)', re.IGNORECASE)
def text_channels(self) -> List[TextChannel]:
return [chan for chan in self.get_all_channels() if isinstance(chan, TextChannel)]
def robotics_facility(self) -> TextChannel:
for chan in self.text_channels():
if chan.name == 'robotics-facility' and chan.guild.name == 'Family Dinner':
return chan
def kaylon_emoji(self) -> Emoji:
return utils.get(self.emojis, name='kaylon')
async def handle_ready(self):
async def alive():
channel: TextChannel = self.robotics_facility()
async def initialize(self):
"""Gets attached to the on_ready event
"""
async def alive(channel: TextChannel):
await channel.send('https://tenor.com/view/terminator-im-back-gif-19144173')
await channel.send(self.kaylon_emoji())
# await alive()
try:
self.data = ReactionData(self.db_path)
LOGGER.info(f'{self.data.row_count():d} reactions in {self.db_path}')
except sqlite3.Error as e:
LOGGER.exception(e)
LOGGER.error(f'self.db_path: {self.db_path}')
# _log.info('[bold bright_green]Starting initialize[/]')
self.fd_guild: Guild = await self.fetch_guild(FD_GUILD_ID)
self.robotics_facility: TextChannel = await self.fetch_channel(ROBOTICS_FACILITY_ID)
self.robotics_facility_dev: TextChannel = await self.fetch_channel(DEV_ROBOTICS_FACILITY_ID)
self.kaylon_emoji: Emoji = utils.get(self.emojis, name='kaylon')
# await alive(self.robotics_facility_dev)
_log.info('[bold bright_green]Done[/][bright_black], laying in wait...[/]')
async def handle_message(self, message: Message):
if message.author != self.user:
await self.read_command(message)
await self.respond_to_joke(message)
await self.respond_to_emoji(message)
async def respond_to_joke(self, message: Message):
for joke in self.jokes:
if (joke_match := joke.scan(message)):
start, end = joke_match.start(), joke_match.end()
_log.info(
f'[light_slate_blue]{joke.__class__.__name__}[/]' +
f'{message.content[:start]}[green]{message.content[start:end]}[/]{message.content[end:]}'
)
await joke.respond(message, self, joke_match)
async def read_command(self, message: Message):
for mention in message.mentions:
@@ -78,7 +62,7 @@ class Kwaylon(Client):
if (most_match := self.most_regex.match(message.content)):
emoji_ref = most_match.group('emoji')
emoji_name = get_emoji_name(emoji_ref)
LOGGER.info(f'Most {emoji_name}')
_log.info(f'Most {emoji_name}')
async with message.channel.typing():
with self.data.connect() as con:
@@ -94,10 +78,11 @@ class Kwaylon(Client):
con.close()
if df.shape[0] > 0:
LOGGER.info(f'{df.shape[0]} messages with {emoji_ref} after filtering')
_log.info(
f'{df.shape[0]} messages with {emoji_ref} after filtering')
if 'leaderboard' in message.content:
LOGGER.info(f'Building leaderboard')
_log.info(f'Building leaderboard')
res = f'{emoji_ref} totals, past {days} days\n'
if (board := await self.leaderboard(df)) is not None:
res += board
@@ -105,7 +90,8 @@ class Kwaylon(Client):
else:
if len(message.mentions) > 0:
df = df[df['auth_id'].isin([m.id for m in message.mentions])]
df = df[df['auth_id'].isin(
[m.id for m in message.mentions])]
most = df.sort_values('count').iloc[-1]
msg = await self.fetch_message(most)
@@ -114,13 +100,7 @@ class Kwaylon(Client):
# else:
# await message.reply(f"NObody (in the past {days} days)...gah, leave me alone!")
LOGGER.info(f'Done')
async def respond_to_joke(self, message: Message):
for joke in self.jokes:
if (joke_match := joke.scan(message)):
LOGGER.info(f'{joke.__class__.__name__} detected: {message.content}, {joke_match.group()}')
await joke.respond(message, self, joke_match)
_log.info(f'Done')
async def leaderboard(self, df: pd.DataFrame) -> str:
df = df.groupby('auth_id').sum()
@@ -136,7 +116,7 @@ class Kwaylon(Client):
return res
async def handle_raw_reaction(self, payload: RawReactionActionEvent):
LOGGER.info(payload)
_log.info(payload)
guild = await self.fetch_guild(payload.guild_id)
channel = await guild.fetch_channel(payload.channel_id)