Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ============ TELEGRAM BOT CONFIGURATION ============
# Get BOT_TOKEN from @BotFather on Telegram
BOT_TOKEN=your_bot_token_from_botfather

# Get API_ID and API_HASH from https://my.telegram.org/apps
API_ID=123456789
API_HASH=your_api_hash_here

# Optional: Userbot session string (generated via str_gen.py)
# Leave empty to use phone_number authentication instead
SESSION_STRING=

# Optional: Phone number for userbot (if SESSION_STRING is empty)
PHONE_NUMBER=+1234567890

# ============ USER & PERMISSIONS ============
# Space-separated list of Telegram user IDs with sudo (full) access
SUDO_USERS_ID=123456789 987654321

# Userbot command prefix (default: backslash)
USERBOT_PREFIX=\

# ============ LOGGING & NOTIFICATIONS ============
# Telegram group ID for bot logs (must be negative: -100...)
LOG_GROUP_ID=-1001234567890

# Telegram group ID for global ban notifications (negative)
GBAN_LOG_GROUP_ID=-1009876543210

# Telegram chat ID for message dumps/archives (negative)
MESSAGE_DUMP_CHAT=-1005555555555

# ============ DATABASE CONFIGURATION ============
# PostgreSQL connection string (replaces MongoDB)
# Format: postgresql://username:password@host:port/database
# For local development: postgresql://postgres:password@localhost/wbb
DATABASE_URL=postgresql://user:password@localhost/wbb

# ============ EXTERNAL SERVICES ============
# ARQ (Async Request Queue) API endpoint
ARQ_API_URL=https://arq.hamker.dev

# Anthropic API key
ANTHROPIC_API_KEY=your_anthropic_api_key

# ============ BOT FEATURES & SETTINGS ============
# Welcome message auto-kick delay in seconds (default: 300)
WELCOME_DELAY_KICK_SEC=300

# Enable mention logging (0/1 or true/false)
LOG_MENTIONS=0

# RSS feed check interval in seconds (default: 300)
RSS_DELAY=300

# Enable PM permit system (0/1 or true/false, default: 1)
PM_PERMIT=1

# ============ APPLICATION SETTINGS ============
# Application timezone (default: Asia/Amman)
# See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TZ=Asia/Amman

# Maximum concurrent tasks (default: 2)
MAX_CONCURRENT_TASKS=2

# Logging level (true/false, enables verbose logging)
LOG_LEVEL=true

# Python output buffering (1 = unbuffered, required for Railway)
PYTHONUNBUFFERED=1
31 changes: 31 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
modules = ["python-3.12", "nix"]
[agent]
expertMode = true
stack = "BEST_EFFORT_FALLBACK"

[nix]
channel = "stable-25_05"
packages = ["cacert", "cargo", "exiftool", "ffmpeg-full", "freetype", "ghostscript", "imagemagickBig", "lcms2", "libiconv", "libimagequant", "libjpeg", "libtiff", "libuv", "libwebp", "libxcrypt", "mupdf", "netpbm", "openjpeg", "openssl", "pkg-config", "poppler_utils", "postgresql", "rustc", "tcl", "tk", "zlib"]

[workflows]
runButton = "Project"

[[workflows.workflow]]
name = "Project"
mode = "parallel"
author = "agent"

[[workflows.workflow.tasks]]
task = "workflow.run"
args = "Start application"

[[workflows.workflow]]
name = "Start application"
author = "agent"

