fgMerge branch 'frost' of https://github.com/Aevann1/Drama into frost
This commit is contained in:
commit
1a21d92d2d
7 changed files with 142 additions and 3 deletions
|
@ -1,5 +1,4 @@
|
||||||
import gevent.monkey
|
|
||||||
gevent.monkey.patch_all()
|
|
||||||
from os import environ, path
|
from os import environ, path
|
||||||
import secrets
|
import secrets
|
||||||
from flask import *
|
from flask import *
|
||||||
|
|
17
files/assets/js/chat.js
Normal file
17
files/assets/js/chat.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
let socket=io()
|
||||||
|
|
||||||
|
document.getElementById('chatsend').onclick = function () {
|
||||||
|
console.log('clicked')
|
||||||
|
text = document.getElementById('input-text').value
|
||||||
|
socket.emit('speak', text);
|
||||||
|
document.getElementById('input-text').value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.on('speak', function(json) {
|
||||||
|
console.log(json);
|
||||||
|
document.getElementsByClassName('desktop-avatar')[0].src = json['avatar']
|
||||||
|
document.getElementsByClassName('userlink')[0].href = json['userlink']
|
||||||
|
document.getElementsByClassName('username')[0].innerHTML = json['username']
|
||||||
|
document.getElementsByClassName('chat-message')[0].innerHTML = json['text']
|
||||||
|
document.getElementById('chat-text').append(document.getElementsByClassName('chat-line')[0].cloneNode(true))
|
||||||
|
})
|
6
files/assets/js/jquery-2.0.3.min.js
vendored
Normal file
6
files/assets/js/jquery-2.0.3.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
files/assets/js/socketio.js
Normal file
7
files/assets/js/socketio.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -16,3 +16,4 @@ from .feeds import *
|
||||||
from .awards import *
|
from .awards import *
|
||||||
from .giphy import *
|
from .giphy import *
|
||||||
from .subs import *
|
from .subs import *
|
||||||
|
from .chat import *
|
33
files/routes/chat.py
Normal file
33
files/routes/chat.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import time
|
||||||
|
from files.helpers.wrappers import auth_required
|
||||||
|
from files.helpers.sanitize import sanitize
|
||||||
|
from files.helpers.const import *
|
||||||
|
from datetime import datetime
|
||||||
|
from flask_socketio import SocketIO, emit
|
||||||
|
from files.__main__ import app
|
||||||
|
from flask import render_template
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if SITE=='devrama.xyz':
|
||||||
|
@app.get("/chat")
|
||||||
|
@auth_required
|
||||||
|
def chat( v):
|
||||||
|
return render_template("chat.html", v=v)
|
||||||
|
|
||||||
|
|
||||||
|
sex = SocketIO(app, logger=True, engineio_logger=True, debug=True, async_mode='gevent')
|
||||||
|
|
||||||
|
@sex.on('speak')
|
||||||
|
@auth_required
|
||||||
|
def speak(data, v):
|
||||||
|
|
||||||
|
data={
|
||||||
|
"avatar": v.profile_url,
|
||||||
|
"username":v.username,
|
||||||
|
"text":sanitize(data[:1000].strip()),
|
||||||
|
"time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time()))),
|
||||||
|
"userlink":v.url
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('speak', data, broadcast=True)
|
||||||
|
return '', 204
|
76
files/templates/chat.html
Normal file
76
files/templates/chat.html
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
{% extends "default.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
<title>Chat</title>
|
||||||
|
<meta name="description" content="Chat">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div id="chat-line-template" class="d-none">
|
||||||
|
<div class="chat-line my-2">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="rounded mb-auto d-none d-md-block chat-profile">
|
||||||
|
<img class="desktop-avatar rounded-circle w-100">
|
||||||
|
</span>
|
||||||
|
<div class="pl-md-3 text-muted">
|
||||||
|
<div>
|
||||||
|
<img class="mobile-avatar profile-pic-30 mr-2 d-inline-block d-md-none" data-toggle="tooltip" data-placement="right">
|
||||||
|
<a href="" class="font-weight-bold text-black userlink" target="_blank">@<span class="username"></span></a>
|
||||||
|
<div style="overflow:hidden">
|
||||||
|
<span class="chat-message text-black text-break"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container p-md-0 chat-container">
|
||||||
|
<div id="chat-window">
|
||||||
|
<div id="chat-text" class="fullchat">
|
||||||
|
</div>
|
||||||
|
<div id="system-template">
|
||||||
|
<div class="system-line">
|
||||||
|
<p class="message text-muted"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="position-relative form-group d-flex pb-3">
|
||||||
|
<div class="position-absolute text-muted text-small" style="bottom: -1.5rem; line-height: 1;">
|
||||||
|
<span id="typing-indicator"></span>
|
||||||
|
<span id="loading-indicator" class="d-none"></span>
|
||||||
|
</div>
|
||||||
|
<input id="input-text" type="text" class="form-control" placeholder="Message" autocomplete="off" autofocus />
|
||||||
|
<button id="chatsend" class="btn btn-primary ml-3" type="submit">Send</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/assets/js/socketio.js"></script>
|
||||||
|
<script src="/assets/js/chat.js?v=11"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#chat-window {
|
||||||
|
max-height:calc(100vh - 300px);
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fullchat .chat-profile {
|
||||||
|
min-width: 42px;
|
||||||
|
width: 42px;
|
||||||
|
height: 42px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chat-window::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#chat-window {
|
||||||
|
-ms-overflow-style: none;
|
||||||
|
scrollbar-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue