Ask coding questions

← Back to all posts
co-op Python chatroom
JamesGordon1 (128)

I need to co-op with someone to make a chatroom in python. I don't know anything about how to make servers and i need to also remove the persons from a txt file when they leave the repl

Comments
hotnewtop
BillWadsworth (1)

I've done some work on multiplayer using socket, it doesn't seem to work on repl

sugarfi (599)

I don't think I can collaborate at the moment, but I can offer some pointers: 1. Look into the socket library for servers. 2. Don't use a text file to store online users, use a list.

JamesGordon1 (128)

will anyone here collab with me

Thecrowbar1234 (140)

In order to update in realtime, your going to need a database, the corresponding module, and threading. the database is to store the data, and threading is used to run multiple pieces of code. I don't know how to use it, but I understand the concept. Here are some very useful databases I suggest : Repl.it DB, google firebase, MongoDB

[deleted]

You can have a example of my irc. Ill be making the database public for you
IRC: https://repl.it/@TaylorLiang/IRC3
DB: https://repl.it/@TaylorLiang/irc-db

JacobErnste (0)

from time import sleep as sp
from replit import clear
players = []
def starter():
clear()
print ("Welcome to Simple chat!")
print("")
print ("What would you like to do?")
print ("1- Login")
print ("2- Sign up")
start = int(input("(Only the number): "))
if start == 1:
clear()
print("Sign-in to your account with your username")
username = input("Username: ")
found = 0
with open("users.txt") as openlist:
for line in openlist:
for part in line.split():
if username in part:
found = 1
if found == 1:
clear()
list1 = open("users_online.txt","a")
list1.write(username)
list1.write("\n")
list1.close()
print ("Welcome to the chatroom", part)
else:
clear()
print ("User not found, please sign up if you dont have an acount")
sp(1)
starter()
else:
def user():
clear()
print("Please type the username that you want")
username = input("Username: ")
taken = 0
with open("users.txt") as openfile:
for line in openfile:
for part in line.split():
if username in part:
taken = 1
if taken == 0:
list2 = open("users.txt","a")
list2.write(username)
list2.write("\n")
list2.close()
clear()
print ("Thank you for signing-up with Simple chat", username)
sp(1)
starter()
else:
clear()
print ("Username taken, please pick a difrent one")
sp(1)
user()
user()
starter()

JacobErnste (0)

Also you need to add a sign up otherwise tour good james
@JacobErnste

Foster_Bryant (97)

@JacobErnste I'm sorry but there is so much that needs to be fixed with this...instead of print("") just add \n in the string in the print function that is before it.. Also you didn't add any indentation at all.