reorganized into a package
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"beans": "https://c.tenor.com/TjX1yORoln0AAAAM/this-is-beans-beans.gif",
|
|
||||||
"not like this": "https://tenor.com/view/not-like-this-the-matrix-panic-neo-angry-gif-5216157"
|
|
||||||
}
|
|
||||||
1
kwaylon/__init__.py
Normal file
1
kwaylon/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .kwaylon import Kwaylon
|
||||||
@@ -7,7 +7,7 @@ from pathlib import Path
|
|||||||
import discord
|
import discord
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from msg import message_df, full_reaction_df, message_dict, LOGGER, reaction_df
|
from .msg import message_df, full_reaction_df, message_dict, LOGGER, reaction_df
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from discord import RawReactionActionEvent, RawReactionClearEmojiEvent
|
from discord import RawReactionActionEvent, RawReactionClearEmojiEvent
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
import data
|
from . import data, jokes
|
||||||
import jokes
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
@@ -18,16 +15,16 @@ LIL_STINKY_ID = 704043422276780072
|
|||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RoboPage(discord.Client):
|
class Kwaylon(discord.Client):
|
||||||
db_path: str = 'messages.db'
|
db_path: str = '../messages.db'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(RoboPage, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
attrs = filter(lambda n: n.endswith('Joke') and n not in ['Joke', 'GifJoke'], dir(jokes))
|
attrs = filter(lambda n: n.endswith('Joke') and n not in ['Joke', 'GifJoke'], dir(jokes))
|
||||||
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
||||||
self.jokes = list(attrs)
|
self.jokes = list(attrs)
|
||||||
self.most_regex = re.compile(
|
self.most_regex = re.compile(
|
||||||
"^who is the most\s+(?P<emoji>\S+)\s*?(?:in the past (?P<days>\d+) days)?\??$",
|
'^who is the most\s+(?P<emoji>\S+)\s*?(?:in the past (?P<days>\d+) days)?\??$',
|
||||||
re.IGNORECASE,
|
re.IGNORECASE,
|
||||||
)
|
)
|
||||||
self.leaderboard_regex = re.compile(
|
self.leaderboard_regex = re.compile(
|
||||||
@@ -80,7 +77,7 @@ class RoboPage(discord.Client):
|
|||||||
|
|
||||||
async def handle_raw_reaction(self, payload: Union[RawReactionActionEvent, RawReactionClearEmojiEvent]):
|
async def handle_raw_reaction(self, payload: Union[RawReactionActionEvent, RawReactionClearEmojiEvent]):
|
||||||
LOGGER.info(payload)
|
LOGGER.info(payload)
|
||||||
guild = await client.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)
|
||||||
message = await channel.fetch_message(payload.message_id)
|
message = await channel.fetch_message(payload.message_id)
|
||||||
|
|
||||||
@@ -114,7 +111,7 @@ class RoboPage(discord.Client):
|
|||||||
emoji_name=get_emoji_name(match.group('emoji')),
|
emoji_name=get_emoji_name(match.group('emoji')),
|
||||||
days=days
|
days=days
|
||||||
)
|
)
|
||||||
user: discord.User = await client.fetch_user(user_id=data.index[0])
|
user: discord.User = await self.fetch_user(user_id=data.index[0])
|
||||||
LOGGER.info(f'User: {user.mention}')
|
LOGGER.info(f'User: {user.mention}')
|
||||||
msg = f'{user.mention} with {data.iloc[0]:.0f}x {match.group("emoji")} over the past {days} days'
|
msg = f'{user.mention} with {data.iloc[0]:.0f}x {match.group("emoji")} over the past {days} days'
|
||||||
msg += '\n' + await self.worst_offsenses(user=user, days=days, top=3, emoji_str=match.group('emoji'))
|
msg += '\n' + await self.worst_offsenses(user=user, days=days, top=3, emoji_str=match.group('emoji'))
|
||||||
@@ -138,31 +135,3 @@ def get_emoji_name(string: str) -> str:
|
|||||||
if (m := re.search('<:(?P<name>\w+):(?P<id>\d+)>', string)):
|
if (m := re.search('<:(?P<name>\w+):(?P<id>\d+)>', string)):
|
||||||
string = m.group('name')
|
string = m.group('name')
|
||||||
return string.lower().strip()
|
return string.lower().strip()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
client = RoboPage()
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_ready():
|
|
||||||
await client.handle_ready()
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_message(message: discord.Message):
|
|
||||||
await client.handle_message(message)
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_raw_reaction_add(payload: RawReactionActionEvent):
|
|
||||||
await client.handle_raw_reaction(payload)
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_raw_reaction_remove(payload: RawReactionActionEvent):
|
|
||||||
await client.handle_raw_reaction(payload)
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
client.run(os.getenv('DISCORD_TOKEN'))
|
|
||||||
@@ -1,23 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Dict, Iterable
|
from typing import Dict, Iterable
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def convert_emoji(emoji):
|
|
||||||
try:
|
|
||||||
emoji.name.encode('ascii')
|
|
||||||
except UnicodeEncodeError as e:
|
|
||||||
emoji.name = emoji.name.encode('unicode-escape').decode('ascii')
|
|
||||||
return emoji
|
|
||||||
|
|
||||||
|
|
||||||
async def message_df(client: discord.Client, **kwargs):
|
async def message_df(client: discord.Client, **kwargs):
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
[message_dict(m) async for m in message_gen(client, **kwargs)]
|
[message_dict(m) async for m in message_gen(client, **kwargs)]
|
||||||
@@ -70,35 +60,3 @@ def reaction_dict(r: discord.Reaction) -> Dict:
|
|||||||
'emoji id': r.emoji.id if r.is_custom_emoji() else None,
|
'emoji id': r.emoji.id if r.is_custom_emoji() else None,
|
||||||
'count': int(r.count),
|
'count': int(r.count),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def emoji_totals(edf: pd.DataFrame) -> pd.DataFrame:
|
|
||||||
totals = edf.groupby('display_name').sum()['count'].sort_values(ascending=False).apply(int)
|
|
||||||
max_channels = (
|
|
||||||
edf
|
|
||||||
.groupby(['display_name', 'channel'])
|
|
||||||
.sum()['count']
|
|
||||||
.sort_values(ascending=False)
|
|
||||||
.groupby(level=0)
|
|
||||||
.apply(lambda gdf: gdf.idxmax()[1])
|
|
||||||
)
|
|
||||||
return pd.DataFrame({
|
|
||||||
'total': totals,
|
|
||||||
'max channel': max_channels,
|
|
||||||
# 'worst': cdf.groupby('display_name').max()['link']
|
|
||||||
}).sort_values('total', ascending=False)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
client = discord.Client()
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_ready():
|
|
||||||
print(f'{client.user} has connected to Discord!')
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
client.run(os.getenv('DISCORD_TOKEN'))
|
|
||||||
34
main.py
Normal file
34
main.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from discord import Message, RawReactionActionEvent
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from kwaylon import Kwaylon
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# https://discordpy.readthedocs.io/en/stable/quickstart.html
|
||||||
|
client = Kwaylon()
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_ready():
|
||||||
|
await client.handle_ready()
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message(message: Message):
|
||||||
|
await client.handle_message(message)
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_reaction_add(payload: RawReactionActionEvent):
|
||||||
|
await client.handle_raw_reaction(payload)
|
||||||
|
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_raw_reaction_remove(payload: RawReactionActionEvent):
|
||||||
|
await client.handle_raw_reaction(payload)
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
client.run(os.getenv('DISCORD_TOKEN'))
|
||||||
Reference in New Issue
Block a user