Implement server webhook icons as cosmetics & fixes

This commit is contained in:
Jeremy Zhang
2017-09-13 05:55:51 +00:00
parent d9edf7e8ef
commit c23b71d050
14 changed files with 186 additions and 18 deletions

View File

@ -1,10 +1,13 @@
/* global $, Materialize, location */
function postForm(user_id, css) {
function postForm(user_id, css, css_limit, webhook_icon) {
if (css_limit == "") {
css_limit = 0;
}
var funct = $.ajax({
dataType: "json",
method: "POST",
data: {"user_id": user_id, "css": css}
data: {"user_id": user_id, "css": css, "css_limit": css_limit, "webhook_icon": webhook_icon}
});
return funct.promise();
}
@ -36,7 +39,9 @@ $(function() {
return;
}
var css_checked = $("#new_css_switch").is(':checked');
var formPost = postForm(user_id, css_checked);
var css_limit = $("#new_css_limit").val();
var webhook_icon_checked = $("#new_webhook_icon_switch").is(':checked');
var formPost = postForm(user_id, css_checked, css_limit, webhook_icon_checked);
formPost.done(function (data) {
location.reload();
});
@ -94,4 +99,19 @@ function update_css_limit(user_id, value) {
Materialize.toast('Oh no! Something has failed changing the css limit field!', 10000);
}
});
}
function update_webhook_icon_switch(user_id, element) {
var webhook_checked = $(element).is(':checked');
var formPatch = patchForm(user_id, {"webhook_icon": webhook_checked});
formPatch.done(function (data) {
Materialize.toast('Webhook Icon updated!', 10000);
});
formPatch.fail(function (data) {
if (data.status == 409) {
Materialize.toast('This user id does not exists!', 10000);
} else {
Materialize.toast('Oh no! Something has failed changing the webhook icon toggle!', 10000);
}
});
}

View File

@ -65,6 +65,17 @@ $("#discordio").keyup(function(event){
}
});
$("#webhook_icon").keyup(function(event){
if(event.keyCode == 13){
var pathname = window.location.pathname;
var value = $("#webhook_icon").val()
var payload = {"webhook_icon": value}
$.post(pathname, payload, function(data) {
Materialize.toast('Updated Webhook Icon setting!', 2000)
});
}
});
function initiate_ban(guild_id, user_id) {
var reason = prompt("Please enter your reason for ban");
var payload = {

View File

@ -46,4 +46,21 @@
}
});
});
$("#buy-webhook-guest-user-avatar-btn").click(function () {
var formPatch = patchForm("webhook_icon", 1);
formPatch.done(function (data) {
alert("Successfully bought webhook guest user avatar perk!");
location.reload();
});
formPatch.fail(function (data) {
if (data.status == 400) {
Materialize.toast('Item already purchased!', 10000);
} else if (data.status == 402) {
Materialize.toast('Insufficient token funds!', 10000);
} else {
Materialize.toast('Purchasing webhook guest user avatar perk failed!', 10000);
}
});
});
})();