def handle_redaction_query(call): system.clear(message=call.message) try: redaction.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def add_client(self, message): chat_id = message.chat.id if chat_id == self.REDACTION_CHAT_ID: return username = message.chat.username if message.chat.username is not None else "Безіменний" name = message.chat.first_name if message.chat.first_name is not None else "Безіменний" surname = message.chat.last_name if message.chat.last_name is not None else "0" register_date = datetime.now() last_interaction = register_date try: owner_registered = len( self.data.get_owner(where={"ChatID": chat_id})) >= 1 except: error_logging.send_error_info_message( bot=self.bot, current_frame=error_logging.currentframe(), additional_info=None) return if chat_id == self.REDACTION_CHAT_ID: return if not owner_registered: self.data.add_owner_account(balance=0) owner_account_id = self.data.get_owner_account( order_by={"OwnerAccountID": "DESC"})[0].OwnerAccountID self.data.add_owner(chat_id=chat_id, nickname=username, name=name, surname=surname, register_date=register_date, last_interaction_time=last_interaction, owner_account_id=owner_account_id)
def handle_channel_query(call): system.update_client_interaction_time(call.message) try: channel.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def handle_payment_query(call): system.clear(message=call.message) try: order.payment.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def add_client(self, message): username = message.chat.username if message.chat.username is not None else "Безіменний" name = message.chat.first_name if message.chat.first_name is not None else "Безіменний" surname = message.chat.last_name if message.chat.last_name is not None else "0" register_date = datetime.now() last_interaction = register_date chat_id = message.chat.id try: client_registered = len( self.data.get_client(where={"ChatID": chat_id})) == 1 except: error_logging.send_error_info_message( bot=self.bot, current_frame=error_logging.currentframe(), additional_info=None) return if chat_id == self.REDACTION_CHAT_ID: return if not client_registered: self.data.add_client(chat_id=chat_id, username=username, name=name, surname=surname, register_date=register_date, last_interaction_time=last_interaction)
def update_value(self, table, column, value, where, where_value): values = str() for col, val in zip(column, value): if val[0] == None: values += f"{col[0]} = Null, " elif isinstance(val[0], datetime): date_time = val[0].strftime("%Y-%m-%d %H:%M:%S") values += f"{col[0]} = '{date_time}', " elif isinstance(val[0], date): values += f"{col[0]} = '{str(val[0])}', " elif not isinstance(val[0], int): values += f"{col[0]} = N'{val[0]}', " else: values += f"[{col[0]}] = {val[0]}, " values = values[:-2] if not isinstance(where_value, int): where_value = "N'{}'".format(where_value) query = """ UPDATE [{}] SET {} WHERE [{}] = {}""".format(table, values, where, where_value) try: self.cursor.execute(query) self.connection.commit() print("{} {} updated succesfully!".format(table, column)) except: error_logging.send_error_info_message( bot=self.bot, current_frame=error_logging.currentframe(), additional_info=query) print("{} {} failed to update(((".format(table, column))
def add_value(self, table, *values): value = str() for item in values: if item == None: value += "Null, " elif isinstance(item, datetime): date_time = item.strftime("%Y-%m-%d %H:%M:%S") value += f"'{date_time}', " elif isinstance(item, date): value += f"'{str(item)}', " elif isinstance(item, int) or isinstance(item, float): value += "{}, ".format(item) else: item = item.replace("'", "`") value += "N'{}', ".format(item) value = value[:-2] #erase , in the end query = """ INSERT INTO [{}] VALUES ({})""".format(table, value) try: self.cursor.execute(query) self.connection.commit() print("{} added succesfully!".format(table)) except: error_logging.send_error_info_message( bot=self.bot, current_frame=error_logging.currentframe(), additional_info=query) print("New {} not added(((".format(table))
def handle_order_query(call): system.clear(message=call.message) system.update_client_interaction_time(call.message) try: order.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def handle_account_query(call): system.clear(chat_id=call.message.chat.id) system.update_client_interaction_time(call.message) try: account.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def redaction_decision(call): system.clear(chat_id=call.message.chat.id) system.update_client_interaction_time(call.message) try: redaction.process_callback(call) except: oops(call, current_frame=error_logging.currentframe())
def select_table(self, table, values, sign, where=None, order_by=None): select_clause = str() # Values for value in values: if value != "*": select_clause += "[{}], ".format(value) else: select_clause += "{}, ".format(value) select_clause = select_clause[:-2] # Where clause where_clause = str() if where is not None: where_clause = "WHERE " index = 0 for key, value in where.items(): if not isinstance(value, int) and not isinstance(value, date): value = "N'{}%'".format(value) where_clause += "{} LIKE {} AND ".format(key, value) else: if isinstance(value, datetime): date_time = value.strftime("%Y-%m-%d %H:%M:%S") value = f"'{date_time}', " elif isinstance(value, date): value = f"'{str(value)}'" where_clause += "{} {} {} AND ".format( key, sign[index], value) index += 1 where_clause = where_clause[:-4] # Order By clause order_by_clause = str() if order_by is not None: value, direction = [[k, v] for k, v in order_by.items()][0] order_by_clause = f"ORDER BY {value} {direction}" table = f"[{table}]" if "[" not in table else table query = """ SELECT {} FROM {} {} {}""".format(select_clause, table, where_clause, order_by_clause) try: self.cursor.execute(query) rows = self.cursor.fetchall() except: error_logging.send_error_info_message( bot=self.bot, current_frame=error_logging.currentframe(), additional_info=query) return list() return rows
def handle_etc_query(call): if call.data == "DELETE": try: bot.delete_message(chat_id=call.message.chat.id, message_id=call.message.message_id) except: bot.answer_callback_query(call.id, text=data.message.delete_error) elif call.data == "IGNORE": bot.answer_callback_query(call.id) else: oops(call, current_frame=error_logging.currentframe())
def process_payment(self, message, channel_id, order_forming, content): chat_id = message.chat.id ad_photo = content["Photo"] ad_text = content["Text"] ad_comment = content["Comment"] ad_post_date = content["PostDate"] channel = self.data.get_channel(where={"ChannelID":channel_id})[0] # create invoice and check it's status invoice_data, order_reference = self.api_create_invoice(price=channel.Price, channel_name=channel.Name) invoice_link = invoice_data["invoiceUrl"] payment_status_response = self.api_check_status(order_reference) # add new paymnet to DB self.add_new_payment(order_id=None, payment_status_response=payment_status_response) # form receipt and send it to client markup = InlineKeyboardMarkup() button = InlineKeyboardButton(text="Оплатити", url=invoice_link) markup.add(button) receipt_text = self.data.message.form_order_receipt(channel.Name.strip(), ad_post_date, channel.Price) try: message = self.bot.send_message(chat_id=message.chat.id, text=receipt_text, reply_markup=markup, parse_mode="HTML") except: self.bot.send_message(chat_id=chat_id, text=self.data.message.order_payment_error) error_logging.send_error_info_message(bot=self.bot, current_frame=error_logging.currentframe(), additional_info="Вірогідно OrderReference") return # check payment status succesful_payment, payment_status_response = self.check_pay(message=message, order_reference=order_reference) # form order if payment was succesful (add it to DB) if succesful_payment: order_id = order_forming(message, channel_id, ad_photo, ad_text, ad_comment, ad_post_date) else: order_id = None message_id = message.message_id self.bot.edit_message_text(chat_id=chat_id, message_id=message_id, reply_markup=None, text=self.data.message.order_payment_time_is_up) # update payment status self.add_new_payment(order_id=order_id, payment_status_response=payment_status_response, update=True)