├── .gitignore ├── Dockerfile ├── README.md ├── fabfile.py ├── powerbot ├── __init__.py ├── app.py └── handlers │ ├── __init__.py │ ├── new_members_handler.py │ ├── start_handler.py │ └── sticker_document_handler.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | *.pyc 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3 2 | 3 | WORKDIR /app 4 | 5 | COPY requirements.txt ./ 6 | RUN pip install --no-cache-dir -r requirements.txt 7 | COPY . /app 8 | 9 | CMD [ "python", "powerbot/app.py" ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # powerbot 2 | 3 | 4 | ## Build image 5 | 6 | fab build 7 | 8 | ## Run Powerbot 9 | 10 | docker run -ti --env 'TELEGRAM_TOKEN=XXXX' --env 'ADMIN=YYYY' powerbot 11 | -------------------------------------------------------------------------------- /fabfile.py: -------------------------------------------------------------------------------- 1 | from fabric.api import * 2 | from fabric.context_managers import shell_env 3 | 4 | def build(): 5 | local('docker build -t powerbot .') 6 | -------------------------------------------------------------------------------- /powerbot/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tualatrix/powerbot/e14b02f6772c0cc8afe1c6fa8e006a473d3bb5d2/powerbot/__init__.py -------------------------------------------------------------------------------- /powerbot/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from telegram.ext import (Updater, CommandHandler) 4 | 5 | from handlers.new_members_handler import new_members_handler 6 | from handlers.start_handler import start_handler 7 | from handlers.sticker_document_handler import sticker_document_handler 8 | 9 | def error_handler(bot, update, error): 10 | print('Update "%s" caused error "%s"' % (update, error)) 11 | 12 | def run(): 13 | token = os.getenv('TELEGRAM_TOKEN') 14 | 15 | updater = Updater(token) 16 | dispatcher = updater.dispatcher 17 | 18 | dispatcher.add_handler(start_handler) 19 | dispatcher.add_handler(new_members_handler) 20 | dispatcher.add_handler(sticker_document_handler) 21 | dispatcher.add_error_handler(error_handler) 22 | 23 | updater.start_polling() 24 | updater.idle() 25 | 26 | if __name__ == '__main__': 27 | run() -------------------------------------------------------------------------------- /powerbot/handlers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tualatrix/powerbot/e14b02f6772c0cc8afe1c6fa8e006a473d3bb5d2/powerbot/handlers/__init__.py -------------------------------------------------------------------------------- /powerbot/handlers/new_members_handler.py: -------------------------------------------------------------------------------- 1 | from telegram.ext import Filters, MessageHandler 2 | 3 | def process_new_chat_members(bot, update): 4 | update.message.delete() 5 | 6 | new_members_handler = MessageHandler(Filters.group & Filters.status_update.new_chat_members, process_new_chat_members) -------------------------------------------------------------------------------- /powerbot/handlers/start_handler.py: -------------------------------------------------------------------------------- 1 | from telegram.ext import Updater, CommandHandler 2 | 3 | def start(bot, update): 4 | update.message.reply_text('Hello World!') 5 | 6 | start_handler = CommandHandler('start', start) -------------------------------------------------------------------------------- /powerbot/handlers/sticker_document_handler.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from telegram import update 4 | from telegram.ext import (Filters, MessageHandler) 5 | 6 | def process_sticker_document(bot, update): 7 | admin = os.getenv('ADMIN') 8 | if update.message.from_user.username != admin: 9 | update.message.delete() 10 | 11 | sticker_document_handler = MessageHandler(Filters.document | Filters.sticker | Filters.audio | Filters.video | Filters.voice, 12 | process_sticker_document) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-telegram-bot --------------------------------------------------------------------------------