added from_sql and to_sql methods to MsgData
This commit is contained in:
22
robopage.py
22
robopage.py
@@ -6,8 +6,8 @@ from threading import Lock
|
||||
import discord
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import jokes
|
||||
import msg
|
||||
from jokes import CumJoke, BlackJoke, AssJoke, DominosJoke
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
@@ -21,12 +21,9 @@ class RoboPage(discord.Client):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RoboPage, self).__init__(*args, **kwargs)
|
||||
self.jokes = [
|
||||
CumJoke(),
|
||||
BlackJoke(),
|
||||
AssJoke(),
|
||||
DominosJoke()
|
||||
]
|
||||
attrs = filter(lambda n: n.endswith('Joke') and not n.startswith('Joke'), dir(jokes))
|
||||
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
||||
self.jokes = list(attrs)
|
||||
self.lock = Lock()
|
||||
|
||||
def run(self):
|
||||
@@ -40,9 +37,9 @@ class RoboPage(discord.Client):
|
||||
self.data: msg.MsgData = await msg.MsgData.create(
|
||||
client=self,
|
||||
limit=3000,
|
||||
# limit=20,
|
||||
days=14,
|
||||
)
|
||||
self.data.to_sql('messages.db')
|
||||
LOGGER.info(str(self.data.msgs.columns))
|
||||
LOGGER.info(str(self.data.reactions.columns))
|
||||
|
||||
@@ -51,7 +48,7 @@ class RoboPage(discord.Client):
|
||||
|
||||
if message.author != self.user:
|
||||
if 'most cancelled' in message.content:
|
||||
await message.reply(self.get_cancelled_totals(days=14))
|
||||
await message.reply(self.data.cancellation_leaderboard(14))
|
||||
|
||||
elif (m := re.search('top cancelled (?P<name>\w+)', message.content)) is not None:
|
||||
async with self.data.lock:
|
||||
@@ -62,11 +59,6 @@ class RoboPage(discord.Client):
|
||||
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
|
||||
await joke.respond(message, self, scan_res)
|
||||
|
||||
def get_cancelled_totals(self, days):
|
||||
res = self.data.cancellation_totals(days)
|
||||
res = f'Cancellation totals, past {days} days\n' + msg.report_string(res.iloc[:5])
|
||||
return res
|
||||
|
||||
def top_cancellations(self, user: str, days: int):
|
||||
cdf = self.data.cancellations(days)
|
||||
cdf = cdf[cdf['display_name'].str.contains(user, case=False)]
|
||||
@@ -88,7 +80,7 @@ if __name__ == '__main__':
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f'{client.user} has connected to Discord!')
|
||||
print(len(list(client.get_all_members())))
|
||||
await client.handle_ready()
|
||||
print(client.data.cancellation_totals(14))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user