-
Notifications
You must be signed in to change notification settings - Fork 14
/
verify.js
72 lines (58 loc) · 3.26 KB
/
verify.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
'use_strict'
const Discord = require('discord.js')
const config = require('./config.json')
const completemsg = `Thank you for agreeing to the rules and code of conduct! You are now a verified member of the guild! \nFeel free to choose what roles you’d like, introduce yourself or check out a our other channels. \n\n**Your unique token is your signature that you have read and understood our rules.**\n`
const shortcode = (n) => {
const possible = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghjklmnopqrstuvwxyz0123456789'
let text = ''
for (var i = 0; i < n + 1; i++) text += possible.charAt(Math.floor(Math.random() * possible.length))
return text;
}
const client = new Discord.Client()
client.on('ready', () => {
client.user.setActivity(config.playing)
console.log(`[VERIFYBOT] Connected as ${client.user.username}#${client.user.discriminator} ${client.user.id}`)
})
client.on('guildMemberAdd', (member) => {
if (member.user.bot || member.guild.id !== config.guild) return
const token = shortcode(8)
const welcomemsg = `Welcome to the guild! We hope you find a home here! Check out the \`#general\` channel to make sure that we jive, and as long as our goals are similar, then there’s a place at the table waiting for you. \n\n If you accept the code of conduct, please verify your agreement by replying to **this DM** with the verification phrase: \n\n\`I agree to abide by all rules. My token is ${token}.\`\n\n **This message is case-sensitive, and please include the period at the end! ** \n\nQuestions? Get at a staff member in the server or via DM.`
console.log(`${member.user.username}#${member.user.discriminator} joined! CODE: "${token}"`)
member.send(welcomemsg)
member.user.token = token
})
const verifymsg = 'I agree to abide by all rules. My token is {token}.'
client.on('message', (message) => {
if (message.author.bot || !message.author.token || message.channel.type !== `dm`) return
if (message.content !== (verifymsg.replace('{token}', message.author.token))) return
message.channel.send({
embed: {
color: Math.floor(Math.random() * (0xFFFFFF + 1)),
description: completemsg,
timestamp: new Date(),
footer: {
text: `Verification Success`
}
}
})
client.guilds.get(config.guild).member(message.author).roles.add(config.role) // ensure this is a string in the config ("")
.then(console.log(`TOKEN: ${message.author.token} :: Role ${config.role} added to member ${message.author.id}`))
.catch(console.error)
})
client.on('disconnect', (event) => {
setTimeout(() => client.destroy().then(() => client.login(config.token)), 10000)
console.log(`[DISCONNECT] Notice: Disconnected from gateway with code ${event.code} - Attempting reconnect.`)
})
client.on('reconnecting', () => {
console.log(`[NOTICE] ReconnectAction: Reconnecting to Discord...`)
})
client.on('error', console.error)
client.on('warn', console.warn)
process.on('unhandledRejection', (error) => {
console.error(`Uncaught Promise Error: \n${error.stack}`)
})
process.on('uncaughtException', (err) => {
let errmsg = (err ? err.stack || err : '').toString().replace(new RegExp(`${__dirname}/`, 'g'), './')
console.error(errmsg)
})
client.login(config.token)