mirror of
https://github.com/DerTyp7/discord-twitch-bot.git
synced 2025-10-30 05:07:13 +01:00
init
This commit is contained in:
1442
setup_server/package-lock.json
generated
Normal file
1442
setup_server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
setup_server/package.json
Normal file
20
setup_server/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "setup_server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.1",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"ejs": "^3.1.8",
|
||||
"express": "^4.18.2",
|
||||
"express-session": "^1.17.3",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
||||
63
setup_server/server.js
Normal file
63
setup_server/server.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const path = require("path");
|
||||
const ejs = require("ejs");
|
||||
const { v4 } = require("uuid");
|
||||
const session = require("express-session");
|
||||
const cookieParser = require("cookie-parser");
|
||||
const bodyParser = require("body-parser");
|
||||
const port = 3000;
|
||||
const oneDay = 1000 * 60 * 60 * 24;
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
app.set("view engine", "ejs");
|
||||
app.use(
|
||||
session({
|
||||
secret: "thisismysecrctekeyfhrgfgrfrty84fwir767",
|
||||
saveUninitialized: true,
|
||||
cookie: { maxAge: oneDay },
|
||||
resave: false,
|
||||
})
|
||||
);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
let discordAuthenticated = false;
|
||||
let twitchAuthenticated = false;
|
||||
|
||||
if (req.session.discordCode && req.session.discordGuildId) {
|
||||
discordAuthenticated = true;
|
||||
}
|
||||
|
||||
if (req.session.twtichCode) {
|
||||
twitchAuthenticated = true;
|
||||
}
|
||||
|
||||
res.render("./index.ejs", {
|
||||
discordAuthenticated: discordAuthenticated,
|
||||
twitchAuthenticated: twitchAuthenticated,
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/logout", (req, res) => {
|
||||
req.session.destroy();
|
||||
res.redirect("/");
|
||||
});
|
||||
|
||||
app.get("/authorize/twitch", (req, res) => {
|
||||
req.session.twtichCode = req.query.code;
|
||||
res.redirect("/");
|
||||
});
|
||||
|
||||
app.get("/authorize/discord", (req, res) => {
|
||||
req.session.discordCode = req.query.code;
|
||||
req.session.discordGuildId = req.query.guild_id;
|
||||
res.redirect("/");
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
});
|
||||
12
setup_server/views/authorize.html
Normal file
12
setup_server/views/authorize.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Authorize</title>
|
||||
</head>
|
||||
<body>
|
||||
auth
|
||||
</body>
|
||||
</html>
|
||||
23
setup_server/views/index.ejs
Normal file
23
setup_server/views/index.ejs
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
discord <%= discordAuthenticated %> twitch <%= twitchAuthenticated%>
|
||||
<a
|
||||
id="discordLink"
|
||||
href="https://discord.com/api/oauth2/authorize?client_id=1037396501732794489&permissions=8&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauthorize%2Fdiscord&response_type=code&scope=identify%20bot"
|
||||
>Connect with Discord</a
|
||||
>
|
||||
<a
|
||||
id="twitchLink"
|
||||
href="https://id.twitch.tv/oauth2/authorize?client_id=evozwlc7xv0aggczc6ya92vnsrsxp2&redirect_uri=http://localhost:3000/authorize/twitch&response_type=code&scope=channel%3Aread%3Asubscriptions"
|
||||
>Connect with Twitch</a
|
||||
>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user