alert when bot isnt in guild
This commit is contained in:
parent
e7ef270d39
commit
e27b7d679d
@ -93,6 +93,8 @@ async function showEditSubModal(subId) {
|
||||
$("#subFormModal .form-edit").hide();
|
||||
$("#subChannels").val("").change();
|
||||
$("#subFilters").val("").change();
|
||||
$("#subImagePreview img").attr("src", "").hide();
|
||||
$("#subImagePreview small").show();
|
||||
}
|
||||
else {
|
||||
const subscription = subTable.row(function(idx, data, node) {
|
||||
@ -212,6 +214,10 @@ async function loadSubscriptions(guildId) {
|
||||
}
|
||||
|
||||
$(document).on("selectedServerChange", async function() {
|
||||
|
||||
// Hide alerts
|
||||
$("#serverJoinAlert").attr("style", "display: none !important");
|
||||
|
||||
const activeServer = getCurrentlyActiveServer();
|
||||
await loadSubscriptions(activeServer.guild_id);
|
||||
await loadChannelOptions(activeServer.guild_id);
|
||||
@ -244,27 +250,37 @@ async function loadChannelOptions(guildId) {
|
||||
|
||||
// Clear select2 input
|
||||
$("#subChannels").val("").change();
|
||||
|
||||
try {
|
||||
const channels = await loadChannels(guildId);
|
||||
console.log(JSON.stringify(channels));
|
||||
console.debug(JSON.stringify(channels));
|
||||
|
||||
// If we have reached the discord API rate limit
|
||||
if (channels.message && channels.message.includes("rate limit")) {
|
||||
throw new Error(
|
||||
`${channels.message} Retry after ${channels.retry_after} seconds.`
|
||||
)
|
||||
}
|
||||
|
||||
// If we can't fetch channels due to error
|
||||
if (channels.code === 50001) {
|
||||
showServerJoinAlert();
|
||||
|
||||
// Also check that the user hasn't changed the currently active guild, otherwise
|
||||
// the alert will show under the wrong server.
|
||||
if (getCurrentlyActiveServer().guild_id === guildId)
|
||||
showServerJoinAlert();
|
||||
|
||||
const guildName = getServerFromSnowflake(guildId).name;
|
||||
|
||||
throw new Error(
|
||||
`Unable to retrieve channels from Guild '${guildId}'.
|
||||
`Unable to retrieve channels from Guild <b>${guildName}</b>.
|
||||
Ensure that @PYRSS is a member with permissions
|
||||
to view channels.`
|
||||
);
|
||||
}
|
||||
|
||||
channels.forEach(channel => {
|
||||
|
||||
// We only want TextChannels, which have a type of 0
|
||||
if (channel.type !== 0)
|
||||
return;
|
||||
|
||||
@ -323,11 +339,25 @@ async function loadFilterOptions(guildId) {
|
||||
function showServerJoinAlert() {
|
||||
const guildId = getCurrentlyActiveServer().guild_id;
|
||||
const inviteUrl = `https://discord.com/oauth2/authorize
|
||||
?client_id=1129345991758336020
|
||||
&permissions=2147534848&scope=bot+applications.commands
|
||||
&guild_id=${guildId}
|
||||
&disable_guild_select=true`
|
||||
?client_id=1129345991758336020
|
||||
&permissions=2147534848&scope=bot+applications.commands
|
||||
&guild_id=${guildId}
|
||||
&disable_guild_select=true`
|
||||
|
||||
$("#serverJoinAlert a.alert-link").attr("href", inviteUrl);
|
||||
$("#serverJoinAlert").show();
|
||||
}
|
||||
|
||||
$("#subImage").on("change", function () {
|
||||
const [file] = $("#subImage")[0].files;
|
||||
if (file) {
|
||||
$("#subImagePreview small").hide();
|
||||
$("#subImagePreview img").attr("src", URL.createObjectURL(file)).show();
|
||||
}
|
||||
});
|
||||
imgInp.onchange = evt => {
|
||||
const [file] = imgInp.files
|
||||
if (file) {
|
||||
blah.src = URL.createObjectURL(file)
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
</div>
|
||||
|
||||
<div class="col-12 m-0">
|
||||
<div id="serverJoinAlert" class="alert alert-warning alert-dismissable fade show mt-4 d-flex align-items-center" role="alert" style="display: hidden">
|
||||
<div id="serverJoinAlert" class="alert alert-warning alert-dismissable fade show mt-4 d-flex align-items-center" role="alert" style="display: none !important">
|
||||
<i class="bi bi-warning"></i>
|
||||
<span>
|
||||
<strong>Warning:</strong>
|
||||
|
Loading…
x
Reference in New Issue
Block a user