rate limit handling for generate channels
All checks were successful
Build and Push Docker Image / build (push) Successful in 14s
All checks were successful
Build and Push Docker Image / build (push) Successful in 14s
This commit is contained in:
parent
56e125c0bf
commit
082cf2989d
@ -58,6 +58,63 @@ function loadedChannels(serverId) {
|
|||||||
return _loadedChannels[serverId]
|
return _loadedChannels[serverId]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rateLimitedLoadingChannels = retryAfterSeconds => {
|
||||||
|
createModal({
|
||||||
|
title: "Failed to Fetch Server Channels",
|
||||||
|
texts: [
|
||||||
|
{ content: "Discord is rate-limiting your request." },
|
||||||
|
{ content: `This happens when making requests too quickly. Retry after ${retryAfterSeconds} seconds to continue without issue.` }
|
||||||
|
],
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
className: "btn-warning px-4",
|
||||||
|
iconClass: "bi-arrow-return-right",
|
||||||
|
closeModal: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const notAuthorisedLoadingChannels = () => {
|
||||||
|
// Mark the sidebar item as non-operational
|
||||||
|
$(`.sidebar .sidebar-item[data-id="${serverId}"]`).addClass("is-not-operational");
|
||||||
|
|
||||||
|
const inviteBotToServer = () => {
|
||||||
|
window.open(
|
||||||
|
`https://discord.com/oauth2/authorize
|
||||||
|
?client_id=${discordClientId}
|
||||||
|
&permissions=2147534848
|
||||||
|
&scope=bot+applications.commands
|
||||||
|
&guild_id=${serverId}
|
||||||
|
&disable_guild_select=true`,
|
||||||
|
"_blank"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inform the user auth problem
|
||||||
|
createModal({
|
||||||
|
title: "Failed to Fetch Server Channels",
|
||||||
|
texts: [
|
||||||
|
{ content: "The Discord Bot is unable to access this server's channels, certain features will not work." },
|
||||||
|
{ content: "Ensure the Bot is a member, and has the neccessary permissions to operate." }
|
||||||
|
],
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: "Invite the Bot",
|
||||||
|
className: "btn-primary me-3",
|
||||||
|
iconClass: "bi-envelope-plus",
|
||||||
|
closeModal: true,
|
||||||
|
onClick: inviteBotToServer
|
||||||
|
},
|
||||||
|
{
|
||||||
|
className: "btn-secondary",
|
||||||
|
iconClass: "bi-arrow-return-right",
|
||||||
|
closeModal: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).on("selectedServerChange", async function() {
|
$(document).on("selectedServerChange", async function() {
|
||||||
serverId = selectedServer.id; // take note incase 'selectedServer' changes
|
serverId = selectedServer.id; // take note incase 'selectedServer' changes
|
||||||
|
|
||||||
@ -71,43 +128,20 @@ $(document).on("selectedServerChange", async function() {
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
logError(error);
|
logError(error);
|
||||||
|
|
||||||
// Mark the sidebar item as non-operational
|
switch (error?.status) {
|
||||||
$(`.sidebar .sidebar-item[data-id="${serverId}"]`).addClass("is-not-operational");
|
case 429:
|
||||||
|
rateLimitedLoadingChannels(error.responseJSON.retry_after);
|
||||||
|
break;
|
||||||
|
|
||||||
const inviteBotToServer = () => {
|
case 403:
|
||||||
window.open(
|
notAuthorisedLoadingChannels();
|
||||||
`https://discord.com/oauth2/authorize
|
break;
|
||||||
?client_id=${discordClientId}
|
|
||||||
&permissions=2147534848
|
default:
|
||||||
&scope=bot+applications.commands
|
alert("unknown error loading channels");
|
||||||
&guild_id=${serverId}
|
break;
|
||||||
&disable_guild_select=true`,
|
|
||||||
"_blank"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform the user of the problem
|
|
||||||
createModal({
|
|
||||||
title: "Failed to Fetch Server Channels",
|
|
||||||
texts: [
|
|
||||||
{ content: "The Discord Bot is unable to access this server's channels, certain features will not work." },
|
|
||||||
{ content: "Ensure the Bot is a member, and has the neccessary permissions to operate." }
|
|
||||||
],
|
|
||||||
buttons: [
|
|
||||||
{
|
|
||||||
text: "Invite the Bot",
|
|
||||||
className: "btn-primary me-3",
|
|
||||||
iconClass: "bi-envelope-plus",
|
|
||||||
closeModal: true,
|
|
||||||
onClick: inviteBotToServer
|
|
||||||
},
|
|
||||||
{
|
|
||||||
className: "btn-secondary",
|
|
||||||
iconClass: "bi-arrow-return-right",
|
|
||||||
closeModal: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
$(".sidebar .sidebar-item").prop("disabled", false);
|
$(".sidebar .sidebar-item").prop("disabled", false);
|
||||||
@ -237,7 +271,7 @@ async function loadServers() {
|
|||||||
$(".sidebar .server-rate-limit").hide();
|
$(".sidebar .server-rate-limit").hide();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const servers = await generateServers();
|
const servers = await ajaxRequest("/generate-servers/", "GET");
|
||||||
servers.forEach(server => addToLoadedServers(server, false));
|
servers.forEach(server => addToLoadedServers(server, false));
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user