randydev commited on
Commit
f7bc7c5
·
verified ·
1 Parent(s): 5fb202f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -2
main.py CHANGED
@@ -2,7 +2,7 @@ import logging
2
  from contextlib import asynccontextmanager
3
  from akenoai import AkenoXToJs as js
4
  from akenoai.runner import run_fast
5
- from config import API_ID, API_HASH, BOT_TOKEN
6
 
7
  logger = logging.getLogger(__name__)
8
  LOGS = logging.getLogger("[akenox]")
@@ -17,6 +17,13 @@ client = js.create_pyrogram(
17
  bot_token=BOT_TOKEN
18
  )
19
 
 
 
 
 
 
 
 
20
  def get_random_from_channel(link):
21
  clean_link = link.split("?")[0]
22
  target_link = clean_link.split("/c/") if "/c/" in clean_link else clean_link.split("/")
@@ -31,12 +38,39 @@ def get_random_from_channel(link):
31
  @fast_app.on_event("startup")
32
  async def startup_event():
33
  user = await client.start()
 
34
  LOGS.info(f"Started Bot: {user.me.first_name}")
35
-
 
36
  @fast_app.get("/")
37
  async def hello():
38
  return {"success": "hello world!"}
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  @fast_app.get("/user/get_user")
41
  async def get_user(user_id=None):
42
  try:
 
2
  from contextlib import asynccontextmanager
3
  from akenoai import AkenoXToJs as js
4
  from akenoai.runner import run_fast
5
+ from config import API_ID, API_HASH, BOT_TOKEN, SESSION
6
 
7
  logger = logging.getLogger(__name__)
8
  LOGS = logging.getLogger("[akenox]")
 
17
  bot_token=BOT_TOKEN
18
  )
19
 
20
+ user_client = js.create_pyrogram(
21
+ name="fastapi-user",
22
+ api_id=API_ID,
23
+ api_hash=API_HASH,
24
+ session_string=SESSION
25
+ )
26
+
27
  def get_random_from_channel(link):
28
  clean_link = link.split("?")[0]
29
  target_link = clean_link.split("/c/") if "/c/" in clean_link else clean_link.split("/")
 
38
  @fast_app.on_event("startup")
39
  async def startup_event():
40
  user = await client.start()
41
+ userbot = await user_client.start()
42
  LOGS.info(f"Started Bot: {user.me.first_name}")
43
+ LOGS.info(f"Started UserBot: {userbot.me.first_name}")
44
+
45
  @fast_app.get("/")
46
  async def hello():
47
  return {"success": "hello world!"}
48
 
49
+ @fast_app.get("/user/get_story")
50
+ async def get_user_story(link=None):
51
+ username, random_id = utils.get_random_from_channel(link_story)
52
+ try:
53
+ stories = await user_client.get_stories(username, story_ids=[random_id])
54
+ except Exception as e:
55
+ return {"error": str(e)}
56
+ if stories:
57
+ for story in stories:
58
+ file_id = (
59
+ story.photo.file_id if story and story.photo else None
60
+ or story.video.file_id if story and story.video else None
61
+ )
62
+ caption = story.caption or f"By {user_client.me.mention}"
63
+ if file_id:
64
+ return {
65
+ "uploaded_file_id": file_id,
66
+ "caption": caption
67
+ }
68
+ else:
69
+ return {
70
+ "uploaded_file_id": None,
71
+ "caption": None
72
+ }
73
+
74
  @fast_app.get("/user/get_user")
75
  async def get_user(user_id=None):
76
  try: