mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2025-06-16 19:35:24 +02:00
Initial structure for discordbot addition
This commit is contained in:
77
webapp/titanembeds/static/css/administrate_guild.css
Normal file
77
webapp/titanembeds/static/css/administrate_guild.css
Normal file
@ -0,0 +1,77 @@
|
||||
/* Responsive table CSS, directly from materializecss - slightly modified */
|
||||
/* Used to accomplish having permanent horizontal table */
|
||||
|
||||
table.responsive-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
display: block;
|
||||
position: relative;
|
||||
table-layout: fixed;
|
||||
/* sort out borders */
|
||||
}
|
||||
table.responsive-table td:empty:before {
|
||||
content: '\00a0';
|
||||
}
|
||||
table.responsive-table th,
|
||||
table.responsive-table td {
|
||||
margin: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
table.responsive-table th {
|
||||
text-align: left;
|
||||
}
|
||||
table.responsive-table thead {
|
||||
display: block;
|
||||
float: left;
|
||||
}
|
||||
table.responsive-table thead tr {
|
||||
display: block;
|
||||
padding: 0 10px 0 0;
|
||||
}
|
||||
table.responsive-table thead tr th::before {
|
||||
content: "\00a0";
|
||||
}
|
||||
table.responsive-table tbody {
|
||||
display: block;
|
||||
width: auto;
|
||||
position: relative;
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
table.responsive-table tbody tr {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
table.responsive-table th {
|
||||
display: block;
|
||||
text-align: right;
|
||||
}
|
||||
table.responsive-table td {
|
||||
display: block;
|
||||
min-height: 1.25em;
|
||||
text-align: left;
|
||||
padding: 13px 5px;
|
||||
}
|
||||
table.responsive-table tr {
|
||||
padding: 0 10px;
|
||||
}
|
||||
table.responsive-table thead {
|
||||
border: 0;
|
||||
border-right: 1px solid #d0d0d0;
|
||||
}
|
||||
table.responsive-table.bordered th {
|
||||
border-bottom: 0;
|
||||
border-left: 0;
|
||||
}
|
||||
table.responsive-table.bordered td {
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
border-bottom: 0;
|
||||
}
|
||||
table.responsive-table.bordered tr {
|
||||
border: 0;
|
||||
}
|
||||
table.responsive-table.bordered tbody tr {
|
||||
border-right: 1px solid #d0d0d0;
|
||||
}
|
187
webapp/titanembeds/static/css/embedstyle.css
Normal file
187
webapp/titanembeds/static/css/embedstyle.css
Normal file
@ -0,0 +1,187 @@
|
||||
html {
|
||||
background-color: #455a64;
|
||||
color: white;
|
||||
}
|
||||
|
||||
main {
|
||||
min-height: calc(100vh - 80px);
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 50px;
|
||||
background-color: #37474f;
|
||||
}
|
||||
|
||||
nav {
|
||||
background-color: #263238;
|
||||
background: linear-gradient(rgba(38, 50, 56, 1), rgba(255,0,0,0));
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
nav .brand-logo {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 993px) {
|
||||
.container {
|
||||
width: 85%;
|
||||
}
|
||||
}
|
||||
|
||||
.side-nav {
|
||||
color: white;
|
||||
background-color: #607d8b;
|
||||
}
|
||||
|
||||
.side-nav .userView .name {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.side-nav li>a {
|
||||
color: #eceff1;
|
||||
}
|
||||
|
||||
.side-nav .subheader {
|
||||
color: #cfd8dc;
|
||||
font-variant: small-caps;
|
||||
}
|
||||
|
||||
.role-title {
|
||||
margin-bottom: -15px !important;
|
||||
font-variant: normal !important;
|
||||
font-size: 80% !important;
|
||||
}
|
||||
|
||||
.divider {
|
||||
background-color: #90a4ae;
|
||||
}
|
||||
|
||||
.channel-hash {
|
||||
font-size: 95%;
|
||||
color: #b0bec5;
|
||||
}
|
||||
|
||||
.membercircle {
|
||||
margin-top: 5px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.membername {
|
||||
position: absolute;
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.chatcontent {
|
||||
padding-left: 1%;
|
||||
padding-top: 1%;
|
||||
padding-bottom: 40px;
|
||||
|
||||
/* https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/ */
|
||||
/* These are technically the same, but use both */
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
|
||||
-ms-word-break: break-all;
|
||||
/* This is the dangerous one in WebKit, as it breaks things wherever */
|
||||
word-break: break-all;
|
||||
/* Instead use this non-standard one: */
|
||||
word-break: break-word;
|
||||
|
||||
/* Adds a hyphen where the word breaks, if supported (No Blink) */
|
||||
-ms-hyphens: auto;
|
||||
-moz-hyphens: auto;
|
||||
-webkit-hyphens: auto;
|
||||
hyphens: auto;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 601px) {
|
||||
nav a.button-collapse {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.chatusername {
|
||||
font-weight: bold;
|
||||
color: #eceff1;
|
||||
}
|
||||
|
||||
.chattimestamp {
|
||||
font-size: 10px;
|
||||
color: #90a4ae;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.footercontainer {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
margin: 10px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#messageboxouter {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.currentuserchip {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
top: -6px;
|
||||
padding: 6px;
|
||||
padding-right: 9px;
|
||||
background-color: #455a64;
|
||||
}
|
||||
|
||||
.currentuserimage {
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
.currentusername {
|
||||
position: relative;
|
||||
top: 7px;
|
||||
left: 5px;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
position: relative;
|
||||
top: -19px;
|
||||
}
|
||||
|
||||
.left {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background-color: #546e7a;
|
||||
}
|
||||
|
||||
.betatag {
|
||||
font-variant: small-caps;
|
||||
font-size: 15px;
|
||||
color: #eceff1;
|
||||
}
|
||||
|
||||
#channeltopic {
|
||||
width: 80%;
|
||||
margin-left: 30px;
|
||||
margin-right: auto;
|
||||
font-size: 85%;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #82b1ff;
|
||||
}
|
||||
|
||||
#fetching-indicator {
|
||||
position: absolute;
|
||||
right: 1vw;
|
||||
bottom: 13px;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
}
|
60
webapp/titanembeds/static/css/style.css
Normal file
60
webapp/titanembeds/static/css/style.css
Normal file
@ -0,0 +1,60 @@
|
||||
html {
|
||||
background-color: #7986cb;
|
||||
color: white;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1 0 auto;
|
||||
}
|
||||
|
||||
nav {
|
||||
background-color: #3f51b5;
|
||||
background: linear-gradient(rgba(63, 81, 181, 1), rgba(255,0,0,0));
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.page-footer {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 992px) {
|
||||
nav .brand-logo {
|
||||
left: 10%;
|
||||
}
|
||||
}
|
||||
|
||||
.btn {
|
||||
background-color: #303f9f;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background-color: #3f51b5;
|
||||
}
|
||||
|
||||
.btn:focus {
|
||||
background-color: #536dfe;
|
||||
}
|
||||
|
||||
.avatar_menu {
|
||||
background-size: contain;
|
||||
}
|
||||
|
||||
.center_content {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.betatag {
|
||||
font-variant: small-caps;
|
||||
font-size: 25px;
|
||||
border-radius: 50px;
|
||||
border: 2px solid #37474f;
|
||||
color: #eceff1;
|
||||
}
|
77
webapp/titanembeds/static/js/administrate_guild.js
Normal file
77
webapp/titanembeds/static/js/administrate_guild.js
Normal file
@ -0,0 +1,77 @@
|
||||
$('#unauth_users').change(function() {
|
||||
var pathname = window.location.pathname;
|
||||
var checked = $(this).is(':checked')
|
||||
var payload = {"unauth_users": checked}
|
||||
$.post(pathname, payload, function(data) {
|
||||
Materialize.toast('Updated guest users setting!', 2000)
|
||||
});
|
||||
});
|
||||
|
||||
function initiate_ban(guild_id, user_id) {
|
||||
var reason = prompt("Please enter your reason for ban");
|
||||
var payload = {
|
||||
"reason": reason,
|
||||
"guild_id": guild_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
var pathname = document.location.origin + "/user/ban"
|
||||
|
||||
if (reason != null) {
|
||||
$.post(pathname, payload)
|
||||
.done(function(){
|
||||
location.reload();
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
if (error == "CONFLICT") {
|
||||
Materialize.toast('User is already banned!', 2000)
|
||||
} else {
|
||||
Materialize.toast('An error has occured!', 2000)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function remove_ban(guild_id, user_id) {
|
||||
var payload = {
|
||||
"guild_id": guild_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
var pathname = document.location.origin + "/user/ban"
|
||||
|
||||
$.ajax({
|
||||
url: pathname + '?' + $.param(payload),
|
||||
type: 'DELETE',
|
||||
success: function() {
|
||||
location.reload();
|
||||
},
|
||||
error: function(jqxhr, status, error) {
|
||||
if (error == "CONFLICT") {
|
||||
Materialize.toast('User is already pardoned!', 2000)
|
||||
} else {
|
||||
Materialize.toast('An error has occured!', 2000)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function revoke_user(guild_id, user_id) {
|
||||
var payload = {
|
||||
"guild_id": guild_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
var confirmation = confirm("Are you sure that you want to kick user?")
|
||||
var pathname = document.location.origin + "/user/revoke"
|
||||
if (confirmation) {
|
||||
$.post(pathname, payload)
|
||||
.done(function(){
|
||||
location.reload();
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
if (error == "CONFLICT") {
|
||||
Materialize.toast('User is already revoked!', 2000)
|
||||
} else {
|
||||
Materialize.toast('An error has occured!', 2000)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
550
webapp/titanembeds/static/js/embed.js
Normal file
550
webapp/titanembeds/static/js/embed.js
Normal file
@ -0,0 +1,550 @@
|
||||
/* global $ */
|
||||
/* global Materialize */
|
||||
/* global Mustache */
|
||||
/* global guild_id */
|
||||
/* global bot_client_id */
|
||||
/* global moment */
|
||||
|
||||
(function () {
|
||||
var logintimer; // timer to keep track of user inactivity after hitting login
|
||||
var fetchtimeout; // fetch routine timer
|
||||
var currently_fetching; // fetch lock- if true, do not fetch
|
||||
var last_message_id; // last message tracked
|
||||
var selected_channel = guild_id; // user selected channel, defaults to #general channel
|
||||
var guild_channels = {}; // all server channels used to highlight channels in messages
|
||||
var times_fetched = 0; // kept track of how many times that it has fetched
|
||||
var fetch_error_count = 0; // Number of errors fetch has encountered
|
||||
|
||||
function element_in_view(element, fullyInView) {
|
||||
var pageTop = $(window).scrollTop();
|
||||
var pageBottom = pageTop + $(window).height();
|
||||
var elementTop = $(element).offset().top;
|
||||
var elementBottom = elementTop + $(element).height();
|
||||
|
||||
if (fullyInView === true) {
|
||||
return ((pageTop < elementTop) && (pageBottom > elementBottom));
|
||||
} else {
|
||||
return ((elementTop <= pageBottom) && (elementBottom >= pageTop));
|
||||
}
|
||||
}
|
||||
|
||||
function query_guild() {
|
||||
var funct = $.ajax({
|
||||
dataType: "json",
|
||||
url: "/api/query_guild",
|
||||
data: {"guild_id": guild_id}
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
function create_authenticated_user() {
|
||||
var funct = $.ajax({
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
url: "/api/create_authenticated_user",
|
||||
data: {"guild_id": guild_id}
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
function create_unauthenticated_user(username) {
|
||||
var funct = $.ajax({
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
url: "/api/create_unauthenticated_user",
|
||||
data: {"username": username, "guild_id": guild_id}
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
function fetch(channel_id, after=null) {
|
||||
var funct = $.ajax({
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
url: "/api/fetch",
|
||||
data: {"guild_id": guild_id,"channel_id": channel_id, "after": after}
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
function post(channel_id, content) {
|
||||
var funct = $.ajax({
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
url: "/api/post",
|
||||
data: {"guild_id": guild_id, "channel_id": channel_id, "content": content}
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
$(function(){
|
||||
$("#loginmodal").modal({
|
||||
dismissible: false, // Modal can be dismissed by clicking outside of the modal
|
||||
opacity: .5, // Opacity of modal background
|
||||
inDuration: 300, // Transition in duration
|
||||
outDuration: 200, // Transition out duration
|
||||
startingTop: '4%', // Starting top style attribute
|
||||
endingTop: '10%', // Ending top style attribute
|
||||
}
|
||||
);
|
||||
|
||||
$('#loginmodal').modal('open');
|
||||
lock_login_fields();
|
||||
|
||||
var guild = query_guild();
|
||||
guild.fail(function() {
|
||||
unlock_login_fields();
|
||||
});
|
||||
|
||||
guild.done(function(data) {
|
||||
initialize_embed(data);
|
||||
});
|
||||
});
|
||||
|
||||
function lock_login_fields() {
|
||||
$("#loginProgress").show();
|
||||
$("#discordlogin_btn").attr("disabled",true);
|
||||
$("#custom_username_field").prop("disabled",true);
|
||||
logintimer = setTimeout(function() {
|
||||
unlock_login_fields();
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
function unlock_login_fields() {
|
||||
$("#loginProgress").hide();
|
||||
$("#discordlogin_btn").attr("disabled",false);
|
||||
$("#custom_username_field").prop("disabled",false);
|
||||
clearTimeout(logintimer);
|
||||
}
|
||||
|
||||
function initialize_embed(guildobj) {
|
||||
if (guildobj === undefined) {
|
||||
var guild = query_guild();
|
||||
guild.done(function(data) {
|
||||
prepare_guild(data);
|
||||
$('#loginmodal').modal('close');
|
||||
unlock_login_fields();
|
||||
});
|
||||
} else {
|
||||
prepare_guild(guildobj);
|
||||
$('#loginmodal').modal('close');
|
||||
unlock_login_fields();
|
||||
}
|
||||
}
|
||||
|
||||
function prepare_guild(guildobj) {
|
||||
fill_channels(guildobj.channels);
|
||||
fill_discord_members(guildobj.discordmembers);
|
||||
fill_authenticated_users(guildobj.embedmembers.authenticated);
|
||||
fill_unauthenticated_users(guildobj.embedmembers.unauthenticated);
|
||||
run_fetch_routine();
|
||||
}
|
||||
|
||||
function fill_channels(channels) {
|
||||
var template = $('#mustache_channellistings').html();
|
||||
Mustache.parse(template);
|
||||
$("#channels-list").empty();
|
||||
for (var i = 0; i < channels.length; i++) {
|
||||
var chan = channels[i];
|
||||
guild_channels[chan.channel.id] = chan;
|
||||
if (chan.read) {
|
||||
var rendered = Mustache.render(template, {"channelid": chan.channel.id, "channelname": chan.channel.name});
|
||||
$("#channels-list").append(rendered);
|
||||
$("#channel-" + chan.channel.id.toString()).click({"channel_id": chan.channel.id.toString()}, function(event) {
|
||||
select_channel(event.data.channel_id);
|
||||
});
|
||||
if (chan.channel.id == selected_channel) {
|
||||
if (chan.write) {
|
||||
$("#messagebox").prop('disabled', false);
|
||||
$("#messagebox").prop('placeholder', "Enter message");
|
||||
} else {
|
||||
$("#messagebox").prop('disabled', true);
|
||||
$("#messagebox").prop('placeholder', "Messages is disabled in this channel.");
|
||||
}
|
||||
$("#channeltopic").text(chan.channel.topic);
|
||||
}
|
||||
}
|
||||
}
|
||||
$("#channel-"+selected_channel).parent().addClass("active");
|
||||
}
|
||||
|
||||
function mention_member(member_id) {
|
||||
if (!$('#messagebox').prop('disabled')) {
|
||||
$('#messagebox').val( $('#messagebox').val() + "[@" + member_id + "] " );
|
||||
$('.button-collapse').sideNav('hide');
|
||||
$("#messagebox").focus();
|
||||
}
|
||||
}
|
||||
|
||||
function fill_discord_members(discordmembers) {
|
||||
var template = $('#mustache_authedusers').html();
|
||||
Mustache.parse(template);
|
||||
$("#discord-members").empty();
|
||||
var guild_members = {};
|
||||
for (var i = 0; i < discordmembers.length; i++) {
|
||||
var member = discordmembers[i];
|
||||
if (member["hoist-role"]) {
|
||||
if (!(member["hoist-role"]["id"] in guild_members)) {
|
||||
guild_members[member["hoist-role"]["id"]] = {};
|
||||
guild_members[member["hoist-role"]["id"]]["name"] = member["hoist-role"]["name"];
|
||||
guild_members[member["hoist-role"]["id"]]["members"] = [];
|
||||
guild_members[member["hoist-role"]["id"]]["position"] = member["hoist-role"]["position"]
|
||||
}
|
||||
guild_members[member["hoist-role"]["id"]]["members"].push(member);
|
||||
} else {
|
||||
if (!("0" in guild_members)) {
|
||||
guild_members["0"] = {};
|
||||
guild_members["0"]["name"] = null;
|
||||
guild_members["0"]["members"] = [];
|
||||
guild_members["0"]["position"] = 0;
|
||||
}
|
||||
guild_members["0"]["members"].push(member);
|
||||
}
|
||||
}
|
||||
var guild_members_arr = [];
|
||||
for (key in guild_members) {
|
||||
guild_members_arr.push(guild_members[key]);
|
||||
}
|
||||
guild_members_arr.sort(function(a, b) {
|
||||
return parseInt(b.position) - parseInt(a.position);
|
||||
});
|
||||
var template_role = $('#mustache_memberrole').html();
|
||||
Mustache.parse(template_role);
|
||||
var template_user = $('#mustache_authedusers').html();
|
||||
Mustache.parse(template_user);
|
||||
$("#discord-members").empty();
|
||||
var discordmembercnt = 0;
|
||||
for (var i = 0; i < guild_members_arr.length; i++) {
|
||||
var roleobj = guild_members_arr[i];
|
||||
if (!roleobj["name"]) {
|
||||
roleobj["name"] = "Uncategorized";
|
||||
}
|
||||
var rendered_role = Mustache.render(template_role, {"name": roleobj["name"] + " - " + roleobj["members"].length});
|
||||
discordmembercnt += roleobj["members"].length;
|
||||
$("#discord-members").append(rendered_role);
|
||||
for (var j = 0; j < roleobj.members.length; j++) {
|
||||
var member = roleobj.members[j];
|
||||
var rendered_user = Mustache.render(template_user, {"id": member.id.toString() + "d", "username": member.username, "avatar": member.avatar_url});
|
||||
$("#discord-members").append(rendered_user);
|
||||
$( "#discorduser-" + member.id.toString() + "d").click({"member_id": member.id.toString()}, function(event) {
|
||||
mention_member(event.data.member_id);
|
||||
});
|
||||
if (member.color) {
|
||||
$( "#discorduser-" + member.id.toString() + "d").css("color", "#" + member.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
$("#discord-members-count").html(discordmembercnt);
|
||||
}
|
||||
|
||||
function fill_authenticated_users(users) {
|
||||
var template = $('#mustache_authedusers').html();
|
||||
Mustache.parse(template);
|
||||
$("#embed-discord-members").empty();
|
||||
$("#embed-discord-members-count").html(users.length);
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
var member = users[i];
|
||||
var rendered = Mustache.render(template, {"id": member.id.toString() + "a", "username": member.username, "avatar": member.avatar_url});
|
||||
$("#embed-discord-members").append(rendered);
|
||||
$( "#discorduser-" + member.id.toString() + "a").click({"member_id": member.id.toString()}, function(event) {
|
||||
mention_member(event.data.member_id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function fill_unauthenticated_users(users) {
|
||||
var template = $('#mustache_unauthedusers').html();
|
||||
Mustache.parse(template);
|
||||
$("#embed-unauth-users").empty();
|
||||
$("#guest-members-count").html(users.length);
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
var member = users[i];
|
||||
var rendered = Mustache.render(template, {"username": member.username, "discriminator": member.discriminator});
|
||||
$("#embed-unauth-users").append(rendered);
|
||||
}
|
||||
}
|
||||
|
||||
function wait_for_discord_login() {
|
||||
_wait_for_discord_login(0);
|
||||
}
|
||||
|
||||
function _wait_for_discord_login(index) {
|
||||
setTimeout(function() {
|
||||
var usr = create_authenticated_user();
|
||||
usr.done(function(data) {
|
||||
initialize_embed();
|
||||
return;
|
||||
});
|
||||
usr.fail(function(data) {
|
||||
if (data.status == 403) {
|
||||
Materialize.toast('Authentication error! You have been banned.', 10000);
|
||||
} else if (index < 10) {
|
||||
_wait_for_discord_login(index + 1);
|
||||
}
|
||||
});
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function select_channel(channel_id) {
|
||||
if (selected_channel != channel_id) {
|
||||
selected_channel = channel_id;
|
||||
last_message_id = null;
|
||||
$("#channels-list > li.active").removeClass("active");
|
||||
$("#channel-"+selected_channel).parent().addClass("active");
|
||||
clearTimeout(fetchtimeout);
|
||||
run_fetch_routine();
|
||||
}
|
||||
}
|
||||
|
||||
function replace_message_mentions(message) {
|
||||
var mentions = message.mentions;
|
||||
for (var i = 0; i < mentions.length; i++) {
|
||||
var mention = mentions[i];
|
||||
message.content = message.content.replace(new RegExp("<@" + mention.id + ">", 'g'), "@" + mention.username + "#" + mention.discriminator);
|
||||
message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), "@" + mention.username + "#" + mention.discriminator);
|
||||
message.content = message.content.replace("<@&" + guild_id + ">", "@everyone");
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
function getPosition(string, subString, index) {
|
||||
return string.split(subString, index).join(subString).length;
|
||||
}
|
||||
|
||||
function format_bot_message(message) {
|
||||
if (message.author.id == bot_client_id && (message.content.includes("**") && ( (message.content.includes("<")&&message.content.includes(">")) || (message.content.includes("[") && message.content.includes("]")) ))) {
|
||||
var usernamefield = message.content.substring(getPosition(message.content, "**", 1)+3, getPosition(message.content, "**", 2)-1);
|
||||
message.content = message.content.substring(usernamefield.length+7);
|
||||
message.author.username = usernamefield.split("#")[0];
|
||||
message.author.discriminator = usernamefield.split("#")[1];
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
function parse_message_time(message) {
|
||||
var mome = moment(message.timestamp);
|
||||
message.formatted_timestamp = mome.toDate().toString();
|
||||
message.formatted_time = mome.format("h:mm A");
|
||||
return message;
|
||||
}
|
||||
|
||||
function parse_message_attachments(message) {
|
||||
for (var i = 0; i < message.attachments.length; i++) {
|
||||
var attach = "";
|
||||
if (message.content.length != 0) {
|
||||
attach = " ";
|
||||
}
|
||||
attach += message.attachments[i].url;
|
||||
message.content += attach;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
function handle_last_message_mention() {
|
||||
var lastmsg = $("#chatcontent p:last-child");
|
||||
var content = lastmsg.text().toLowerCase();
|
||||
var username_discrim = $("#currentusername").text().toLowerCase();
|
||||
if (content.includes("@everyone") || content.includes("@" + username_discrim)) {
|
||||
lastmsg.css( "color", "#ff5252" );
|
||||
lastmsg.css( "font-weight", "bold" );
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(unsafe) { /* http://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript */
|
||||
return unsafe
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function nl2br (str, is_xhtml) { /* http://stackoverflow.com/questions/2919337/jquery-convert-line-breaks-to-br-nl2br-equivalent/ */
|
||||
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
|
||||
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
|
||||
}
|
||||
|
||||
function parse_channels_in_message(message) {
|
||||
var channelids = Object.keys(guild_channels);
|
||||
for (var i = 0; i < channelids.length; i++) {
|
||||
var pattern = "<#" + channelids[i] + ">";
|
||||
message.content = message.content.replace(new RegExp(pattern, "g"), "#" + guild_channels[channelids[i]].channel.name);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
function fill_discord_messages(messages, jumpscroll) {
|
||||
if (messages.length == 0) {
|
||||
return last_message_id;
|
||||
}
|
||||
var last = 0;
|
||||
var template = $('#mustache_usermessage').html();
|
||||
Mustache.parse(template);
|
||||
for (var i = messages.length-1; i >= 0; i--) {
|
||||
var message = messages[i];
|
||||
message = replace_message_mentions(message);
|
||||
message = format_bot_message(message);
|
||||
message = parse_message_time(message);
|
||||
message = parse_message_attachments(message);
|
||||
message = parse_channels_in_message(message);
|
||||
var rendered = Mustache.render(template, {"id": message.id, "full_timestamp": message.formatted_timestamp, "time": message.formatted_time, "username": message.author.username, "discriminator": message.author.discriminator, "content": nl2br(escapeHtml(message.content))});
|
||||
$("#chatcontent").append(rendered);
|
||||
last = message.id;
|
||||
handle_last_message_mention();
|
||||
}
|
||||
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
|
||||
$('#chatcontent').linkify({
|
||||
target: "_blank"
|
||||
});
|
||||
return last;
|
||||
}
|
||||
|
||||
function run_fetch_routine() {
|
||||
if (currently_fetching) {
|
||||
return;
|
||||
}
|
||||
currently_fetching = true;
|
||||
times_fetched += 1;
|
||||
var channel_id = selected_channel;
|
||||
var fet;
|
||||
var jumpscroll;
|
||||
$("#fetching-indicator").fadeIn(800);
|
||||
if (last_message_id == null) {
|
||||
$("#chatcontent").empty();
|
||||
fet = fetch(channel_id);
|
||||
jumpscroll = true;
|
||||
} else {
|
||||
fet = fetch(channel_id, last_message_id);
|
||||
jumpscroll = element_in_view($('#discordmessage_'+last_message_id), true);
|
||||
}
|
||||
fet.done(function(data) {
|
||||
var status = data.status;
|
||||
update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator);
|
||||
last_message_id = fill_discord_messages(data.messages, jumpscroll);
|
||||
if (status.manage_embed) {
|
||||
$("#administrate_link").show();
|
||||
} else {
|
||||
$("#administrate_link").hide();
|
||||
}
|
||||
if (times_fetched % 10 == 0) {
|
||||
var guild = query_guild();
|
||||
guild.done(function(guildobj) {
|
||||
fill_channels(guildobj.channels);
|
||||
fill_discord_members(guildobj.discordmembers);
|
||||
fill_authenticated_users(guildobj.embedmembers.authenticated);
|
||||
fill_unauthenticated_users(guildobj.embedmembers.unauthenticated);
|
||||
fetchtimeout = setTimeout(run_fetch_routine, 5000);
|
||||
});
|
||||
} else {
|
||||
fetchtimeout = setTimeout(run_fetch_routine, 5000);
|
||||
}
|
||||
});
|
||||
fet.fail(function(data) {
|
||||
if (data.status == 403) {
|
||||
$('#loginmodal').modal('open');
|
||||
Materialize.toast('Authentication error! You have been disconnected by the server.', 10000);
|
||||
} else if (data.status == 401) {
|
||||
$('#loginmodal').modal('open');
|
||||
Materialize.toast('Session expired! You have been logged out.', 10000);
|
||||
}
|
||||
});
|
||||
fet.catch(function(data) {
|
||||
if (500 <= data.status && data.status < 600) {
|
||||
if (fetch_error_count % 5 == 0) {
|
||||
Materialize.toast('Fetching messages error! EndenDragon probably broke something. Sorry =(', 10000);
|
||||
}
|
||||
fetch_error_count += 1;
|
||||
fetchtimeout = setTimeout(run_fetch_routine, 10000);
|
||||
}
|
||||
});
|
||||
fet.always(function() {
|
||||
currently_fetching = false;
|
||||
$("#fetching-indicator").fadeOut(800);
|
||||
});
|
||||
}
|
||||
|
||||
function update_embed_userchip(authenticated, avatar, username, userid, discrim=null) {
|
||||
if (authenticated) {
|
||||
$("#currentuserimage").show();
|
||||
$("#currentuserimage").attr("src", avatar);
|
||||
$("#currentusername").text(username + "#" + discrim);
|
||||
} else {
|
||||
$("#currentuserimage").hide();
|
||||
$("#currentusername").text(username + "#" + userid);
|
||||
}
|
||||
}
|
||||
|
||||
$("#discordlogin_btn").click(function() {
|
||||
lock_login_fields();
|
||||
wait_for_discord_login();
|
||||
});
|
||||
|
||||
$("#custom_username_field").keyup(function(event){
|
||||
if (event.keyCode == 13) {
|
||||
if (!(new RegExp(/^[a-z\d\-_\s]+$/i).test($(this).val()))) {
|
||||
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
|
||||
return;
|
||||
}
|
||||
if($(this).val().length >= 2 && $(this).val().length <= 32) {
|
||||
lock_login_fields();
|
||||
var usr = create_unauthenticated_user($(this).val());
|
||||
usr.done(function(data) {
|
||||
initialize_embed();
|
||||
});
|
||||
usr.fail(function(data) {
|
||||
if (data.status == 429) {
|
||||
Materialize.toast('Sorry! You are allowed to log in as a guest once every 15 minutes.', 10000);
|
||||
} else if (data.status == 403) {
|
||||
Materialize.toast('Authentication error! You have been banned.', 10000);
|
||||
} else if (data.status == 406) {
|
||||
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
|
||||
}
|
||||
unlock_login_fields();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#messagebox").keyup(function(event){
|
||||
if ($(this).val().length == 1) {
|
||||
$(this).val($.trim($(this).val()));
|
||||
}
|
||||
if(event.keyCode == 13 && $(this).val().length >= 1 && $(this).val().length <= 350) {
|
||||
$(this).val($.trim($(this).val()));
|
||||
$(this).blur();
|
||||
$("#messagebox").attr('readonly', true);
|
||||
var funct = post(selected_channel, $(this).val());
|
||||
funct.done(function(data) {
|
||||
$("#messagebox").val("");
|
||||
clearTimeout(fetchtimeout);
|
||||
run_fetch_routine();
|
||||
});
|
||||
funct.fail(function(data) {
|
||||
Materialize.toast('Failed to send message.', 10000);
|
||||
});
|
||||
funct.catch(function(data) {
|
||||
if (data.status == 429) {
|
||||
Materialize.toast('You are sending messages too fast! 1 message per 10 seconds', 10000);
|
||||
}
|
||||
});
|
||||
funct.always(function() {
|
||||
$("#messagebox").attr('readonly', false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#guild-btn').sideNav({
|
||||
menuWidth: 300, // Default is 300
|
||||
edge: 'left', // Choose the horizontal origin
|
||||
closeOnClick: true, // Closes side-nav on <a> clicks, useful for Angular/Meteor
|
||||
draggable: true // Choose whether you can drag to open on touch screens
|
||||
}
|
||||
);
|
||||
|
||||
$('#members-btn').sideNav({
|
||||
menuWidth: 300, // Default is 300
|
||||
edge: 'right', // Choose the horizontal origin
|
||||
draggable: true // Choose whether you can drag to open on touch screens
|
||||
}
|
||||
);
|
||||
})();
|
BIN
webapp/titanembeds/static/titanembeds.mp4
Normal file
BIN
webapp/titanembeds/static/titanembeds.mp4
Normal file
Binary file not shown.
BIN
webapp/titanembeds/static/titanembeds.ogg
Normal file
BIN
webapp/titanembeds/static/titanembeds.ogg
Normal file
Binary file not shown.
BIN
webapp/titanembeds/static/titanembeds.webm
Normal file
BIN
webapp/titanembeds/static/titanembeds.webm
Normal file
Binary file not shown.
Reference in New Issue
Block a user