Skip to content

Commit

Permalink
Add discord invite endpoint, readd bot endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed May 13, 2024
1 parent 100c2ea commit dd96fe2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.env
.env.prod
.env.dev
.venv
node_modules
__pycache__
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MIT

1. Make a pull request to the server by editing the `server_config.ini` file per your server requirements (see subsection below for more details)
2. Create a new role for the bot, which satisfies the criteria given in the next section.
3. **After** your PR is merged, navigate to the [this URL](https://discord.com/oauth2/authorize?client_id=843107899944861706&permissions=469764096&redirect_uri=https%3A%2F%2Fosdg.iiit.ac.in%2Fcasbot%2Fbot&response_type=code&scope=bot%20identify) to invite the bot and add it to your server. Note that you must have "Manage Server" permission on this server. (If you're new to Discord roles, read the FAQ:
3. **After** your PR is merged, navigate to the [this URL](https://osdg.iiit.ac.in/casbot/discord/invite) to invite the bot and add it to your server. Note that you must have "Manage Server" permission on this server. (If you're new to Discord roles, read the FAQ:
[link](https://support.discord.com/hc/en-us/articles/214836687-Role-Management-101))

### Configuration parameters
Expand Down
29 changes: 27 additions & 2 deletions portal/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ app.get(`${config.SUBPATH}/`, (req, res) => {
});

app.get(`${config.SUBPATH}/discord`, (req, res) => {
let redirect_uri = `${config.BASE_URL}/discord/callback`;
res.redirect(
`https://discordapp.com/api/oauth2/authorize?client_id=${config.DISCORD_CLIENT_ID}&scope=identify&response_type=code&redirect_uri=${config.DISCORD_REDIRECT}`,
`https://discordapp.com/api/oauth2/authorize?client_id=${config.DISCORD_CLIENT_ID}&scope=identify&response_type=code&redirect_uri=${redirect_uri}`,
);
});

app.get(`${config.SUBPATH}/discord/invite`, (req, res) => {
let redirect_uri = `${config.BASE_URL}/bot`;
res.redirect(
`https://discord.com/oauth2/authorize?client_id=${config.DISCORD_CLIENT_ID}&permissions=275347671040&redirect_uri=${redirect_uri}&response_type=code&scope=bot`,
);
});

Expand Down Expand Up @@ -104,7 +112,7 @@ app.get(`${config.SUBPATH}/discord/callback`, async (req, res) => {
}

const code = req.query.code;
const redirect_uri = config.DISCORD_REDIRECT;
const redirect_uri = `${config.BASE_URL}/discord/callback`;
const responseJson = await makeQuery(code, redirect_uri);
const accessToken = responseJson.access_token;

Expand All @@ -129,6 +137,23 @@ app.get(`${config.SUBPATH}/discord/callback`, async (req, res) => {
res.redirect(`${config.SUBPATH}/cas`);
});

app.get(`${config.SUBPATH}/bot`, async (req, res) => {
if (!req.query.code || !req.query.guild_id) {
res.send("You are not discord :angry:", 400);
return;
}

const code = req.query.code;
const redirect_uri = `${config.BASE_URL}/bot`;
const responseJson = await makeQuery(code, redirect_uri);
if (responseJson && responseJson.access_token) {
res.send("Added successfully!");
} else {
logger.error(responseJson);
res.send("Unkown error occured");
}
});

const CAS = require("cas");

const cas = new CAS({
Expand Down
2 changes: 0 additions & 2 deletions portal/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const ATLAS_URL = `${process.env.MONGO_URI}/${process.env.MONGO_DATABASE}`;

const DISCORD_CLIENT_ID = process.env.DISCORD_CLIENT_ID;
const DISCORD_SECRET = process.env.DISCORD_SECRET;
const DISCORD_REDIRECT = `${BASE_URL}/discord/callback`;

// secret for express middleware
const SECRET = process.env.SECRET;
Expand All @@ -29,5 +28,4 @@ module.exports = {
ATLAS_URL,
DISCORD_CLIENT_ID,
DISCORD_SECRET,
DISCORD_REDIRECT,
};

0 comments on commit dd96fe2

Please sign in to comment.