Share your repls and programming experiences

← Back to all posts
🐍😎 Python Chat! 🐍😎
JBloves27 (1901)

🐍😎 A fully functional Python Chat! 🐍😎

Made by moi

About

This is a chatting program, used with filing (a bad technique, but I only knew this way for console python). You can chat, but you have to reload the page every few minutes for the messages to load.

Code

The code is actually pretty simple, it uses file opening, and file writing, etc. I added colors, just to make it more fun ^_^

Credits

Credits to @DominicHuieWhit for the datetime! :) Also to @tickedoffsquid for making a suggestion!

Closing

I hope you guys enjoy using this program! IF you haven't already, visit this for more info! Thanks!

NOTE: Please don't ask for editing access, it annoys me and you can just fork it. Thanks!

( o_o)

Update1: I added a automatic time! yay! It's less complicated!

Update2: I added colors and a different login system, and you cant hack >:)

Update3: The quit is fixed! I added a menu, so you can choose if its a message or not!

Update4: I added a more easy and fixed automatic time!


Edit1: Visit here for more about the timezones!

Edit2: Heyo guys! Thanks for making this to trending! :D

Comments
hotnewtop
Bookie0 (6358)

Instead of adding the time, you should add automatically add it! :)

Also this isn't really easy to read:

Perhaps take off the italic?

And you could not need to have to ask the user each time for the time (no pun intended), instead you could add like settings to automatically add the time or not. And there aren't much colors..

And what if I want to say quit in the text, without actually quitting lol?

:D

JBloves27 (1901)

lol, ok. so @Bookie0

  1. got it
  2. sure
  3. er, cant you add more words before the word quit? lol
  4. :D
Bookie0 (6358)

@JBYT27 yes but what if I want to just say 'quit'? :malicious:

JBloves27 (1901)

hahaha, ok, so how should i make it quit? Because i would like the program to say 'someone left' @Bookie0

Z10n12345 (3)

@JBYT27 Maybe !Quit so it's obvious that they're running a command and want to quit?

Bookie0 (6358)

@Z10n12345 perhaps..perhaps..perrrrrhaps

JBloves27 (1901)

lol, maybe, but then it would kinda look weird, a seperate screen with a console... @Bookie0

Bookie0 (6358)

@JBYT27 I mean the problem with that (and any other 'commands' like that) is that what if the user wants to write !quit, for example to respond to someone asking how to quit lol

Z10n12345 (3)

@Bookie0 I would say:
"!quit"
if that were the case or:
say !quit

Z10n12345 (3)

@Bookie0 Because if I knew that saying !quit would kick me out, I wouldn't say it, but if someone asked, I would avoid saying it directly or disguise it. kind of like in a game chat, when someone asks how to directly message someone, you would say:
say @username "message"
or whatever it is.

ApoorvAgrawal (51)

@JBYT27 Maybe you should have a menu that pops up when a user types "quit", it would ask them if they were sending quit or if they were trying to leave the chat.

iocoder (164)

@Z10n12345 u know u just pinged someone named username

JBloves27 (1901)

I fixed the quit thing! @Bookie0

AndrewMarkarian (21)

Yes please we need to.

YeetsaJr (20)

@JBYT27 Sorry if this is a stupid question but, what do you put in for the timezone? I've tried CST, cst, PST, pst, etc. What am I doing wrong lol? ¯_(ツ)_/¯

JBloves27 (1901)

Nah, its ok. ;). Anyways, try est. It seems like only some of them work, and i cant fix the functions of modules. You aren't doing anything wrong, its just the module use is funky xd @YeetsaJr

Z10n12345 (3)

Yeah, I knew it would do that, so I checked that that was actually an account before I sent it. Either it isn't an account, or the user is just really, really inactive. @CodingRedpanda

iocoder (164)

@Z10n12345 i think their really inactive

SilvermoonCat (458)

