Browse Source

Complete bot.py. Add groups to config. Change /post to POST.

Update gitignore.
master
Ceda EI 1 year ago
parent
commit
d7c4f7e14c
4 changed files with 20 additions and 2 deletions
  1. +1
    -0
      .gitignore
  2. +15
    -1
      bot/bot.py
  3. +3
    -0
      bot/sample.config.py
  4. +1
    -1
      bot/server.py

+ 1
- 0
.gitignore View File

@@ -114,3 +114,4 @@ dmypy.json
# Pyre type checker
.pyre/

config.py

+ 15
- 1
bot/bot.py View File

@@ -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()

+ 3
- 0
bot/sample.config.py View File

@@ -4,3 +4,6 @@ api_key = "123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Port to connect to server
port = 9876

# Groups to read from
groups = []

+ 1
- 1
bot/server.py View File

@@ -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…
Cancel
Save