spotted.utils package
Submodules
spotted.utils.constants module
Constants used by the util module
spotted.utils.conversation_util module
Common functions needed in conversation handlers
- spotted.utils.conversation_util.conv_cancel(family)[source]
Creates a function used to handle the /cancel command in the conversation. Invoking /cancel will exit the conversation immediately
- Parameters:
family (
str
) – family of the command- Returns:
Callable
[[Update
,CallbackContext
],int
] – function used to handle the /cancel command
spotted.utils.info_util module
Common info needed in both command and callback handlers
- class spotted.utils.info_util.EventInfo(bot, ctx, update=None, message=None, query=None)[source]
Bases:
object
Class that contains all the relevant information related to an event
- async answer_callback_query(text=None)[source]
Calls the answer_callback_query method of the bot class, while also handling the exception
- Parameters:
text (
str
, default:None
) – Text to show to the user
- property args: list[str]
Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned
- property callback_key: str
Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned
- property context: CallbackContext
Context generated by some event
- async edit_inline_keyboard(chat_id=None, message_id=None, new_keyboard=None)[source]
Generic wrapper used to edit the inline keyboard of a message with the telegram bot, while also handling the exception
- Parameters:
chat_id (
int
, default:None
) – id of the chat the message to edit belongs to or the current chat if Nonemessage_id (
int
, default:None
) – id of the message to edit. It is the current message if left Nonenew_keyboard (
InlineKeyboardMarkup
, default:None
) – new inline keyboard to assign to the message
- classmethod from_job(ctx)[source]
Instance of EventInfo created by a job update
- Parameters:
context – context passed by the handler
- Returns:
EventInfo
– instance of the class
- property inline_keyboard: InlineKeyboardMarkup
InlineKeyboard attached to the message
- property is_forwarded_post: bool
Whether the message is in fact a forwarded post from the channel to the group
- property reply_markup: InlineKeyboardMarkup
Reply_markup of the message that caused the update
- async send_post_to_admins()[source]
Sends the post to the admin group, so it can be approved
- Returns:
bool
– whether or not the operation was successful
- async send_post_to_channel(user_id)[source]
Sends the post to the channel, so it can be enjoyed by the users (and voted, if comments are disabled)
- async send_post_to_channel_group()[source]
Sends the post to the group associated to the channel, so that users can vote the post (if comments are enabled)
- async show_admins_votes(pending_post, reason=None)[source]
After a post is been approved or rejected, shows the admins that approved or rejected it and edit the message to show the admin’s votes
- Parameters:
pending_post (
PendingPost
) – post to show the admin’s votes forreason (
str
|None
, default:None
) – reason for the rejection, currently used on autoreply
spotted.utils.keyboard_util module
Creates the inlinekeyboard sent by the bot in its messages. Callback_data format: <callback_family>_<callback_name>,[arg]
- spotted.utils.keyboard_util.get_approve_kb(pending_post=None, approve=-1, reject=-1)[source]
Generates the InlineKeyboard for the pending post. If the pending post is None, the keyboard will be generated with 0 votes. Otherwise, the keyboard will be generated with the correct number of votes. To avoid unnecessary queries, the number of votes can be passed as an argument and will be assumed to be correct.
- Parameters:
pending_post (
PendingPost
, default:None
) – existing pending post to which the keyboard is attachedapprove (
int
, default:-1
) – number of approve votes known in advancereject (
int
, default:-1
) – number of reject votes known in advance
- Returns:
InlineKeyboardMarkup
– new inline keyboard
- spotted.utils.keyboard_util.get_autoreply_kb(page, items_per_page)[source]
Generates the keyboard for the autoreplies
- Parameters:
- Returns:
list
[list
[InlineKeyboardButton
]] – new part of keyboard
- spotted.utils.keyboard_util.get_confirm_kb()[source]
Generates the InlineKeyboard to confirm the creation of the post
- Returns:
InlineKeyboardMarkup
– new inline keyboard
- spotted.utils.keyboard_util.get_paused_kb(page, items_per_page)[source]
Generates the InlineKeyboard for the paused post
- Parameters:
page (
int
) – page of the autoreplies- Returns:
InlineKeyboardMarkup
– autoreplies keyboard append with resume button
- async spotted.utils.keyboard_util.get_post_outcome_kb(bot, votes, reason=None)[source]
Generates the InlineKeyboard for the outcome of a post
- spotted.utils.keyboard_util.get_preview_kb()[source]
Generates the InlineKeyboard to choose if the post should be previewed or not
- Returns:
InlineKeyboardMarkup
– new inline keyboard
- spotted.utils.keyboard_util.get_published_post_kb()[source]
Generates the InlineKeyboard for the published post adding the report button if needed
- Returns:
InlineKeyboardMarkup
|None
– new inline keyboard
- spotted.utils.keyboard_util.get_settings_kb()[source]
Generates the InlineKeyboard to edit the settings
- Returns:
InlineKeyboardMarkup
– new inline keyboard
Module contents
Modules that provide various util