Complete bot.py. Add groups to config. Change /post to POST.
Update gitignore.
This commit is contained in:
parent
68a4d440e6
commit
d7c4f7e14c
|
@ -114,3 +114,4 @@ dmypy.json
|
|||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
config.py
|
||||
|
|
16
bot/bot.py
16
bot/bot.py
|
@ -1,13 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import config
|
||||
import logging
|
||||
import requests
|
||||
from telegram.ext import Updater, MessageHandler, Filters
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
|
||||
%(message)s', level=logging.INFO)
|
||||
|
||||
|
||||
def message_handling(bot, update):
|
||||
pass
|
||||
print("in here")
|
||||
if update.message.chat.id in config.groups:
|
||||
print("in here")
|
||||
for i in update.message.text.split("\n"):
|
||||
params = {"message": (f"TG - {update.message.from_user.first_name}"
|
||||
f": {i}")}
|
||||
requests.post("http://localhost:" + str(config.port) + "/post",
|
||||
data=params)
|
||||
print(params)
|
||||
|
||||
|
||||
updater = Updater(token=config.api_key)
|
||||
dispatcher = updater.dispatcher
|
||||
dispatcher.add_handler(MessageHandler(Filters.text, message_handling))
|
||||
updater.start_polling()
|
||||
|
|
|
@ -4,3 +4,6 @@ api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|||
|
||||
# Port to connect to server
|
||||
port = 9876
|
||||
|
||||
# Groups to read from
|
||||
groups = []
|
||||
|
|
|
@ -21,4 +21,4 @@ with open('schema.sql') as fp:
|
|||
cursor.executescript(fp.read())
|
||||
|
||||
app.add_url_rule('/get', 'get', lambda: get(db))
|
||||
app.add_url_rule('/post', 'post', lambda: post(db))
|
||||
app.add_url_rule('/post', 'post', lambda: post(db), methods=["POST"])
|
||||
|
|
Loading…
Reference in New Issue