File size: 14,530 Bytes
8bef42a
2c0a8e1
0196b87
fe64cf2
3a640bd
 
1bf167b
63ec517
340a40e
96915e7
ef02c8d
92b5cba
d465bd1
e7b7d36
 
d465bd1
 
e7b7d36
f7bc7c5
ff41199
0559244
 
8bef42a
 
 
 
63ec517
f4176dd
92b5cba
 
 
 
 
 
 
 
 
 
 
eb70033
fe64cf2
 
 
 
088a482
8a408ab
 
 
d746030
8a408ab
 
 
088a482
f4176dd
8a408ab
 
 
426d389
8a408ab
 
 
 
0559244
99d08e8
8bef42a
 
 
 
 
50ac6a3
f7bc7c5
 
 
 
 
 
26c910c
 
 
 
 
 
 
 
 
 
 
3a640bd
 
b9d4fbc
3a640bd
 
 
 
 
 
 
 
 
 
 
 
 
bbe7806
3a640bd
 
 
54ef781
f4176dd
ecf3d1e
54ef781
 
ecf3d1e
f7bc7c5
54ef781
 
f4176dd
460a580
6c9a559
e7b7d36
0559244
 
e7b7d36
 
 
3abaf09
 
e7b7d36
 
 
3abaf09
 
e7b7d36
3abaf09
 
e7b7d36
 
 
ecf3d1e
1001fe0
8bef42a
f4176dd
2c0a8e1
1ad52b3
f7bc7c5
 
 
 
441fb2e
 
 
 
 
 
 
 
7442c8d
2c0a8e1
7442c8d
 
1058cc1
441fb2e
7442c8d
441fb2e
 
 
2c0a8e1
7442c8d
2c0a8e1
 
 
 
f4176dd
f979266
 
 
 
 
 
 
 
 
 
54ef781
a8d50f1
e1ba038
 
 
f86d818
 
 
058bc13
e1ba038
 
 
b71807f
 
 
 
 
 
 
 
 
 
54ef781
b71807f
 
 
0b24500
 
 
 
b71807f
 
 
 
 
 
 
 
e1ba038
f86d818
e1ba038
 
 
 
 
e1dde85
f86d818
e1ba038
 
 
 
b71807f
f4176dd
dd6b23e
a8d50f1
96915e7
a8d50f1
dd6b23e
 
 
3f46fa7
a8d50f1
 
 
 
f4176dd
dd06910
137e850
97c2ebc
0559244
d676f4e
97c2ebc
 
 
 
 
 
 
 
de5e9fe
 
137e850
 
 
d676f4e
 
d230be6
137e850
d676f4e
 
 
 
137e850
d230be6
d676f4e
 
d230be6
 
d676f4e
 
 
77411ed
7176b19
d676f4e
 
fb2f620
62cdb83
137e850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b36489
137e850
 
3a325e3
 
710af12
 
 
 
 
 
3a61d82
710af12
54ef781
710af12
2525200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a61d82
54ef781
f4176dd
1001fe0
d82dee8
0559244
f154ce2
d82dee8
 
 
 
1001fe0
 
 
 
 
 
 
 
 
 
 
 
 
92e82d0
 
 
 
 
1001fe0
 
92e82d0
 
1001fe0
92e82d0
15bf604
 
 
 
 
d82dee8
 
1001fe0
54ef781
5edf6d2
de45c67
f4176dd
2f6f0d3
 
 
 
f4176dd
2f6f0d3
 
f4176dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
import logging
import base64
import requests
import uvloop
import aiofiles
import aiohttp
from bs4 import BeautifulSoup
from akenoai import OldAkenoXToJs
from akenoai.runner import run_fast
from akenoai.clients import create_pyrogram
from akenoai.clients.enums import ChatMembersFilter
from fastapi.middleware.cors import CORSMiddleware

from pyrogram.enums import *
from pyrogram.errors import *
from pyrogram.types import *
from pyrogram import filters

from config import API_ID, API_HASH, BOT_TOKEN, SESSION

from src.catergory import router as catergory_router

logger = logging.getLogger(__name__)
LOGS = logging.getLogger("[akenox]")
logger.setLevel(logging.DEBUG)

js = OldAkenoXToJs()
fast_app = js.get_app()

origins = [
    "https://randydev-meta-ai.hf.space"
]
fast_app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

import uvloop

uvloop.install()

