mirror of
https://github.com/Faridik/Carolyn.git
synced 2026-07-08 13:21:53 +00:00
Закатал бота в контейнер. Пока не придумал как обновлять код в контейнере.
This commit is contained in:
parent
ddbc890328
commit
aac92a8d75
@ -1,28 +0,0 @@
|
||||
#Подключение к боту
|
||||
from telegram.ext import Updater
|
||||
updater = Updater(token='1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8', use_context=True)
|
||||
|
||||
dispatcher = updater.dispatcher
|
||||
|
||||
import logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
#Стартовое сообщение (к команде /start)
|
||||
def start(update, context):
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text="Hello World! Это не просто копипаста, я вот что-то подправил даже")
|
||||
|
||||
from telegram.ext import CommandHandler
|
||||
start_handler = CommandHandler('start', start)
|
||||
dispatcher.add_handler(start_handler)
|
||||
|
||||
#Ответ на не командное сообщение (отвечает тем же сообщением)
|
||||
def echo(update, context):
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
||||
|
||||
from telegram.ext import MessageHandler, Filters
|
||||
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
||||
dispatcher.add_handler(echo_handler)
|
||||
|
||||
#Начало работы бота
|
||||
updater.start_polling()
|
||||
23
TelegramBot/Dockerfile
Normal file
23
TelegramBot/Dockerfile
Normal file
@ -0,0 +1,23 @@
|
||||
# For more information, please refer to https://aka.ms/vscode-docker-python
|
||||
FROM python:3.8-slim-buster
|
||||
|
||||
# Keeps Python from generating .pyc files in the container
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
# Turns off buffering for easier container logging
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Install pip requirements
|
||||
COPY requirements.txt .
|
||||
RUN python -m pip install -r requirements.txt
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
|
||||
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
|
||||
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
|
||||
USER appuser
|
||||
|
||||
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
|
||||
CMD ["python", "bot.py"]
|
||||
47
TelegramBot/bot.py
Normal file
47
TelegramBot/bot.py
Normal file
@ -0,0 +1,47 @@
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import time
|
||||
|
||||
from telegram.ext import Updater
|
||||
from telegram.ext import CommandHandler
|
||||
from telegram.ext import MessageHandler, Filters
|
||||
|
||||
TOKEN = "1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8" # os.environ["TOKEN"]
|
||||
|
||||
logging.basicConfig(
|
||||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
|
||||
)
|
||||
|
||||
updater = Updater(token=TOKEN, use_context=True)
|
||||
dispatcher = updater.dispatcher
|
||||
|
||||
# ================================================================ BOT COMMANDS
|
||||
|
||||
# Стартовое сообщение (к команде /start)
|
||||
def start(update, context):
|
||||
|
||||
context.bot.send_message(
|
||||
chat_id=update.effective_chat.id,
|
||||
text=f"Hello World! It's {time.time()}\n" \
|
||||
f"{platform.platform()}\n\n"
|
||||
)
|
||||
|
||||
# Ответ на не командное сообщение (отвечает тем же сообщением)
|
||||
def echo(update, context):
|
||||
context.bot.send_message(
|
||||
chat_id=update.effective_chat.id,
|
||||
text=update.message.text
|
||||
)
|
||||
|
||||
|
||||
# ==================================================================== HANDLERS
|
||||
|
||||
start_handler = CommandHandler("start", start)
|
||||
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
||||
|
||||
dispatcher.add_handler(start_handler)
|
||||
dispatcher.add_handler(echo_handler)
|
||||
|
||||
# Начало работы бота
|
||||
updater.start_polling()
|
||||
1
TelegramBot/requirements.txt
Normal file
1
TelegramBot/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
python-telegram-bot==13.7
|
||||
@ -9,4 +9,11 @@ services:
|
||||
environment:
|
||||
SECRETKEY: "HELLO-WORLD-@21XX 15AF"
|
||||
volumes:
|
||||
- ./SpreadsheetsService:/app:Z
|
||||
- ./SpreadsheetsService:/app
|
||||
telegrambot:
|
||||
container_name: "carolyn-telegrambot"
|
||||
build: ./TelegramBot
|
||||
environment:
|
||||
TOKEN: "1903048555:AAFK-d7prKvOvwwXo0IPzeRwJ1ZcuOT5ty8"
|
||||
volumes:
|
||||
- ./TelegramBot:/app
|
||||
Loading…
x
Reference in New Issue
Block a user