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