def message(self): user_state = db_persistence.get_state(self.peer_id) if user_state is not None: if user_state == UserState.ID: try: __uuid = str(uuid.UUID(self.event.message.get('text'))) if db_persistence.is_exist(_uuid=__uuid): if not db_persistence.get_ids(_uuid=__uuid)[0][1]: db_persistence.update_connection( {'uuid': __uuid}, { 'vkID': self.peer_id, 'user_name': self.from_user }) self.text = "Your account is full registered" else: self.text = "This account is already registered!" else: self.text = 'Wrong id! Try again...' except ValueError: self.text = 'Wrong id! Try again...' else: self.text = "Simple message!" else: self.text = "Simple message!" db_persistence.insert_or_update_user_state(self.peer_id, UserState.INITIAL)
def sub(self): if not db_persistence.is_exist(vk_id=self.from_id): self.text = f'@id{self.from_id}\n You are not registered!' return if db_persistence.is_listening(self.peer_id, self.from_id): self.text = f'@id{self.from_id}\n You are already listener of this chat!' return db_persistence.add_listener(self.peer_id, self.from_id) self.text = f'@id{self.from_id}\n I add you to listener of this chat!'
def new_acc(self): _uuid = utils.get_uuid() if db_persistence.is_exist(vk_id=self.peer_id): self.text = vk_dict.ALREADY_EXIST.format(id=_uuid) return self.text = vk_dict.NEW_ACC_MESSAGE.format(id=_uuid) db_persistence.insert_new_connection(_uuid=_uuid, vk_id=self.peer_id, user_name=self.from_user)
def unsub(self): if not db_persistence.is_exist(vk_id=self.from_id): self.text = f'@id{self.from_id}\n You are not registered!' return if not db_persistence.is_listening(self.peer_id, self.from_id): self.text = f'@id{self.from_id}\n You are not listener of this chat!' return db_persistence.remove_listener(self.peer_id, self.from_id) self.text = f'@id{self.from_id}\n I remove you from listener of this chat!'
def from_tg_to_vk(vk_id, message: Message): vk_bot.loop.run_until_complete( vk_bot.write_msg(message=message, peer_id=vk_id)) chat_listeners = db_persistence.get_chat_listeners(vk_id) message._tg_id = message.from_id message._from_id = vk_id if len(chat_listeners) > 0: message.chat_title = vk_bot.loop.run_until_complete( vk_bot.get_chat_title(peer_id=vk_id)) for chat_listener in chat_listeners: chat_listener_id = int(chat_listener[0]) if db_persistence.is_exist(vk_id=chat_listener_id) \ and db_persistence.is_fully_registered(chat_listener_id): tg_id = db_persistence.get_ids(vk_id=chat_listener_id)[0][2] if tg_id != message.tg_id: from_vk_to_tg(tg_id, message)
def callback_func(call): if call.data == 'new_acc': if db.is_exist(tg_id=call.message.chat.id): bot.send_message(call.message.chat.id, dict.ALREADY_EXIST) return _uuid = get_uuid() bot.edit_message_text(text=dict.NEW_ACC_MESSAGE.format(id=_uuid), chat_id=call.message.chat.id, message_id=call.message.id) db.insert_new_connection(_uuid=_uuid, tg_id=call.message.chat.id) elif call.data == 'ex_acc': markup = ForceReply(selective=False) bot.delete_message(call.message.chat.id, call.message.id) bot.send_message(call.message.chat.id, dict.EX_ACC_MESSAGE, reply_markup=markup) def next_handler_step(message): try: __uuid = str(uuid.UUID(message.text)) if db.is_exist(_uuid=__uuid): if not db.get_ids(_uuid=__uuid)[0][2]: db.update_connection({'uuid': __uuid}, {'tgID': message.chat.id}) bot.send_message(message.chat.id, "Your account is full registered") else: bot.send_message( message.chat.id, "This account is already registered!") else: bot.send_message(message.chat.id, 'Wrong id! Try again...') except ValueError: bot.send_message(message.chat.id, 'Wrong id! Try again...') bot.register_next_step_handler(call.message, next_handler_step) elif 'reply_to' in call.data: if db.get_tg_state(call.message.chat.id) == TgUserState.INITIAL: vk_peer_id = call.data[9:] call.data = vk_peer_id get_chat_id(call) else: bot.send_message(call.message.chat.id, 'Something went wrong! Try again') db.insert_or_update_tg_state(call.message.chat.id, TgUserState.INITIAL)
def next_handler_step(message): try: __uuid = str(uuid.UUID(message.text)) if db.is_exist(_uuid=__uuid): if not db.get_ids(_uuid=__uuid)[0][2]: db.update_connection({'uuid': __uuid}, {'tgID': message.chat.id}) bot.send_message(message.chat.id, "Your account is full registered") else: bot.send_message( message.chat.id, "This account is already registered!") else: bot.send_message(message.chat.id, 'Wrong id! Try again...') except ValueError: bot.send_message(message.chat.id, 'Wrong id! Try again...')
def chat_message(self): chat_listeners = db_persistence.get_chat_listeners(self.peer_id) if len(chat_listeners) > 0: for chat_listener in chat_listeners: chat_listener_id = int(chat_listener[0]) if chat_listener_id != self.from_id: if db_persistence.is_exist( vk_id=chat_listener_id ) and db_persistence.is_fully_registered(chat_listener_id): tg_id = db_persistence.get_ids( vk_id=chat_listener_id)[0][2] self.event.client_info.update( {'from_title': f'{self.from_user}'}) self.event.message.update( {'chat_title': self.chat_title}) connector.from_vk_to_tg(tg_id, Message.from_vk(self.event))