Я создал систему, которая позволяет людям задавать вопросы о коде и общаться в чате. Я хотел сделать эту систему меньше и лучше, потому что по какой-то причине ее легко обойти.
Модули / пакеты, которые я использовал для этого проекта чата
import os
import time
Теперь собственно сценарий, содержащий около 56 строк кода!
print("Codehelp || Question through a terminal.")
#### Codehelp Variables
chat = open('publiclogs.txt','r')
name = input("Enter Username: ")
crown = "👑"
owner = False
#### Codehelp Scripts
if name == "":
print("nINVALID! Name must not be Empty..n")
time.sleep(2)
exit()
while True:
with open('publiclogs.txt','a') as chat_txt:
chat_txt.close()
chat = open('chat.txt','r')
print(chat.read())
message = input("Enter Your message: ")
os.system("clear")
if message.lower() == "":
os.system("clear")
print("You must type something in order to send a messagen")
input("Press enter to continue ")
os.system("clear")
elif message.lower() == ".ask":
title = input("Enter title of Question. Also be specific: ")
description = input("Enter description: ")
tags = input("Enter TAGS. Seperate by ',': ")
os.system("clear")
with open('question.txt','a') as ask_txt:
ask_txt.write(f'TITLE: {title}n')
ask_txt.write(f'DESCRIPTION: {description}n')
ask_txt.write(f'TAGS: {tags}n')
ask_txt.write(f'Written by {name}n')
ask_txt.write(f'-------------------n')
ask_txt.close()
with open('publiclogs.txt','a') as chat_txt:
chat_txt.write(f'New Question has been asked! View question.txt!n')
chat_txt.close()
elif message.lower() == ".login":
print("Welcome to the Admin log-in!")
time.sleep(2)
password = input("What's the Password: ")
print("Removed from Codehelp Currently..")
else:
if owner == True:
with open('chat.txt','a') as chat_txt:
chat_txt.write(f'{crown} {name}:{message}n')
chat_txt.close()
else:
with open('chat.txt','a') as chat_txt:
chat_txt.write(f'{name}: {message}n')
chat_txt.close()
Что я мог сделать, чтобы улучшить этот код?