chat with ppl pt2

I know I know this can be easily hacked (proxy), But @python660 is kind enough to help me prepare a auth to make chats more secure (the new and improved proxy that I will use next time), this is on beta only. So after @python660 has completed this, I will release the full version which will not just include normal chats. It includes a lot of features, trust me.
The new version (not beta) will include:
Able to add chats to other people
Able to access the chats that you have added
Able to delete chats permanently
Possibly more to come


Link: Chat with your friends! - Replit

5 Likes
from replit import db
import os
from getkey import getkey,keys
from idkwhttph import *
from time import sleep
import sys
import os
import re

def clear_last_line():
    # Move the cursor to the beginning of the last line
    sys.stdout.write('\033[F')
    # Clear the line
    sys.stdout.write('\033[K')
    # Move the cursor to the beginning of the line
    sys.stdout.write('\033[F')
print('Connecting to the database')
while True:
  try:
    
    db.db_url = "https://replit-database-proxy-10.idkwhttph.repl.co"
    clear()
    break
  except:
    print('?Error connecting to database, reconnecting...')
try:
  print(db['server_chat'])
  clear()
except:
  db['server_chat'] = {'System':'Hey! Its the start of the chat! Type something!'}


    

if os.environ['REPL_OWNER'] in db.keys():
  pass
else:

    clear()
    db[os.environ['REPL_OWNER']] = {}
changelogs = """
Update 1.0
    Fixed the server_chat
    You can now chat without your past messages being gone
Update 1.1
    Fixed your name from being {name}{messages}
    if message history is > 10000, it deletes 1k of the past messages.
Update 1.2
    fixed messages being double printed
Update 1.3
    fixed messages sticking together or coming out as lists ( eg. HELLOWORLD or ['Hello','World'])

             """
def check_if_10000(chat):
  if len(db[chat].keys()) >=1000:
    x = 0
    for i in db[chat]:
      if x >=1+2:
        break
      del db[chat][i]
      x+=1
    pass
  pass

def check_if_10000_1(chat):
  if len(db[chat].keys()) >=1000:
    for i in db[chat]:
        if len(db[chat].keys()) <=1000 :
          break
        del db[os.environ['REPL_OWNER']][chat][i]
    pass
  pass

def chat_with_who_personal(chat):
    clear()
    
    msg = []
    check_if_10000_1(chat)
    x = 0
    print_layer()
    print('\n\n')

    snapshot_keys = list(db[os.environ["REPL_OWNER"]][chat].keys())
    snapshot_values = list(db[os.environ['REPL_OWNER']][chat].values())

    # Print the snapshot
    for key, value in zip(snapshot_keys, snapshot_values):
        kay = key.split(":")[0]
        print(f'{kay}: {value.strip()}\n')

    print('')
    while True:
        check_if_10000(chat)
        print('')
        msg = input('type a message here -> ')

        clear_last_line()
        if msg == 'exit_chat':
            return
        else:
            msg = msg.split(maxsplit = 1)

            username = os.environ["REPL_OWNER"]
            key = f'{username}:{" ".join(msg)}'
            unique_key = key
            counter = 1

            while unique_key in db[os.environ["REPL_OWNER"]][chat].keys():
                unique_key = key + f'_{counter}'
                counter += 1
            db[os.environ["REPL_OWNER"]][chat][unique_key] = f"{msg}\n"
            print('sending message')
            snapshot = db[os.environ["REPL_OWNER"]][chat]  # Update the snapshot

            clear_last_line()
            clear()
            print_layer()
            print('\n\n')
        
            snapshot_keys = list(db[os.environ["REPL_OWNER"]][chat].keys())
            snapshot_values = list(db[os.environ['REPL_OWNER']][chat].values())
        
            # Print the snapshot
            for key, value in zip(snapshot_keys, snapshot_values):
                kay = key.split(":")[0]
                print(f'{kay}: {value.strip()}\n')
            sleep(1)


        msg = []



def chat_with_who(chat):
    clear()
    
    msg = []
    check_if_10000(chat)
    x = 0
    print_layer()
    print('\n\n')

    snapshot_keys = list(db[chat].keys())
    snapshot_values = list(db[chat].values())

    # Print the snapshot
    for key, value in zip(snapshot_keys, snapshot_values):
        kay = key.split(":")[0]
        print(f'{kay}: {value.strip()}\n')

    print('')
    while True:
        check_if_10000(chat)
        print('')
        msg = input('type a message here -> ')

        clear_last_line()
        if msg == 'exit_chat':
            return
        else:

            username = os.environ["REPL_OWNER"]
            key = f'{username}:{msg}'
            unique_key = key
            counter = 1

            while unique_key in db[chat].keys():
                unique_key = key + f'_{counter}'
                counter += 1
            db[chat][unique_key] = f"{msg}\n"
            print('sending message')
            snapshot = db[chat]  # Update the snapshot

            clear_last_line()

            clear()
            print_layer()
            print('\n\n')
        
            snapshot_keys = list(db[chat].keys())
            snapshot_values = list(db[chat].values())
        
            # Print the snapshot
            for key, value in zip(snapshot_keys, snapshot_values):
                kay = key.split(":")[0]
                print(f'{kay}: {value.strip()}\n')
            sleep(1)


        msg = []








clear()
#main loop
while True:
    try:
        clear()
        print_layer()
        printInMiddle('Welcome to chat with your friends!')
        print('\n\n')
        print('')
        print_layer()
        printInMiddle('Changelogs')
        print('')
        print(changelogs)
        print('')
        print_layer()
        print('')
        print('Who do you want to chat with? type add contact to add contacts!')
        print('')
        print('server_chat')
        try:
          for i in db[os.environ['REPL_OWNER']].keys():
            print(i)
        except:
          pass
        print('')
        x = input('-> ')
        clear()
        if x == 'server_chat':
          chat_with_who('server_chat')
        elif x == 'add contact':
          clear()
          print_layer()
          print('Who?')
          add_contact = input('->')
          if add_contact in db.keys():
            if add_contact in db[os.environ['REPL_OWNER']].keys():
              print('??? CONTACT IS IN YOUR CONTACT LIST! ???')
              sleep(5)
              clear()
    
            else:
              db[os.environ['REPL_OWNER']][f'{add_contact}'] = {'System':'Hey! Its the start of the chat! Type something!'}
              db[add_contact][f'{os.environ["REPL_OWNER"]}'] = {'System':'Hey! Its the start of the chat! Type something!'}
    
          else:
            print('Contact has not run the code yet!')
        else:
          chat_with_who_personal(x)
    except:
        clear()
    

Cooooodee here