From 3e5357d27f606a60d99deae62ea77fa117905667 Mon Sep 17 00:00:00 2001 From: Ske Date: Tue, 13 Nov 2018 14:01:24 +0100 Subject: [PATCH] Whoops pt. 2 --- src/pluralkit/bot/__init__.py | 2 ++ src/pluralkit/bot/proxy.py | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pluralkit/bot/__init__.py b/src/pluralkit/bot/__init__.py index 60020bc7..a02faa10 100644 --- a/src/pluralkit/bot/__init__.py +++ b/src/pluralkit/bot/__init__.py @@ -123,6 +123,8 @@ def run(): embed = None traceback_str = "```python\n{}```".format(traceback.format_exc()) + if len(traceback.format_exc()) >= (2000 - len("```python\n```")): + traceback_str = "```python\n...{}```".format(traceback.format_exc()[- (2000 - len("```python\n...```")):]) await log_channel.send(content=traceback_str, embed=embed) bot_token = os.environ["TOKEN"] diff --git a/src/pluralkit/bot/proxy.py b/src/pluralkit/bot/proxy.py index bb34d592..eac8c41a 100644 --- a/src/pluralkit/bot/proxy.py +++ b/src/pluralkit/bot/proxy.py @@ -11,6 +11,11 @@ from pluralkit.bot.channel_logger import ChannelLogger logger = logging.getLogger("pluralkit.bot.proxy") +def fix_webhook(webhook: discord.Webhook) -> discord.Webhook: + # Workaround for https://github.com/Rapptz/discord.py/issues/1242 and similar issues (#1150) + webhook._adapter.store_user = webhook._adapter._store_user + webhook._adapter.http = None + return webhook def extract_leading_mentions(message_text): # This regex matches one or more mentions at the start of a message, separated by any amount of spaces @@ -75,16 +80,14 @@ async def get_or_create_webhook_for_channel(conn, channel: discord.TextChannel): session = channel._state.http._session hook = discord.Webhook.partial(webhook_id, webhook_token, adapter=discord.AsyncWebhookAdapter(session)) - # Workaround for https://github.com/Rapptz/discord.py/issues/1242 hook._adapter.store_user = hook._adapter._store_user - return hook + return fix_webhook(hook) # If not, we create one and save it created_webhook = await channel.create_webhook(name="PluralKit Proxy Webhook") - created_webhook._adapter.store_user = created_webhook._adapter._store_user await db.add_webhook(conn, channel.id, created_webhook.id, created_webhook.token) - return created_webhook + return fix_webhook(created_webhook) async def make_attachment_file(message: discord.Message):