operations¶
Attributes¶
Maximum time difference in minutes |
Classes¶
Functions¶
|
Determines whether the time difference between two given time objects is less than one hour. |
Module Contents¶
- MAX_TIME_DIFF = 20¶
Maximum time difference in minutes
- less_than_one_hour(time1: datetime.datetime.time, time2: dict) bool ¶
Determines whether the time difference between two given time objects is less than one hour.
- Parameters:
time1 (datetime.time) – A datetime.time object.
time2 (dict) – A dictionary containing a ‘time’ key, which holds a time string in the format ‘%H:%M’.
- Returns:
True if the difference between the two times is less than one hour, False otherwise.
- Return type:
bool
- class DatabaseOperations¶
- static user_exists(user_id: int) bool ¶
Check if a user with the given ID exists in the ‘users’ table.
- Parameters:
user_id (int) – The ID of the user to check.
- Returns:
True if the user exists, False otherwise.
- Return type:
bool
- static user_already_registered(user_id: int) bool ¶
Check if a user is already registered in the ‘users’ table.
- Parameters:
user_id (int) – The ID of the user to check.
- Returns:
True if the user is registered, False otherwise.
- Return type:
bool
- static get_username(user_id: int) str ¶
Retrieve the username associated with a user ID.
- Parameters:
user_id (int) – The ID of the user to look up.
- Returns:
The username associated with the given user ID, or None if no user
- Return type:
str
- static get_user_property(user_id: int, key: str) str | bool ¶
Read a specific property of a user from the ‘users’ table.
- Parameters:
user_id (int) – The ID of the user whose property is being read.
key (str) – The column name in the ‘users’ table to retrieve.
- Returns:
The value of the specified property for the user, or None if the user is not found.
- Return type:
str | bool
- static get_user_information(user_id: int) tuple[bool, bool] ¶
Retrieve specific information about a user.
- Parameters:
user_id (int) – The ID of the user whose information is being retrieved.
- Returns:
A tuple containing the response message and alert mode for the user, or (None, None) if the user is not found.
- Return type:
tuple
- static update_user_property(user_id: int, key: str, value: str | bool) None ¶
Update a specific property of a user in the ‘users’ table.
- Parameters:
user_id (int) – The ID of the user whose property is to be updated.
key (str) – The column name in the ‘users’ table to update.
value (str | bool) – The new value for the property.
- static create_user(user_id: int, username: str) None ¶
Create a new user in the ‘users’ table with default values.
- Parameters:
user_id (int) – The ID of the new user.
username (str) – The username of the new user.
- static delete_user(user_id: int) None ¶
Delete a user from the ‘users’ table and all its relative data.
- Parameters:
user_id (int) – The ID of the user to delete.
- static get_contacts(user_id: int) list[tuple[int, str, bool]] ¶
Retrieve the contact information for a user.
- Parameters:
user_id (int) – The ID of the user whose contacts are being retrieved.
- Returns:
A list of tuples containing the contact ID, tag, and pair status for each contact.
- Return type:
list[tuple[int, str, bool]]
- static get_paired_contacts(user_id: int) list[tuple[int, str]] ¶
Retrieve the paired contacts information for a user.
- Parameters:
user_id (int) – The ID of the user whose contacts are being retrieved.
- Returns:
A list of tuples containing the contact ID and tag for each contact.
- Return type:
list[tuple[int, str, bool]]
- static add_contacts(user_id: int, username: str, target_usernames: list[str]) list[dict] ¶
Add new contacts for a user and handle contact requests.
- Parameters:
user_id (int) – The ID of the user adding contacts.
username (str) – The username of the user adding contacts.
target_usernames (list[str]) – A list of usernames to add as contacts.
- Returns:
A list of notifications with contact IDs and tags for successfully added contacts.
- Return type:
list[dict]
- static update_contacts_property(user_id: int, target_username: str, key: str, value: int | bool) None ¶
Update a specific property of a contact in the ‘contacts’ table.
- Parameters:
user_id (int) – The ID of the user who owns the contact.
target_username (str) – The username of the contact.
key (str) – The column name in the ‘contacts’ table to update.
value (int | bool) – The new value for the property.
- static update_contact_pairing(user_id: int, contact_id: int, key: str, value: int | bool) None ¶
Update a specific property of a contact in the ‘contacts’ table.
- Parameters:
user_id (int) – The ID of the user who owns the contact.
contact_id (int) – The ID of the contact.
key (str) – The column name in the ‘contacts’ table to update.
value (int | bool) – The new value for the property.
- static update_contacts_reload(username: str, user_id: int) None ¶
Reload the contact_id property when a user reconnects.
- Parameters:
username (str) – The username of the user that just reconnected.
user_id (int) – The contact_id of the user that just reconnected.
- static delete_contact(user_id: int, target_usernames: list[str]) None ¶
Delete contacts from the user’s contact list.
- Parameters:
user_id (int) – The ID of the user from whom contacts will be deleted.
target_usernames (list[str]) – A list of usernames to delete from the contacts.
- static get_contact_requests(user_id: int) list[tuple[int, str]] ¶
Retrieve the contact requests for a user.
- Parameters:
user_id (int) – The ID of the user whose contact requests are being retrieved.
- Returns:
A list of tuples containing the requester ID and requester tag for each contact request.
- Return type:
list[tuple[int, str]]
- static delete_contact_request(user_id: int, requester_user_id: int) None ¶
Delete contacts requests from the user’s contact requests list.
- Parameters:
user_id (int) – The ID of the user from whom contact requests will be deleted.
requester_user_id (int) – The ID of the user whose will be deleted from the contact requests.
- static get_user_verifications(user_id: int) list[tuple[datetime.datetime.time, str, bool]] ¶
Retrieve the verifications for a user.
- Parameters:
user_id (int) – The ID of the user whose verifications are being retrieved.
- Returns:
A list of tuples containing the time, description, and active status for each verification.
- Return type:
list
- static get_idle_users_verifications() list[tuple[int, datetime.datetime.time, str, bool]] ¶
Retrieves a list of verifications from users who have not responded.
The method queries the database for users with active daily messages but have a response_message flag set to True.
- Returns:
- A list of tuples, each containing:
user ID (int)
time of the message (datetime.time)
description of the message (str)
whether the message is active (bool)
- Return type:
list[tuple[int, datetime.time, str, bool]]
- static delete_verifications(user_id: int, times_to_delete: list) None ¶
Delete specific verifications for a user.
- Parameters:
user_id (int) – The ID of the user from whom verifications will be deleted.
times_to_delete (list) – A list of times specifying which verifications to delete.
- static update_verification_status(user_id: int, times_to_update: list, active: bool) None ¶
Update the status of specific verifications for a user.
- Parameters:
user_id (int) – The ID of the user whose verification statuses are being updated.
times_to_update (list) – A list of times specifying which verifications to update.
active (bool) – The new status for the verifications (active or inactive).
- static skip_verifications(user_id: int, times_to_skip: list) None ¶
Mark specific verifications as skipped (inactive).
- Parameters:
user_id (int) – The ID of the user whose verifications are being skipped.
times_to_skip (list) – A list of times specifying which verifications to skip.
- static undoskip_verifications(user_id: int, times_to_undoskip: list) None ¶
Revert the status of specific verifications to active.
- Parameters:
user_id (int) – The ID of the user whose verifications are being reverted.
times_to_undoskip (list) – A list of times specifying which verifications to reactivate.
- static add_verifications(user_id: int, new_verifications: list, skip_check: bool = False) list[str] ¶
Add new verifications for a user.
- Parameters:
user_id (int) – The ID of the user for whom verifications are being added.
new_verifications (list) – A list of new verification entries to add.
skip_check (bool) – Whether to skip validation checks for existing verifications.
- Returns:
A list of times for which verifications were not valid.
- Return type:
list
- static transfer_pending_requests(user_id: int, target_username: str) list[tuple[int, str]] ¶
Transfer pending requests to the ‘contact_requests’ table and delete them from the ‘pending_requests’ table.
- Parameters:
user_id (int) – The ID of the user receiving the pending requests.
target_username (str) – The username associated with the pending requests.
- Returns:
A list of requester IDs whose requests were transferred.
- Return type:
list[int]
- static add_bug_report(user_id: int, username: str, message: str) int ¶
Write a bug report for a user.
- Parameters:
user_id (int) – The ID of the user submitting the bug report.
username (str) – The username of the user submitting the bug report.
message (str) – The content of the bug report.
- Returns:
The ID of the newly created bug report.
- Return type:
int
- static get_check_queue_items() list[tuple[int, datetime.datetime.time, str, int, int]] ¶
Retrieves all checks from the check queue.
Queries the check_queue table to get all queued checks.
- Returns:
- A list of tuples, each containing:
user ID (int)
time of the check (datetime.time)
description of the check (str)
reminder count (int)
waiting time (int)
- Return type:
list[tuple[int, datetime.time, str, int, int]]
- static update_check_queue_property(user_id: int, key: str, value: int) None ¶
Updates a specific property of a user’s check queue entry.
Allows updating any integer field in the check_queue table for the given user based on the provided key.
- Parameters:
user_id (int) – The ID of the user.
key (str) – The name of the field to be updated.
value (int) – The new value to be set for the specified field.
- static add_check_queue_item(user_id: int, time: datetime.datetime.time, desc: str, waiting_time: int) None ¶
Initializes a check queue entry for a user.
Inserts a new entry into the check_queue table with the given user ID, time, description, and waiting time. The reminder_count is set to 0 by default.
- Parameters:
user_id (int) – The ID of the user.
time (datetime.time) – The time associated with the check.
desc (str) – The description of the check.
waiting_time (int) – The waiting time before the next reminder.
- static delete_check_queue_item(user_id: int) None ¶
Deletes a user’s check queue entry.
Removes the entry from the check_queue table for the specified user.
- Parameters:
user_id (int) – The ID of the user whose check queue entry should be deleted.