-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathbot.py
More file actions
129 lines (110 loc) · 5.15 KB
/
bot.py
File metadata and controls
129 lines (110 loc) · 5.15 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import aiohttp, asyncio, warnings, pytz, datetime
import logging
import logging.config
import glob, sys
import importlib.util
from pathlib import Path
from pyrogram import Client, __version__, errors
from pyrogram.raw.all import layer
from pyrogram import idle
from config import Config
from plugins.web_support import web_server
from plugins.file_rename import app
# Get logging configurations
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[logging.FileHandler('BotLog.txt'),
logging.StreamHandler()]
)
#logger = logging.getLogger(__name__)
logging.getLogger("pyrofork").setLevel(logging.WARNING)
class TechifyBots(Client):
def __init__(self):
super().__init__(
name="RenameBot",
api_id=Config.API_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN,
workers=200,
plugins={"root": "plugins"},
sleep_threshold=5,
max_concurrent_transmissions=50
)
async def start(self):
await super().start()
me = await self.get_me()
self.mention = me.mention
self.username = me.username
self.uptime = Config.BOT_UPTIME
self.premium = Config.PREMIUM_MODE
self.uploadlimit = Config.UPLOAD_LIMIT_MODE
Config.BOT = self
app = aiohttp.web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await aiohttp.web.TCPSite(app, bind_address, Config.PORT).start()
path = "plugins/*.py"
files = glob.glob(path)
for name in files:
with open(name) as a:
patt = Path(a.name)
plugin_name = patt.stem.replace(".py", "")
plugins_path = Path(f"plugins/{plugin_name}.py")
import_path = "plugins.{}".format(plugin_name)
spec = importlib.util.spec_from_file_location(import_path, plugins_path)
load = importlib.util.module_from_spec(spec)
spec.loader.exec_module(load)
sys.modules["plugins" + plugin_name] = load
print("Digital Botz Imported " + plugin_name)
print(f"{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️")
if Config.ADMIN:
if Config.STRING_SESSION:
try: await self.send_message(Config.ADMIN, f"𝟮𝗚𝗕+ ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\nNote: 𝐓𝐞𝐥𝐞𝐠𝐫𝐚𝐦 𝐩𝐫𝐞𝐦𝐢𝐮𝐦 𝐚𝐜𝐜𝐨𝐮𝐧𝐭 𝐬𝐭𝐫𝐢𝐧𝐠 𝐬𝐞𝐬𝐬𝐢𝐨𝐧 𝐫𝐞𝐪𝐮𝐢𝐫𝐞𝐝 𝐓𝐡𝐞𝐧 𝐬𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝟐𝐆𝐁+ 𝐟𝐢𝐥𝐞𝐬.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**")
except: pass
else:
try: await self.send_message(Config.ADMIN, f"𝟮𝗚𝗕- ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**")
except: pass
if Config.LOG_CHANNEL:
try:
curr = datetime.datetime.now(pytz.timezone("Asia/Kolkata"))
date = curr.strftime('%d %B, %Y')
time = curr.strftime('%I:%M:%S %p')
await self.send_message(Config.LOG_CHANNEL, f"**__{me.mention} Iꜱ Rᴇsᴛᴀʀᴛᴇᴅ !!**\n\n📅 Dᴀᴛᴇ : `{date}`\n⏰ Tɪᴍᴇ : `{time}`\n🌐 Tɪᴍᴇᴢᴏɴᴇ : `Asia/Kolkata`\n\n🉐 Vᴇʀsɪᴏɴ : `v{__version__} (Layer {layer})`</b>")
except:
print("Pʟᴇᴀꜱᴇ Mᴀᴋᴇ Tʜɪꜱ Iꜱ Aᴅᴍɪɴ Iɴ Yᴏᴜʀ Lᴏɢ Cʜᴀɴɴᴇʟ")
async def stop(self, *args):
if Config.ADMIN:
try: await self.send_message(Config.ADMIN, f"**Bot Stopped....**")
except: pass
print("Bot Stopped 🙄")
await super().stop()
tb = TechifyBots()
def main():
async def start_services():
if Config.STRING_SESSION:
await asyncio.gather(app.start(), tb.start())
else:
await asyncio.gather(tb.start())
# Idle mode start karo
await idle()
# Bot stop karo
if Config.STRING_SESSION:
await asyncio.gather(app.stop(), tb.stop())
else:
await asyncio.gather(tb.stop())
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
print("\n🛑 Bot stopped by user!")
finally:
loop.close()
if __name__ == "__main__":
warnings.filterwarnings("ignore", message="There is no current event loop")
try:
main()
except errors.FloodWait as ft:
print(f"⏳ FloodWait: Sleeping for {ft.value} seconds")
asyncio.run(asyncio.sleep(ft.value))
print("Now Ready For Deploying!")
main()