Whatever I enter it’s always invalid timezone :(

SilvermoonCat (458)

@JBYT27 k I'm in PST but yea EST works, nice chat!

RayhanADev (2595)

xDxDxD them file names make me laugh
also hiya m8!

JBloves27 (1901)

Hahahaha, yep! XD
hiya to you too! @RayhanADev

OldWizard209 (1608)

Hey @JBYT27 . I had a question. How did you make it so that i=when u sign up, it automatically saves the username and pas. . Can you give me the code to do that. I will credit you if ever post something containing that code.

JBloves27 (1901)

Sure, so you do the following: @OldWizard209

import os
...
user = os.environ['REPL_OWNER']
print(user)

I hope this helps!

OldWizard209 (1608)

No, this gives out the username on repl.it. I am talking about the LogIN, SignIn Interface. How does the program know I have an account or not? I need the code for that. thnx @JBYT27

JBloves27 (1901)

ohhh, ok. here's the code: *Note: It works, but there is one error i cant fix.** @OldWizard209

import os, time
from replit import db

red = "\033[0;31m"
green = "\033[0;32m"
white = "\033[0;37m"

def clear():
  os.system('clear')

def login2(): # making the login system
  clear() # the clear() thing
  print("Account:")
  yn = input("[1] Login\n[2] Sign Up\n[3] Quit\n>>> ")

  if yn == "1":
    clear()
    print("Login\n")
    user = input("Username: ")
    passcode = input("Password: ")
    try:
      Password = db[user]

      if Password == passcode:
        clear()
        print(green+"Logged in!"+white)
        time.sleep(2) # waiting 2 seconds
        clear()

      else:
        clear()
        print(red+"Incorrect!"+white)
        time.sleep(2)
        login2()

    except:
      clear()
      print(red+"That username is not included!"+white)
      time.sleep(2)
      login2()

  elif yn == "2":
    clear()
    print("Sign up\n")
    newuser = input("Username: ")
    newpasscode = input("Password: ")

    try:
      db[newuser] = newpasscode
      clear()
      print(green+"Account made!"+white)
      time.sleep(2)
      clear()
      login2()
    
    except:
      clear()
      print(red+"Account already made!"+white)
      time.sleep(2)
      clear()
      login2()

  elif yn == "3":
    clear()
    print(red+"ByeBye!"+white)
    time.sleep(2)
    clear()
    quit()

  else:
    clear()
    print(red+"Invalid Command!"+white)
    time.sleep(2)
    clear()
    login2()

I hope this helps!

I added some additional stuff you can delete ;)

OldWizard209 (1608)

OOH thanks a lot. I wish i had put this in the ask section so u cud have got 5 cycles..... @JBYT27

tickedoffsquid (17)

you should have it save the timezone so you do not have to type it each time, just a thought

JBloves27 (1901)

Thanks for the suggestion and its done! @tickedoffsquid

MarcusWeinberger (795)

Dang I never knew about the REPL_OWNER env variable - I was confused for a moment how you knew who I was ahah

SeamusDonahue (458)

it asks if I want to add the time when I say quit but otherwise really cool!

JBloves27 (1901)

Yeah, so it adds the time when you left. Thanks! @SeamusDonahue

SeamusDonahue (458)

ahh I see, I thought that might have been a glitch so nvm, very cool repl. @JBYT27

SeamusDonahue (458)

oh btw real glitch, I was able to register an account with my username twice... @JBYT27

SeamusDonahue (458)

okay but now it just says "invalid time zone" what is a valid timezone? @JBYT27

JBloves27 (1901)

Well, est works, im pretty sure gmt works as well. I havent tested out ALL timezones, but you can try est for now @SeamusDonahue

SeamusDonahue (458)

two things, yes est works but not my timezone (cst) and also i noticed its writing to a file, which on repl.it only applies to the person using it for as long as the page is open, you are the only one that saves changes because you own the repl. @JBYT27

JBloves27 (1901)

Oh, ok. Hmmm... ill fix that in a few @SeamusDonahue

AndrewMarkarian (21)

@JBYT27 My timezone is PST and it just gives me an error please fix it.

JBloves27 (1901)

Yeah, i cant fix that because im using a module, sry @AndrewMarkarian

AndrewMarkarian (21)

And sorry but is this multiplayer or private?

AndrewMarkarian (21)

@JBYT27 Sorry for late response, but can you talk globally or with friends if you invite them?

AndrewMarkarian (21)

How do I set it up. The accounting system does not show up and I don't really get how to talk privately or publicly. Sorry I only come once a week. @JBYT27

JBloves27 (1901)

Uh, so you have a replit account, so it should automatically do it for you. You have to keep checking for messages, also, people may not talk on this... np @AndrewMarkarian

Gh0stHack3r (63)

Wow, this Is awesome I typed a Hi In the chat (^_^)! It saves your password and username... LOL I love It!

AndrewMarkarian (21)

How did you make an account? I want to do it too.

DominicHuieWhit (52)

