Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,9 +13,9 @@ logger = logging.getLogger(__name__)
|
|
| 13 |
API_ID = 29988110
|
| 14 |
API_HASH = "a524f28572523984696d1d3a95d0d6ae"
|
| 15 |
# Use environment variable for session string if available, otherwise fallback to the hardcoded one
|
| 16 |
-
SESSION_STRING = os.environ.get("SESSION_STRING")
|
| 17 |
|
| 18 |
-
WORKER_URL = "https://
|
| 19 |
|
| 20 |
# Initialize the Telethon client
|
| 21 |
client = TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH)
|
|
@@ -36,16 +36,18 @@ async def forward_to_worker(payload: dict):
|
|
| 36 |
return None
|
| 37 |
|
| 38 |
BOT_STATE = True # Default is ON
|
|
|
|
| 39 |
|
| 40 |
@client.on(events.NewMessage)
|
| 41 |
async def handle_new_message(event):
|
| 42 |
"""
|
| 43 |
Handles routing of messages:
|
| 44 |
- /bot on and /bot off commands to control AI state.
|
|
|
|
| 45 |
- Forwards outgoing commands to worker.
|
| 46 |
- Forwards incoming PMs/mentions to worker if AI is ON.
|
| 47 |
"""
|
| 48 |
-
global BOT_STATE
|
| 49 |
text = event.message.message
|
| 50 |
|
| 51 |
if not text:
|
|
@@ -64,6 +66,14 @@ async def handle_new_message(event):
|
|
| 64 |
BOT_STATE = False
|
| 65 |
await event.reply("🛑 **Userbot AI Mode: OFF**\nAI is paused. You can reply manually. (Commands still work)")
|
| 66 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
elif lower_text.startswith('/broadcast'):
|
| 68 |
broadcast_msg = text[10:].strip()
|
| 69 |
if not broadcast_msg:
|
|
@@ -97,8 +107,10 @@ async def handle_new_message(event):
|
|
| 97 |
if is_command:
|
| 98 |
should_forward = True
|
| 99 |
else:
|
| 100 |
-
# For incoming messages,
|
| 101 |
-
if
|
|
|
|
|
|
|
| 102 |
if event.is_private or event.mentioned:
|
| 103 |
should_forward = True
|
| 104 |
|
|
|
|
| 13 |
API_ID = 29988110
|
| 14 |
API_HASH = "a524f28572523984696d1d3a95d0d6ae"
|
| 15 |
# Use environment variable for session string if available, otherwise fallback to the hardcoded one
|
| 16 |
+
SESSION_STRING = os.environ.get("SESSION_STRING", "1BVtsOJMBu3q-X4DctbZDC3qTnBwJmu7h3JMcnKeoJgJ42rIhGDDlAE9t72Bq9_QcUN5ySo91VpfCVd4uExaS_j5BoFhGCBPulf5PnEpBB0pL1rjYq38esDooBbCYM2JZFAmdwWvyBRcxcn2DQG0CXBGsr4v8X82stRrxUifbtsJ9lLHkQxPM42EW42xGrjV5PECd60V-A2O1P_6XwUIrqQQ6qG_-JV0MdlOunbPnCuK6GqbH8nTeWYLxA40OgCXVqGisJ8xB5JcoG9aRTfYa_QSWIivdZHsWj8cNY1lLFvr9eSRT022xGgIIQ1LURBmZi06rWzprlZ6HoLapm7jME6EBGcAaWNM=")
|
| 17 |
|
| 18 |
+
WORKER_URL = "https://yuya.nmsgpt.workers.dev/"
|
| 19 |
|
| 20 |
# Initialize the Telethon client
|
| 21 |
client = TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH)
|
|
|
|
| 36 |
return None
|
| 37 |
|
| 38 |
BOT_STATE = True # Default is ON
|
| 39 |
+
NMS_STATE = False # Default is OFF
|
| 40 |
|
| 41 |
@client.on(events.NewMessage)
|
| 42 |
async def handle_new_message(event):
|
| 43 |
"""
|
| 44 |
Handles routing of messages:
|
| 45 |
- /bot on and /bot off commands to control AI state.
|
| 46 |
+
- /nms on and /nms off to reply to every message.
|
| 47 |
- Forwards outgoing commands to worker.
|
| 48 |
- Forwards incoming PMs/mentions to worker if AI is ON.
|
| 49 |
"""
|
| 50 |
+
global BOT_STATE, NMS_STATE
|
| 51 |
text = event.message.message
|
| 52 |
|
| 53 |
if not text:
|
|
|
|
| 66 |
BOT_STATE = False
|
| 67 |
await event.reply("🛑 **Userbot AI Mode: OFF**\nAI is paused. You can reply manually. (Commands still work)")
|
| 68 |
return
|
| 69 |
+
elif lower_text == '/nms on':
|
| 70 |
+
NMS_STATE = True
|
| 71 |
+
await event.reply("✅ **NMS Auto-Reply Mode: ON**\nAI will now reply to EVERY incoming message.")
|
| 72 |
+
return
|
| 73 |
+
elif lower_text == '/nms off':
|
| 74 |
+
NMS_STATE = False
|
| 75 |
+
await event.reply("🛑 **NMS Auto-Reply Mode: OFF**\nAI stopped replying to every message.")
|
| 76 |
+
return
|
| 77 |
elif lower_text.startswith('/broadcast'):
|
| 78 |
broadcast_msg = text[10:].strip()
|
| 79 |
if not broadcast_msg:
|
|
|
|
| 107 |
if is_command:
|
| 108 |
should_forward = True
|
| 109 |
else:
|
| 110 |
+
# For incoming messages, check NMS_STATE first, then BOT_STATE
|
| 111 |
+
if NMS_STATE:
|
| 112 |
+
should_forward = True
|
| 113 |
+
elif BOT_STATE:
|
| 114 |
if event.is_private or event.mentioned:
|
| 115 |
should_forward = True
|
| 116 |
|