-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (83 loc) · 3.37 KB
/
main.py
File metadata and controls
102 lines (83 loc) · 3.37 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
import time
import logging
import asyncio
import config
from pyrogram import Client, idle
from pyromod import listen
from pyrogram.errors import (
ApiIdInvalid,
ApiIdPublishedFlood,
AccessTokenInvalid,
)
# ──────────────────────────────────────
# Logging Configuration
# ──────────────────────────────────────
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
)
# Reduce Mongo noise
logging.getLogger("pymongo").setLevel(logging.WARNING)
LOGGER = logging.getLogger("BadStringBot")
# ──────────────────────────────────────
# Start Time
# ──────────────────────────────────────
START_TIME = time.time()
# ──────────────────────────────────────
# Pyrogram Client
# ──────────────────────────────────────
app = Client(
name="BadStringBot",
api_id=config.API_ID,
api_hash=config.API_HASH,
bot_token=config.BOT_TOKEN,
in_memory=True,
plugins=dict(root="Bad"), # plugins folder
)
# ──────────────────────────────────────
# Main Runner
# ──────────────────────────────────────
def main():
LOGGER.info("🚀 Bad String Session Manager starting...")
try:
app.start()
except ApiIdInvalid:
LOGGER.error("❌ Invalid API_ID")
raise SystemExit(1)
except ApiIdPublishedFlood:
LOGGER.error("❌ API_ID / API_HASH flood banned")
raise SystemExit(1)
except AccessTokenInvalid:
LOGGER.error("❌ Invalid BOT_TOKEN")
raise SystemExit(1)
except Exception as e:
LOGGER.exception(f"❌ Unexpected error while starting bot: {e}")
raise SystemExit(1)
# Bot info
me = app.get_me()
LOGGER.info(f"✅ Bot started successfully: @{me.username}")
LOGGER.info("⚙️ Features enabled: String Generation + Session Utilities")
# Send "I am alive" message to LOGGER_ID
try:
app.send_message(
config.LOGGER_ID,
f"**✅ ʙᴏᴛ sᴛᴀʀᴛᴇᴅ sᴜᴄᴄᴇssғᴜʟʟʏ!**\n\n"
f"**ʙᴏᴛ :** @{me.username}\n"
f"**ɴᴀᴍᴇ :** {me.first_name}\n"
f"**ɪᴅ :** `{me.id}`\n"
f"**sᴛᴀᴛᴜs :** ɪ ᴀᴍ ᴀʟɪᴠᴇ 🏴☠️"
)
LOGGER.info(f"✅ Alive message sent to LOGGER_ID: {config.LOGGER_ID}")
except Exception as e:
LOGGER.exception("❌ Failed to send alive message")
# Idle (keep alive)
idle()
# Shutdown
LOGGER.info("🛑 Stopping bot...")
app.stop()
LOGGER.info("✅ Bot stopped cleanly")
# ──────────────────────────────────────
# Entry Point
# ──────────────────────────────────────
if __name__ == "__main__":
main()