From 4682bc7fc808fe66986b5e0439c2ab97c4274b66 Mon Sep 17 00:00:00 2001 From: Kairo Date: Fri, 26 Jun 2026 20:58:19 -0400 Subject: [PATCH] eee --- .gitignore | 2 ++ Dockerfile | 8 ++++++++ README.md | 3 +++ commands.py | 11 +++++++++++ main.py | 41 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ utils.py | 30 ++++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 commands.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 utils.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..112f331 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..062ac94 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.11-slim +WORKDIR /app +RUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y git +# ?? +RUN git clone https://git.jackrabbits.gay/merrin/NFASBB.git NFASBB +COPY . . +CMD pip install --no-cache-dir -r NFASBB/requirements.txt && python NFASBB/main.py \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..024a424 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# NoVA Furs Artists Suggestion Box Bot + +Thank u [https://github.com/dzulldev/Menfess](https://github.com/dzulldev/Menfess) \ No newline at end of file diff --git a/commands.py b/commands.py new file mode 100644 index 0000000..71cf109 --- /dev/null +++ b/commands.py @@ -0,0 +1,11 @@ +from telegram import Update + + +async def start(update: Update, _): + await update.message.reply_text( + "Hi! Send your message and it will be posted anonymously." + ) + + +async def healthcheck(update: Update, _): + await update.message.reply_text("NFASBB Bot Healthy!") diff --git a/main.py b/main.py new file mode 100644 index 0000000..0fb749f --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +from telegram import Update +from telegram.ext import ( + Application, + CommandHandler, + MessageHandler, + filters, + ContextTypes, +) +import os +from dotenv import load_dotenv +from utils import get_hashed_id, user_is_limited +from commands import start, healthcheck + +load_dotenv() +TOKEN = os.getenv("BOT_TOKEN") +CHANNEL_ID = int(os.getenv("CHANNEL_ID")) + + +async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): + user_id = str(update.effective_user.id) + hashed_id = get_hashed_id(user_id) + if user_is_limited(hashed_id): + await update.message.reply_text("You are timed out. Please try again later.") + return + + message = update.message.text.strip() + await context.bot.send_message(chat_id=CHANNEL_ID, text=message) + await update.message.reply_text("Your message has been posted!") + + +def main(): + app = Application.builder().token(TOKEN).build() + app.add_handler(CommandHandler("start", start)) + app.add_handler(CommandHandler("health", healthcheck)) + app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) + print("Bot is running!") + app.run_polling() + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..eec582d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +python-telegram-bot==22.8 +python-dotenv==1.2.2 \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..12b5f71 --- /dev/null +++ b/utils.py @@ -0,0 +1,30 @@ +from collections import defaultdict +import time +import os +from dotenv import load_dotenv +import hashlib + +load_dotenv() +MAX_REQUESTS_PER_HOUR = int(os.getenv("MAX_REQUESTS_PER_HOUR")) +user_requests = defaultdict(list) + + +def user_is_limited(hashed_id: str) -> bool: + current_time = time.time() + + # Prune old requests (older than 1 hour) + user_requests[hashed_id] = [ + ts for ts in user_requests[hashed_id] if current_time - ts < 3600 + ] + + if len(user_requests[hashed_id]) >= MAX_REQUESTS_PER_HOUR: + return True + + user_requests[hashed_id].append(current_time) + return False + + +def get_hashed_id(user_id: str) -> str: + daily_date = time.strftime("%Y-%m-%d") + combined = f"{user_id}{daily_date}" + return hashlib.sha256(combined.encode()).hexdigest()[:16]