implement send_event (almost)
This commit is contained in:
parent
54be436606
commit
f243b8cfc7
|
|
@ -0,0 +1,3 @@
|
||||||
|
SZYNOWO_TOKEN=
|
||||||
|
SZYNOWO_CHAT=
|
||||||
|
SZYNOWO_FORWARD_TO=
|
||||||
44
main.py
44
main.py
|
|
@ -1,4 +1,7 @@
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Optional, Tuple
|
||||||
from telegram.ext import Updater, CommandHandler, CallbackContext
|
from telegram.ext import Updater, CommandHandler, CallbackContext
|
||||||
|
from telegram import Update, ParseMode
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
@ -20,21 +23,50 @@ class Bot:
|
||||||
self.dispatcher.add_handler(
|
self.dispatcher.add_handler(
|
||||||
CommandHandler(f[4:], getattr(self, f)))
|
CommandHandler(f[4:], getattr(self, f)))
|
||||||
|
|
||||||
def cmd_start(self, update, context):
|
def cmd_start(self, update: Update, context: CallbackContext):
|
||||||
context.bot.send_message(chat_id=update.effective_chat.id,
|
context.bot.send_message(chat_id=update.effective_chat.id,
|
||||||
text=f'Hi! effective_chat.id={update.effective_chat.id}')
|
text=f'Hi! effective_chat.id={update.effective_chat.id}')
|
||||||
|
|
||||||
def cmd_test(self, update, context: CallbackContext):
|
def send_event(self, date: datetime, header: str, description: str, location: str, latlong: Optional[Tuple[float, float]] = None, is_new: bool = True):
|
||||||
context.bot.send_message(chat_id=self.chat, text="Test")
|
messages = []
|
||||||
msg = context.bot.send_poll(
|
d = date.strftime("%Y-%m-%d %H:%M")
|
||||||
|
text = f"""\
|
||||||
|
*{header}*
|
||||||
|
_{d}, {location}_
|
||||||
|
{description}
|
||||||
|
"""
|
||||||
|
m = self.updater.bot.send_message(
|
||||||
|
self.chat, text=text, parse_mode=ParseMode.MARKDOWN)
|
||||||
|
messages.append(m)
|
||||||
|
if latlong is not None:
|
||||||
|
m = self.updater.bot.send_location(
|
||||||
|
self.chat, latitude=latlong[0], longitude=latlong[1])
|
||||||
|
messages.append(m)
|
||||||
|
m = self.updater.bot.send_poll(
|
||||||
self.chat,
|
self.chat,
|
||||||
"Poll title",
|
f'Wpadasz? ({header})',
|
||||||
['Będę', 'Nie będę', '🍆'],
|
['Będę', 'Nie będę', '🍆'],
|
||||||
is_anonymous=False,
|
is_anonymous=False,
|
||||||
allows_multiple_answers=False,
|
allows_multiple_answers=False,
|
||||||
)
|
)
|
||||||
|
messages.append(m)
|
||||||
|
|
||||||
for chat in self.forward_to:
|
for chat in self.forward_to:
|
||||||
msg.forward(chat)
|
for msg in messages:
|
||||||
|
msg.forward(chat)
|
||||||
|
|
||||||
|
def cmd_test(self, update: Update, context: CallbackContext):
|
||||||
|
context.bot.send_message(chat_id=self.chat, text="Test")
|
||||||
|
self.send_event(datetime.now(), "Header",
|
||||||
|
"Description", "Szynowa 18", (51.060938, 17.057193))
|
||||||
|
|
||||||
|
def cmd_location(self, update: Update, context: CallbackContext):
|
||||||
|
print(type(update))
|
||||||
|
context.bot.send_location(
|
||||||
|
update.effective_chat.id,
|
||||||
|
51,
|
||||||
|
19
|
||||||
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.updater.start_polling()
|
self.updater.start_polling()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue