send polls and forward
This commit is contained in:
parent
e05d676a96
commit
54be436606
3
Pipfile
3
Pipfile
|
|
@ -5,9 +5,10 @@ name = "pypi"
|
|||
|
||||
[packages]
|
||||
python-telegram-bot = "*"
|
||||
pydotenv = "*"
|
||||
python-dotenv = "*"
|
||||
|
||||
[dev-packages]
|
||||
autopep8 = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "74444b947cc346f6dedcd20230cadb9a8234f84b29f6fd60f8d148f0ddfab0d3"
|
||||
"sha256": "9276e37b6f692e59a274d4d5465ce7ccf6f75fbf0fb37807717943fa32892dce"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
|
@ -38,12 +38,13 @@
|
|||
],
|
||||
"version": "==2021.10.8"
|
||||
},
|
||||
"pydotenv": {
|
||||
"python-dotenv": {
|
||||
"hashes": [
|
||||
"sha256:5f6d78d3a7ed5124d7836bc1beeadd855dab4e2fdbea9338e6ff61dc1e46829f"
|
||||
"sha256:14f8185cc8d494662683e6914addcb7e95374771e707601dfc70166946b4c4b8",
|
||||
"sha256:bbd3da593fc49c249397cbfbcc449cf36cb02e75afc8157fcc6a81df6fb7750a"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.0.7"
|
||||
"version": "==0.19.1"
|
||||
},
|
||||
"python-telegram-bot": {
|
||||
"hashes": [
|
||||
|
|
@ -124,5 +125,30 @@
|
|||
"version": "==3.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
"develop": {
|
||||
"autopep8": {
|
||||
"hashes": [
|
||||
"sha256:276ced7e9e3cb22e5d7c14748384a5cf5d9002257c0ed50c0e075b68011bb6d0",
|
||||
"sha256:aa213493c30dcdac99537249ee65b24af0b2c29f2e83cd8b3f68760441ed0db9"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.5.7"
|
||||
},
|
||||
"pycodestyle": {
|
||||
"hashes": [
|
||||
"sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20",
|
||||
"sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==2.8.0"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
|
||||
"sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
|
||||
],
|
||||
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==0.10.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
main.py
40
main.py
|
|
@ -1,19 +1,51 @@
|
|||
from telegram.ext import Updater, CommandHandler, CallbackContext
|
||||
import os
|
||||
import logging
|
||||
from telegram.ext import Updater
|
||||
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):
|
||||
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}')
|
||||
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')
|
||||
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()
|
||||
Loading…
Reference in New Issue