-
Notifications
You must be signed in to change notification settings - Fork 11
/
bot.py
53 lines (42 loc) · 1.02 KB
/
bot.py
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
import os
import logging
from logging.handlers import RotatingFileHandler
from pyrogram import Client
from pyrogram import idle
from plugins.config import *
# Prepare bot client
bot = Client(
"botclient",
bot_token=BOT_TOKEN,
api_id=API_ID,
api_hash=API_HASH,
sleep_threshold=30
)
# Prepare user client if session string is provided
if SESSION_STRING:
user_client = Client(
"UserClient",
session_string=SESSION_STRING,
api_id=API_ID,
api_hash=API_HASH,
sleep_threshold=30,
no_updates=True
)
else:
user_client = None
# Start the clients
if __name__ == "__main__":
# Create download directory if it does not exist
if not os.path.isdir(DOWN_DIR):
os.makedirs(DOWN_DIR)
# Start bot client
bot.start()
# Start user client if available
if user_client:
user_client.start()
# Keep the main thread running
idle()
# Stop the clients
bot.stop()
if user_client:
user_client.stop()