forked from hydrix777/ShortenerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
73 lines (63 loc) · 2.36 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# HuzunluArtemis - 2021 (Licensed under GPL-v3)
import logging
from config import Config
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
import logging, os, time
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__)
def ReadableTime(seconds: int) -> str:
result = ''
(days, remainder) = divmod(seconds, 86400)
days = int(days)
if days != 0:
result += f'{days}d'
(hours, remainder) = divmod(remainder, 3600)
hours = int(hours)
if hours != 0:
result += f'{hours}h'
(minutes, seconds) = divmod(remainder, 60)
minutes = int(minutes)
if minutes != 0:
result += f'{minutes}m'
seconds = int(seconds)
result += f'{seconds}s'
return result
class Bot(Client):
def __init__(self):
super().__init__(
session_name='ShortenerBot',
api_id=Config.APP_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN,
workers=343,
plugins={"root": "plugins"},
sleep_threshold=5,
)
async def start(self):
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 Config.OWNER_ID != 0:
try:
await self.send_message(
text= "🇬🇧 i reborn from the ashes of darkness\n🇹🇷 karanlığın küllerinden yeniden doğdum",
chat_id=Config.OWNER_ID)
except Exception as t:
LOGGER.error(str(t))
async def stop(self, *args):
if Config.OWNER_ID != 0:
texto = f"🇬🇧 I took my last breath.\nthe age i died: {ReadableTime(time.time() - Config.botStartTime)}" + \
f"\n\n🇹🇷 son nefesimi verdim.\nöldüğümde yaşım: {ReadableTime(time.time() - Config.botStartTime)}"
try:
await self.send_message(text= texto,chat_id=Config.OWNER_ID)
except Exception as t:
LOGGER.warning(str(t))
await super().stop()
LOGGER.info(msg="App Stopped.")
exit()
app = Bot()
app.run()