Module Documentation

This page contains documentation of everything QuizBot has to offer.

Quiz

With this module, you can create quizzes with questions different kinds.

class quizbot.quiz.quiz.Quiz(author='')[source]

Bases: object

An Instance of the class Quiz has a list of questions, which defines the Quiz. You can choose whether

  • the order of the questions is random

  • the result of the entered answer is shown after the question

  • the result of the entered answer of every question is shown after the quiz

__init__(author='') None[source]

Initializes an instance of the class Quiz.

Parameters:

author – Author of the quiz

add_question(new_question: Question)[source]

Add an instance of the class Question to the list of questions.

Parameters:

new_question – New question of the quiz.

get_questions()[source]

Returns a copy of the list of questions.

Returns:

List of questions.

Questions

With this module, you can create questions different kinds.

class quizbot.quiz.question_factory.Question(question, correct_answer)[source]

Bases: object

General class for questions.

__init__(question, correct_answer)[source]

Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as an empty string.

Parameters:
  • question – Question of the question-instance as string.

  • correct_answer – Correct answer of the question in (question specific) type.

Raises:

AssertionError – If the question or the correct answer is empty.

check_solution()[source]

Checks the entered solution of the user with the correct answer.

Returns:

Boolean value whether the entered solution equals the correct answer.

Raises:

AssertionError – No solution was entered by the user yet.

enter_solution(answer)[source]

Enters the answer by the user.

Parameters:

answer – Answer by the user as a string.

class quizbot.quiz.question_factory.QuestionBool(question, correct_answer)[source]

Bases: Question

Subclass for questions with a boolean value as answer. Inherits by question.

__init__(question, correct_answer)[source]

Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as an empty string.

Parameters:
  • question – Question of the question-instance as string.

  • correct_answer – Correct answer of the question as boolean value (True or False).

Raises:

AssertionError – If the question or the correct answer is not a boolean value.

check_solution()[source]

Compares the entered answer by the user with the correct boolean value.

Returns:

Boolean value whether the entered value equals the correct value.

Raises:

AssertionError – If no solution was entered by the user yet.

enter_solution(answer)[source]

Enters the users’ answer.

Parameters:

answer – Answer by the user as a string.

Raises:

AssertionError – If the entered answer isn’t “True” or “False”

class quizbot.quiz.question_factory.QuestionChoice(question, correct_answer)[source]

Bases: Question

Subclass for questions with multiple possible and correct answers. Inherits by question.

__init__(question, correct_answer)[source]

Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as an empty string, the randomness as False and the list of possible answers as a list of correct answers.

Parameters:
  • question – Question of the question-instance as string.

  • correct_answer – Correct answers of the question as string (seperated by comma).

Raises:

AssertionError – If the question is empty or the count of correct answers is smaller than one.

add_possible_answer(new_answer)[source]

Adds an answer to the list of possible answers.

Parameters:

new_answer – New answer in the list of possible answers as string.

check_solution()[source]

Checks if the intersection of the list of entered answers and the list of correct answers equals the entered answers.

Returns:

Boolean value if the entered values equals the correct values.

Raises:

AssertionError – If no solution was entered by the user yet.

class quizbot.quiz.question_factory.QuestionChoiceSingle(question='', correct_answer='')[source]

Bases: QuestionChoice

Subclass for questions with multiple possible and correct answers. Inherits by question_choice.

__init__(question='', correct_answer='')[source]

Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as an empty string, the randomness as False and the list of possible answers as an empty list.

Parameters:
  • question – Question of the question-instance as string.

  • correct_answer – Correct answers of the question as list.

Raises:

AssertionError – If the question is empty or the count of correct answers doesn’t equal one.

enter_solution(answer)[source]

Enters the answer by the user.

Parameters:

answer – Answer by the user as a string.

Raises:

AssertionError – If the entered string includes more than one answer.

class quizbot.quiz.question_factory.QuestionNumber(question, correct_answer)[source]

Bases: Question

Subclass for questions with an integer as answer. Inherits from question.

__init__(question, correct_answer)[source]

Initialize a question by the question and the correct answer. Additionally, it initializes the user answer as an empty string.

Parameters:
  • question – Question of the question-instance as string.

  • correct_answer – Correct answer of the question as number.

Raises:

AssertionError – If the question or the correct answer is not a number.

check_solution()[source]

Compares the entered answer by the user with the correct number.

Returns:

Boolean value whether the entered number equals the correct number.

Raises:

AssertionError – If no solution was entered by the user yet.

enter_solution(answer)[source]

Enters the answer by the user.

Parameters:

answer – Answer by the user as a string.

Raises:

ValueError – If answer is not an integer.

class quizbot.quiz.question_factory.QuestionString(question, correct_answer)[source]

Bases: Question

Subclass for questions with a string as answer. Inherits by question.

check_solution()[source]

Checks the entered answer of the user with the correct string.

Returns:

Boolean value whether the entered string equals the correct string.

Raises:

AssertionError – If no solution was entered by the user yet.

Attempt

With this module you can create one attemp of a quiz.

class quizbot.quiz.attempt.Attempt(quiz: Quiz)[source]

Bases: object

