Update bot.py
Browse files
bot.py
CHANGED
@@ -1,93 +1,36 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
from pyrogram import Client, types
|
4 |
-
from database.users_chats_db import db
|
5 |
-
from database.ia_filterdb import Media
|
6 |
-
from typing import Union, Optional, AsyncGenerator
|
7 |
-
from utils import temp, __repo__, __license__, __copyright__, __version__
|
8 |
-
from info import API_ID, API_HASH, BOT_TOKEN, LOG_CHANNEL, UPTIME, WEB_SUPPORT, LOG_MSG
|
9 |
-
import asyncio
|
10 |
-
import uvicorn
|
11 |
-
from fastapi_app import app as fastapi_app
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
super().__init__(
|
20 |
-
name="Professor-Bot",
|
21 |
-
api_id=API_ID,
|
22 |
-
api_hash=API_HASH,
|
23 |
-
bot_token=BOT_TOKEN,
|
24 |
-
plugins=dict(root="plugins")
|
25 |
-
)
|
26 |
-
logger.info("Bot initialized.")
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
temp.BANNED_CHATS = b_chats
|
33 |
-
logger.info("Banned users and chats loaded.")
|
34 |
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
self.name = me.first_name
|
46 |
-
self.mention = me.mention
|
47 |
-
self.username = me.username
|
48 |
-
self.log_channel = LOG_CHANNEL
|
49 |
-
self.uptime = UPTIME
|
50 |
-
curr = datetime.datetime.now(pytz.timezone("Asia/Kolkata"))
|
51 |
-
date = curr.strftime('%d %B, %Y')
|
52 |
-
tame = curr.strftime('%I:%M:%S %p')
|
53 |
-
log_message = LOG_MSG.format(me.first_name, date, tame, __repo__, __version__, __license__, __copyright__)
|
54 |
-
logger.info(log_message)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
logger.info("Log message sent to LOG_CHANNEL.")
|
59 |
-
except Exception as e:
|
60 |
-
logger.warning(f"Bot Isn't Able To Send Message To LOG_CHANNEL \n{e}")
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
await app.setup()
|
65 |
-
await web.TCPSite(app, "0.0.0.0", 8080).start()
|
66 |
-
logger.info("Web Response Is Running......🕸️")
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
async def stop(self, *args):
|
72 |
-
logger.info("Stopping bot...")
|
73 |
-
await super().stop()
|
74 |
-
logger.info(f"Bot Is Restarting ⟳...")
|
75 |
-
|
76 |
-
async def iter_messages(self, chat_id: Union[int, str], limit: int, offset: int = 0) -> Optional[AsyncGenerator["types.Message", None]]:
|
77 |
-
logger.info(f"Iterating messages in chat_id: {chat_id}, limit: {limit}, offset: {offset}")
|
78 |
-
current = offset
|
79 |
-
while True:
|
80 |
-
new_diff = min(200, limit - current)
|
81 |
-
if new_diff <= 0:
|
82 |
-
logger.info("No more messages to iterate.")
|
83 |
-
return
|
84 |
-
messages = await self.get_messages(chat_id, list(range(current, current+new_diff+1)))
|
85 |
-
logger.info(f"Retrieved {len(messages)} messages.")
|
86 |
-
for message in messages:
|
87 |
-
yield message
|
88 |
-
current += 1
|
89 |
-
logger.info(f"Yielding message with ID: {message.id}")
|
90 |
-
|
91 |
-
if __name__ == "__main__":
|
92 |
-
bot = Bot()
|
93 |
-
asyncio.run(bot.start())
|
|
|
1 |
+
# Dockerfile
|
2 |
+
FROM python:3.10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Create a non-root user with valid username format
|
5 |
+
RUN adduser --disabled-password --gecos '' professor && \
|
6 |
+
mkdir -p /app && \
|
7 |
+
chown -R professor:professor /app
|
8 |
|
9 |
+
# Install system dependencies
|
10 |
+
RUN apt-get update && apt-get upgrade -y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Copy requirements and install
|
13 |
+
COPY requirements.txt /requirements.txt
|
14 |
+
RUN pip install --upgrade pip && \
|
15 |
+
pip install -r /requirements.txt
|
|
|
|
|
16 |
|
17 |
+
# Switch to non-root user
|
18 |
+
USER professor
|
19 |
+
WORKDIR /app
|
20 |
|
21 |
+
# Copy application files
|
22 |
+
COPY --chown=professor:professor . .
|
23 |
|
24 |
+
# Set environment variables
|
25 |
+
ENV LOG_PATH=/app/BotLog.txt
|
26 |
+
ENV UVICORN_HOST=0.0.0.0
|
27 |
+
ENV UVICORN_PORT=8000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# Ensure the log file is writable
|
30 |
+
RUN touch $LOG_PATH && chmod 666 $LOG_PATH
|
|
|
|
|
|
|
31 |
|
32 |
+
# Expose port for FastAPI
|
33 |
+
EXPOSE 8000
|
|
|
|
|
|
|
34 |
|
35 |
+
# Start the FastAPI app
|
36 |
+
CMD ["uvicorn", "fastapi_app:app", "--host", "$UVICORN_HOST", "--port", "$UVICORN_PORT", "--log-level", "info"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|