예제 #1
0
 async def get_paid_content(
     self,
     check: bool = False,
     refresh: bool = True,
     limit: int = 10,
     offset: int = 0,
     inside_loop: bool = False,
 ) -> list[create_message | create_post] | ErrorDetails:
     result, status = await api_helper.default_data(self, refresh)
     if status:
         return result
     link = endpoint_links(global_limit=limit, global_offset=offset).paid_api
     final_results = await self.session_manager.json_request(link)
     if not isinstance(final_results, ErrorDetails):
         if len(final_results) > 0 and not check:
             results2 = await self.get_paid_content(
                 limit=limit, offset=limit + offset, inside_loop=True
             )
             final_results.extend(results2)
         if not inside_loop:
             temp: list[create_message | create_post] = []
             for final_result in final_results:
                 content = None
                 if final_result["responseType"] == "message":
                     user = create_user(final_result["fromUser"], self)
                     content = create_message(final_result, user)
                     print
                 elif final_result["responseType"] == "post":
                     user = create_user(final_result["author"], self)
                     content = create_post(final_result, user)
                 if content:
                     temp.append(content)
             final_results = temp
         self.paid_content = final_results
     return final_results
예제 #2
0
    async def get_chats(
        self,
        links: Optional[list[str]] = None,
        limit: int = 100,
        offset: int = 0,
        refresh: bool = True,
        inside_loop: bool = False,
    ) -> list[dict[str, Any]]:
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        if links is None:
            links = []
        api_count = self.chatMessagesCount
        if api_count and not links:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).list_chats
            ceil = math.ceil(api_count / limit)
            numbers = list(range(ceil))
            for num in numbers:
                num = num * limit
                link = link.replace(f"limit={limit}", f"limit={limit}")
                new_link = link.replace("offset=0", f"offset={num}")
                links.append(new_link)
        multiplier = self.session_manager.max_threads
        if links:
            link = links[-1]
        else:
            link = endpoint_links(
                identifier=self.id, global_limit=limit, global_offset=offset
            ).list_chats
        links_2 = api_helper.calculate_the_unpredictable(link, limit, multiplier)
        final_links = links
        if not inside_loop:
            final_links += links_2
        else:
            final_links = links_2
        results = await self.session_manager.async_requests(final_links)
        has_more = results[-1]["hasMore"]
        final_results = [x["list"] for x in results]
        final_results = list(chain.from_iterable(final_results))
        for result in final_results:
            result["withUser"] = create_user(result["withUser"], self)
            result["lastMessage"] = create_message(
                result["lastMessage"], result["withUser"]
            )

        if has_more:
            results2 = await self.get_chats(
                links=[final_links[-1]],
                limit=limit,
                offset=limit + offset,
                inside_loop=True,
            )
            final_results.extend(results2)

        final_results.sort(key=lambda x: x["withUser"].id, reverse=True)
        self.chats = final_results
        return final_results
예제 #3
0
 def __init__(self, option: dict[str, Any], user: create_user) -> None:
     self.responseType: Optional[str] = option.get("responseType")
     self.text: Optional[str] = option.get("text")
     self.lockedText: Optional[bool] = option.get("lockedText")
     self.isFree: Optional[bool] = option.get("isFree")
     self.price: Optional[float] = option.get("price")
     self.isMediaReady: Optional[bool] = option.get("isMediaReady")
     self.mediaCount: Optional[int] = option.get("mediaCount")
     self.media: list[dict[str, Any]] = option.get("media", [])
     self.previews: list[dict[str, Any]] = option.get("previews", [])
     self.isTip: Optional[bool] = option.get("isTip")
     self.isReportedByMe: Optional[bool] = option.get("isReportedByMe")
     self.fromUser = (
         user
         if user.id == option["fromUser"]["id"]
         else user_model.create_user(option["fromUser"], user.get_authed())
     )
     self.isFromQueue: Optional[bool] = option.get("isFromQueue")
     self.queueId: Optional[int] = option.get("queueId")
     self.canUnsendQueue: Optional[bool] = option.get("canUnsendQueue")
     self.unsendSecondsQueue: Optional[int] = option.get("unsendSecondsQueue")
     self.id: Optional[int] = option.get("id")
     self.isOpened: Optional[bool] = option.get("isOpened")
     self.isNew: Optional[bool] = option.get("isNew")
     self.createdAt: Optional[str] = option.get("createdAt")
     self.changedAt: Optional[str] = option.get("changedAt")
     self.cancelSeconds: Optional[int] = option.get("cancelSeconds")
     self.isLiked: Optional[bool] = option.get("isLiked")
     self.canPurchase: Optional[bool] = option.get("canPurchase")
     self.canPurchaseReason: Optional[str] = option.get("canPurchaseReason")
     self.canReport: Optional[bool] = option.get("canReport")
