mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2025-06-16 19:35:24 +02:00
Basic message relaying via WS
This commit is contained in:
@ -7,6 +7,12 @@ from .blueprints import api, user, admin, embed, gateway
|
||||
import os
|
||||
from titanembeds.database import get_administrators_list
|
||||
|
||||
if config.get("websockets-mode", None) == "eventlet":
|
||||
import eventlet
|
||||
eventlet.monkey_patch()
|
||||
elif config.get("websockets-mode", None) == "gevent":
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
os.chdir(config['app-location'])
|
||||
app = Flask(__name__, static_folder="static")
|
||||
@ -20,7 +26,7 @@ app.secret_key = config['app-secret']
|
||||
db.init_app(app)
|
||||
rate_limiter.init_app(app)
|
||||
sslify = SSLify(app, permanent=True)
|
||||
socketio.init_app(app)
|
||||
socketio.init_app(app, message_queue=config["redis-uri"], path='gateway', async_mode=config.get("websockets-mode", None))
|
||||
|
||||
app.register_blueprint(api.api, url_prefix="/api", template_folder="/templates")
|
||||
app.register_blueprint(admin.admin, url_prefix="/admin", template_folder="/templates")
|
||||
|
@ -1,6 +1,22 @@
|
||||
from titanembeds.utils import socketio
|
||||
from flask_socketio import Namespace, emit
|
||||
from flask_socketio import Namespace, emit, disconnect, join_room
|
||||
import functools
|
||||
from flask import request, session
|
||||
|
||||
def authenticated_only(f):
|
||||
@functools.wraps(f)
|
||||
def wrapped(*args, **kwargs):
|
||||
if False:
|
||||
pass
|
||||
#disconnect()
|
||||
else:
|
||||
return f(*args, **kwargs)
|
||||
return wrapped
|
||||
|
||||
class Gateway(Namespace):
|
||||
def on_connect(self):
|
||||
emit('key', {'data': 'Connected', 'best_pone': "rainbow"})
|
||||
emit('hello')
|
||||
|
||||
def on_identify(self, data):
|
||||
room = data["guild_id"]
|
||||
join_room(room)
|
@ -249,12 +249,6 @@
|
||||
} else {
|
||||
primeEmbed();
|
||||
}
|
||||
|
||||
/* SocketIO Test */
|
||||
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + "/gateway", {path: '/gateway'});
|
||||
socket.on('connect', function() {
|
||||
console.log("Socket.IO Connected!");
|
||||
});
|
||||
});
|
||||
|
||||
function changeTheme(theme=null, keep_custom_css=true) {
|
||||
@ -756,20 +750,16 @@
|
||||
} else {
|
||||
$("#administrate_link").hide();
|
||||
}
|
||||
if (times_fetched % 10 == 0 || priority_query_guild) {
|
||||
var guild = query_guild();
|
||||
guild.done(function(guildobj) {
|
||||
priority_query_guild = false;
|
||||
fill_channels(guildobj.channels);
|
||||
fill_discord_members(guildobj.discordmembers);
|
||||
fill_authenticated_users(guildobj.embedmembers.authenticated);
|
||||
fill_unauthenticated_users(guildobj.embedmembers.unauthenticated);
|
||||
$("#instant-inv").attr("href", guildobj.instant_invite);
|
||||
fetchtimeout = setTimeout(run_fetch_routine, 5000);
|
||||
});
|
||||
} else {
|
||||
fetchtimeout = setTimeout(run_fetch_routine, 5000);
|
||||
}
|
||||
var guild = query_guild();
|
||||
guild.done(function(guildobj) {
|
||||
priority_query_guild = false;
|
||||
fill_channels(guildobj.channels);
|
||||
fill_discord_members(guildobj.discordmembers);
|
||||
fill_authenticated_users(guildobj.embedmembers.authenticated);
|
||||
fill_unauthenticated_users(guildobj.embedmembers.unauthenticated);
|
||||
$("#instant-inv").attr("href", guildobj.instant_invite);
|
||||
initiate_websockets();
|
||||
});
|
||||
});
|
||||
fet.fail(function(data) {
|
||||
if (data.status == 403) {
|
||||
@ -953,4 +943,15 @@
|
||||
// basically copied and pasted of browser ponies bookmarklet
|
||||
(function (srcs,cfg) { var cbcount = 1; var callback = function () { -- cbcount; if (cbcount === 0) { BrowserPonies.setBaseUrl(cfg.baseurl); if (!BrowserPoniesBaseConfig.loaded) { BrowserPonies.loadConfig(BrowserPoniesBaseConfig); BrowserPoniesBaseConfig.loaded = true; } BrowserPonies.loadConfig(cfg); if (!BrowserPonies.running()) BrowserPonies.start(); } }; if (typeof(BrowserPoniesConfig) === "undefined") { window.BrowserPoniesConfig = {}; } if (typeof(BrowserPoniesBaseConfig) === "undefined") { ++ cbcount; BrowserPoniesConfig.onbasecfg = callback; } if (typeof(BrowserPonies) === "undefined") { ++ cbcount; BrowserPoniesConfig.oninit = callback; } var node = (document.body || document.documentElement || document.getElementsByTagName('head')[0]); for (var id in srcs) { if (document.getElementById(id)) continue; if (node) { var s = document.createElement('script'); s.type = 'text/javascript'; s.id = id; s.src = srcs[id]; node.appendChild(s); } else { document.write('\u003cscript type="text/javscript" src="'+ srcs[id]+'" id="'+id+'"\u003e\u003c/script\u003e'); } } callback();})({"browser-ponies-script":"https://panzi.github.io/Browser-Ponies/browserponies.js","browser-ponies-config":"https://panzi.github.io/Browser-Ponies/basecfg.js"},{"baseurl":"https://panzi.github.io/Browser-Ponies/","fadeDuration":500,"volume":1,"fps":25,"speed":3,"audioEnabled":false,"showFps":false,"showLoadProgress":true,"speakProbability":0.1,"spawn":{"applejack":1,"fluttershy":1,"pinkie pie":1,"rainbow dash":1,"rarity":1,"twilight sparkle":1}});
|
||||
});
|
||||
|
||||
function initiate_websockets() {
|
||||
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + "/gateway", {path: '/gateway', transports: ['websocket']});
|
||||
socket.on('connect', function() {
|
||||
socket.emit('identify', {"guild_id": guild_id});
|
||||
});
|
||||
|
||||
socket.on('MESSAGE_CREATE', function(msg) {
|
||||
console.log(msg);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
@ -90,4 +90,4 @@ def bot_alive():
|
||||
return results
|
||||
|
||||
rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address
|
||||
socketio = SocketIO(path='gateway')
|
||||
socketio = SocketIO()
|
Reference in New Issue
Block a user