handlers package

Description

Modules that handle the events the bot recognizes and reacts to

callback_handlers

Commands for the meme bot

modules.handlers.callback_handlers.approve_no_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the approve_yes callback. Approves the post, deleting it from the pending_post table, publishing it in the channel and putting it in the published post table

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.approve_yes_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the approve_yes callback. Approves the post, deleting it from the pending_post table, publishing it in the channel and putting it in the published post table

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.confirm_no_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the confirm_no callback. Saves the post as pending and sends it to the admins for them to check

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.confirm_yes_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the confirm_yes callback. Saves the post as pending and sends it to the admins for them to check

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.meme_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → int

Passes the callback to the correct handler

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

value passed to the handler, if requested

Return type

int

modules.handlers.callback_handlers.settings_anonimo_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the settings_sei_ghei callback. Removes the user_id from the table of credited users, if present

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.settings_credit_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the settings_foto_cane callback. Adds the user_id to the table of credited users, if it wasn’t already there

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.vote_no_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the vote_no callback. Downvotes the post

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

modules.handlers.callback_handlers.vote_yes_callback(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → Tuple[str, telegram.inline.inlinekeyboardmarkup.InlineKeyboardMarkup, int]

Handles the vote_yes callback. Upvotes the post

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

text and replyMarkup that make up the reply, new conversation state

Return type

Tuple[str, InlineKeyboardMarkup, int]

command_handlers

Commands for the meme bot

modules.handlers.command_handlers.ban_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /ban command Ban a user by replying to one of his pending posts with /ban

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.cancel_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → int

Handles the reply to the /cancel command. Exit from the post pipeline

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

value passed to the handler, if requested

Return type

int

modules.handlers.command_handlers.forwarded_post_msg(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the post forwarded in the channel group. Sends a reply in the channel group and stores it in the database, so that the post can be voted

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.help_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /help command

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.post_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → int

Handles the /post command Checks that the user is in a private chat and it’s not banned and start the post process

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

value passed to the handler, if requested

Return type

int

modules.handlers.command_handlers.post_msg(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext) → int

Handles the reply to the /post command. Checks the message the user wants to post, and goes to the final step

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

Returns

value passed to the handler, if requested

Return type

int

modules.handlers.command_handlers.reply_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /reply command Send a message to a user by replying to one of his pending posts with /reply + the message you want to send

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.rules_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /rules command

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.sban_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /sban command Sban a user by using this command and listing all the user_id to sban

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.settings_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /settings command

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler

modules.handlers.command_handlers.start_cmd(update: telegram.update.Update, context: telegram.ext.callbackcontext.CallbackContext)

Handles the /start command

Parameters
  • update (Update) – update event

  • context (CallbackContext) – context passed by the handler