forked from hplatforms/URL-Yukleyici
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
59 lines (52 loc) · 2.01 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
54
55
56
57
58
59
# HuzunluArtemis - 2021 (Licensed under GPL-v3)
import logging
import os
import time
from config import BOT_TOKEN, APP_ID, API_HASH, DOWNLOAD_LOCATION, OWNER_ID, SESSION_NAME, SEND_LOGS_WHEN_DYING
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from functions.utils import ReadableTime
from pyromod import listen
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()],
level=logging.INFO)
LOGGER = logging.getLogger(__name__)
botStartTime = time.time()
class Bot(Client):
def __init__(self):
super().__init__(
name=SESSION_NAME,
api_id=APP_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workers=343,
plugins={"root": "plugins"},
sleep_threshold=5,
)
async def start(self):
if not os.path.isdir(DOWNLOAD_LOCATION): os.makedirs(DOWNLOAD_LOCATION)
await super().start()
me = await self.get_me()
self.username = '@' + me.username
LOGGER.info(f"{me.first_name} with for Pyrogram v{__version__} (Layer {layer}) started on {me.username}.")
if OWNER_ID != 0:
try:
await self.send_message(text="Karanlığın küllerinden yeniden doğdum.",
chat_id=OWNER_ID)
except Exception as t:
LOGGER.error(str(t))
async def stop(self, *args):
if OWNER_ID != 0:
texto = f"Son nefesimi verdim.\nÖldüğümde yaşım: {ReadableTime(time.time() - botStartTime)}"
try:
if SEND_LOGS_WHEN_DYING:
await self.send_document(document='log.txt', caption=texto, chat_id=OWNER_ID)
else:
await self.send_message(text=texto, chat_id=OWNER_ID)
except Exception as t:
LOGGER.warning(str(t))
await super().stop()
LOGGER.info(msg="App Stopped.")
exit()
app = Bot()
app.run()