-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
270 lines (189 loc) · 9.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
const discord = require("discord.js");
const keepAlive = require('./keepAlive.js');
const client = new discord.Client()
const {
token,
prefix,
ServerID
} = require("./config.json")
client.on("ready", () => {
console.log("I am ready to receive and Send Mails :D")
client.user.setActivity("Watching My Dm's :D")
})
client.on("channelDelete", (channel) => {
if (channel.parentID == channel.guild.channels.cache.find((x) => x.name == "MODMAIL").id) {
const person = channel.guild.members.cache.find((x) => x.id == channel.name)
if (!person) return;
let yembed = new discord.MessageEmbed()
.setAuthor("MAIL DELETED", client.user.displayAvatarURL())
.setColor('RED')
.setThumbnail(client.user.displayAvatarURL())
.setDescription("Your mail is deleted by moderator and if you have any problem with that than you can open mail again by sending message here.")
return person.send(yembed)
}
})
client.on("message", async message => {
if (message.author.bot) return;
let args = message.content.slice(prefix.length).split(' ');
let command = args.shift().toLowerCase();
if (message.guild) {
if (command == "setup") {
if (!message.member.hasPermission("ADMINISTRATOR")) {
return message.channel.send("You need Admin Permissions to setup the modmail system!")
}
if (!message.guild.me.hasPermission("ADMINISTRATOR")) {
return message.channel.send("Bot need Admin Permissions to setup the modmail system!")
}
let role = message.guild.roles.cache.find((x) => x.name == "SUPPORTER")
let everyone = message.guild.roles.cache.find((x) => x.name == "@everyone")
if (!role) {
role = await message.guild.roles.create({
data: {
name: "SUPPORTER",
color: "GREEN"
},
reason: "Role needed for ModMail System"
})
}
await message.guild.channels.create("MODMAIL", {
type: "category",
topic: "All the mail will be here :D",
permissionOverwrites: [{
id: role.id,
allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"]
},
{
id: everyone.id,
deny: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"]
}
]
})
return message.channel.send("Setup is Completed :D")
} else if (command == "close") {
if (message.channel.parentID == message.guild.channels.cache.find((x) => x.name == "MODMAIL").id) {
const person = message.guild.members.cache.get(message.channel.name)
if (!person) {
return message.channel.send("I am Unable to close the channel and this error is coming because probaly channel name is changed.")
}
await message.channel.delete()
let yembed = new discord.MessageEmbed()
.setAuthor("MAIL CLOSED", client.user.displayAvatarURL())
.setColor("RED")
.setThumbnail(client.user.displayAvatarURL())
.setFooter("Mail is closed by " + message.author.username)
if (args[0]) yembed.setDescription(args.join(" "))
return person.send(yembed)
}
} else if (command == "open") {
const category = message.guild.channels.cache.find((x) => x.name == "MODMAIL")
if (!category) {
return message.channel.send("Moderation system is not setuped in this server, use " + prefix + "setup")
}
if (!message.member.roles.cache.find((x) => x.name == "SUPPORTER")) {
return message.channel.send("You need supporter role to use this command")
}
if (isNaN(args[0]) || !args.length) {
return message.channel.send("Please Give the ID of the person")
}
const target = message.guild.members.cache.find((x) => x.id === args[0])
if (!target) {
return message.channel.send("Unable to find this person.")
}
const channel = await message.guild.channels.create(target.id, {
type: "text",
parent: category.id,
topic: "Mail is Direct Opened by **" + message.author.username + "** to make contact with " + message.author.tag
})
let nembed = new discord.MessageEmbed()
.setAuthor("DETAILS", target.user.displayAvatarURL({
dynamic: true
}))
.setColor("BLUE")
.setThumbnail(target.user.displayAvatarURL({
dynamic: true
}))
.setDescription(message.content)
.addField("Name", target.user.username)
.addField("Account Creation Date", target.user.createdAt)
.addField("Direct Contact", "Yes(it means this mail is opened by a supporter)");
channel.send(nembed)
let uembed = new discord.MessageEmbed()
.setAuthor("DIRECT MAIL OPENED")
.setColor("GREEN")
.setThumbnail(client.user.displayAvatarURL())
.setDescription("You have been contacted by Supporter of **" + message.guild.name + "**, Please wait until he send another message to you!");
target.send(uembed);
let newEmbed = new discord.MessageEmbed()
.setDescription("Opened The Mail: <#" + channel + ">")
.setColor("GREEN");
return message.channel.send(newEmbed);
} else if (command == "help") {
let embed = new discord.MessageEmbed()
.setAuthor('MODMAIL BOT', client.user.displayAvatarURL())
.setColor("GREEN")
.setDescription("This bot is made by CTK WARRIOR, You can remove credits :D")
.addField(prefix + "setup", "Setup the modmail system(This is not for multiple server.)", true)
.addField(prefix + "open", 'Let you open the mail to contact anyone with his ID', true)
.setThumbnail(client.user.displayAvatarURL())
.addField(prefix + "close", "Close the mail in which you use this command.", true);
return message.channel.send(embed)
}
}
if (message.channel.parentID) {
const category = message.guild.channels.cache.find((x) => x.name == "MODMAIL")
if(!category) return;
if (message.channel.parentID == category.id) {
let member = message.guild.members.cache.get(message.channel.name)
if (!member) return message.channel.send('Unable To Send Message')
let lembed = new discord.MessageEmbed()
.setColor("GREEN")
.setFooter(message.author.username, message.author.displayAvatarURL({
dynamic: true
}))
.setDescription(message.content)
return member.send(lembed)
}
}
if (!message.guild) {
const guild = await client.guilds.cache.get(ServerID) || await client.guilds.fetch(ServerID).catch(m => {})
if (!guild || !guild.members.cache.some(x => x.id === message.author.id)) return;
const category = guild.channels.cache.find((x) => x.name == "MODMAIL")
if (!category) return;
const main = guild.channels.cache.find((x) => x.name == message.author.id)
if (!main) {
let mx = await guild.channels.create(message.author.id, {
type: "text",
parent: category.id,
topic: "This mail is created for helping **" + message.author.tag + " **"
})
let sembed = new discord.MessageEmbed()
.setAuthor("MAIN OPENED")
.setColor("GREEN")
.setThumbnail(client.user.displayAvatarURL())
.setDescription("Conversation is now started, you will be contacted by supporters soon :D")
message.author.send(sembed)
let eembed = new discord.MessageEmbed()
.setAuthor("DETAILS", message.author.displayAvatarURL({
dynamic: true
}))
.setColor("BLUE")
.setThumbnail(message.author.displayAvatarURL({
dynamic: true
}))
.setDescription(message.content)
.addField("Name", message.author.username)
.addField("Account Creation Date", message.author.createdAt)
.addField("Direct Contact", "No(it means this mail is opened by person not a supporter)")
return mx.send(eembed)
}
let xembed = new discord.MessageEmbed()
.setColor("YELLOW")
.setFooter(message.author.tag, message.author.displayAvatarURL({
dynamic: true
}))
.setDescription(message.content)
main.send(xembed)
}
})
keepAlive();
client.login(token)