mirror of https://gitlab.com/litecord/litecord.git
channel: add dm_checks module
- channel.messages: check block state before message send
This commit is contained in:
parent
28811da1b4
commit
7e425229f9
|
|
@ -0,0 +1,26 @@
|
|||
from quart import current_app as app
|
||||
|
||||
from litecord.errors import Forbidden
|
||||
from litecord.enums import RelationshipType
|
||||
|
||||
|
||||
class ForbiddenDM(Forbidden):
|
||||
error_code = 50007
|
||||
|
||||
|
||||
async def dm_pre_check(user_id: int, channel_id: int, peer_id: int):
|
||||
"""Check if the user can DM the peer."""
|
||||
# first step is checking if there is a block in any direction
|
||||
blockrow = await app.db.fetchrow("""
|
||||
SELECT rel_type
|
||||
FROM relationships
|
||||
WHERE rel_type = $3
|
||||
AND user_id IN ($1, $2)
|
||||
AND peer_id IN ($1, $2)
|
||||
""", user_id, peer_id, RelationshipType.BLOCK.value)
|
||||
|
||||
if blockrow is not None:
|
||||
raise ForbiddenDM()
|
||||
|
||||
# TODO: check mutual guilds and guild settings for
|
||||
# each user
|
||||
|
|
@ -14,6 +14,7 @@ from litecord.schemas import validate, MESSAGE_CREATE
|
|||
from litecord.utils import pg_set_json
|
||||
|
||||
from litecord.embed.sanitizer import fill_embed, proxify, fetch_metadata
|
||||
from litecord.blueprints.channel.dm_checks import dm_pre_check
|
||||
|
||||
|
||||
log = Logger(__name__)
|
||||
|
|
@ -307,6 +308,10 @@ async def _create_message(channel_id):
|
|||
|
||||
# TODO: check connection to the gateway
|
||||
|
||||
if ctype == ChannelType.DM:
|
||||
# guild_id is the dm's peer_id
|
||||
await dm_pre_check(user_id, channel_id, guild_id)
|
||||
|
||||
can_everyone = await channel_perm_check(
|
||||
user_id, channel_id, 'mention_everyone', False
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue