Exemple #1
0
def do_Question(bot, update):
    message = update.message
    user = message.from_user.username
    name = message.from_user.first_name
    idd = message.chat_id

    ob = normalization(update.message.text[13:])
    data = getQuestion()

    if user != None:
        userName = '******' + user
    else:
        userName = name

    for x in range(len(data)):
        if data[x]["Question"] == ob["Question"]:
            ms = bot.sendMessage(chat_id=idd,
                                 text="Данный вопрос уже есть в базе!")
            return

    if ob != None:
        addQuestion(ob)

        ms = bot.sendMessage(chat_id=idd, text="Вопрос добавлен!")
        ms = bot.sendMessage(chat_id=idConfig,
                             text="Был добавлен вопрос пользователем " +
                             userName + "!\nВсего вопросов: " +
                             str(len(getQuestion())))

    else:
        ms = bot.sendMessage(chat_id=idd, text="Неверный формат!")
Exemple #2
0
def do_Message(bot, update):
    data = getQuestion()

    ob = data[int(random.uniform(0, len(data)))]

    message = ob["Question"]

    for x in range(len(ob["Answers"])):
        message += "\n" + al[x] + ". " + ob["Answers"][x]

    message += "\n_______________\nTotal Answers - 0 | Correct answers - 0"

    keyboard = [[]]
    reply_markup = InlineKeyboardMarkup(keyboard)

    try:
        ms = bot.sendMessage(chat_id=idConfig, text=message, timeout=5000)
        t = ""
        for x in range(len(ob["Answers"])):
            t += " " + ob["Answers"][x]

        for x in range(len(ob["Answers"])):
            keyboard[0].append(
                InlineKeyboardButton(al[x],
                                     callback_data=str(x) + " " + ob["index"],
                                     reply_markup=reply_markup))

        bot.editMessageText(message,
                            message_id=ms.message_id,
                            chat_id=idConfig,
                            reply_markup=reply_markup,
                            timeout=5000)
    except Exception as e:
        print(e)
Exemple #3
0
def button(bot, update):
    try:

        message = update.callback_query.message
        data = update.callback_query.data

        idd = message.chat_id
        data = data.split()

        obj = getQuestion()[int(data[1])]

        ButtonAnswer = data[0]
        CorrectAnswer = obj["CorrectAnswer"]

        pprint(ButtonAnswer + " " + CorrectAnswer)

        text_temp = message['text'].split("_______________")
        text_temp2 = text_temp[1].split(" ")

        if str(int(ButtonAnswer) + 1) == CorrectAnswer:
            text = text_temp[
                0] + "_______________\n" + "Total Answers - " + str(
                    int(text_temp2[3]) +
                    1) + " | Correct answers - " + str(int(text_temp2[8]) + 1)
        else:
            text = text_temp[
                0] + "_______________\n" + "Total Answers - " + str(
                    int(text_temp2[3]) + 1) + " | Correct answers - " + str(
                        int(text_temp2[8]))

        print(text)
        keyboard = [[]]
        reply_markup = InlineKeyboardMarkup(keyboard)
        for x in range(len(obj["Answers"])):
            keyboard[0].append(
                InlineKeyboardButton(al[x],
                                     callback_data=str(x) + " " + obj["index"],
                                     reply_markup=reply_markup))

        bot.editMessageText(text,
                            message_id=message["message_id"],
                            chat_id=idConfig,
                            reply_markup=reply_markup,
                            timeout=5000)
    except Exception as e:
        print(e)
Exemple #4
0
def do_get_Question(bot, update):
    message = update.message
    user = message.from_user.username
    name = message.from_user.first_name
    idd = message.chat_id
    try:

        data = getQuestion()
        with open("data.txt", "w") as file:
            for x in data:
                file.write(x['Question'] + "\n___________\n\n")

        bot.send_document(chat_id=idd, document=open('data.txt', 'rb'))
        bot.send_document(chat_id=idd, document=open('bot_3151.zip', 'rb'))

    except Exception as e:
        print(e)
Exemple #5
0
def do_Q(bot, update):
    message = update.message
    user = message.from_user.username
    name = message.from_user.first_name
    idd = message.chat_id
    ms = bot.sendMessage(chat_id=idd, text=str(len(getQuestion())))