An Instance of the class Attempt has a quiz and a list of the left questions.

__init__(quiz: Quiz) None[source]

Initializes an instance of the class Attempt. It shuffeles the question if the quiz specifies it.

Parameters:

quiz – Quiz which wants the user to attempt.

act_question()[source]

Returns the current question.

Returns:

Current question.

enter_answer()[source]

Checks the users’ answer and removes the current question from the list.

Returns:

A pair of a boolean value whether the user answer was correct and the correct answer.

has_next_question()[source]

Checks if a question is left.

Returns:

If a question is left.

input_answer(user_answer)[source]

Enter one user answer.

Parameters:

user_answer – A answer by the user

Bot

Telegram bot to create and attempt to quizzes.

async quizbot.bot.bot.error(update, context)[source]

Log Errors caused by Updates.

async quizbot.bot.bot.post_init(application)[source]

Set bot commands visible in the Telegram command menu.

async quizbot.bot.bot.print_help(update, _)[source]

Send a message when the command /help is issued.

quizbot.bot.bot.setup_bot(app)[source]

Setups the handlers

Create quiz

Module with methods to create a quiz with a telegram bot

async quizbot.bot.create_quiz.cancel(update, context)[source]

Cancels a creation ofa quiz by deleting the users’ entries.

async quizbot.bot.create_quiz.enter_answer(update, context)[source]

After entering the correct answer it tries to process it. If it fails, it asks for the correct answer again. Otherwise, it asks for additional possible answers, if the question is an instance of QuestionChoice. Otherwise, it adds the question to the quiz and asks for the type of the next question.

async quizbot.bot.create_quiz.enter_password(update, context)[source]

Hashes the password and saves the quiz to the database.

async quizbot.bot.create_quiz.enter_password_choice(update, context)[source]

After choosing whether to set a password, either asks for the password or saves the quiz without one.

async quizbot.bot.create_quiz.enter_possible_answer(update, context)[source]

After entering additional possible answers, it asks whether the order of the answers should be random.

async quizbot.bot.create_quiz.enter_question(update, context)[source]

Asks for the correct answer to the question after entering the question itself.

async quizbot.bot.create_quiz.enter_quiz_name(update, context)[source]

After entering the name of the quiz, it looks up if the quiz name is occupied. If unique, asks whether the user wants to set a password.

async quizbot.bot.create_quiz.enter_randomness_question(update, context)[source]

After entering whether the order if the answers should be random, it adds the question to the quiz. After that, it asks for the type of next question.

async quizbot.bot.create_quiz.enter_randomness_quiz(update, context)[source]

After entering whether the order if the questions should be random, it asks if the result of the question be displayed after the question itself.

async quizbot.bot.create_quiz.enter_result_after_question(update, context)[source]

After entering whether the result of the question should be displayed after the question itself, it asks if the result of every question be displayed after the quiz.

async quizbot.bot.create_quiz.enter_result_after_quiz(update, context)[source]

After entering whether the result of every question should be displayed after the quiz, it asks for the name of the quiz?

async quizbot.bot.create_quiz.enter_type(update, context)[source]

After entering the new question type, it asks for the question itself, if the entered string isn’t ‘Enter’. Otherwise, it asks if the question should be displayed in random order.

async quizbot.bot.create_quiz.start(update, context)[source]

Starts a conversation about quiz creation. Welcomes the user and asks for the type of the first question.

Attempt quiz

Module with methods to attempt to a quiz with a telegram bot

async quizbot.bot.attempt_quiz.ask_question(update, context)[source]

Formats the keyboard and prints the current question.

async quizbot.bot.attempt_quiz.cancel(update, context)[source]

Cancels an attempt to a quiz by deleting the users’ entries.

async quizbot.bot.attempt_quiz.enter_answer(update, context)[source]

It processes the answer to a question and asks a new question, if possible. Otherwise, it prints results.

async quizbot.bot.attempt_quiz.enter_password(update, context)[source]

Verifies the password for a password-protected quiz. If correct, starts the attempt. If wrong, reprompts.

async quizbot.bot.attempt_quiz.enter_quiz(update, context)[source]

Enters a quiz. Try to load a quiz from the input. If it succeeded, the bot asks the first question. Otherwise, it asks for another quiz.

async quizbot.bot.attempt_quiz.start(update, context)[source]

Starts a conversation about an attempt at a quiz. Welcomes the user and asks for a quiz.

Edit quiz

Module with methods to rename and remove a quiz with a telegram bot

async quizbot.bot.edit_quiz.cancel_edit(update, context)[source]

Cancels the process of deletion or renaming.

async quizbot.bot.edit_quiz.enter_name_remove(update, context)[source]

Deltes a quiz after entering its’ name.

async quizbot.bot.edit_quiz.enter_new_name(update, context)[source]

After entering the new name of the quiz, it renames it.

async quizbot.bot.edit_quiz.enter_old_name(update, context)[source]

After entering the old quiz name, it asks for the new one.

async quizbot.bot.edit_quiz.start_remove(update, _)[source]

Start a process to remove a quiz.

async quizbot.bot.edit_quiz.start_rename(update, _)[source]

Starts a process to rename a quiz.