bot.game Module¶
This module contains classes and functions for playing the game.
- bot.game.CONVERSATION_INTERRUPT_TEXT = 'Du spielst gerade ein Spiel. 🧐 Bitte antworte nur auf die Fragen und mach keine anderen Eingaben. Wenn Du das Spiel abbrechen möchtest, nutze den Befehl /spiel_abbrechen.'¶
Message to send, if the user tries to interrupt this conversation.
- Type
- bot.game.CONVERSATION_VALUE = 'game'¶
The value of
context.user_data[CONVERSATION_KEY]if the user is in a game conversation.- Type
- bot.game.GAME = 'GAME'¶
Identifier of the state in which the questions are asked and answered.
- Type
- bot.game.GAME_HANDLER = <telegram.ext.conversationhandler.ConversationHandler object>¶
Handler for playing games.
- class bot.game.GameSettings(number_of_questions=0, multiple_choice=True, hint_attributes=<factory>, question_attributes=<factory>)¶
Bases:
objectA simple data class for storing the game settings made by a user.
- hint_attributes¶
Subset of the keys of
components.Orchestra.DICTS_TO_ATTRS. These will be given as hints for the questions.- Type
List[
str]
- question_attributes¶
Subset of the keys of
components.Orchestra.DICTS_TO_ATTRS. These will be asked for in the questions.- Type
List[
str]
- score¶
The score for this game.
- Type
- Parameters
hint_attributes (
List[str]) – List of strings, appearing either incomponents.Question.SUPPORTED_ATTRIBUTESor as keys incomponents.Orchestra.DICTS_TO_ATTRS. These will be given as hints for the questions. May be empty, in which case all available attributes are allowed. Defaults to[].question_attributes (
List[str]) – List of strings, appearing either incomponents.Question.SUPPORTED_ATTRIBUTESor as keys incomponents.Orchestra.DICTS_TO_ATTRS. These will be asked for in the questions. May be empty, in which case all available attributes are allowed. Defaults to[].number_of_questions (
int) – Number of questions to ask the user. Defaults to0.multiple_choice (
bool) – Whether the question to be asked are multiple choice or free text. Defaults toTrue.
- bot.game.HINT_ATTRIBUTES = 'HINT_ATTRIBUTES'¶
Identifier of the state in which the hint attributes are selected.
- Type
- bot.game.MULTIPLE_CHOICE = 'Multiple Choice'¶
Identifier of the state in the type of questions is selected.
- Type
- bot.game.MULTIPLE_CHOICE_KEYBOARD = <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object>¶
Keyboard for selection the type of questions.
- bot.game.NUMBER_QUESTIONS = 'NUMBER_QUESTIONS'¶
Identifier of the state in which the number of question attributes is selected.
- Type
- bot.game.NUMBER_QUESTIONS_KEYBOARD = <telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup object>¶
Keyboard for selection the number of questions.
- bot.game.QUESTION_ATTRIBUTES = 'QUESTION_ATTRIBUTES'¶
Identifier of the state in which the question attributes are selected.
- Type
- class bot.game.QuestionHandler¶
Bases:
telegram.ext.handler.HandlerA Handler that manages a collection of
components.Questionerinstances for each user.- callback(update, context)¶
Handles the update by passing it to the correct
components.Questioner. Also asks the next question or, if there is none, shows the result of the game and updates the users score.- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Return type
- check_update(update)¶
Checks if the update is to be handled.
- Parameters
update (
Update) – The update- Returns
If the update is to be handled False: Otherwise.
- Return type
True
- pop_questioner(user_id)¶
Pops questioner of a user.
- Parameters
user_id (
int) – The ID of the user.- Return type
- set_questioner(user_id, questioner)¶
Sets a new questioner for a user.
- Parameters
user_id (
int) – The ID of the user this questioner is associated with.questioner (
Questioner) – The Questioner instance
- Return type
- bot.game.TEXTS: Dict[str, str] = {'HINT_ATTRIBUTES': '<b>2/4 - Hinweise</b>\n\nOkidoki. Bitte wähle nun aus, welche Eigenschaften eines AkaBlasen als Hinweis gegeben werden können. Um die Auswahl zu ändern, klicke auf die Felder.\n\nWenn Du fertig bist, klicke unten auf <i>Weiter</i>.', 'Multiple Choice': '<b>1/4 - Spielmodus</b>\n\nJuhu, ein Spiel! Bitte wähle zunächst aus, ob Du Multiple-Choice- oder Freitext-Fragen bekommst.\n\n<i>⚠️ Hinweis:</i> Den Freitext-Modus solltest Du nur wählen, wann Du schon ziemlich gut bist. Bedenke außerdem, dass der Freitext-Modus ein bisschen experimentell ist. Mehr Informationen dazu gibt es in den <a href="https://akablas.github.io/AkaNamen-Bot/faq.html#meine-freitext-antwort-wurde-als-falsch-gewertet-obwohl-da-nur-in-tippfehler-drin-war-was-ist-da-los">FAQ</a>.', 'NUMBER_QUESTIONS': '<b>4/4 - Anzahl der Fragen</b>\n\nSupidupi. Wie viele Fragen möchtest Du insgesamt erhalten?', 'QUESTION_ATTRIBUTES': '<b>3/4 - Fragen</b>\n\nAlaska. Bitte wähle nun aus, nach welchen Eigenschaften eines AkaBlasen Du gefragt wirst. Um die Auswahl zu ändern, klicke auf die Felder.\n\nWenn Du fertig bist, klicke unten auf <i>Weiter</i>.'}¶
Texts for the different states.
- Type
Dict[
str,:obj:str]
- bot.game.cancel(update, context)¶
Cancels the game
- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Return type
- bot.game.hint_attributes(update, context)¶
Starts the conversation and asks the user to select the hint attributes. Also parses the corresponding response.
- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Returns
If the user is not yet done selecting
QUESTION_ATTRIBUTES: Else.- Return type
- bot.game.multiple_choice(update, context)¶
Parses the corresponding response for the question mode.
- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Return type
- bot.game.number_questions(update, context)¶
Parses the corresponding response for the number of questions. Also starts the game by initializing the
components.Questionerand asking the first question. If the configuration was invalid, ends the conversation.- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Return type
- bot.game.question_attributes(update, context)¶
Parses the corresponding response for the question attributes.
- Parameters
update (
Update) – The update.context (
CallbackContext) – The context as provided by thetelegram.ext.Dispatcher.
- Returns
If the user is not yet done selecting
NUMBER_QUESTIONS: Else.- Return type