@JBYT27
from datetime import datetime
from pytz import timezone
tz = timezone(input('timezone'))
date = datetime.now(tz)
print(date.strftime("%m/%d/%Y %H:%M:%S"))

you might be able to use that for the time thing

JBloves27 (1901)

hmmm, ok! Thanks! I'll add that later! @DominicHuieWhit

Agzamikail (2)

Can you please give the code

JBloves27 (1901)

? wdym? the code is in a different file. Anyways, I'll just give u it :@Agzamikail

import os, time, sys
from datetime import datetime
from pytz import timezone

def clear():
  os.system('clear')

italic = "\033[3m"
red = "\033[0;31m"
green = "\033[0;32m"
orange = "\033[0;33m"
blue = "\033[0;34m"
purple = "\033[0;35m"
cyan = "\033[0;36m"
white = "\033[0;37m" 
black = "\033[0;30m"
reset='\033[0m'

time.sleep(1)
clear()
print(purple+"Glitch Chat!"+white)
time.sleep(3.5)
clear()

username = os.environ['REPL_OWNER']
try:
  print(green+'Welcome '+blue+f'{username}'+green+' to the '+purple+'Glitch Chat!'+white)
  time.sleep(2)
  clear()
except:
  username = 'Guest'
  print(green+'Welcome '+blue+f'{username}'+green+'! '+red+f'It also seems like you don\'t have an account yet...\nVisit {sys.exc_info()} for more!')
  os.environ['REPLIT_DB_URL']
  time.sleep(2)
  clear()

text_join=True
tz2=True
chatting=True
while chatting:
  print(purple+'Glitch Chat!'+white)
  print(italic+'\n<~> Enter \'quit\' to quit the program\n'+white)
  file = open('messages.txt','r')
  file2=file.read()
  if file2 == '':
    print(red+'There are no messages yet, you should start one!'+white)
  else:
    print(cyan+file2+orange)#This reads and prints everything in the file
  message=input('\nWhat is your message?\n[:> ')
  if tz2 == False:
    clear()
    pass
  else:
    try:
      tz = timezone(input('What is the timezone?\n[:> '))
      tz2 = False
    except:
      print(red+"Invalid time zone!"+white)
      time.sleep(2)
      clear()
      continue
    clear()

  if message == 'quit':
    mq = input('Is it a message or do you want to quit? m/q\n[:> ').lower()
    if mq == 'm':
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()
    elif mq == 'q':
      chatting=False
      with open('messages.txt','a') as file:#writes in the file the following:
        date = datetime.now(tz)
        file.write(f'{username} has left at {date.strftime("%m/%d/%Y %H:%M:%S")}!\n')#writes the following
        file.close()#closes the file
      clear()
    else:
      clear()
  else:
    if text_join == True:
      with open('messages.txt','a') as file:#this opens the file and appends something
        date = datetime.now(tz)
        file.write(f'{username} has joined at {date.strftime("%m/%d/%Y %H:%M:%S")}!\n')#writes in the file
        file.close()#closes the file. If you dont, you cant create more than one line.
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()#closes the file
      text_join=False
    else:
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()#closes the file
      text_join=False

Here you go!

Agzamikail (2)

Can you please give the code

JBloves27 (1901)

? wdym? the code is in a different file. Anyways, I'll just give u it :@Agzamikail

import os, time, sys
from datetime import datetime
from pytz import timezone

def clear():
  os.system('clear')

italic = "\033[3m"
red = "\033[0;31m"
green = "\033[0;32m"
orange = "\033[0;33m"
blue = "\033[0;34m"
purple = "\033[0;35m"
cyan = "\033[0;36m"
white = "\033[0;37m" 
black = "\033[0;30m"
reset='\033[0m'

time.sleep(1)
clear()
print(purple+"Glitch Chat!"+white)
time.sleep(3.5)
clear()

username = os.environ['REPL_OWNER']
try:
  print(green+'Welcome '+blue+f'{username}'+green+' to the '+purple+'Glitch Chat!'+white)
  time.sleep(2)
  clear()
except:
  username = 'Guest'
  print(green+'Welcome '+blue+f'{username}'+green+'! '+red+f'It also seems like you don\'t have an account yet...\nVisit {sys.exc_info()} for more!')
  os.environ['REPLIT_DB_URL']
  time.sleep(2)
  clear()

