Multiple changes

Started switching to generics
Added tickets
This commit is contained in:
Dusty Pianalto
2019-12-01 10:30:03 -09:00
parent 27231fda7b
commit b8f751bae9
37 changed files with 1482 additions and 144 deletions
+158
View File
@@ -0,0 +1,158 @@
# noinspection PyPackageRequirements
import discord
async def on_message(bot, message, user_info):
if not user_info.get('disable_logging'):
if message.guild:
msg_data = {
'author': str(message.author.id),
'channel': str(message.channel.id),
'mention_everyone': message.mention_everyone,
'created_at': message.created_at
}
if message.mentions:
msg_data['mentions'] = [str(user.id) for user in message.mentions]
if message.channel_mentions:
msg_data['channel_mentions'] = [str(channel.id) for channel in message.channel_mentions]
if message.role_mentions:
msg_data['role_mentions'] = [str(role.id) for role in message.role_mentions]
if message.embeds:
msg_data['embeds'] = [e.to_dict() for e in message.embeds]
if message.content:
msg_data['content'] = message.content
if message.webhook_id:
msg_data['webhook_id'] = message.webhook_id
if message.tts:
msg_data['tts'] = message.tts
if message.attachments:
msg_data['attachments'] = [{
'id': str(a.id),
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in message.attachments]
bot.fs_db.document(f'guilds/{message.guild.id}/messages/{message.id}').set(msg_data)
else:
msg_data = {
'author': str(message.author.id),
'created_at': message.created_at
}
if message.mentions:
msg_data['mentions'] = [str(user.id) for user in message.mentions]
if message.embeds:
msg_data['embeds'] = [e.to_dict() for e in message.embeds]
if message.content:
msg_data['content'] = message.content
if message.webhook_id:
msg_data['webhook_id'] = message.webhook_id
if message.tts:
msg_data['tts'] = message.tts
if message.attachments:
msg_data['attachments'] = [{
'id': str(a.id),
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in message.attachments]
bot.fs_db.document(f'dm_channels/{message.channel.id}/messages/{message.id}').set(msg_data)
async def on_message_edit(bot, before: discord.Message, after: discord.Message, user_config):
if not user_config.get('disable_logging'):
if after.guild:
msg_ref = bot.fs_db.document(f'guilds/{after.guild.id}/messages/{after.id}')
msg_data = (await bot.loop.run_in_executor(bot.tpe, msg_ref.get)).to_dict()
if before.content != after.content:
if before.content:
if msg_data.get('previous_content') and isinstance(msg_data['previous_content'], list):
msg_data['previous_content'].append(before.content)
else:
msg_data['previous_content'] = [before.content, ]
msg_data['content'] = after.content
if before.embeds != after.embeds:
if before.embeds:
if msg_data.get('previous_embeds') and isinstance(msg_data['previous_embeds'], list):
msg_data['previous_embeds'].append(before.embeds[0].to_dict())
else:
msg_data['previous_embeds'] = [before.embeds[0].to_dict(), ]
msg_data['embeds'] = [e.to_dict() for e in after.embeds]
if before.pinned != after.pinned:
msg_data['pinned'] = after.pinned
if before.mentions != after.mentions:
msg_data['mentions'] = [str(user.id) for user in after.mentions]
if before.channel_mentions != after.channel_mentions:
msg_data['channel_mentions'] = [str(user.id) for user in after.channel_mentions]
if before.role_mentions != after.role_mentions:
msg_data['role_mentions'] = [str(user.id) for user in after.role_mentions]
if before.attachments != after.attachments:
if before.attachments:
if msg_data.get('previous_attachments') and isinstance(msg_data['previous_attachments'], list):
msg_data['previous_attachments'].append([{
'id': str(a.id),
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in before.attachments])
else:
msg_data['previous_attachments'] = [[{
'id': a.id,
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in before.attachments], ]
msg_data['attachments'] = [{
'id': a.id,
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in after.attachments]
bot.fs_db.document(f'guilds/{after.guild.id}/messages/{after.id}').set(msg_data)
else:
msg_ref = bot.fs_db.document(f'dm_channels/{after.channel.id}/messages/{after.id}')
msg_data = (await bot.loop.run_in_executor(bot.tpe, msg_ref.get)).to_dict()
if before.content != after.content:
if before.content:
if msg_data.get('previous_content') and isinstance(msg_data['previous_content'], list):
msg_data['previous_content'].append(before.content)
else:
msg_data['previous_content'] = [before.content, ]
msg_data['content'] = after.content
if before.embeds != after.embeds:
if before.embeds:
if msg_data.get('previous_embeds') and isinstance(msg_data['previous_embeds'], list):
msg_data['previous_embeds'].append(before.embeds[0].to_dict())
else:
msg_data['previous_embeds'] = [before.embeds[0].to_dict(), ]
msg_data['embeds'] = [e.to_dict() for e in after.embeds]
if before.pinned != after.pinned:
msg_data['pinned'] = after.pinned
if before.mentions != after.mentions:
msg_data['mentions'] = [str(user.id) for user in after.mentions]
if before.attachments != after.attachments:
if before.attachments:
if msg_data.get('previous_attachments') and isinstance(msg_data['previous_attachments'], list):
msg_data['previous_attachments'].append([{
'id': str(a.id),
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in before.attachments])
else:
msg_data['previous_attachments'] = [[{
'id': a.id,
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in before.attachments], ]
msg_data['attachments'] = [{
'id': a.id,
'size': a.size,
'filename': a.filename,
'url': a.url
} for a in after.attachments]
bot.fs_db.document(f'dm_channels/{after.channel.id}/messages/{after.id}').set(msg_data)
+16 -5
View File
@@ -84,7 +84,8 @@ class Paginator:
field_name_char: str = '\uFFF6',
inline_char: str = '\uFFF5',
max_line_length: int = 100,
embed=False):
embed=False,
header: str = ''):
_max_len = 6000 if embed else 1980
assert 0 < max_lines <= max_chars
@@ -110,6 +111,7 @@ class Paginator:
self._embed_thumbnail = None
self._embed_url = None
self._bot = bot
self._header = header
def set_embed_meta(self, title: str = None,
description: str = None,
@@ -129,7 +131,7 @@ class Paginator:
self._embed_thumbnail = thumbnail
self._embed_url = url
def pages(self) -> typing.List[str]:
def pages(self, page_headers: bool = True) -> typing.List[str]:
_pages = list()
_fields = list()
_page = ''
@@ -138,10 +140,16 @@ class Paginator:
_field_value = ''
_inline = False
def open_page():
def open_page(initial: bool = False):
nonlocal _page, _lines, _fields
if not self._embed:
_page = self._prefix
if initial and not page_headers:
_page = self._header
elif page_headers:
_page = self._header
else:
_page = ''
_page += self._prefix
_lines = 0
else:
_fields = list()
@@ -156,7 +164,7 @@ class Paginator:
_pages.append(_fields)
open_page()
open_page()
open_page(initial=True)
if not self._embed:
for part in [str(p) for p in self._parts]:
@@ -254,6 +262,9 @@ class Paginator:
# noinspection PyProtectedMember
return self.__class__ == other.__class__ and self._parts == other._parts
def set_header(self, header: str = ''):
self._header = header
def add_page_break(self, *, to_beginning: bool = False) -> None:
self.add(self._page_break, to_beginning=to_beginning)