-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
259 lines (176 loc) · 9.13 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
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
const discord = require("discord.js");
const client = new discord.Client()
const { prefix, ServerID } = require("./package.json")
const package = require('./package.json');
client.on("ready", () => {
console.log("Bot online")
client.user.setActivity("Checking mails for propaganda")
})
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 Closed", client.user.displayAvatarURL())
.setColor('RED')
.setDescription("Ticket has been closed, please dont not respond to this message until you need any more help")
return person.send(yembed)
}
})
client.on("message", async message => {
if (message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
let command = args.shift().toLowerCase();
if (message.guild) {
if (command == "mod-mail") {
if (!message.content.startsWith(prefix)) return;
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 == "Staff")
let everyone = message.guild.roles.cache.find((x) => x.name == "@everyone")
if (!role) {
role = await message.guild.roles.create({
data: {
name: "Staff",
color: "YELLOW"
},
reason: "Role needed for ModMail System"
})
}
await message.guild.channels.create("MODMAIL", {
type: "category",
topic: "All the mail will be here",
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 ✅")
} else if (command == "close") {
if (!message.content.startsWith(prefix)) return;
if (!message.member.roles.cache.find((x) => x.name == "Staff")) {
return message.channel.send("You need Staff role to use this command")
}
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(`Reason: ${args.join(" ")}`)
return person.send(yembed)
}
} else if (command == "open") {
if (!message.content.startsWith(prefix)) return;
const category = message.guild.channels.cache.find((x) => x.name == "MODMAIL")
if (!category) {
return message.channel.send("Modmail system is not setuped in this server, use " + prefix + "setup")
}
if (!message.member.roles.cache.find((x) => x.name == "Staff")) {
return message.channel.send("You need `Staff` 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 Staff)");
channel.send(nembed)
let uembed = new discord.MessageEmbed()
.setAuthor("DIRECT MAIL OPENED")
.setColor("GREEN")
.setThumbnail(client.user.displayAvatarURL())
.setDescription("You have been contacted by Staff 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") {
if (!message.content.startsWith(prefix)) return;
let embed = new discord.MessageEmbed()
.setAuthor('MODMAIL BOT')
.addField("setup", "Setup the modmail system(This is not for multiple server.)", true)
.addField("open", 'Let you open the mail to contact anyone with his ID', true)
.setThumbnail(client.user.displayAvatarURL())
.addField("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 (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")
.setAuthor(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) 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("SUPPORT MAIL OPENED")
.setColor("GREEN")
.setThumbnail(client.user.displayAvatarURL())
.setDescription("Conversation is now started, you will be contacted by History of Everything free moderator soon")
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 staff)")
return mx.send(eembed)
}
let xembed = new discord.MessageEmbed()
.setColor("RED")
.setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
.setDescription(message.content)
main.send(xembed)
}
})
client.login(process.env.TOKEN)