Skip to content

Commit

Permalink
Keep reference (#31)
Browse files Browse the repository at this point in the history
* Keep reference

* lint
  • Loading branch information
amadejkastelic authored Dec 7, 2024
1 parent 0222333 commit 7246aa9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
16 changes: 14 additions & 2 deletions bot/adapters/discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ async def _handle_message(self, message: discord.Message, user: discord.User):
)
return

new_message = (await asyncio.gather(message.delete(), message.channel.send('🔥 Working on it 🥵')))[1]
new_message = (
await asyncio.gather(
message.delete(),
message.channel.send(content='🔥 Working on it 🥵', reference=message.reference),
)
)[1]

try:
post = await service.get_post(
Expand All @@ -156,7 +161,12 @@ async def _handle_message(self, message: discord.Message, user: discord.User):
raise e

try:
msg = await self._send_post(post=post, send_func=message.channel.send, author=user)
msg = await self._send_post(
post=post,
send_func=message.channel.send,
author=user,
reference=message.reference,
)
logger.info('User sent message with url', user=user.display_name, url=url)
except Exception as e:
logger.error('Failed sending message', url=url, error=str(e))
Expand Down Expand Up @@ -398,9 +408,11 @@ async def _send_post(
post: domain.Post,
send_func: typing.Callable,
author: typing.Union[discord.User, discord.Member],
reference: typing.Optional[discord.MessageReference] = None,
) -> discord.Message:
send_kwargs = {
'suppress_embeds': True,
'reference': reference,
}
file = None
if post.buffer:
Expand Down
5 changes: 5 additions & 0 deletions bot/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import typing
from contextlib import contextmanager

try:
import pylibmagic # noqa: F401 # pylint: disable=unused-import
except ImportError:
pass

import aiohttp
import magic
import markdownify
Expand Down
23 changes: 22 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ psycopg = { extras = ["binary"], version = "^3.2.3" }
aiograpi = "^0.0.3"
pytubefix = "^8.6.0"
markdownify = "^0.14.1"
pylibmagic = "^0.5.0"

[tool.poetry.dev-dependencies]
black = "^24.10.0"
Expand Down

0 comments on commit 7246aa9

Please sign in to comment.