Handler database and subscribe operations#

Handler DB and SUB operations#

Module for control the database.

class handler_db_sub_operations.HandlerDB[source]#

Handler-class for manage database.

async static add_new_email(email, tg_id, username, firstname, exists_in_db=True)[source]#

Add a new email to DB.

Parameters:
  • email (str) – EMail.

  • tg_id (int) – TG ID.

  • username (str) – Username.

  • firstname (str) – Firstname of user / admin.

  • exists_in_db – Bool-result from past-check.

Returns:

Result.

Return type:

bool

async static add_new_promo_code(promo, num_uses, type_promo)[source]#

Function for add a new promo code from admin. | Admin control.

Parameters:
  • promo (str) – A new promo code.

  • num_uses (int) – Number of uses the promo code.

  • type_promo (str) – Type of the promo code.

Returns:

Result | Data of promo.

Return type:

tuple

async static add_new_ticket_data(id_ticket, username, tg_id_sender, ticket_data, create_at, subject)[source]#

Function for add new ticket data.

Parameters:
  • id_ticket (str) – ID Ticket.

  • username (str) – Sender’s Telegram Username.

  • tg_id_sender (int) – Sender’s Telegram ID.

  • ticket_data (str) – Data of the Ticket.

  • create_at (str) – CREATE_AT - data of the ticket.

  • subject (str) – Subject of the ticket.

Returns:

None.

Return type:

None

async static check_promo_code(promo)[source]#

Get and check promo code from database.

Parameters:

promo (str) – Promo code from user.

Returns:

Result | Data of promo.

Return type:

tuple

async static check_refund_token(message)[source]#

Check (look for) refund token from database.

Parameters:

message (aiogram.types.message.Message | aiogram.types.callback_query.CallbackQuery) – Message from user | Callback Query.

Returns:

REF-Token or False (otherwise).

Return type:

str | bool

async static check_subscription(message)[source]#

Check subscription by message from user.

Parameters:

message (aiogram.types.message.Message | aiogram.types.callback_query.CallbackQuery) – Message from user | Callback Query.

Returns:

tuple.

Return type:

tuple

async static check_subscription_by_refund_token(refund_token)[source]#

Check subscription by refund token from user.

Parameters:

refund_token (str) – REF-token.

Returns:

Data.

Return type:

tuple

async static delete_promo_code(promo)[source]#

Function for delete a promo code from admin. | Admin control.

Parameters:

promo (str) – A promo code.

Returns:

Result of delete a promo code.

Return type:

bool

async static delete_record_for_subscribe(ref_token)[source]#

Delete a record from database | CW PREMIUM Subscription.

Parameters:

ref_token (str) – REF-token.

Returns:

Result of delete.

Return type:

tuple

async static get_admin_email_from_file(file_path='bot.json')[source]#

Get data of the ADMIN Manager Bot.

Parameters:

file_path – File Path of JSON-API-keys for Bot.

Returns:

Dict with data.

Return type:

str

async static get_analytic_datas()[source]#

Get Analytics.

Returns:

Tuple with data.

Return type:

tuple

async static get_data(file_path='bot.json')[source]#

Get data of the ADMIN Manager Bot.

Parameters:

file_path – File Path of JSON-API-keys for Bot.

Returns:

Dict with data.

Return type:

dict

async static get_email_data(tg_id)[source]#

Get email data by tg id.

Parameters:

tg_id (int) – Tg ID.

Returns:

Tuple with EMail-data.

Return type:

tuple

async static get_temp_code_for_check_email(tg_id)[source]#

Get temp-code by tg id.

Parameters:

tg_id (int) – Tg ID.

Returns:

Tuple with EMail-code-verification.

Return type:

tuple

async static get_ticket_data(tg_id, builder)[source]#

Get ticket data.

Parameters:
  • tg_id (int) – User’s id – tg_id.

  • builder (InlineKeyboardBuilder) – Builder.

Returns:

Tuple with data.

Return type:

aiogram.utils.keyboard.InlineKeyboardBuilder | tuple

async static get_users_tickets_for_admin()[source]#

Get ticket data.

Returns:

Tuple with data.

Return type:

aiogram.utils.keyboard.InlineKeyboardBuilder | tuple

async static insert_new_record_for_subscribe(message, days, token_successful_payment='PROMO', promo='none')[source]#

Insert a new record to database | CW PREMIUM Subscription.

Parameters:
  • message (aiogram.types.message.Message | aiogram.types.callback_query.CallbackQuery) – Message from user.

  • days (int) – Count of days for use CW PREMIUM.

  • token_successful_payment (str) – Token of successful payment.

  • promo (str) – A promo code.

Returns:

Result.

Return type:

tuple

async static show_promo_datas()[source]#

Show promo datas from database without authorization.

Returns:

PROMO Data.

Return type:

bool | tuple

async static sub_promo_code(promo)[source]#

Subtract the number of subscription uses.

Parameters:

promo (str) – Promo code.

Returns:

Result | Data of promo.

Return type:

bool | tuple

async static update_analytic_datas_count_ai_queries(count=1)[source]#

Update analytic datas. Update CAQ.

Parameters:

count (int) – Count of AI queries.

Returns:

None.

Return type:

None

async static update_analytic_datas_count_tickets_system(count=1)[source]#

Update count of tickets. Update CTS.

Parameters:

count (int) – Count of Tickets in the TSystem.

Returns:

None.

Return type:

None

async static update_temp_code_for_check_email(tg_id, code, firstname, username, command, admin_id='None')[source]#

Update temp-code by tg id.

Parameters:
  • tg_id (int) – Tg ID.

  • code (str) – Code for ver.

  • firstname (str) – First name of user / admin.

  • username (str) – Username.

  • command (str) – Command

  • admin_id – ID Admin.

Returns:

Result.

Return type:

tuple

async static update_yookassa_data(call, confirmation_id, admin_id='None', admin_email='None')[source]#

Update payment data of yookassa in DB.

Parameters:
  • call (CallbackQuery) – Callback Query

  • confirmation_id (str) – Confirmation ID.

  • admin_id – ID Admin.

  • admin_email – Admin EMail.

Returns:

Result.

Return type:

tuple

async static yookassa_delete_record_conf_id(tg_id)[source]#

Fast delete record (confirmation-id of payment from yookassa).

Return type:

None

async static yookassa_get_conf_id(tg_id)[source]#

Get yookassa payment confirmation id from DB by TG ID.

Parameters:

tg_id (int) – TG ID.

Returns:

Tuple with data-result.

Return type:

tuple

async static yookassa_up_query(confirmation_id, tg_id)[source]#

Yookassa fast-query for update data.

Parameters:
  • confirmation_id (str) – Confirmation ID.

  • tg_id (int) – TG ID.

Returns:

None.

Return type:

None

class handler_db_sub_operations.SubOperations[source]#

Operations for manage subscription.

async static days_to_sec(days)[source]#

Converter ‘DAYS TO SECONDS’.

Parameters:

days (int) –

Return type:

int

async static sec_to_days(sec)[source]#

Converter ‘SECONDS TO DAYS’.

Parameters:

sec (int | float) –

Return type:

int | float