forked from s4m33r89/NeonFilter-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
130 lines (110 loc) ยท 4.32 KB
/
bot.py
File metadata and controls
130 lines (110 loc) ยท 4.32 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
130
import sys, glob, importlib, logging, logging.config, pytz, asyncio
from pathlib import Path
# Get logging configurations
logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("pyrogram").setLevel(logging.ERROR)
logging.getLogger("cinemagoer").setLevel(logging.ERROR)
from pyrogram import Client, idle
from database.users_chats_db import db
from info import *
from utils import temp
from typing import Union, Optional, AsyncGenerator
from Script import script
from datetime import date, datetime
from aiohttp import web
from plugins import web_server
from plugins.clone import restart_bots
from Neon.bot import NeonBot
from Neon.util.keepalive import ping_server
from Neon.bot.clients import initialize_clients
# ------------------- Added Keep-Alive Function -------------------
from info import KEEP_ALIVE_URL
import aiohttp
async def keep_alive():
"""Send a request every 300 seconds to keep the bot alive (if required)."""
async with aiohttp.ClientSession() as session:
while True:
try:
await session.get(KEEP_ALIVE_URL)
logging.info("Sent keep-alive request.")
except Exception as e:
logging.error(f"Keep-alive request failed: {e}")
await asyncio.sleep(300)
# ----------------------------------------------------------------
# ------------------- Updated plugin loader -------------------
def get_all_plugin_files(root="plugins"):
"""
Recursively get all .py files in the plugins folder and subfolders.
"""
files = []
for path in Path(root).rglob("*.py"):
if path.name != "__init__.py": # skip __init__.py
files.append(path)
return files
files = get_all_plugin_files()
# -------------------------------------------------------------
NeonBot.start()
loop = asyncio.get_event_loop()
async def start():
print('\n')
print('Initalizing Your Bot')
bot_info = await NeonBot.get_me()
await initialize_clients()
# ------------------- Import plugins -------------------
for plugin_path in files:
plugin_name = plugin_path.stem
import_path = ".".join(plugin_path.with_suffix("").parts) # convert path to module path
spec = importlib.util.spec_from_file_location(import_path, plugin_path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
sys.modules[import_path] = mod
print(f"โจ Neon Imported => {plugin_name}")
# -------------------------------------------------------
if ON_HEROKU:
asyncio.create_task(ping_server())
# Start keep-alive if KEEP_ALIVE_URL is defined
if KEEP_ALIVE_URL:
asyncio.create_task(keep_alive())
b_users, b_chats = await db.get_banned()
temp.BANNED_USERS = b_users
temp.BANNED_CHATS = b_chats
me = await NeonBot.get_me()
temp.BOT = NeonBot
temp.ME = me.id
temp.U_NAME = me.username
temp.B_NAME = me.first_name
logging.info(script.LOGO)
tz = pytz.timezone('Asia/Kolkata')
today = date.today()
now = datetime.now(tz)
time = now.strftime("%H:%M:%S %p")
try:
await NeonBot.send_message(chat_id=LOG_CHANNEL, text=script.RESTART_TXT.format(today, time))
except:
print("Make Your Bot Admin In Log Channel With Full Rights")
for ch in CHANNELS:
try:
k = await NeonBot.send_message(chat_id=ch, text="**Bot Restarted**")
await k.delete()
except:
print("Make Your Bot Admin In File Channels With Full Rights")
try:
k = await NeonBot.send_message(chat_id=AUTH_CHANNEL, text="**Bot Restarted**")
await k.delete()
except:
print("Make Your Bot Admin In Force Subscribe Channel With Full Rights")
if CLONE_MODE == True:
print("Restarting All Clone Bots.......")
await restart_bots()
print("Restarted All Clone Bots.")
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await web.TCPSite(app, bind_address, PORT).start()
await idle()
if __name__ == '__main__':
try:
loop.run_until_complete(start())
except KeyboardInterrupt:
logging.info('Service Stopped Bye ๐')