This commit is contained in:
17
.gitea/workflows/deploy.yml
Normal file
17
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
name: deploy misc services
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: z420
|
||||
steps:
|
||||
- name: deploy
|
||||
run: |
|
||||
cd /home/sirian/services/misc
|
||||
git pull origin main
|
||||
docker compose build
|
||||
docker compose up -d --remove-orphans
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
secrets/bot_token.txt
|
||||
12
README.md
Normal file
12
README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Z420 Misc Stack
|
||||
|
||||
Miscellaneous services for z420.
|
||||
|
||||
## Services
|
||||
- Telegram Bot
|
||||
|
||||
## Setup
|
||||
|
||||
1. Copy bot token: `cp secrets/bot_token.txt.example secrets/bot_token.txt`
|
||||
2. Edit token
|
||||
3. Deploy: `docker compose up -d`
|
||||
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
services:
|
||||
telegram-bot:
|
||||
build: ./telegram_bot
|
||||
container_name: telegram-bot
|
||||
volumes:
|
||||
- /mnt/piratointi/tv_media/channel3:/app/media_folder
|
||||
secrets:
|
||||
- bot_token
|
||||
restart: unless-stopped
|
||||
|
||||
secrets:
|
||||
bot_token:
|
||||
file: ./secrets/bot_token.txt
|
||||
1
secrets/bot_token.txt.example
Normal file
1
secrets/bot_token.txt.example
Normal file
@@ -0,0 +1 @@
|
||||
place your token here
|
||||
8
telegram_bot/Dockerfile
Normal file
8
telegram_bot/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
RUN pip install --no-cache-dir python-telegram-bot
|
||||
|
||||
CMD ["python", "bot.py"]
|
||||
23
telegram_bot/bot.py
Normal file
23
telegram_bot/bot.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
from telegram import Update
|
||||
from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes
|
||||
|
||||
with open("/run/secrets/bot_token", 'r') as f:
|
||||
BOT_TOKEN = f.read().strip()
|
||||
|
||||
SAVE_FOLDER = "/app/media_folder"
|
||||
|
||||
async def media_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
if update.message.photo:
|
||||
file = await update.message.photo[-1].get_file()
|
||||
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.jpg")
|
||||
await file.download_to_drive(filename)
|
||||
elif update.message.video:
|
||||
file = await update.message.video.get_file()
|
||||
filename = os.path.join(SAVE_FOLDER, f"{file.file_unique_id}.mp4")
|
||||
await file.download_to_drive(filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = ApplicationBuilder().token(BOT_TOKEN).build()
|
||||
app.add_handler(MessageHandler(filters.PHOTO | filters.VIDEO, media_handler))
|
||||
app.run_polling()
|
||||
Reference in New Issue
Block a user