repl.it
@LoneAce/

Python Chatroom

Python

Feel free to use the code for reference

fork
loading
Files
  • main.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import smtplib, json_store_client, getpass, hashlib, datetime, sys, os
from termcolor import colored
from time import sleep, ctime

def clear():
  print('\x1b[2J\x1b[H',end='')

def login():
  #global opt2, pw, usr
  global mod
  while True:
    x=0
    clear()
    opt1=1
    if opt1==1:
      opt2=input(colored("Enter display name:\n\t","green"))
      if opt2=="LoneAce" or opt2=="MOD":
        with smtplib.SMTP('smtp.gmail.com',587) as smtp:
          smtp.ehlo() #starts email procedure
          smtp.starttls() #encrypts
          smtp.ehlo() #starts the email procedure again
          pw=getpass.getpass(colored("Enter password:\n","green"))
          #pw=input(colored("Enter password:\n\t","green"))
          try:
            smtp.login("[email protected]",pw)
            x=chat("[MOD] {} ".format(opt2),True)
          except:
            print(colored("Invalid Admin password","red"))
            sleep(1)
      elif opt2=="" or opt2==" ":
        print(colored("Enter a name","red"))
        sleep(2)
      elif opt2[0:4]!="[MOD]":
        x=chat(opt2[5:],False)
      else:
        x=chat(opt2,False)
    if x==2:
      sys.exit()
#This code is completely made by LoneAce and tested by close friends

def chat(usr,mod):
  read=False
  client=json_store_client.Client(os.getenv('key'))
  banned_list = ['konata', 'hana', 'kagami', 'cirno', 'tsukasa', 'miyuki', 'yutaka', 'minami', 'madoka', 'sayaka', 'mami', 'kyoto', 'homura', 'iroha', 'hinata', 'himezaka', 'ika', 'reimu', 'marisa', 'rumia', 'cimo', 'daiyousei', 'koakuma', 'meiling', 'flandre', 'remilia', 'patchouli', 'rem', 'ram', 'senko', 'platelet', 'neptunia', 'nepgear', 'miku']
  if usr.lower() in banned_list:
    print(colored("You have been banned","red"))
    sys.exit()
  while True:
    clear()
    msg=client.get(str(men(hex(57005))),300)
    clear()
    print(colored(ctime(),"white"))
    for i in msg:
      if i[2:5]!="MOD":
        print(colored(i,"green"))
      else:
        print(colored(i,"cyan"))
      if i=="kick":
        if mod==False:
          return 2
    if read==False:
      opt3=input(colored("\nEnter to update log\nEnter message: ","yellow"))
    else:
      sleep(1)
    if len(msg)>=50:
      client.save(str(men(hex(57005))),["Please do not use vulgarities",""])
    if usr[1:4]=="MOD" and opt3=="/reset":
      client.save(str(men(hex(57005))),["Please do not use vulgarities",""])
      print(colored("Reset!","red"))
      sleep(0.5)
    elif opt3=="/read":
      read=True
    elif opt3=="/kick":
      if mod==True:
        msgsave="kick"
        msg=client.get(str(men(hex(57005))))
        msg.append(msgsave)
        client.save(str(men(hex(57005))),msg)
    elif opt3!="" and opt3!=" ":
      msgsave="<{}> {}".format(usr,opt3)
      msg=client.get(str(men(hex(57005))))
      msg.append(msgsave)
      client.save(str(men(hex(57005))),msg)


def men(x):
  md5=hashlib.md5()
  x=bytes(x,'utf-8')
  md5.update(x)
  return md5.digest()

login()
?