spotted.handlers package

Submodules

spotted.handlers.anonym_comment module

Anonym Comment on a post in the comment group

async spotted.handlers.anonym_comment.anonymous_comment_msg(update, context)[source]

Handles a new anonym comment on a post in the comment group. Deletes the original post and sends a message with the same text, to avoid any abuse.

Parameters:

spotted.handlers.approve module

Approve actions the admin can take on a pending post.

async spotted.handlers.approve.approve_no_callback(update, context)[source]

Handles the approve_no callback. Add a negative vote to the post, updating the keyboard if necessary. If the number of negative votes is greater than the number of votes required, the post is rejected, deleting it from the pending_post table and notifying the user

Parameters:
async spotted.handlers.approve.approve_status_callback(update, context)[source]

Handles the approve_status callback. Pauses or resume voting on a specific pending post

Parameters:
Returns:

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

async spotted.handlers.approve.approve_yes_callback(update, context)[source]

Handles the approve_yes callback. Add a positive vote to the post, updating the keyboard if necessary. If the number of positive votes is greater than the number of votes required, the post is approved, deleting it from the pending_post table and copying it to the channel

Parameters:
async spotted.handlers.approve.reject_post(info, pending_post, reason=None)[source]

Rejects a pending post

Parameters:
  • info (EventInfo) – information about the callback

  • pending_post (PendingPost) – pending post to reject

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreply

spotted.handlers.autoreply module

/autoreply command

async spotted.handlers.autoreply.autoreply_callback(update, context)[source]

Handles the autoreply callback. Reply to the user with the autoreply message to inform them about the reason of the rejection

Parameters:
async spotted.handlers.autoreply.autoreply_cmd(update, context)[source]

Handles the /autoreply command. Used by replying to one of his pending posts with /autoreply + one of the keys in the autoreplies dictionary in the config file. Send a message to the user with the autoreply message to inform them about a problem with their post

Parameters:

spotted.handlers.ban module

/ban command

async spotted.handlers.ban.ban_cmd(update, context)[source]

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

Parameters:

spotted.handlers.cancel module

/cancel command

async spotted.handlers.cancel.cancel_cmd(update, context)[source]

Handles the /cancel command. Exits from the post pipeline and removes the eventual pending post of the user

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.clean_pending module

/clean_pending command

async spotted.handlers.clean_pending.clean_pending_cmd(_, context)[source]

Handles the /clean_pending command. Automatically rejects all pending posts that are older than the chosen amount of hours

Parameters:
  • _ – update event

  • context (CallbackContext) – context passed by the handler

spotted.handlers.constants module

Constants used by the bot handlers

class spotted.handlers.constants.ConversationState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum for the states of the conversation. The end state must have value -1, since it is the convention used by the ConversationHandler to terminate the conversation.

END = -1
POSTING = 1
POSTING_CONFIRM = 3
POSTING_PREVIEW = 2
REPORTING_SPOT = 4
REPORTING_USER = 5
REPORTING_USER_REASON = 6
SENDING_USER_REPORT = 7

spotted.handlers.db_backup module

/db_backup command

async spotted.handlers.db_backup.db_backup_cmd(_, context)[source]

Handles the /db_backup command. Automatically upload and send current version of db for backup

Parameters:
  • _ – update event

  • context (CallbackContext) – context passed by the handler

spotted.handlers.follow_comment module

Detect Comment on a post in the comment group

async spotted.handlers.follow_comment.follow_spot_comment(update, context)[source]

Handles a new comment on a post in the comment group. Checks if someone is following the post, and sends them an update in case.

Parameters:

spotted.handlers.follow_spot module

Handles callback when the ‘Follow Spot’ button is clicked.

async spotted.handlers.follow_spot.follow_spot_callback(update, context)[source]

Handles the follow callback.

Parameters:

spotted.handlers.forwarded_post module

Message forwarded by the telegram channel

async spotted.handlers.forwarded_post.forwarded_post_msg(update, context)[source]

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:

spotted.handlers.help module

/help command

async spotted.handlers.help.help_cmd(update, context)[source]

Handles the /help command. Sends an help message

Parameters:

spotted.handlers.job_handlers module

Scheduled jobs of the bot

async spotted.handlers.job_handlers.clean_pending_job(context)[source]

Job called each day at 05:00 utc. Automatically rejects all pending posts that are older than the chosen amount of hours

Parameters:

context (CallbackContext) – context passed by the jobqueue

async spotted.handlers.job_handlers.db_backup_job(context)[source]

Job called each day at 05:00 utc. Automatically upload and send last version of db for backup

Parameters:

context (CallbackContext) – context passed by the jobqueue

spotted.handlers.purge module

/purge command

async spotted.handlers.purge.purge_cmd(update, context)[source]

