-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (65 loc) · 3.93 KB
/
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
from flask import Flask, request
import requests
import threading
from rich.console import Console
from rich.prompt import Prompt
import time
import logging
import random
app = Flask(__name__)
console = Console()
DEBUG = False
WELCOME_MESSAGE = """
░▒▓██████▓▒░░▒▓███████▓▒░░▒▓███████▓▒░░▒▓████████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░▒▓████████▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓████████▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
"""
LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$?!@#%&*()_+-=[]{}|;:,.<>"
def send(dest, message, senderUsername):
data = {
"message": message,
"sender": senderUsername
}
try:
r = requests.post(f"http://{dest}:5000", json=data)
except:
console.print(f"[bold red]Impossible de se connecter à {dest}[/bold red]")
def chat():
time.sleep(1)
for i in range(10):print()
console.print(f"[bold blue]{WELCOME_MESSAGE}[/bold blue]")
print()
username = Prompt.ask("Entrez votre nom d'utilisateur")
dest = Prompt.ask("Entrez le destinataire")
message = ""
while message != "/exit":
message = Prompt.ask(">")
send(dest, message, username)
console.print(f"[bold]{username}:[/bold] {message}")
if message == "/matrix":
print_matrix()
def print_matrix():
for i in range(50):
console.print(f"[bold green]{''.join([LETTERS[random.randint(0, len(LETTERS)-1)] for i in range(200)])}[/bold green]")
time.sleep(0.01)
@app.route("/", methods=["POST"])
def receive():
data = request.json
message = data["message"]
sender = data["sender"]
console.print(f"[bold blue]{sender}:[/bold blue] {message}")
if message == "/matrix":
print_matrix()
return "OK"
if __name__ == "__main__":
# Disable flask logs
if not DEBUG:
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
chatThread = threading.Thread(target=chat)
chatThread.start()
app.run(debug=DEBUG, host="0.0.0.0", port=5000)