52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from telegram.ext import Updater, CommandHandler, CallbackContext
|
|
import os
|
|
import logging
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
|
|
class Bot:
|
|
def __init__(self, token, chat, forward_to=None):
|
|
self.chat = chat
|
|
self.forward_to = forward_to or []
|
|
self.updater = Updater(token=token, use_context=True)
|
|
self.dispatcher = self.updater.dispatcher
|
|
for f in dir(self):
|
|
if f.startswith("cmd_"):
|
|
self.dispatcher.add_handler(
|
|
CommandHandler(f[4:], getattr(self, f)))
|
|
|
|
def cmd_start(self, update, context):
|
|
context.bot.send_message(chat_id=update.effective_chat.id,
|
|
text=f'Hi! effective_chat.id={update.effective_chat.id}')
|
|
|
|
def cmd_test(self, update, context: CallbackContext):
|
|
context.bot.send_message(chat_id=self.chat, text="Test")
|
|
msg = context.bot.send_poll(
|
|
self.chat,
|
|
"Poll title",
|
|
['Będę', 'Nie będę', '🍆'],
|
|
is_anonymous=False,
|
|
allows_multiple_answers=False,
|
|
)
|
|
for chat in self.forward_to:
|
|
msg.forward(chat)
|
|
|
|
def run(self):
|
|
self.updater.start_polling()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
b = Bot(
|
|
token=os.environ['SZYNOWO_TOKEN'],
|
|
chat=os.environ['SZYNOWO_CHAT'],
|
|
forward_to=[s.strip() for s in os.environ.get(
|
|
'SZYNOWO_FORWARD_TO', '').split(',')],
|
|
)
|
|
|
|
b.run()
|