Get guild ID from the callback URL instead, allow me to not have to create the webhook in order to get the ID and then have to delete it if it isn't allowed to be created.
This commit is contained in:
parent
eef056fe59
commit
8dd58b81c5
1 changed files with 7 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { Request, ResponseToolkit } from "@hapi/hapi";
|
|
||||||
import { CHANNEL_DATA, DISCORD_API_URI } from "@/constants";
|
import { CHANNEL_DATA, DISCORD_API_URI } from "@/constants";
|
||||||
|
import { Request, ResponseToolkit } from "@hapi/hapi";
|
||||||
import { config, db } from "@/main";
|
import { config, db } from "@/main";
|
||||||
import boom from "@hapi/boom";
|
import boom from "@hapi/boom";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
@ -7,7 +7,8 @@ import axios from "axios";
|
||||||
export default {
|
export default {
|
||||||
method: `GET`, path: `/discord/auth/callback`,
|
method: `GET`, path: `/discord/auth/callback`,
|
||||||
async handler(request: Request, h: ResponseToolkit) {
|
async handler(request: Request, h: ResponseToolkit) {
|
||||||
let code = request.query.code;
|
let { code, guild_id: gID } = request.query;
|
||||||
|
|
||||||
|
|
||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.set(`client_id`, config.discord.client_id);
|
data.set(`client_id`, config.discord.client_id);
|
||||||
|
|
@ -22,20 +23,11 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let { guild_id, id, token } = r.data.webhook;
|
let { id, token } = r.data.webhook;
|
||||||
|
|
||||||
// Assert the guild is allowed to be setup.
|
db[gID] = JSON.parse(JSON.stringify(CHANNEL_DATA))
|
||||||
if (!config.guilds[guild_id]) {
|
db[gID].webhook.token = token;
|
||||||
|
db[gID].webhook.id = id;
|
||||||
// Delete the webhook so that it doesn't remain in the server
|
|
||||||
await axios.delete(r.data.webhook.url);
|
|
||||||
|
|
||||||
throw boom.notFound(`Cannot save a webhook for a guild that doesn't have a config set up.`);
|
|
||||||
};
|
|
||||||
|
|
||||||
db[guild_id] = JSON.parse(JSON.stringify(CHANNEL_DATA))
|
|
||||||
db[guild_id].webhook.token = token;
|
|
||||||
db[guild_id].webhook.id = id;
|
|
||||||
|
|
||||||
return r.data;
|
return r.data;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue