eee
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
__pycache__
|
||||
.env
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
# NoVA Furs Artists Suggestion Box Bot
|
||||
|
||||
Thank u [https://github.com/dzulldev/Menfess](https://github.com/dzulldev/Menfess)
|
||||
+11
@@ -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!")
|
||||
@@ -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()
|
||||
@@ -0,0 +1,2 @@
|
||||
python-telegram-bot==22.8
|
||||
python-dotenv==1.2.2
|
||||
@@ -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]
|
||||
Reference in New Issue
Block a user