from src.combo import router as combo_router
# from src.recent_torrents import router as recent_torrents_router
# from src.search_torrent_url import router as search_torrent_url_router
# from src.search_torrents import router as search_torrents_router
from src.sites_list_torrens import router as sites_list_torrens_router
# from src.trending_torrents import router as trending_torrents_router

# torrent router
fast_app.include_router(combo_router)
fast_app.include_router(catergory_router)
# fast_app.include_router(recent_torrents_router)
# fast_app.include_router(search_torrent_url_router)
# fast_app.include_router(search_torrents_router)
fast_app.include_router(sites_list_torrens_router)
# fast_app.include_router(sites_list_torrens_router)
# fast_app.include_router(trending_torrents_router)


bot = create_pyrogram(
    name="fastapi-bot",
    api_id=API_ID,
    api_hash=API_HASH,
    bot_token=BOT_TOKEN
)

user_client = create_pyrogram(
    name="fastapi-user",
    api_id=API_ID,
    api_hash=API_HASH,
    session_string=SESSION
)

def get_random_from_channel(link):
    clean_link = link.split("?")[0]
    target_link = clean_link.split("/c/") if "/c/" in clean_link else clean_link.split("/")
    random_id = int(target_link[-1].split("/")[-1]) if len(target_link) > 1 else None
    desired_username = target_link[3] if len(target_link) > 3 else None
    username = (
        "@" + desired_username if desired_username else "-100" + target_link[1].split("/")[0]
        if len(target_link) > 1 else None
    )
    return username, random_id

async def upload_to_catbox(dl_path: str) -> str:
    base_url = "https://catbox.moe/user/api.php"
    proxy_url = f"http://186.26.92.180:58339"
    async with aiohttp.ClientSession() as session:
        form_data = aiohttp.FormData()
        form_data.add_field("reqtype", "fileupload")

        async with aiofiles.open(dl_path, mode="rb") as file:
            file_data = await file.read()
            form_data.add_field(
                "fileToUpload",
                file_data,
                filename=dl_path.split("/")[-1],
                content_type="application/octet-stream"
            )

        async with session.post(base_url, data=form_data, proxy=proxy_url) as response:
            response.raise_for_status()
            return (await response.text()).strip()

""""
@fast_app.on_event("startup")
async def startup_event():
    # user = await bot.start()
    # userbot = await user_client.start()
    LOGS.info(f"Started Bot: {user.me.first_name}")
    LOGS.info(f"Started UserBot: {userbot.me.first_name}")


@fast_app.get("/user/status/ban")
async def user_status_ban(username: str = None):
    username_ch = "RendyProjects"
    try:
        mention_user = await bot.get_users(username)
        user = await bot.get_chat_member(username_ch, username)
        if user.status == ChatMemberStatus.BANNED:
            return {
                "message": f"❌ you {mention_user.first_name} have been blocked from the RendyProjects",
                "is_ban": True,
                "user_id": mention_user.id
            }
        return {
            "message": "User is not banned",
            "is_ban": False,
            "user_id": mention_user.id
        }
    except PeerIdInvalid:
        return False
    except UserNotParticipant:
        return False

async def hello():
    return {"success": "hello world!"}

@fast_app.get("/user/get_story")
async def get_user_story(link: str = None):
    username, random_id = get_random_from_channel(link)
    try:
        stories = await user_client.get_stories(username, story_ids=[random_id])
    except Exception as e:
        return {"error": str(e)}
    if stories:
        for story in stories:
            file_id = (
                story.photo.file_id if story and story.photo else None
                or story.video.file_id if story and story.video else None
            )
            caption = story.caption or f"By {user_client.me.mention}"
            if file_id:
                image_path = await user_client.download_media(file_id)
                
                with open(image_path, "rb") as f:
                    base64_image = base64.b64encode(f.read()).decode("utf-8")
                # url_dl = await upload_to_catbox(image_path)
                return {
                    "download": base64_image,
                    "random_file_id": file_id,
                    "caption": caption
                }
    return {
        "download": None,
        "random_file_id": None,
        "caption": None
    }

@fast_app.get("/user/media-dl/file_id")
async def get_download_media_file(file_id: str = None):
    try:
        image_path = await user_client.download_media(file_id)
    except Exception as e:
        return {"error": str(e)}
    with open(image_path, "rb") as f:
        base64_image = base64.b64encode(f.read()).decode("utf-8")
    return {
        "download": base64_image,
    }
"""