[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python -m wbb"

[workflows.workflow.metadata]
outputType = "console"
31 changes: 21 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,44 @@ FROM python:3.12-slim-bullseye AS base

WORKDIR /wbb

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONDONTWRITEBYTECODE=1

# install required system dependencies for python packages
# Install system dependencies
RUN apt-get update -y && apt-get install -y --no-install-recommends \
curl ca-certificates \
git gcc build-essential \
curl \
ca-certificates \
git \
gcc \
build-essential \
iputils-ping \
&& rm -rf /var/lib/apt/lists/*

# install uv
# Install uv package manager
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh

ENV PATH="/root/.local/bin/:$PATH"

COPY .python-version .
COPY pyproject.toml .
COPY uv.lock .

# ============= PRODUCTION STAGE =============
FROM base
FROM base AS production

ENV UV_NO_DEV=1
RUN uv sync

# Install dependencies without dev packages
RUN uv sync --no-dev

# Copy application code
COPY . .

# Starting Bot
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import asyncio; from wbb import log; log.info('Health check passed')" || exit 1

# Start bot
ENTRYPOINT ["uv", "run", "python", "-m", "wbb"]
53 changes: 51 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
version: '3.8'

services:
postgres:
image: postgres:15-alpine
container_name: wbb-postgres
environment:
POSTGRES_USER: wbb_user
POSTGRES_PASSWORD: wbb_password
POSTGRES_DB: wbb
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=en_US.UTF-8"
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U wbb_user -d wbb"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped

wbb:
build: .
restart: always
container_name: williambutcherbot
environment:
- PYTHONUNBUFFERED=1
PYTHONUNBUFFERED: 1
TZ: Asia/Amman
DATABASE_URL: postgresql://wbb_user:wbb_password@postgres:5432/wbb
BOT_TOKEN: ${BOT_TOKEN}
API_ID: ${API_ID}
API_HASH: ${API_HASH}
SESSION_STRING: ${SESSION_STRING:-}
PHONE_NUMBER: ${PHONE_NUMBER:-}
SUDO_USERS_ID: ${SUDO_USERS_ID}
LOG_GROUP_ID: ${LOG_GROUP_ID}
GBAN_LOG_GROUP_ID: ${GBAN_LOG_GROUP_ID}
MESSAGE_DUMP_CHAT: ${MESSAGE_DUMP_CHAT}
ARQ_API_URL: ${ARQ_API_URL:-https://arq.hamker.dev}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
WELCOME_DELAY_KICK_SEC: ${WELCOME_DELAY_KICK_SEC:-300}
LOG_MENTIONS: ${LOG_MENTIONS:-0}
RSS_DELAY: ${RSS_DELAY:-300}
PM_PERMIT: ${PM_PERMIT:-1}
MAX_CONCURRENT_TASKS: ${MAX_CONCURRENT_TASKS:-2}
LOG_LEVEL: ${LOG_LEVEL:-false}
volumes:
- ./sessions:/wbb/sessions
- ./logs:/wbb/logs
depends_on:
postgres:
condition: service_healthy
restart: unless-stopped

volumes:
postgres_data:
driver: local
8 changes: 8 additions & 0 deletions nixpacks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[phases.setup]
nixPkgs = ["python312", "uv", "ffmpeg", "gcc", "curl", "git", "zip", "postgresql_15"]

[phases.install]
cmds = ["uv sync --no-dev --frozen"]

[start]
cmd = "uv run python -m wbb"
49 changes: 30 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
[project]
name = "williambutcherbot"
version = "0.1.0"
version = "0.2.0"
description = "A Telegram Bot for group management and more."
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
# ============ CORE TELEGRAM ============
"pyrogram>=2.0.0", # FIXED: Was missing
"tgcrypto~=1.2.5",
"pyromod~=3.1.6",
"kurigram==2.2.12",
# ============ DATABASE (PostgreSQL) ============
"asyncpg>=0.29.0", # NEW: PostgreSQL async driver (replaces motor)
# Note: Removed 'motor' dependency
# ============ ASYNC & HTTP ============
"aiohttp~=3.13.3",
"aiofiles~=23.2.1",
"uvloop~=0.19.0",
# ============ MEDIA & PROCESSING ============
"ffmpeg-python~=0.2.0",
"gTTS~=2.5.1",
"dnspython==2.1.0",
"gtts~=2.5.1",
"pillow>=10.0.0", # Updated version
"img2pdf~=0.5.1",
"yt-dlp>=2024.1.0", # FIXED: Replaced deprecated youtube_dl
# ============ TRANSLATION & SEARCH ============
"google-trans-new>=1.1.9", # FIXED: Replaced googletrans RC version
"search-engine-parser~=0.6.8",
# ============ UTILITIES ============
"future~=1.0.0",
"googletrans~=4.0.0rc1",
"motor~=3.6",
"pillow",
"psutil~=5.9.8",
"pykeyboard~=0.1.5",
"python-arq~=6.0.7",
"requests~=2.32.4",
"search-engine-parser~=0.6.8",
"psutil>=5.9.0", # Updated version
"pytz~=2024.1",
"speedtest-cli~=2.1.3",
"TgCrypto~=1.2.5",
"uvloop~=0.19.0",
"youtube_dl~=2021.12.17",
"bs4~=0.0.2",
"python-dotenv~=1.0.1",
"beautifulsoup4>=4.12.0", # FIXED: Replaced bs4 meta package
"feedparser~=6.0.11",
"pyromod~=3.1.6",
"fuzzysearch~=0.7.3",
"img2pdf~=0.5.1",
"python-dotenv~=1.0.1",
"cryptography>=42.0.0",
# ============ TASK QUEUE ============
"python-arq~=6.0.7",
# ============ MISC ============
"pykeyboard~=0.1.5",
"telegraph~=2.2.0",
"pytube~=15.0.0",
"pytz~=2024.1",
"kurigram==2.2.12",
"dnspython>=2.4.0", # FIXED: Updated from pinned 2.1.0
]

[dependency-groups]
Expand Down
7 changes: 7 additions & 0 deletions railway.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
builder = "nixpacks"

[deploy]
startCommand = "uv run python -m wbb"
restartPolicyType = "on_failure"
restartPolicyMaxRetries = 10
5 changes: 5 additions & 0 deletions replit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{pkgs}: {
deps = [
pkgs.ffmpeg
];
}
77 changes: 77 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# ============ CORE TELEGRAM ============
pyrogram>=2.0.0
TgCrypto>=1.2.5
pyromod>=3.1.6
kurigram==2.2.12

# ============ DATABASE (PostgreSQL) ============
asyncpg>=0.29.0

# ============ ASYNC & HTTP ============
aiohttp>=3.9.0
aiofiles>=23.2.1
uvloop>=0.19.0

# ============ MEDIA & PROCESSING ============
ffmpeg-python>=0.2.0
gTTS>=2.5.0
Pillow>=10.0.0
img2pdf>=0.5.1
yt-dlp>=2024.1.0

# ============ TRANSLATION & SEARCH ============
google-trans-new>=1.1.9
search-engine-parser>=0.6.8

# ============ UTILITIES ============
future>=1.0.0
requests>=2.32.0
psutil>=5.9.0
pytz>=2024.1
speedtest-cli>=2.1.3
beautifulsoup4>=4.12.0
feedparser>=6.0.11
fuzzysearch>=0.7.3
python-dotenv>=1.0.1
cryptography>=42.0.0

# ============ ARQ / TASK QUEUE ============
python-arq>=6.0.7

# ============ MISC ============
pykeyboard>=0.1.5
telegraph>=2.2.0
pytube>=15.0.0
dnspython>=2.4.0
cryptography>=42.0.0
google-trans-new>=1.1.9
aiofiles
aiohttp
asyncpg
beautifulsoup4
cryptography
dnspython
feedparser
ffmpeg-python
future
fuzzysearch
google-trans-new
gTTS
img2pdf
kurigram
Pillow
psutil
pykeyboard
pyrogram
pyromod
python-dotenv
python-arq
pytube
pytz
requests
search-engine-parser
speedtest-cli
telegraph
tgcrypto
uvloop
yt-dlp
Loading