-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
138 lines (123 loc) · 5.49 KB
/
server.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const Discord = require("discord.js"); // discord.js v11
const client = new Discord.Client();
const fs = require('fs');
const prefix = "PREFIX HERE"
const verifyj = JSON.parse(fs.readFileSync("./verify.json", "utf8"))
client.on('message', async message => {
let messageArray = message.content.split(" ");
if(message.content === `${prefix}setcaptcha`) {
let filter = m => m.author.id === message.author.id;
let ch;
if(!message.member.hasPermission("MANAGE_GUILD")) return message.channel.send('You don\'t have permission').then(msg => {
msg.delete(4500);
message.delete(4500);
});
message.channel.send(':pencil: **| Now type the verify channel name... :pencil2: **').then(msg => {
message.channel.awaitMessages(filter, {
max: 1,
time: 90000,
errors: ['time']
})
.then(collected => {
collected.first().delete();
ch = collected.first().content;
let chf = message.guild.channels.find('name', `${ch}`)
if(!chf) return msg.edit(':x: **| Wrong Channel Name (Type The Command Again) .**') && console.log('cant find this channel')
let rr;
msg.edit(':scroll: **| Please type verified role name.... :pencil2: **').then(msg => {
message.channel.awaitMessages(filter, {
max: 1,
time: 90000,
errors: ['time']
})
.then(collected => {
collected.first().delete();
rr = collected.first().content;
let rf = message.guild.roles.find('name', `${rr}`)
if(!rf) return msg.edit(':x: **| Wrong Role Name (Type The Command Again)**') && console.log('cant find this role')
msg.edit('✅ **| Done successfully.. **').then(msg => {
message.channel.awaitMessages(filter, {
max: 1,
time: 90000,
errors: ['time']
})
let embed = new Discord.RichEmbed()
.setTitle('**Done The Captcha Has Been Setup**')
.addField('Captcha Channel:', `${ch}`)
.addField('Verfied Role:', `${rr}`)
.setThumbnail(message.author.avatarURL)
.setFooter(`${client.user.username}`)
message.channel.sendEmbed(embed)
verifyj[message.guild.id] = {
channel: ch,
rolev: rr,
onoff: 'On'
}
fs.writeFile("./verify.json", JSON.stringify(verifyj), (err) => {
if (err) console.error(err)
})
}
)
})
})
})
})
}})
client.on('message', async message => {
if(message.content == `${prefix}captcha off`) {
if(!verifyj[message.guild.id]) verifyj[message.guild.id] = {
channel: "Undefined",
onoff: "Off",
rolev: "Undefined"
}
if(verifyj[message.guild.id].onoff === "Off") return message.channel.send('Already Turned Off !')
verifyj[message.guild.id].onoff = "off"
message.channel.send(':white_check_mark: | Successfully turned off')
fs.writeFile("./verify.json", JSON.stringify(verifyj), (err) => {
if (err) console.error(err)
})
}
})
client.on('message', async message => {
if(message.author.bot) return;
if(!message.channel.type === 'dm') return;
let rf = message.guild.roles.find('name', `${verifyj[message.guild.id].rolev}`)
let mem = message.guild.member(message.author)
if(message.content.startsWith(prefix + 'captcha')) {
if(!verifyj[message.guild.id]) verifyj[message.guild.id] = {
channel: "Undefined",
onoff: "Off",
rolev: "Undefined"
}
if(verifyj[message.guild.id].onoff === "Off") return console.log('the command is turned off')
if(message.channel.name !== verifyj[message.guild.id].channel) return console.log('wrong channel')
if(mem.roles.has(rf.id)) return message.channel.send(':x: | You Are Already Verfied !')
const type = require('./verifycodes.json');
const item = type[Math.floor(Math.random() * type.length)];
const filter = response => {
return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
};
const embed = new Discord.RichEmbed()
.setTitle('**You Should Write The Captcha Code In 15 Seconds**')
.setColor("RANDOM")
.setImage(`${item.type}`)
.setFooter('Requested By' + message.author.tag)
message.channel.sendEmbed(embed).then(() => {
message.channel.awaitMessages(filter, { maxMatches: 1, time: 15000, errors: ['time'] })
.then((collected) => {
message.author.send(`**${collected.first().author} successfully you got verfied role :white_check_mark:**`);
message.channel.send(`**${collected.first().author} successfully you got verfied role :white_check_mark:**`);
console.log(`[Typing] ${collected.first().author} verfied himself ! .`);
message.guild.member(collected.first().author).addRole(rf)
})
.catch(collected => {
message.author.send('Timeout !')
console.log('[Typing] Error: No one type the captcha code.');
console.log(collected)
})
fs.writeFile("./verify.json", JSON.stringify(verifyj), (err) => {
if (err) console.error(err)
})
})
}})
client.login("PUT UR TOKEN HERE");