Use existing power levels as base for user levels instead of hardcoded values
This commit is contained in:
@@ -503,14 +503,15 @@ class PortalMetadata(BasePortal, ABC):
|
|||||||
levels.users[self.main_intent.mxid] = 100
|
levels.users[self.main_intent.mxid] = 100
|
||||||
return levels
|
return levels
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def _get_level_from_participant(participant: TypeParticipant) -> int:
|
def _get_level_from_participant(cls, participant: TypeParticipant,
|
||||||
|
levels: PowerLevelStateEventContent) -> int:
|
||||||
# TODO use the power level requirements to get better precision in channels
|
# TODO use the power level requirements to get better precision in channels
|
||||||
if isinstance(participant, (ChatParticipantAdmin, ChannelParticipantAdmin)):
|
if isinstance(participant, (ChatParticipantAdmin, ChannelParticipantAdmin)):
|
||||||
return 50
|
return levels.state_default or 50
|
||||||
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
|
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
|
||||||
return 95
|
return levels.get_user_level(cls.az.bot_mxid) - 5
|
||||||
return 0
|
return levels.users_default or 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _participant_to_power_levels(levels: PowerLevelStateEventContent,
|
def _participant_to_power_levels(levels: PowerLevelStateEventContent,
|
||||||
@@ -541,7 +542,7 @@ class PortalMetadata(BasePortal, ABC):
|
|||||||
|
|
||||||
puppet = p.Puppet.get(TelegramID(participant.user_id))
|
puppet = p.Puppet.get(TelegramID(participant.user_id))
|
||||||
user = u.User.get_by_tgid(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:
|
if user:
|
||||||
await user.register_portal(self)
|
await user.register_portal(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user