mirror of https://gitlab.com/litecord/litecord.git
channel.dm_checks: add friend check override
- user_storage: add UserStorage.are_friends_with
This commit is contained in:
parent
d7bb5f9804
commit
6defce0f9e
|
|
@ -22,8 +22,16 @@ async def dm_pre_check(user_id: int, channel_id: int, peer_id: int):
|
|||
if blockrow is not None:
|
||||
raise ForbiddenDM()
|
||||
|
||||
# check if theyre friends
|
||||
friends = await app.user_storage.are_friends_with(user_id, peer_id)
|
||||
|
||||
# if they're mutual friends, we don't do mutual guild checking
|
||||
if friends:
|
||||
return
|
||||
|
||||
# now comes the fun part, which is guild settings.
|
||||
mutual_guilds = await app.user_storage.get_mutual_guilds(user_id, peer_id)
|
||||
mutual_guilds = set(mutual_guilds)
|
||||
|
||||
# user_settings.restricted_guilds gives us the dms a user doesn't
|
||||
# want dms from, so we use that setting from both user and peer
|
||||
|
|
|
|||
|
|
@ -301,3 +301,31 @@ class UserStorage:
|
|||
mutual_guilds = [r['guild_id'] for r in mutual_guilds]
|
||||
|
||||
return mutual_guilds
|
||||
|
||||
async def are_friends_with(self, user_id: int, peer_id: int) -> bool:
|
||||
"""Return if two people are friends.
|
||||
|
||||
This returns false even if there is a friend request.
|
||||
"""
|
||||
return await self.db.fetchval("""
|
||||
SELECT
|
||||
(
|
||||
SELECT EXISTS(
|
||||
SELECT rel_type
|
||||
FROM relationships
|
||||
WHERE user_id = $1
|
||||
AND peer_id = $2
|
||||
AND rel_type = 1
|
||||
)
|
||||
)
|
||||
AND
|
||||
(
|
||||
SELECT EXISTS(
|
||||
SELECT rel_type
|
||||
FROM relationships
|
||||
WHERE user_id = $2
|
||||
AND peer_id = $1
|
||||
AND rel_type = 1
|
||||
)
|
||||
)
|
||||
""", user_id, peer_id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue