All discord functionality seems to be working here?? Not sure what happened but yay

This commit is contained in:
Opaque02 2024-10-09 22:32:45 +10:00
parent 19046311dd
commit f07b10da0a

View File

@ -114,26 +114,21 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] });
if (this.adminMode === AdminMode.LINK) { if (this.adminMode === AdminMode.LINK) {
this.adminLinkUnlink(adminSearchResult, "discord", "link"); this.adminLinkUnlink(adminSearchResult, "discord", "link")
.then(response => {
if (response.error) {
return this.showMessage(response.errorType, adminSearchResult, true);
} else {
return this.showMessage(this.SUCCESS_DISCORD_LINKED, adminSearchResult, false);
}
});
} else if (this.adminMode === AdminMode.SEARCH) { } else if (this.adminMode === AdminMode.SEARCH) {
this.adminSearch(adminSearchResult) this.adminSearch(adminSearchResult)
.then(response => { .then(response => {
if (response.error) { if (response.error) {
let errorString: string; return this.showMessage(response.errorType, adminSearchResult, true);
switch (response.errorType) {
case "Error":
errorString = this.ERR_GENERIC_ERROR;
break;
case "UsernameNotFound":
errorString = this.ERR_USERNAME_NOT_FOUND;
break;
default:
errorString = this.ERR_GENERIC_ERROR;
break;
}
return this.showMessage(errorString, adminSearchResult, true);
} }
this.updateAdminPanelInfo(response.adminSearchResult); this.updateAdminPanelInfo(response.adminSearchResult ?? adminSearchResult);
}); });
} }
@ -170,9 +165,18 @@ export default class AdminUiHandler extends FormModalUiHandler {
img.setScale(0.5); img.setScale(0.5);
img.setInteractive(); img.setInteractive();
img.on("pointerdown", () => { img.on("pointerdown", () => {
this.adminLinkUnlink(this.convertInputsToAdmin(), "discord", adminResult[aR] === "" ? "link" : "unlink"); this.adminLinkUnlink(this.convertInputsToAdmin(), "discord", adminResult[aR] === "" ? "link" : "unlink").then(response => {
console.log(response);
});
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] });
this.updateAdminPanelInfo(adminResult); //this.updateAdminPanelInfo(adminResult);
this.adminSearch(adminResult)
.then(response => {
if (response.error) {
return this.showMessage(response.errorType, adminResult, true);
}
this.updateAdminPanelInfo(response.adminSearchResult ?? adminResult);
});
}); });
this.addInteractionHoverEffect(img); this.addInteractionHoverEffect(img);
this.modalContainer.add(img); this.modalContainer.add(img);
@ -230,10 +234,10 @@ export default class AdminUiHandler extends FormModalUiHandler {
if (!adminInfo.ok) { if (!adminInfo.ok) {
console.error(adminInfo); console.error(adminInfo);
console.log(adminSearchResult); console.log(adminSearchResult);
return { adminSearchResult: adminSearchResult, error: true, errorType: "Error" }; return { adminSearchResult: adminSearchResult, error: true, errorType: this.ERR_GENERIC_ERROR };
} else if (adminInfo.status === this.httpUserNotFoundErrorCode) { // username doesn't exist } else if (adminInfo.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
console.log(adminSearchResult); console.log(adminSearchResult);
return { adminSearchResult: adminSearchResult, error: true, errorType: "UsernameNotFound" }; return { adminSearchResult: adminSearchResult, error: true, errorType: this.ERR_USERNAME_NOT_FOUND };
} else { } else {
const adminInfoJson: AdminSearchInfo = await adminInfo.json(); const adminInfoJson: AdminSearchInfo = await adminInfo.json();
return { adminSearchResult: adminInfoJson, error: false }; return { adminSearchResult: adminInfoJson, error: false };
@ -244,30 +248,29 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
} }
adminLinkUnlink(adminSearchResult: AdminSearchInfo, service: string, mode: string) { async adminLinkUnlink(adminSearchResult: AdminSearchInfo, service: string, mode: string) {
Utils.apiPost(`admin/account/${service}-${mode}`, `username=${encodeURIComponent(adminSearchResult.username)}&discordId=${encodeURIComponent(adminSearchResult.discordId)}`, "application/x-www-form-urlencoded", true) try {
.then(response => { const response = await Utils.apiPost(`admin/account/${service}-${mode}`, `username=${encodeURIComponent(adminSearchResult.username)}&discordId=${encodeURIComponent(adminSearchResult.discordId)}`, "application/x-www-form-urlencoded", true);
if (!response.ok) { //.then(response => {
console.error(response); if (!response.ok) {
return this.showMessage(this.ERR_GENERIC_ERROR, adminSearchResult, true); console.error(response);
} else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist return { adminSearchResult: adminSearchResult, error: true, errorType: this.ERR_GENERIC_ERROR };
//console.log(adminSearchResult); } else if (response.status === this.httpUserNotFoundErrorCode) { // username doesn't exist
return this.showMessage(this.ERR_USERNAME_NOT_FOUND, adminSearchResult, true); return { adminSearchResult: adminSearchResult, error: true, errorType: this.ERR_USERNAME_NOT_FOUND };
} else { } else {
let successString: string = ""; //let successString: string = "";
if (service === "discord") { //if (service === "discord") {
successString = mode === "link" ? this.SUCCESS_DISCORD_LINKED : this.SUCCESS_DISCORD_UNLINKED; // successString = mode === "link" ? this.SUCCESS_DISCORD_LINKED : this.SUCCESS_DISCORD_UNLINKED;
} else if (service === "google") { //} else if (service === "google") {
successString = mode === "link" ? this.SUCCESS_GOOGLE_LINKED : this.SUCCESS_GOOGLE_UNLINKED; // successString = mode === "link" ? this.SUCCESS_GOOGLE_LINKED : this.SUCCESS_GOOGLE_UNLINKED;
} //}
return this.showMessage(successString, adminSearchResult, false); return { adminSearchResult: adminSearchResult, error: false };
} }
}) //})
.catch((err) => { } catch (err) {
console.error(err); console.error(err);
this.scene.ui.revertMode(); return { error: true, errorType: err };
this.scene.ui.revertMode(); }
});
} }
updateAdminPanelInfo(adminSearchResult: AdminSearchInfo, mode?: AdminMode) { updateAdminPanelInfo(adminSearchResult: AdminSearchInfo, mode?: AdminMode) {