def send_pm(self, content: dict = None, message: str = None, to: str = None, state: int = 6): if state == 7: users = "Users list:" for user in self.server.clients: users += f' {user.login},' msg = encrypt(self.public_key, users) pack = {'message': msg, 'state': 7} pack = pickle.dumps(pack) self.transport.write(pack) return for user in self.server.clients: if user.login == to: msg = encrypt(user.public_key, message) pack = { 'login': content['login'], 'message': msg, 'state': state, 'color': content['color'] } if state == 14: pack['attach'] = encrypt_bytes(self.public_key, content['attach']) pack['fname'] = content['fname'] pack['state'] = 14 pack = pickle.dumps(pack) user.transport.write(pack) return
def send_pm(self, message: str, to: str = None, state: int = 2): msg = message if state == 2: message = encrypt(self.public, message) pack = { "login": self.login, 'email': self.email, 'message': message, 'to': to, 'state': state, 'color': self.color } self.send_file(pack) if pack['state'] == 4: pack['state'] = 6 print(pack['state']) blue = f'<span style=\"font-weight: 400; color:{self.window.text_color}; font-size: ' \ f'{self.settings["font-size"]};\" >{time.strftime("%H:%M", time.localtime())}</span>' blue += f'<span style=\"color: {self.settings["color"]}\"> {pack["login"]}: </span> <span style=\"' \ f'font-weight: 400; font-style: italic; color: orange;\" > {msg}</span>' self.window.append_text(blue) pack = pickle.dumps(pack) elif state == 3: message = encrypt(self.public, message) pack = { "login": self.login, 'email': self.email, 'message': message, 'state': state, "color": self.color } pack = pickle.dumps(pack) self.transport.write(pack)
def send_data(self, message: str, state=None): message = encrypt(self.public, message) pack = { 'login': self.login, 'email': self.email, 'message': message, 'state': state, 'color': self.color } self.send_file(pack) pack = pickle.dumps(pack) self.transport.write(pack)
def notes_func(text_box): global current_date file = "notes" if current_date == file: # When notes is already open return None save_data(current_date, text_box) current_date = file if not read_to_textbox(text_box, file): # The file did not exist with open(file + ".SDE", 'w') as f: f.write(encrypt("--- ADD NOTES HERE ---\n\n", int(code))) read_to_textbox(text_box, file)
def send_message(self, content: dict, message: str, state: int = None, attach=False): for user in self.server.clients: msg = encrypt(user.public_key, message) pack = { 'login': content['login'], 'message': msg, 'state': state, 'color': content['color'] } if attach: pack['attach'] = encrypt_bytes(user.public_key, content['attach']) pack['fname'] = content['fname'] pack['state'] = 8 pack = pickle.dumps(pack) user.transport.write(pack)
def sign_up(frame, user_name, password): global code, user if not validate_values(frame, user_name, password): return None if check_user(user_name): window(frame, "Close", "User already exists") return None else: user_name = make_folder_name(user_name) os.makedirs(user_name) with FolderManager(user_name): with open("datfile.SDE", 'w') as file: file.write(encrypt(ex_text, int(password))) window(frame, "Close", "User successfully created") time.sleep(2) user = user_name code = password frame.destroy() main()
def save_data(file_date, text_box): data = text_box.get('0.0', 'end') # Get the text that has been entered into the box data = data.rstrip() data = spell_check(data) if data.strip() == "": # Don't save an empty file return None if data.strip().lower() == "delete": try: os.remove(file_date + ".SDE") return None except FileNotFoundError: return None data = encrypt(data, int(code)) # Encrypt the data before saving as a file with open(file_date + ".SDE", 'w') as file: file.write(data)
def save_to_file(text_box, file): if ".SDE" not in file: file += ".SDE" data = text_box.get('0.0', 'end') with open(file, 'w') as f: f.write(encrypt(data, int(code)))