Handles the /purge command. Deletes all posts and the related votes in the database whose actual telegram message could not be found

Parameters:

spotted.handlers.reload module

/reload command

async spotted.handlers.reload.reload_cmd(update, context)[source]

Handles the /reload command. Reload the configuration file, updating the bot’s settings. This incudes both the _settings.yaml_ and the _autorereply.yaml_ file. This way the bot can be updated without restarting it.

In actuality, the current singleton is destroyed and a new one is created as soon as a configuration request is deemed necessary.

Parameters:

Warning

Loading different configurations may cause inconsistencies in live conversations.

spotted.handlers.reply module

/reply command

async spotted.handlers.reply.reply_cmd(update, context)[source]

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:

spotted.handlers.report_spot module

report callback

async spotted.handlers.report_spot.report_spot_callback(update, context)[source]

Handles the report callback.

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.report_spot.report_spot_conv_handler()[source]

Creates the report (user) conversation handler. The states are:

  • reporting_spot: submit the reason of the report. Expects text

Returns:

ConversationHandler – conversation handler

async spotted.handlers.report_spot.report_spot_msg(update, context)[source]

Handles the reply to the key “Report”. Checks the message the user wants to report, and goes to the final step

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.report_user module

/report command

async spotted.handlers.report_user.report_cmd(update, context)[source]

Handles the reply to the key “Report”. Checks the message the user wants to report

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.report_user.report_user_conv_handler()[source]

Creates the /report (user) conversation handler. The states are:

  • reporting_user: submit the username to report. Expects text starting with @ and without spaces in between

  • reporting_user_reason: submit the reason of the report. Expects text

Returns:

ConversationHandler – conversation handler

async spotted.handlers.report_user.report_user_msg(update, context)[source]

Handles the reply to the /report command after sent the @username. Checks the the user wants to report, and goes to ask the reason

Parameters:
Returns:

int – next state of the conversation

async spotted.handlers.report_user.report_user_sent_msg(update, context)[source]

Handles the reply to the /report command after sent the reason. Checks the the user wants to report, and goes to final step

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.rules module

/rules command

async spotted.handlers.rules.rules_cmd(update, context)[source]

Handles the /rules command. Sends a message containing the rules

Parameters:

spotted.handlers.sban module

/sban command

async spotted.handlers.sban.sban_cmd(update, context)[source]

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

Parameters:

spotted.handlers.settings module

/settings command

async spotted.handlers.settings.settings_callback(update, context)[source]

Handles the settings,[ anonimo | credit ] callback.

  • anonimo: Removes the user_id from the table of credited users, if present.

  • credit: Adds the user_id to the table of credited users, if it wasn’t already there.

Parameters:
async spotted.handlers.settings.settings_cmd(update, context)[source]

Handles the /settings command. Let’s the user choose whether his posts will be credited or not

Parameters:

spotted.handlers.spam_comment module

Anonym Comment on a post in the comment group

async spotted.handlers.spam_comment.spam_comment_msg(update, context)[source]

Handles a spam comment on a post in the comment group. Deletes the original post.

Parameters:
Return type:

None

spotted.handlers.spot module

/spot command

async spotted.handlers.spot.spot_cmd(update, context)[source]

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

Parameters:
Returns:

int – next state of the conversation

async spotted.handlers.spot.spot_confirm_query(update, context)[source]

Handles the [ submit | cancel ] callback. Creates the bid or cancels its creation.

  • submit: saves the post as pending and sends it to the admins for them to check.

  • cancel: cancels the current spot conversation

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.spot.spot_conv_handler()[source]

Creates the spot conversation handler. The states are:

  • posting: submit the spot. Expects text, photo or many other formats

  • confirm: confirm or cancel the spot submission. Expects an inline query

Returns:

ConversationHandler – conversation handler

async spotted.handlers.spot.spot_msg(update, context)[source]

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

Parameters:
Returns:

int – next state of the conversation

async spotted.handlers.spot.spot_preview_query(update, context)[source]

Handles the [ accept | reject ] callback. Let the user decide if wants to post the message with or without preview.

  • accept: the post will be published with preview

  • reject: the post will be published without preview

Parameters:
Returns:

int – next state of the conversation

spotted.handlers.start module

/start command

async spotted.handlers.start.start_cmd(update, context)[source]

Handles the /start command. Sends a welcoming message

Parameters:

Module contents

Modules that handle the events the bot recognizes and reacts to

async spotted.handlers.add_commands(app)[source]

Adds the list of commands with their description to the bot

Parameters:

app (Application) – supplied application

spotted.handlers.add_handlers(app)[source]

Adds all the needed handlers to the application

Parameters:

app (Application) – supplied application

spotted.handlers.add_jobs(app)[source]

Adds all the jobs to be scheduled to the application

Parameters:

app (Application) – supplied application