-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (64 loc) · 2.19 KB
/
index.js
File metadata and controls
84 lines (64 loc) · 2.19 KB
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
83
84
const DBL = require('@top-gg/sdk');
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const User = require('./data/User');
const config = require('./config.json')
const webhook = new DBL.Webhook(config.dbl_secret);
const fetch = require('node-fetch');
const Discord = require('discord.js');
const port = config.port || 5000
const {
WebhookClient
} = require('discord.js');
const webhookVote = new WebhookClient(config.webhook_id, config.webhook_url);
app.get('/', (req, res) => {
res.send('Currently Working.')
})
app.get('/dblwebhook', (req, res) => {
res.send('Currently Working.')
})
app.post('/dblwebhook', webhook.middleware(), async (req, res) => {
const votedUser = await fetch(`https://discord.com/api/v8/users/${req.vote.user}`, {
headers: {
Authorization: `Bot ${config.bot_token}`
}
}).then(res => res.json());
console.log(`${votedUser.username} Just Voted!`);
let userV = await User.findOne({
id: req.vote.user
});
if (!userV) {
await User.create({
id: req.vote.user,
votes: 1,
lastVoted: Date.now()
});
userV = await User.findOne({
id: req.vote.user
});
};
const vote_number = userV.votes + 1 || 1;
const embed = new Discord.MessageEmbed()
.setAuthor(`${config.bot_name}'s Voting System'`, `${config.logo || 'https://i.imgur.com/nhyrOYD.png'}`)
.setColor('GREEN')
.setTitle(`${votedUser.username} Just Voted`)
.setDescription(`**${votedUser.username}#${votedUser.discriminator}** (${votedUser.id}) just voted **${config.bot_name}**!`)
.setFooter(`Vote #${vote_number}`)
webhookVote.send(embed);
return await userV.updateOne({
votes: vote_number,
lastVoted: Date.now()
});
});
mongoose.connection.on('connected', () => console.log('Connected to Mongo DB'));
app.listen(port, () => {
console.log(`Running Vote System on Port ${port}`);
mongoose.connect(config.mongo, {
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
}).catch((err) => {
console.log(err)
});
});