コード例 #1
0
    async def on_member_remove(self, member: Member):
        udata_result = RootUserManager.get_root_data_onplat(Platform.DISCORD, member.id, auto_register=True)
        cdata = ChannelManager.get_channel_token(Platform.DISCORD, member.guild.id, auto_register=True)

        if udata_result.success and cdata:
            ProfileManager.mark_unavailable_async(cdata.id, udata_result.model.id)

        sys_channel = member.guild.system_channel
        if sys_channel:
            await sys_channel.send(_("{} left the server.").format(member.mention))
コード例 #2
0
def _check_on_prof_conn_(
        prof_conn: ChannelProfileConnectionModel,
        set_name_to_cache: bool,
        dict_onplat_oids: Dict[ObjectId, List[ObjectId]],
        dict_onplat_data: Dict[ObjectId, OnPlatformUserModel],
        dict_channel: Dict[ObjectId, ChannelModel]) -> bool:
    """Return ``True`` if marked unavailable. Otherwise ``False``."""
    oid_user = prof_conn.user_oid
    list_onplat_oids = dict_onplat_oids.get(oid_user)
    if not list_onplat_oids:
        return False

    model_channel = dict_channel.get(prof_conn.channel_oid)
    if not model_channel:
        return False

    attempts = 0
    attempts_allowed = len(list_onplat_oids)

    for oid_onplat in list_onplat_oids:
        model_onplat = dict_onplat_data.get(oid_onplat)
        if not model_onplat:
            MailSender.send_email_async(
                f"Missing OnPlatform data of data ID: {oid_onplat}<br>"
                f"Root User ID: {prof_conn.user_oid}",
                subject="Missing OnPlatform Data in Root User Model"
            )
            continue

        n = model_onplat.get_name(model_channel)

        if n:
            if set_name_to_cache:
                set_uname_cache(model_onplat.id, n)

            break

        attempts += 1

    if attempts >= attempts_allowed:
        ProfileManager.mark_unavailable_async(model_channel.id, oid_user)

    return attempts >= attempts_allowed
コード例 #3
0
ファイル: member.py プロジェクト: stefaneutu/Jelly-Bot
def handle_member_left(request, event, destination):
    for user in event.left.members:
        uid = user.user_id

        udata_result = RootUserManager.get_root_data_onplat(Platform.LINE, uid)
        cdata = ChannelManager.get_channel_token(
            Platform.LINE,
            LineApiUtils.get_channel_id(event),
            auto_register=True)

        if udata_result.success and cdata:
            ProfileManager.mark_unavailable_async(cdata.id,
                                                  udata_result.model.id)

    LINE.temp_apply_format(event_dest_fmt,
                           logging.INFO,
                           "LINE Left Group.",
                           extra={
                               ExtraKey.Event: event,
                               ExtraKey.Destination: destination
                           })
コード例 #4
0
ファイル: user.py プロジェクト: stefaneutu/Jelly-Bot
    def get_name(self, channel_data=None) -> Optional[str]:
        # Checking `get_oid()` because the model might be constructed in the code (no ID) and
        # call `get_name()` afterward without storing it to the database
        if self.get_oid() is not None and self.id not in _user_name_cache_:
            n = None

            if self.platform == Platform.LINE:
                from extline import LineApiWrapper
                from models import ChannelCollectionModel

                if isinstance(channel_data, ChannelCollectionModel):
                    raise ValueError(
                        "Finding the user name with `ChannelCollectionModel` "
                        "currently not yet supported. Check issue #38.")

                if channel_data:
                    n = LineApiWrapper.get_user_name_safe(
                        self.token, channel_data)
                else:
                    n = LineApiWrapper.get_user_name_safe(self.token)
            elif self.platform == Platform.DISCORD:
                from extdiscord import DiscordClientWrapper

                n = DiscordClientWrapper.get_user_name_safe(self.token)

            if n:
                set_uname_cache(self.id, n)
            else:
                # Mark unavailable
                from mongodb.factory import ProfileManager, RootUserManager

                root_data_result = RootUserManager.get_root_data_onplat(
                    self.platform, self.token, auto_register=False)
                if root_data_result.success:
                    ProfileManager.mark_unavailable_async(
                        channel_data.id, root_data_result.model.id)

        return _user_name_cache_.get(self.id)