-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (56 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require('dotenv').config()
const axios = require('axios')
const bodyParser = require('body-parser')
const path = require('path')
const express = require('express')
const session = require('express-session')
const ejs = require('ejs')
const app = express()
const passport = require('passport')
const { Strategy } = require('passport-discord')
app.engine('html', ejs.renderFile)
app.set('view engine', 'ejs')
app.set('views', path.join(__dirname, '/views'))
app.use(express.json())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.static('./views'))
const MemoryStore = require('memorystore')(session)
app.use(session({
cookie: { maxAge: 604800000 },
secret: process.env.SECRET,
store: new MemoryStore({
checkPeriod: 604800000
}),
resave: true,
saveUninitialized: true
}))
passport.serializeUser((user, done) => {
done(null, user)
})
passport.deserializeUser((obj, done) => {
done(null, obj)
})
const scopes = ['identify', 'guilds', 'email', 'guilds.join']
passport.use(new Strategy({
clientID: process.env.ID,
clientSecret: process.env.SECRET,
callbackURL: 'https://starbot.website/api/callback',
scope: scopes
}, function (accessToken, refreshToken, profile, done) {
process.nextTick(async function () {
await axios.put(`https://discord.com/api/v8/guilds/1025926077484388373/members/${profile.id}`, {
access_token: accessToken
}, {
headers: {
Authorization: `Bot ${process.env.TOKEN}`
}
})
return done(null, profile)
})
}))
app.use('/', require('./routers/index'))
app.listen(process.env.PORT, () => {
console.log('[SERVER] - Servidor iniciado com Sucesso!')
})
require('./bot')