forked from DigitalBotz/Digital-Rename-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
157 lines (134 loc) · 6.54 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# (c) @RknDeveloperr
# Rkn Developer
# Don't Remove Credit 😔
# Telegram Channel @RknDeveloper & @Rkn_Botz
# Developer @RknDeveloperr
# Special Thanks To @ReshamOwner
# Update Channel @Digital_Botz & @DigitalBotz_Support
"""
Apache License 2.0
Copyright (c) 2022 @Digital_Botz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Telegram Link : https://t.me/Digital_Botz
Repo Link : https://github.com/DigitalBotz/Digital-Rename-Bot
License Link : https://github.com/DigitalBotz/Digital-Rename-Bot/blob/main/LICENSE
"""
# extra imports
import aiohttp, asyncio, warnings, pytz, datetime
import logging
import logging.config
import glob, sys, importlib, pyromod
from pathlib import Path
# pyrogram imports
import pyrogram.utils
from pyrogram import Client, __version__, errors
from pyrogram.raw.all import layer
# bots imports
from config import Config
from plugins.web_support import web_server
from plugins.file_rename import app
pyrogram.utils.MIN_CHANNEL_ID = -1009999999999
# 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("pyrogram").setLevel(logging.WARNING)
class DigitalRenameBot(Client):
def __init__(self):
super().__init__(
name="DigitalRenameBot",
api_id=Config.API_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN,
workers=200,
plugins={"root": "plugins"},
sleep_threshold=15)
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.log = logger
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ᴛᴀʀᴛᴇᴅ.....✨️")
for id in Config.ADMIN:
if Config.STRING_SESSION:
try: await self.send_message(id, f"𝟮𝗚𝗕+ ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\nNote: 𝐓𝐞𝐥𝐞𝐠𝐫𝐚𝐦 𝐩𝐫𝐞𝐦𝐢𝐮𝐦 𝐚𝐜𝐜𝐨𝐮𝐧𝐭 𝐬𝐭𝐫𝐢𝐧𝐠 𝐬𝐞𝐬𝐬𝐢𝐨𝐧 𝐫𝐞𝐪𝐮𝐢𝐫𝐞𝐝 𝐓𝐡𝐞𝐧 𝐬𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝟐𝐆𝐁+ 𝐟𝐢𝐥𝐞𝐬.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**")
except: pass
else:
try: await self.send_message(id, 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):
for id in Config.ADMIN:
try: await self.send_message(id, f"**Bot Stopped....**")
except: pass
print("Bot Stopped 🙄")
await super().stop()
bot_instance = DigitalRenameBot()
def main():
async def start_services():
if Config.STRING_SESSION:
await asyncio.gather(
app.start(), # Start the Pyrogram Client
bot_instance.start() # Start the bot instance
)
else:
await asyncio.gather(bot_instance.start()) # Start the bot instance
loop = asyncio.get_event_loop()
loop.run_until_complete(start_services())
loop.run_forever()
if __name__ == "__main__":
warnings.filterwarnings("ignore", message="There is no current event loop")
try:
main()
except errors.FloodWait as ft:
print(f"Flood Wait Occured, Sleeping For {ft}")
asyncio.sleep(ft.value)
print("Now Ready For Deploying !")
main()
# Rkn Developer
# Don't Remove Credit 😔
# Telegram Channel @RknDeveloper & @Rkn_Botz
# Developer @RknDeveloperr
# Update Channel @Digital_Botz & @DigitalBotz_Support