import telebot
import logging
from telebot import types
import json

logger = telebot.logger
telebot.logger.setLevel(logging.DEBUG)

# importing Flask and other modules
from flask import Flask, request, render_template 
 
# Flask constructor
app = Flask(__name__)   
 
# A decorator used to tell the application
# which URL is associated function
@app.route('/', methods =["GET", "POST"])
def gfg():
    if request.method == "POST":
       # getting input with name = fname in HTML form
       data=request.json
       Score = data.get('Score')
       app.logger.info(Score)
       query = request.args.get('query')
       Querysus=types.CallbackQuery(id=query)
       bot.set_game_score(Querysus.from_user.id,Score,Querysus.message.chat.id,Querysus.message.id)
       # getting input with name = lname in HTML form 
    return render_template("form.html")
 
if __name__=='__main__':
   app.run()


from telebot.async_telebot import AsyncTeleBot
bot = AsyncTeleBot('6829264559:AAG8QJPHJc-fqkoB7vsvGh8Mi50uEbCBjq0')
buttons=[[types.InlineKeyboardButton("Link",url="https://secapedia.duckdns.org:8443/Saber/")]]


@bot.message_handler(commands=['start', 'help'])
async def send_welcome(message):
	await bot.reply_to(message, "Sono venuto")

@bot.message_handler(commands=['play'])
async def send_welcome(message):
        await bot.send_game(chat_id=message.chat.id, reply_to_message_id=message.id,game_short_name="seibahjump")

@bot.message_handler(commands=['armando'])
async def send_welcome(message):
        await bot.send_game(chat_id=message.chat.id, reply_to_message_id=message.id,game_short_name="armandotennis")

@bot.callback_query_handler(func=lambda call: True)
async def test_callback(call):
        if call.game_short_name=="seibahjump":
                data=call.json
                print(data)
                userId=data["from"]["id"]
                chatId=data["message"]["chat"]["id"]
                messageId=data["message"]["message_id"]
                await bot.answer_callback_query(call.id,url="https://secapedia.duckdns.org:8443/Saber/?userId="+str(userId)+"&chatId="+str(chatId)+"&messageId="+str(messageId))
        if call.game_short_name=="armandotennis":
                data=call.json
                print(data)
                userId=data["from"]["id"]
                chatId=data["message"]["chat"]["id"]
                messageId=data["message"]["message_id"]                
                await bot.answer_callback_query(call.id,url="https://secapedia.duckdns.org:8443/Armando/?userId="+str(userId)+"&chatId="+str(chatId)+"&messageId="+str(messageId))


        



@bot.inline_handler(lambda query: query.query == '')
async def query_text(inline_query):

        r = types.InlineQueryResultArticle('1', 'Seibah', types.InputTextMessageContent('Gioca a Saber jump'),reply_markup=types.InlineKeyboardMarkup(buttons))
        await bot.answer_inline_query(inline_query.id, [r])






import asyncio
asyncio.run(bot.polling())
