minetest-telegram-bridge/bot/bot.py

28 lines
869 B
Python

#!/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):
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()