text_join=True
tz2=True
chatting=True
while chatting:
  print(purple+'Glitch Chat!'+white)
  print(italic+'\n<~> Enter \'quit\' to quit the program\n'+white)
  file = open('messages.txt','r')
  file2=file.read()
  if file2 == '':
    print(red+'There are no messages yet, you should start one!'+white)
  else:
    print(cyan+file2+orange)#This reads and prints everything in the file
  message=input('\nWhat is your message?\n[:> ')
  if tz2 == False:
    clear()
    pass
  else:
    try:
      tz = timezone(input('What is the timezone?\n[:> '))
      tz2 = False
    except:
      print(red+"Invalid time zone!"+white)
      time.sleep(2)
      clear()
      continue
    clear()

  if message == 'quit':
    mq = input('Is it a message or do you want to quit? m/q\n[:> ').lower()
    if mq == 'm':
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()
    elif mq == 'q':
      chatting=False
      with open('messages.txt','a') as file:#writes in the file the following:
        date = datetime.now(tz)
        file.write(f'{username} has left at {date.strftime("%m/%d/%Y %H:%M:%S")}!\n')#writes the following
        file.close()#closes the file
      clear()
    else:
      clear()
  else:
    if text_join == True:
      with open('messages.txt','a') as file:#this opens the file and appends something
        date = datetime.now(tz)
        file.write(f'{username} has joined at {date.strftime("%m/%d/%Y %H:%M:%S")}!\n')#writes in the file
        file.close()#closes the file. If you dont, you cant create more than one line.
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()#closes the file
      text_join=False
    else:
      with open('messages.txt','a') as file:
        date = datetime.now(tz)
        file.write(f'{username}: {message} -> {date.strftime("%m/%d/%Y %H:%M:%S")}\n')
        file.close()#closes the file
      text_join=False

Here you go! @Agzamikail

Agzamikail (2)

@JBloves27 thanks, but I don't need the code I'm just wondering how chats work

cole525 (3)

i congratulate you. GMT actually works

cole525 (3)

@ me if you want to talk here

hunterc0le (1)

I see theres an option in it for user login. but how can you create a username and password question for more security? I guess i can always do that separately but itd still be cool

hunterc0le (1)

OMG IM SO STUPID. I see it now, my bad.:) It works really well btw! @JBYT27

lisa2006x (12)

Mhmmmm P O G G E R :p

lisa2006x (12)

Np! I have a question, have you ever hacked something? Like anything.. 🤔 @JBYT27

VishnuBharath (0)

only problem is, when someone who doesn't have editing permissions types, it doesn't save. Idk how to fix that, but im sure it's possible

aCactuar (0)

Why is there not a list of timezones? I, personally, cannot get central timezone in, because I don't know how to format it so the program never recognizes it.

JBloves27 (1901)

Yeah, everyone has been asking the same thing, and I can't fix it because it is a module. However, if you do visit the link above in the desc, you'll get some info. @Jfolh

JBloves27 (1901)

Also, you should try est @Jfolh

aCactuar (0)

it could just be me but this happens every time

JBloves27 (1901)

yeah, only some time zones are valid @Jfolh

aCactuar (0)

@JBYT27 then which are so i can use?

AndrewMarkarian (21)

Um, this is POG and im never coming back.

RhinoRunner (864)
Traceback (most recent call last):
  File "poggers.py", line 76, in <module>
    date = datetime.now(tz)
NameError: name 'tz' is not defined
AndrewMarkarian (21)

@JBYT27 it doesn't work. I says my timezone is wrong and i live in Los Angeles with PST timezone. I will vote on this after bug gets fixed.

JBloves27 (1901)

Hmmm, ok. Ill try my best, however, because it is a module, i may not be able to fix it @AndrewMarkarian

[deleted]

@JBYT27 Sorry bro, I thought this was another project and you were a different person. Hope u can forgive me....UwU

Z10n12345 (3)

It's giving me an error when I try to create an account...

Traceback (most recent call last):
File "poggers.py", line 59, in <module>
if db[new_username]==new_password:
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/replit/database/database.py", line 169, in get item
raise KeyError(key)
KeyError: 'Z10n12345'
exit status 1

And no, I did not use my username as my password.

JBloves27 (1901)

yeah, try again, I was kinda experimenting at that time, sry @Z10n12345

JBloves27 (1901)

It should work now (kinda) @SixBeeps

[deleted]

@JBYT27
It's really cool, you just gotta get it it there so people can use it.