-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
103 lines (89 loc) · 3.19 KB
/
index.js
File metadata and controls
103 lines (89 loc) · 3.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const express = require("express");
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.raw());
let port = 3000;
let config = {
botToken: "",
guildID: "",
chanelID: "",
colorCode: "",
topggAuth: ""
}
const Discord = require('discord.js');
const Intent = Discord.GatewayIntentBits;
const client = new Discord.Client({ intents: [
Intent.Guilds,
Intent.GuildMembers,
Intent.GuildMessages
]});
client.login(config.botToken);
client.once('ready', async () => {
app.listen(port, () => console.log(`Webook listener running on port: ${port}`));
console.log(`Bot online as ${client.user.tag}`);
})
app.post('/server', async (req, res) => {
if (req.headers.authorization === config.topggAuth) {
let guild = await client.guilds.fetch(config.guildID);
let member = await guild.members.fetch(req.body.user);
let channel = await guild.channels.fetch(config.chanelID);
let embed = new Discord.MessageEmbed()
.setTitle("New Server Vote")
.setDescription(`${member.displayName} just voted for ${guild.name} on top.gg!`)
.setAuthor({name: `${member.user.tag}`, iconURL: `${member.user.displayAvatarURL({
extension: 'png', forceStatic: true, size: 2048
})}`})
.setThumbnail(guild.iconURL({
extension: 'png', forceStatic: true, size: 2048
}))
.setColor(config.colorCode)
.setFooter({ text: "Vote recieved on Top.GG", iconURL: "https://avatars.githubusercontent.com/u/34552786?s=280&v=4" });
try {
channel.send({
content: ":arrow_up:",
embeds: [embed]
});
} catch (err) {
console.error(err);
};
res.sendStatus(200);
} else {
res.sendStatus(403);
}
});
app.post('/bot', async (req, res) => {
if (req.headers.authorization === config.topggAuth) {
let guild = await client.guilds.fetch(config.guildID);
let member = await guild.members.fetch(req.body.user);
let channel = await guild.channels.fetch(config.chanelID);
let bot = await client.users.cache.fetch(req.body.bot);
let embed = new Discord.MessageEmbed()
.setTitle("New Bot Vote")
.setAuthor({name: `${member.user.tag}`, iconURL: `${member.user.displayAvatarURL({
extension: 'png', forceStatic: true, size: 2048
})}`})
.setThumbnail(bot.user.displayAvatarURL({
extension: 'png', forceStatic: true, size: 2048
}))
.setColor(config.colorCode)
.setFooter({ text: "Vote recieved on Top.GG", iconURL: "https://avatars.githubusercontent.com/u/34552786?s=280&v=4" });
if (req.body.isWeekend == true) {
embed.setDescription(`${member.displayName} just voted for ${bot.user.name} on top.gg! This counted as 2 votes!`)
} else {
embed.setDescription(`${member.displayName} just voted for ${bot.user.name} on top.gg!`)
}
try {
channel.send({
content: ":arrow_up:",
embeds: [embed]
});
} catch (err) {
console.error(err);
};
res.sendStatus(200);
} else {
res.sendStatus(403);
}
});