spotted.data package
Submodules
spotted.data.config module
Read the bot configuration from the settings.yaml and the autoreplies.yaml files
- class spotted.data.config.Config[source]
Bases:
object
Configurations
- AUTOREPLIES_PATH = 'autoreplies.yaml'
- DEFAULT_AUTOREPLIES_PATH = '/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/spotted/config/yaml/autoreplies.yaml'
- DEFAULT_SETTINGS_PATH = '/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/spotted/config/yaml/settings.yaml'
- SETTINGS_PATH = 'settings.yaml'
- classmethod autoreplies_get(*keys, default=None)[source]
Get the value of the specified key in the autoreplies configuration dictionary. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.
- classmethod debug_get(key, default=None)[source]
Get the value of the specified key in the configuration under the ‘debug’ section. If the key is not present, it will return the default value.
- classmethod override_settings(config)[source]
Overrides the settings with the configuration provided in the config dict.
- Parameters:
config (
dict
) – configuration dict used to override the current settings
- classmethod post_get(key, default=None)[source]
Get the value of the specified key in the configuration under the ‘post’ section. If the key is not present, it will return the default value.
- Parameters:
key (
Literal
['community_group_id'
,'channel_id'
,'channel_tag'
,'comments'
,'admin_group_id'
,'n_votes'
,'remove_after_h'
,'report'
,'report_wait_mins'
,'replace_anonymous_comments'
,'delete_anonymous_comments'
,'blacklist_messages'
]) – key to getdefault (
Any
, default:None
) – default value to return if the key is not present
- Returns:
Any
– value of the key or default value
- classmethod reload(force_reload=False)[source]
Reset the configuration. The next time a setting parameter is required, the whole configuration will be reloaded. If force_reload is True, the configuration will be reloaded immediately.
- Parameters:
force_reload (
bool
, default:False
) – if True, the configuration will be reloaded immediately
spotted.data.data_reader module
Read data from files
- spotted.data.data_reader.get_abs_path(*root_file_path)[source]
Get the abs path from the root directory of the project to the requested path
spotted.data.db_manager module
Handles the management of databases
- class spotted.data.db_manager.DbManager[source]
Bases:
object
Class that handles the management of databases
- classmethod count_from(table_name, select='*', where='', where_args=None)[source]
Returns the number of rows found with the query. Executes “SELECT COUNT(select) FROM table_name [WHERE where (with where_args)]”
- Parameters:
- Returns:
int
– number of rows
- classmethod delete_from(table_name, where='', where_args=None)[source]
Deletes the rows from the specified table, where the condition, when set, is satisfied. Executes “DELETE FROM table_name [WHERE where (with where_args)]”
- classmethod get_db()[source]
Creates the connection to the database. It can be sqlite or postgres
- Returns:
tuple
[Connection
,Cursor
] – sqlite database connection and cursor
- classmethod insert_into(table_name, values, columns='', multiple_rows=False)[source]
Inserts the specified values in the database. Executes “INSERT INTO table_name ([columns]) VALUES (placeholders)”
- Parameters:
table_name (
str
) – name of the table used in the INSERT INTOvalues (
tuple
) – values to be inserted. If multiple_rows is true, tuple of tuples of values to be insertedcolumns (
tuple
|str
, default:''
) – columns that will be inserted, as a tuple of stringsmultiple_rows (
bool
, default:False
) – whether or not multiple rows will be inserted at the same time
- classmethod query_from_file(*file_path)[source]
Commits all the queries in the specified file. The queries must be separated by a —– string Should not be used to select something
- Parameters:
file_path (
str
) – path of the text file containing the queries
- classmethod query_from_string(*queries)[source]
Commits all the queries in the string Should not be used to select something
- Parameters:
queries (
str
) – tuple of queries
- static register_adapters_and_converters()[source]
Registers the adapter and converters for the datetime type. Needed from python 3.12 onwards, as the default option has been deprecated
- classmethod select_from(table_name, select='*', where='', where_args=None, group_by='', order_by='')[source]
Returns the results of a query. Executes “SELECT select FROM table_name [WHERE where (with where_args)] [GROUP_BY group_by] [ORDER BY order_by]”
- Parameters:
table_name (
str
) – name of the table used in the FROMselect (
str
, default:'*'
) – columns considered for the querywhere (
str
, default:''
) – where clause, with %s placeholders for the where_argswhere_args (
tuple
|None
, default:None
) – args used in the where clausegroup_by (
str
, default:''
) – group by clauseorder_by (
str
, default:''
) – order by clause
- Returns:
list
– rows from the select
- classmethod update_from(table_name, set_clause, where='', args=None)[source]
Updates the rows from the specified table, where the condition, when set, is satisfied. Executes “UPDATE table_name SET set_clause (with args) [WHERE where (with args)]”
- Parameters:
table_name (
str
) – name of the table used in the DELETE FROMset_clause (
str
) – set clause, with %s placeholderswhere (
str
, default:''
) – where clause, with %s placeholders for the where argsargs (
tuple
|None
, default:None
) – args used both in the set clause and in the where clause, in this order
spotted.data.pending_post module
Pending post management
- class spotted.data.pending_post.PendingPost(user_id, u_message_id, g_message_id, admin_group_id, date)[source]
Bases:
object
Class that represents a pending post
- Parameters:
- classmethod create(user_message, g_message_id, admin_group_id)[source]
Creates a new post and inserts it in the table of pending posts
- Parameters:
- Returns:
PendingPost
– instance of the class
- classmethod from_group(g_message_id, admin_group_id)[source]
Retrieves a pending post from the info related to the admin group
- Parameters:
- Returns:
PendingPost
|None
– instance of the class
- classmethod from_user(user_id)[source]
Retrieves a pending post from the user_id
- Parameters:
user_id (
int
) – id of the author of the post- Returns:
PendingPost
|None
– instance of the class
- static get_all(admin_group_id, before=None)[source]
Gets the list of pending posts in the specified admin group. If before is specified, returns only the one sent before that timestamp
- Parameters:
- Returns:
list
[PendingPost
] – list of ids of pending posts
spotted.data.post_data module
Data management for the bot
spotted.data.published_post module
Published post management
- class spotted.data.published_post.PublishedPost(channel_id, c_message_id, date)[source]
Bases:
object
Class that represents a published post
- classmethod create(channel_id, c_message_id)[source]
Inserts a new post in the table of published posts
- Parameters:
- Returns:
PublishedPost
– instance of the class
- classmethod from_channel(channel_id, c_message_id)[source]
Retrieves a published post from the info related to the channel
- Parameters:
- Returns:
PublishedPost
|None
– instance of the class
spotted.data.report module
Reports management
- class spotted.data.report.Report(user_id, admin_group_id, g_message_id, channel_id=None, c_message_id=None, target_username=None, date=None)[source]
Bases:
object
Class that represents a report
- Parameters:
user_id (
int
) – id of the user that reportedadmin_group_id (
int
) – id of the admin groupg_message_id (
int
) – id of the post in the groupchannel_id (
int
, default:None
) – id of the channelc_message_id (
int
, default:None
) – id of the post in question in the channeltarget_username (
str
, default:None
) – username of the reported userdate (
datetime
, default:None
) – when the report happened
- classmethod create_post_report(user_id, channel_id, c_message_id, admin_message)[source]
Adds the report of the user on a specific post
- classmethod create_user_report(user_id, target_username, admin_message)[source]
Adds the report of the user targeting another user
- classmethod from_group(admin_group_id, g_message_id)[source]
Gets a report of any type related to the specified message in the admin group
- classmethod get_post_report(user_id, channel_id, c_message_id)[source]
Gets the report of a specific user on a published post
spotted.data.user module
Users management
- class spotted.data.user.User(user_id, private_message_id=None, ban_date=None, follow_date=None)[source]
Bases:
object
Class that represents a user
- Parameters:
user_id (
int
) – id of the userprivate_message_id (
int
|None
, default:None
) – id of the private message sent by the user to the bot. Only used for followingban_date (
datetime
|None
, default:None
) – datetime of when the user was banned. Only used for banned usersfollow_date (
datetime
|None
, default:None
) – datetime of when the user started following a post. Only used for following users
- become_anonym()[source]
Removes the user from the credited list, if he was present
- Returns:
bool
– whether the user was already anonym
- become_credited()[source]
Adds the user to the credited list, if he wasn’t already credited
- Returns:
bool
– whether the user was already credited
- classmethod following_users(message_id)[source]
Returns a list of all the users following the post with the associated private message id used by the bot to send updates about the post by replying to it
- async get_user_sign(bot)[source]
Generates a sign for the user. It will be a random name for an anonym user
- sban()[source]
Removes the user from the banned list
- Returns:
bool
– whether the user was present in the banned list before the sban or not
Module contents
Modules that work with the data section