Use existing power levels as base for user levels instead of hardcoded values

This commit is contained in:
Tulir Asokan
2021-10-11 00:51:50 +03:00
parent 74c43355e4
commit a9dcb34b2d
+7 -6
View File
@@ -503,14 +503,15 @@ class PortalMetadata(BasePortal, ABC):
levels.users[self.main_intent.mxid] = 100
return levels
@staticmethod
def _get_level_from_participant(participant: TypeParticipant) -> int:
@classmethod
def _get_level_from_participant(cls, participant: TypeParticipant,
levels: PowerLevelStateEventContent) -> int:
# TODO use the power level requirements to get better precision in channels
if isinstance(participant, (ChatParticipantAdmin, ChannelParticipantAdmin)):
return 50
return levels.state_default or 50
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
return 95
return 0
return levels.get_user_level(cls.az.bot_mxid) - 5
return levels.users_default or 0
@staticmethod
def _participant_to_power_levels(levels: PowerLevelStateEventContent,
@@ -541,7 +542,7 @@ class PortalMetadata(BasePortal, ABC):
puppet = p.Puppet.get(TelegramID(participant.user_id))
user = u.User.get_by_tgid(TelegramID(participant.user_id))
new_level = self._get_level_from_participant(participant)
new_level = self._get_level_from_participant(participant, levels)
if user:
await user.register_portal(self)