-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (70 loc) · 2.27 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Common
require('dotenv').config();
var cors = require('cors')
//Express
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const bodyParser = require('body-parser');
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
//Discord
const { Client, Intents } = require('discord.js');
const on_message = require('./Discord/on_message');
const IndexRouter = require('./Routers/index_router');
const ForgotRouter = require('./Routers/forgot');
const CallbackRouter = require('./Routers/callback');
const token = process.env.TOKEN;
const client = new Client({
intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_INTEGRATIONS
]
});
app.use((req, res, next) => {
if (req.headers.hasOwnProperty('x-forwarded-proto') && req.headers['x-forwarded-proto'].toString() !== 'https' && process.env.NODE_ENV === 'production') {
res.redirect('https://' + req.headers.host + req.url);
}
else {
next();
}
})
//expose public
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.use(bodyParser.json());
app.use(cors())
app.use('/', IndexRouter);
app.use('/forgot', ForgotRouter);
app.use('/callback', CallbackRouter);
client.once('ready', c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`);
});
process.on('uncaughtException', function (err) {
//log to discord webhook
fetch(process.env.WEBHOOK, {
method: 'post',
body: JSON.stringify({
// content: `Uncaught Exception: ${err}`
}),
headers: { 'Content-Type': 'application/json' },
})
console.log('Caught exception: ' + err);
});
//On a message call the on_message function
client.on("messageCreate", message => {
message.content = message.content.toLowerCase();
on_message(client, message);
})
client.login(token);