Spaces:
Running
Running
Update main.py
#5
by
Ufoptg
- opened
main.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
import logging
|
2 |
-
from pyrogram import Client, filters
|
3 |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
4 |
from pyrogram.types import *
|
5 |
from RyuzakiLib import Tiktok
|
6 |
-
from config import TIKTOK_WEB as tt, API_ID, API_HASH, BOT_TOKEN
|
7 |
import hashlib
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
10 |
logging.basicConfig(level=logging.INFO)
|
11 |
|
@@ -31,6 +36,34 @@ def generate_callback_data(user_id, query):
|
|
31 |
link_storage[callback_data] = query
|
32 |
return callback_data
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
@client.on_message(filters.command("start") & filters.private)
|
35 |
async def welcome_start(client: Client, message: Message):
|
36 |
keyboard = InlineKeyboardMarkup(
|
@@ -88,4 +121,14 @@ async def tiktok_downloader(client: Client, message: Message):
|
|
88 |
await dll.delete()
|
89 |
await message.reply_text(f"Error: {str(e)}")
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
client.run()
|
|
|
1 |
import logging
|
2 |
+
from pyrogram import Client, filters, idle
|
3 |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
4 |
from pyrogram.types import *
|
5 |
from RyuzakiLib import Tiktok
|
6 |
+
from config import TIKTOK_WEB as tt, API_ID, API_HASH, BOT_TOKEN, HUGGING_TOKEN
|
7 |
import hashlib
|
8 |
|
9 |
+
try:
|
10 |
+
from aiohttp import ClientSession as aiohttp_client
|
11 |
+
except ImportError:
|
12 |
+
aiohttp_client = None
|
13 |
+
|
14 |
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
15 |
logging.basicConfig(level=logging.INFO)
|
16 |
|
|
|
36 |
link_storage[callback_data] = query
|
37 |
return callback_data
|
38 |
|
39 |
+
async def async_searcher(
|
40 |
+
url: str,
|
41 |
+
post: bool = False,
|
42 |
+
head: bool = False,
|
43 |
+
headers: dict = None,
|
44 |
+
evaluate=None,
|
45 |
+
object: bool = False,
|
46 |
+
re_json: bool = False,
|
47 |
+
re_content: bool = False,
|
48 |
+
*args,
|
49 |
+
**kwargs,
|
50 |
+
):
|
51 |
+
if aiohttp_client:
|
52 |
+
async with aiohttp_client(headers=headers) as client:
|
53 |
+
method = client.head if head else (client.post if post else client.get)
|
54 |
+
data = await method(url, *args, **kwargs)
|
55 |
+
if evaluate:
|
56 |
+
return await evaluate(data)
|
57 |
+
if re_json:
|
58 |
+
return await data.json()
|
59 |
+
if re_content:
|
60 |
+
return await data.read()
|
61 |
+
if head or object:
|
62 |
+
return data
|
63 |
+
return await data.text()
|
64 |
+
else:
|
65 |
+
raise DependencyMissingError("install 'aiohttp' to use this.")
|
66 |
+
|
67 |
@client.on_message(filters.command("start") & filters.private)
|
68 |
async def welcome_start(client: Client, message: Message):
|
69 |
keyboard = InlineKeyboardMarkup(
|
|
|
121 |
await dll.delete()
|
122 |
await message.reply_text(f"Error: {str(e)}")
|
123 |
|
124 |
+
async def setup():
|
125 |
+
try:
|
126 |
+
await client.start()
|
127 |
+
logger.info("Bot started successfully")
|
128 |
+
await start_periodic_task()
|
129 |
+
# Run the client
|
130 |
+
await idle()
|
131 |
+
except Exception as e:
|
132 |
+
logger.error(f"Error in setup: {e}")
|
133 |
+
|
134 |
client.run()
|