ALERT_WARN = """
🚨 Security Alert: API Key Activity Detected!  

πŸ‘οΈ Full Log:

`{text_log}`

πŸ”— Need help? Contact support: @xpushz  
"""

NOTIF_KEY = """
🚨 **Notification: API Key Expired (Premium Required)!**  

Your current API key has expired. To continue using premium features, please upgrade to **Premium v2** first.  

πŸ”‘ **API Key:** <spoiler>{api_key}</spoiler>  

πŸ”— Need help? Contact support: @xpushz
"""

"""
@fast_app.get("/user/tg/notifications")
async def user_send_notif(user_id: int = None, api_key: str = None):
    try:
        await bot.send_sticker(
            user_id,
            "CAACAgUAAyEGAASPgam4AAI5T2fTWtyF4FNdBlRL-PWcs_l3Y0emAAI-BwACj774VGLOns79NgeCHgQ"
        )
        await bot.send_message(
            user_id,
            text=NOTIF_KEY.format(api_key=api_key)
        )
        return {"status": True}
    except Exception as e:
        return None

@fast_app.get("/user/tg/send_message")
async def user_send_message(user_id: int = None, api_key: str = None, text_log: str = None):
    try:
        await bot.send_message(
            user_id,
            text=ALERT_WARN.format(
                api_key=api_key,
                text_log=text_log
            )
        )
        return {"status": True}
    except Exception as e:
        return None

@fast_app.get("/user/author/admin")
async def get_author_chat_admin(username: str = None):
    same_user = {}
    async for m in user_client.get_chat_members(username, filter=ChatMembersFilter.ADMINISTRATORS):
        if not m.user.is_bot and not m.user.is_deleted:
            same_user[m.user.id] = {
                "first_name": m.user.first_name,
                "username": m.user.username if m.user else None
            }
    return {  
        "admin_list": same_user  
    }

@fast_app.get("/user/raw/getchat")
async def get_chat_raw(username: str = None):
    try:
        user_id = None
        chat_raw = (await bot.get_chat(username)).raw
        ok = await user_client.get_chat(username)
        if ok.pinned_message.from_user:
            user_id = ok.pinned_message.from_user.id if ok.pinned_message.from_user else None
        if not user_id:
            user_id = None
        if user_id:
            response = await js.get_creation_date(
                user_id=user_id
            )
    except Exception as e:
        return {"error": f"Error try again invalid: {str(e)}"}
    return {
        "id": chat_raw.id,
        "about": chat_raw.about,
        "title": ok.title,
        "username": ok.username if ok else None,
        "photo": {
            "id": chat_raw.chat_photo.id,
            "small_file_id": ok.photo.small_file_id,
            "small_photo_unique_id": ok.photo.small_photo_unique_id,
            "big_file_id": ok.photo.big_file_id,
            "big_photo_unique_id": ok.photo.big_photo_unique_id,
            "date": chat_raw.chat_photo.date,
            "dc_id": chat_raw.chat_photo.dc_id,
            "has_animation": ok.photo.has_animation,
            "is_personal": ok.photo.is_personal
        },
        "from_user": {
            "id": ok.pinned_message.from_user.id if ok.pinned_message.from_user else None,
            "first_name": ok.pinned_message.from_user.first_name if ok.pinned_message.from_user else None,
            "last_name": ok.pinned_message.from_user.last_name if ok.pinned_message.from_user else None,
            "status": ok.pinned_message.from_user.status.name if ok.pinned_message.from_user.status else None,
            "last_online_date": ok.pinned_message.from_user.last_online_date if ok.pinned_message.from_user else None,
            "username": ok.pinned_message.from_user.username if ok.pinned_message.from_user else None,
            "is_premium": ok.pinned_message.from_user.is_premium if ok.pinned_message.from_user else None,
            "is_scam": ok.pinned_message.from_user.is_scam if ok.pinned_message.from_user else None,
            "creation_date": response
        },
        "can_view_participants": chat_raw.can_view_participants,
        "can_set_username": chat_raw.can_set_username,
        "can_set_stickers": chat_raw.can_set_stickers,
        "hidden_prehistory": chat_raw.hidden_prehistory,
        "can_set_location": chat_raw.can_set_location,
        "has_scheduled": chat_raw.has_scheduled,
        "can_view_stats": chat_raw.can_view_stats,
        "blocked": chat_raw.blocked,
        "can_delete_channel": chat_raw.can_delete_channel,
        "antispam": chat_raw.antispam,
        "participants_hidden": chat_raw.participants_hidden,
        "translations_disabled": chat_raw.translations_disabled,
        "stories_pinned_available": chat_raw.stories_pinned_available,
        "view_forum_as_messages": chat_raw.view_forum_as_messages,
        "restricted_sponsored": chat_raw.restricted_sponsored,
        "can_view_revenue": chat_raw.can_view_revenue,
        "paid_media_allowed": chat_raw.paid_media_allowed,
        "can_view_stars_revenue": chat_raw.can_view_stars_revenue,
        "paid_reactions_available": chat_raw.paid_reactions_available,
        "stargifts_available": chat_raw.stargifts_available,
        "participants_count": chat_raw.participants_count,
        "online_count": chat_raw.online_count,
        "pinned_msg_id": chat_raw.pinned_msg_id,
        "linked_chat_id": chat_raw.linked_chat_id,
        "pending_suggestions": chat_raw.pending_suggestions,
        "recent_requesters": chat_raw.recent_requesters,
        "available_reactions": {
            "allow_custom": chat_raw.available_reactions.allow_custom
        },
    }

async def send_to_telegram(user_id="@xpushz", text: str = None):
    return await bot.send_message(user_id, text=text)

@fast_app.post("/log_captcha")
async def log_captcha(data: dict):
    user_ip = data.get("user_ip", "Unknown IP")
    timestamp = data.get("challenge_ts", "No Timestamp")
    log_message = f"βœ… CAPTCHA Verified\nπŸ–₯ IP: `{user_ip}`\n⏳ Time: `{timestamp}`"
    await send_to_telegram(text=log_message)
    return {"status": "logged"}
"""

