first commit

This commit is contained in:
usernames122
2025-08-07 23:57:27 +02:00
commit be0fde0bdb
4 changed files with 84 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
venv
webchat.db

20
main.py Normal file
View File

@@ -0,0 +1,20 @@
from flask import Flask, render_template
from flask_socketio import SocketIO, send
import sqlite3
app = Flask(__name__)
socketio = SocketIO(app)
@socketio.on('message')
def onMessage(msg):
send(msg, broadcast=True)
@app.route('/')
def routeLogin():
return render_template("chat.html")
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', debug=True, allow_unsafe_werkzeug=True)

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
flask
flask-socketio

60
templates/chat.html Normal file
View File

@@ -0,0 +1,60 @@
<!DOCTYPE html>
<style>
body {
padding: 0;
margin: 0;
}
div {
height: 88vh;
width:100%;
background-color: black;
overflow-y: scroll;
overflow-x: hidden;
font-family: 'Consolas', 'Arial', sans-serif;
color: white;
}
</style>
<html>
<head>
<title>WebChat...?</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.js"></script>
<script>
var socket;
var nick = "dupel" + Math.round(Math.random() * 1000);
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("nick").innerText = "Chatting as: " + nick;
dick = document.getElementById("messages");
box = document.getElementById("message");
socket = io();
socket.on("connect", function() {
cpplus = document.createElement("p");
cpplus.innerText = "Connected";
dick.append(cpplus);
})
socket.on("disconnect", function() {
cpplus = document.createElement("p");
cpplus.innerText = "Disconnected";
dick.append(cpplus);
})
socket.on("message", function(msg) {
cpplus = document.createElement("p");
cpplus.innerText = msg;
dick.append(cpplus);
})
box.onkeypress = function(e) {
if (e.key == "Enter") {
socket.send(nick + "> " + box.value);
box.value = "";
}
}
})
</script>
</head>
<body>
<label id="nick"></label>
<div id="messages" />
<textarea rows="2" placeholder="We neeed to figure shit out..." id="message"></textarea>
</body>
</html>