This repository has been archived by the owner on May 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
configure_livestream.html
450 lines (400 loc) · 19.4 KB
/
configure_livestream.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
{% extends 'configure_server.html' %}
{% block rightSidebarContents %}
{% set config = serverConfig.youTubeConfig %}
<div class="category-name">
Twitch
</div>
<div class="category-name">
Canais da Twitch
</div>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-3-4">
<div id="communityTitle" class="toggleSubText">
Alguma coisa super topperson aqui
</div>
</div>
<div class="pure-u-1 pure-u-md-1-4">
<button onclick="addEntryWithModal()" style="float: right;" class="button-discord button-discord-info pure-button">{{ DASHBOARD_AddChannel }}</button>
</div>
</div>
<hr>
<div id="custom-config-entries">
</div>
<hr>
<button onclick="transformEntriesToJson()" style="float: right;" class="button-discord button-discord-success pure-button">{{ DASHBOARD_SAVE }}</button>
<br style="clear: both" /> <!-- So dirty! -->
<div class="totallyHidden">
<div id="custom-config-entry-template" class="config-entry">
<div class="discord-generic-entry">
<img class="entry-icon" style="width: 6%; height: auto; border-radius: 999999px; float: left;">
<div class="pure-g">
<div class="pure-u-1 pure-u-md-18-24">
<div style="margin-left: 10px; margin-right: 10px;">
<div class="entry-title">...</div>
<div class="entry-channel toggleSubText">...</div>
</div>
</div>
<div class="pure-u-1 pure-u-md-6-24 vertically-centered-content">
<button class="entry-delete button-discord button-discord-edit pure-button" style="margin-right: 8px; min-width: 0px;"><i class="fas fa-trash" aria-hidden="true"></i></button>
<button class="entry-edit button-discord button-discord-edit pure-button">{{ DASHBOARD_EditButton }}</button>
</div>
</div>
</div>
</div>
<div class="tingle-demo add-new-entry-modal">
<div class="test">
<div class="category-name">{{ DASHBOARD_AddChannel }}</div>
<div style="width: 25%">
<img style="width: 100%; height: auto; float: left; border-radius: 999999px;" class="entry-icon" src="https://i.imgur.com/s4dTtBy.jpg"></img>
</div>
<div style="width: 73%; float: right;">
<div class="flavourText">{{ DASHBOARD_ChannelLink }}</div> <div class="entry-error flavourText totallyHidden" style="color: #f04747;">{{ DASHBOARD_ErrorWhileGettingChannel }}</div>
<input style="width: 100%;" class="entry-url" data-internal-id="inviteUrl" placeholder="https://www.twitch.tv/coloniacontraatacalive" type="text">
<div class="blurSection entry-info">
<div class="flavourText">{{ DASHBOARD_ChannelName }}</div>
<div class="toggleSubText entry-title">A Loritta é muito fofa! <3</div>
<div class="flavourText">{{ DASHBOARD_ChannelToAnnounceLive }}</div>
<select class="entry-repost-id">
{% for textChannel in guild.getTextChannels %}
<option value="{{ textChannel.getId }}">{{ textChannel.getName }}</option>
{% endfor %}
</select>
<div class="flavourText">{{ DASHBOARD_MessageToBroadcastLive }}</div>
<textarea class="entry-description">{{ DASHBOARD_LivestreamTemplate }}</textarea>
<button onclick="sendMessage(this)" class="button-discord button-discord-info pure-button">{{ DASHBOARD_TestMessage }}</button>
</div>
</div>
<br style="clear: both" /> <!-- So dirty! -->
</div>
</div>
<div class="tingle-demo delete-entry-modal">
<div class="test">
<div class="category-name">Deletar canal</div>
Você tem certeza que você deseja fazer isto?
</div>
</div>
<script id="entry-hidden-data" type="text/template">
{{ channels|raw }}
</script>
</div>
<script data-cfasync="false">
function sendMessage(button) {
var payload = {}
payload["type"] = "livestreamMessage"
payload["content"] = $(button).parent().find(".entry-description").val()
payload["textChannelId"] = $(button).parent().find('.entry-repost-id option:selected').val()
payload["channelUrl"] = $(button).parent().parent().find('.entry-url').val()
console.log(payload)
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-bottom-center",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "1000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
toastr.info('Enviando mensagem...', toastr)
var xhr = new XMLHttpRequest();
xhr.open("POST", "{{ websiteUrl }}dashboard/configure/{{ guild.getId }}/testmessage", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
// send the collected data as JSON
xhr.send(JSON.stringify(payload));
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
toastr.clear()
var response = JSON.stringify(xhr.responseText)
// alert("Adicionado no servidor ~ " + xhr.responseText);
toastr.options = {
"closeButton": false,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-bottom-center",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "4000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
if (response["error"] != null) {
toastr.error(response["error"], toastr)
} else {
toastr.success('Mensagem enviada!', toastr)
}
}
}
}
var typingTimer;
function transformEntriesToJson() {
var configAttr = {"type":"{{ saveType }}"}
/* $("body").find("[data-internal-name]").each(function( index ) {
var value = $(this).val();
if ($(this).attr("type") == "checkbox") {
value = $(this).is(':checked')
}
configAttr[$(this).data("internal-name")] = value
}); */
var entries = [];
$(".config-entry").each(function( index ) {
var entry = {};
if ($(this).attr("id") !== "custom-config-entry-template") {
entry["repostToChannelId"] = $(this).attr("data-entry-repost-id");
entry["channelUrl"] = $(this).attr("data-entry-url");
entry["channelId"] = $(this).attr("data-entry-channel-id");
entry["videoSentMessage"] = htmldecode($(this).attr("data-entry-description"));
entries.push(entry);
}
});
configAttr["entries"] = entries;
console.log(configAttr);
var json = JSON.stringify(configAttr);
sendJsonToServer(json);
}
function getContentAsJson(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
console.log(xhr.responseText);
var json = JSON.parse(xhr.responseText)
callback(json);
}
}
}
function addEntryWithModal() {
var guid = uuidv4();
var modal = new tingle.modal({
closeMethods: [],
footer: true
});
modal.addFooterBtn('Salvar', "button-discord button-discord-info pure-button button-discord-modal", function(){
var element = $("#editing-" + guid);
/* if (element.attr("data-is-ready") == "false") { return; } */
var iconUrl = element.attr("data-entry-icon");
var channelId = element.attr("data-entry-channel-id");
var channelUrl = element.attr("data-entry-url");
console.log("addEntryWithModal ~ cId " + channelId);
console.log("addEntryWithModal ~ cUrl " + channelUrl);
var title = element.attr("data-entry-title");
var description = element.find(".entry-description").val()
var textChannelName = element.find(".entry-repost-id").find('option:selected').text()
var textChannelId = element.find(".entry-repost-id").find('option:selected').val()
console.log("addEntryWithModal ~ " + textChannelName);
addNewConfigEntryData(title, iconUrl, channelUrl, channelId, textChannelName, textChannelId, description, guid)
modal.close();
});
modal.addFooterBtn('Cancelar', "button-discord pure-button button-discord-modal button-discord-modal-secondary-action", function(){
modal.close();
});
var cloned = $(".add-new-entry-modal").clone()
cloned.children().attr("id", "editing-" + guid);
cloned.children().attr("data-guid", guid);
modal.setContent(cloned.html());
modal.open();
addInputEvent($("#editing-" + guid));
}
function editEntry(guid) {
if ($("#" + guid).attr("data-is-ready") == "false") {
return;
}
var modal = new tingle.modal({
closeMethods: [],
footer: true
});
modal.addFooterBtn('Salvar', "button-discord button-discord-info pure-button button-discord-modal", function(){
var element = $("#editing-" + guid);
/* if (element.attr("data-is-ready") == "false") { return; } */
var iconUrl = element.attr("data-entry-icon");
var channelId = element.attr("data-entry-channel-id");
var title = element.attr("data-entry-title");
var channelUrl = element.attr("data-entry-url");
var description = element.find(".entry-description").val()
var textChannelName = element.find(".entry-repost-id").find('option:selected').text()
var textChannelId = element.find(".entry-repost-id").find('option:selected').val()
setChannelData($("#" + guid), title, iconUrl, channelUrl, channelId, textChannelName, textChannelId, description, guid)
// addNewConfigEntryData(title, iconUrl, channelId, textChannelName, textChannelId, description, guid)
modal.close();
});
modal.addFooterBtn('Cancelar', "button-discord pure-button button-discord-modal button-discord-modal-secondary-action", function(){
modal.close();
});
var entry = $("#" + guid)
var cloned = $(".add-new-entry-modal").clone()
cloned.children().attr("id", "editing-" + guid);
cloned.children().attr("data-guid", guid);
cloned.find(".entry-info").removeClass("blurSection");
cloned.find(".entry-icon").attr("src", entry.attr("data-entry-icon"))
cloned.find(".entry-title").html(entry.attr("data-entry-title"))
modal.setContent(cloned.html());
modal.open();
$("#editing-" + guid).find(".entry-url").val(entry.attr("data-entry-url"))
$("#editing-" + guid).find(".entry-description").val(htmldecode(entry.attr("data-entry-description")))
$("#editing-" + guid).find(".entry-repost-id").val(entry.attr("data-entry-repost-id")).change();
addInputEvent($("#editing-" + guid));
}
function deleteEntry(guid) {
var modal = new tingle.modal({
closeMethods: [],
footer: true
});
modal.addFooterBtn('Deletar', "button-discord button-discord-info pure-button button-discord-modal", function(){
var element = $("#" + guid);
element.remove();
modal.close();
});
modal.addFooterBtn('Cancelar', "button-discord pure-button button-discord-modal button-discord-modal-secondary-action", function(){
modal.close();
});
var cloned = $(".delete-entry-modal").clone()
modal.setContent(cloned.html());
modal.open();
}
function addInputEvent(element) {
element.find(".entry-url").on('input', function() {
element.find(".entry-info").addClass("blurSection");
clearTimeout(typingTimer);
typingTimer = setTimeout(function() { doneTyping(element) }, 1500);
});
}
function doneTyping(element) {
element.attr("data-is-ready", false)
element.find(".entry-error").addClass("totallyHidden");
var json = getContentAsJson("{{ websiteUrl }}api/v1/get_twitch_info?channelLink=" + encodeURI(element.find(".entry-url").val()), function(json) {
if (json["raw"] != null || json["error"] != null) {
element.find(".entry-info").removeClass("noBlur")
element.find(".entry-info").addClass("blurSection")
element.find(".entry-error").removeClass("totallyHidden");
element.attr("data-is-ready", false)
return;
}
element.find(".entry-info").removeClass("blurSection")
element.find(".entry-info").addClass("noBlur")
element.find(".entry-title").text(json["display_name"])
element.find(".entry-icon").attr("src", json["profile_image_url"])
element.attr("data-entry-title", json["display_name"])
element.attr("data-entry-icon", json["profile_image_url"])
element.attr("data-entry-url", element.find(".entry-url").val())
element.attr("data-is-ready", true)
});
}
function addNewConfigEntry(channelUrl, channelId, channelName, textChannelId, description, guid) {
console.log(channelUrl + " ~ " + guid);
var cloned = $("#custom-config-entry-template").clone();
cloned.find(".entry-channel").text(channelName);
cloned.attr("id", guid);
cloned.attr("data-entry-description", description);
cloned.attr("data-entry-url", channelUrl);
cloned.attr("data-entry-channel-id", channelId);
cloned.attr("data-entry-repost-id", textChannelId);
cloned.attr("data-entry-title", channelName);
cloned.attr("data-is-ready", false)
cloned.find(".entry-edit").attr("onclick", "editEntry('" + guid + "');")
cloned.find(".entry-delete").attr("onclick", "deleteEntry('" + guid + "');")
$("#custom-config-entries").append(cloned);
var json = getContentAsJson("{{ websiteUrl }}api/v1/get_twitch_info?channelLink=" + encodeURI(channelUrl), function(json) {
console.log("callback!");
if (json["error"] != null) {
$("#custom-config-entries").find("#" + guid).remove();
return;
}
cloned.attr("data-is-ready", true)
cloned.attr("data-entry-icon", json["profile_image_url"])
cloned.attr("data-entry-title", json["display_name"])
cloned.attr("data-entry-channel-url", channelUrl)
cloned.find(".entry-title").text(json["display_name"])
cloned.find(".entry-icon").attr("src", json["profile_image_url"])
});
}
function addNewConfigEntryData(channelName, channelIcon, channelUrl, channelId, textChannelName, textChannelId, description, guid) {
console.log("addNewConfigEntryData ~ " + textChannelName);
console.log("addNewConfigEntryData ~ cId " + channelId);
console.log("addNewConfigEntryData ~ cUrl " + channelUrl);
var cloned = $("#custom-config-entry-template").clone();
cloned.attr("id", guid);
setChannelData(cloned, channelName, channelIcon, channelUrl, channelId, textChannelName, textChannelId, description, guid);
$("#custom-config-entries").append(cloned);
}
function setChannelData(cloned, channelName, channelIcon, channelUrl, channelId, textChannelName, textChannelId, description, guid) {
console.log("setChannelData ~ " + textChannelName);
cloned.find(".entry-channel").text("#" + textChannelName);
cloned.find(".entry-title").text(channelName)
cloned.find(".entry-icon").attr("src", channelIcon)
cloned.find(".entry-edit").attr("onclick", "editEntry('" + guid + "');");
cloned.find(".entry-delete").attr("onclick", "deleteEntry('" + guid + "');");
cloned.attr("data-entry-channel-name", channelName);
cloned.attr("data-entry-icon", channelIcon);
cloned.attr("data-entry-description", description);
cloned.attr("data-entry-channel-id", channelId)
cloned.attr("data-entry-url", channelUrl)
cloned.attr("data-entry-repost-id", textChannelId)
console.log("setChannelData ~ cId " + channelId);
console.log("setChannelData ~ cUrl " + channelUrl);
cloned.attr("data-is-ready", true)
}
function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
var jsonFeed = JSON.parse($('#entry-hidden-data').html())
console.log(jsonFeed);
jQuery.each(jsonFeed, function() {
var guid = uuidv4();
console.log(this);
addNewConfigEntry(this["channelUrl"], this["channelId"], "#" + this["textChannelName"], this["repostToChannelId"], this["videoSentMessage"], guid);
});
$("#cmn-toggle-1").click(function(e) {
applyBlur()
});
$("#cmn-toggle-3").click(function(e) {
applyBlur2()
});
function applyBlur() {
var e = $("#hiddenIfDisabled");
if ($('#cmn-toggle-1').is(':checked')) {
e.removeClass();
e.addClass("noBlur");
} else {
e.removeClass();
e.addClass("blurSection");
}
}
function applyBlur2() {
var e = $("#hiddenIfDisabled2");
if ($('#cmn-toggle-3').is(':checked')) {
e.removeClass();
e.addClass("noBlur");
} else {
e.removeClass();
e.addClass("blurSection");
}
}
applyBlur();
applyBlur2();
function htmldecode(s){
window.HTML_ESC_MAP = {
"nbsp":" ","iexcl":"¡","cent":"¢","pound":"£","curren":"¤","yen":"¥","brvbar":"¦","sect":"§","uml":"¨","copy":"©","ordf":"ª","laquo":"«","not":"¬","reg":"®","macr":"¯","deg":"°","plusmn":"±","sup2":"²","sup3":"³","acute":"´","micro":"µ","para":"¶","middot":"·","cedil":"¸","sup1":"¹","ordm":"º","raquo":"»","frac14":"¼","frac12":"½","frac34":"¾","iquest":"¿","Agrave":"À","Aacute":"Á","Acirc":"Â","Atilde":"Ã","Auml":"Ä","Aring":"Å","AElig":"Æ","Ccedil":"Ç","Egrave":"È","Eacute":"É","Ecirc":"Ê","Euml":"Ë","Igrave":"Ì","Iacute":"Í","Icirc":"Î","Iuml":"Ï","ETH":"Ð","Ntilde":"Ñ","Ograve":"Ò","Oacute":"Ó","Ocirc":"Ô","Otilde":"Õ","Ouml":"Ö","times":"×","Oslash":"Ø","Ugrave":"Ù","Uacute":"Ú","Ucirc":"Û","Uuml":"Ü","Yacute":"Ý","THORN":"Þ","szlig":"ß","agrave":"à","aacute":"á","acirc":"â","atilde":"ã","auml":"ä","aring":"å","aelig":"æ","ccedil":"ç","egrave":"è","eacute":"é","ecirc":"ê","euml":"ë","igrave":"ì","iacute":"í","icirc":"î","iuml":"ï","eth":"ð","ntilde":"ñ","ograve":"ò","oacute":"ó","ocirc":"ô","otilde":"õ","ouml":"ö","divide":"÷","oslash":"ø","ugrave":"ù","uacute":"ú","ucirc":"û","uuml":"ü","yacute":"ý","thorn":"þ","yuml":"ÿ","fnof":"ƒ","Alpha":"Α","Beta":"Β","Gamma":"Γ","Delta":"Δ","Epsilon":"Ε","Zeta":"Ζ","Eta":"Η","Theta":"Θ","Iota":"Ι","Kappa":"Κ","Lambda":"Λ","Mu":"Μ","Nu":"Ν","Xi":"Ξ","Omicron":"Ο","Pi":"Π","Rho":"Ρ","Sigma":"Σ","Tau":"Τ","Upsilon":"Υ","Phi":"Φ","Chi":"Χ","Psi":"Ψ","Omega":"Ω","alpha":"α","beta":"β","gamma":"γ","delta":"δ","epsilon":"ε","zeta":"ζ","eta":"η","theta":"θ","iota":"ι","kappa":"κ","lambda":"λ","mu":"μ","nu":"ν","xi":"ξ","omicron":"ο","pi":"π","rho":"ρ","sigmaf":"ς","sigma":"σ","tau":"τ","upsilon":"υ","phi":"φ","chi":"χ","psi":"ψ","omega":"ω","thetasym":"ϑ","upsih":"ϒ","piv":"ϖ","bull":"•","hellip":"…","prime":"′","Prime":"″","oline":"‾","frasl":"⁄","weierp":"℘","image":"ℑ","real":"ℜ","trade":"™","alefsym":"ℵ","larr":"←","uarr":"↑","rarr":"→","darr":"↓","harr":"↔","crarr":"↵","lArr":"⇐","uArr":"⇑","rArr":"⇒","dArr":"⇓","hArr":"⇔","forall":"∀","part":"∂","exist":"∃","empty":"∅","nabla":"∇","isin":"∈","notin":"∉","ni":"∋","prod":"∏","sum":"∑","minus":"−","lowast":"∗","radic":"√","prop":"∝","infin":"∞","ang":"∠","and":"∧","or":"∨","cap":"∩","cup":"∪","int":"∫","there4":"∴","sim":"∼","cong":"≅","asymp":"≈","ne":"≠","equiv":"≡","le":"≤","ge":"≥","sub":"⊂","sup":"⊃","nsub":"⊄","sube":"⊆","supe":"⊇","oplus":"⊕","otimes":"⊗","perp":"⊥","sdot":"⋅","lceil":"⌈","rceil":"⌉","lfloor":"⌊","rfloor":"⌋","lang":"〈","rang":"〉","loz":"◊","spades":"♠","clubs":"♣","hearts":"♥","diams":"♦","\"":"quot","amp":"&","lt":"<","gt":">","OElig":"Œ","oelig":"œ","Scaron":"Š","scaron":"š","Yuml":"Ÿ","circ":"ˆ","tilde":"˜","ndash":"–","mdash":"—","lsquo":"‘","rsquo":"’","sbquo":"‚","ldquo":"“","rdquo":"”","bdquo":"„","dagger":"†","Dagger":"‡","permil":"‰","lsaquo":"‹","rsaquo":"›","euro":"€"};
if(!window.HTML_ESC_MAP_EXP)
window.HTML_ESC_MAP_EXP = new RegExp("&("+Object.keys(HTML_ESC_MAP).join("|")+");","g");
return s?s.replace(window.HTML_ESC_MAP_EXP,function(x){
return HTML_ESC_MAP[x.substring(1,x.length-1)]||x;
}):s;
}
</script>
{% endblock %}