@fast_app.get("/api/twitter")
async def twitter_downloader(link: str):
    # credits @xpushz don't remove credits here
    import akenoai as jsx
    import re
    if not link:
        return {"error": "required link"}
    urls = re.sub(r"(https?:\/\/)(?:www\.)?x\.com", r"\1twitter.com", link)
    if not urls:
        return {"error": None}
    response = await jsx.fetch_and_extract_urls(
        f"https://snapdownloader.com/tools/twitter-video-downloader/download?url={urls}",
        href_url=r"https://video",
        return_unsafe_href=True
    )
    return {"results": response}

"""
@fast_app.get("/user/get_user")
async def get_user(user_id=None):
    try:
        get_users = await bot.get_users(user_id)
        response = await js.get_creation_date(
            user_id=get_users.id
        )
    except Exception:
        return {"error": "Error try again invalid"}
    return {
        "id": get_users.id,
        "is_self": get_users.is_self,
        "is_contact": get_users.is_contact,
        "is_mutual_contact": get_users.is_mutual_contact,
        "is_deleted": get_users.is_deleted,
        "is_bot": get_users.is_bot,
        "is_verified": get_users.is_verified,
        "is_restricted": get_users.is_restricted,
        "is_scam": get_users.is_scam,
        "is_fake": get_users.is_fake,
        "is_support": get_users.is_support,
        "is_premium": get_users.is_premium,
        "is_contact_require_premium": get_users.is_contact_require_premium,
        "is_close_friend": get_users.is_close_friend,
        "is_stories_hidden": get_users.is_stories_hidden,
        "is_stories_unavailable": get_users.is_stories_unavailable,
        "is_business_bot": get_users.is_business_bot,
        "first_name": get_users.first_name,
        "status": get_users.status.name,
        "last_online_date": get_users.last_online_date,
        "dc_id": get_users.dc_id,
        "username": get_users.username if get_users else None,
        "photo": {
            "small_file_id": get_users.photo.small_file_id,
            "small_photo_unique_id": get_users.photo.small_photo_unique_id,
            "big_file_id": get_users.photo.big_file_id,
            "has_animation": get_users.photo.has_animation,
            "is_personal": get_users.photo.is_personal
        },
        "creation_date": response
    }
"""

js.custom_openapi(
    app=fast_app,
    title="AkenoX Beta AI API",
    version="1.0.0",
    summary="Use It Only For Personal Project",
    description="Free API By akenoai-lib",
    routes=fast_app.routes,
)

run_fast(build=fast_app, port=7860)