예제 #4
0
 async def get_user(
     self, identifier: Union[str, int]
 ) -> Union[create_user, ErrorDetails]:
     link = endpoint_links(identifier).users
     response = await self.session_manager.json_request(link)
     if not isinstance(response, ErrorDetails):
         if not response:
             print
         response["session_manager"] = self.session_manager
         response = create_user(response, self)
     return response
예제 #5
0
 async def multi(item: str):
     link = item
     subscriptions = await self.session_manager.json_request(link)
     valid_subscriptions: list[create_user] = []
     extras = {}
     extras["auth_check"] = ""
     if isinstance(subscriptions, ErrorDetails):
         return
     subscriptions = [
         subscription
         for subscription in subscriptions
         if "error" != subscription
     ]
     tasks: list[Task[create_user | ErrorDetails]] = []
     for subscription in subscriptions:
         subscription["session_manager"] = self.session_manager
         if extra_info:
             task = asyncio.create_task(
                 self.get_user(subscription["username"])
             )
             tasks.append(task)
     results2 = await asyncio.gather(*tasks)
     for result in results2:
         if isinstance(result, ErrorDetails):
             continue
         if not result:
             print
         subscription2: create_user = result
         for subscription in subscriptions:
             if subscription["id"] != subscription2.id:
                 continue
             subscription = subscription | subscription2.__dict__
             subscription = create_user(subscription, self)
             if subscription.isBlocked:
                 continue
             valid_subscriptions.append(subscription)
     return valid_subscriptions
예제 #6
0
    async def get_subscriptions(
        self,
        refresh: bool = True,
        identifiers: list[int | str] = [],
        extra_info: bool = True,
        limit: int = 20,
    ) -> list[create_user]:
        result, status = await api_helper.default_data(self, refresh)
        if status:
            return result
        # if self.subscribesCount > 900:
        #     limit = 100
        ceil = math.ceil(self.subscribesCount / limit)
        a = list(range(ceil))
        offset_array: list[str] = []
        for b in a:
            b = b * limit
            link = endpoint_links(global_limit=limit, global_offset=b).subscriptions
            offset_array.append(link)

        results: list[list[create_user]] = []
        if not identifiers:

            async def multi(item: str):
                link = item
                subscriptions = await self.session_manager.json_request(link)
                valid_subscriptions: list[create_user] = []
                extras = {}
                extras["auth_check"] = ""
                if isinstance(subscriptions, ErrorDetails):
                    return
                subscriptions = [
                    subscription
                    for subscription in subscriptions
                    if "error" != subscription
                ]
                tasks: list[Task[create_user | ErrorDetails]] = []
                for subscription in subscriptions:
                    subscription["session_manager"] = self.session_manager
                    if extra_info:
                        task = asyncio.create_task(
                            self.get_user(subscription["username"])
                        )
                        tasks.append(task)
                results2 = await asyncio.gather(*tasks)
                for result in results2:
                    if isinstance(result, ErrorDetails):
                        continue
                    if not result:
                        print
                    subscription2: create_user = result
                    for subscription in subscriptions:
                        if subscription["id"] != subscription2.id:
                            continue
                        subscription = subscription | subscription2.__dict__
                        subscription = create_user(subscription, self)
                        if subscription.isBlocked:
                            continue
                        valid_subscriptions.append(subscription)
                return valid_subscriptions

            # If user is a creator, add them to the subscription list
            if self.isPerformer:
                subscription = await self.convert_to_user()
                if isinstance(subscription, ErrorDetails):
                    return result
                subscription.subscribedByData = {}
                new_date = datetime.now() + relativedelta(years=1)
                subscription.subscribedByData["expiredAt"] = new_date.isoformat()
                subscriptions = [subscription]
                results.append(subscriptions)
            pool = self.pool
            tasks = pool.starmap(multi, product(offset_array))
            results2 = await asyncio.gather(*tasks)
            results2 = list(filter(None, results2))
            results.extend(results2)
        else:
            for identifier in identifiers:
                if self.id == identifier or self.username == identifier:
                    continue
                link = endpoint_links(identifier=identifier).users
                result = await self.session_manager.json_request(link)
                if isinstance(result, ErrorDetails) or not result["subscribedBy"]:
                    continue
                subscription = create_user(result, self)
                if subscription.isBlocked:
                    continue
                results.append([subscription])
                print
            print
        final_results = [x for x in results if x is not None]
        final_results = list(chain(*final_results))
        self.subscriptions = final_results
        return final_results