This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
257 lines (241 loc) · 11.9 KB
/
main.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
const Discord = require('discord.js');
const mongoose = require("mongoose");
const client = new Discord.Client({partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'GUILD_MEMBER', 'USER']});
require("dotenv").config()
const fs = require('fs');
//const alexa = require('alexa-bot-api')
//var chatbot = new alexa('aw2plm')
const db = require("quick.db");
const config = require("./config.json");
const table = new db.table("Tickets");
const dbTable = new db.table("Tickets");
client.commands = new Discord.Collection();
['command', 'event'].forEach(handler => {
require(`./handler/${handler}`)(client, Discord);
});
mongoose.connect(process.env.MONGODB_SRV, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}).then(() => {
console.log("Database Connected");
}).catch((err) => {
console.log(err);
})
client.on("message", async message => {
if(message.channel.type === "dm"){
if(message.author.bot) return;
if(message.content.includes("@everyone") || message.content.includes("@here")) return message.author.send("You may not use everyone/here mentions.")
let active = await dbTable.get(`support_${message.author.id}`)
let guild = client.guilds.cache.get(config.guild);
let channel, found = true;
let user = await dbTable.get(`isBlocked${message.author.id}`);
if(user === true || user === "true") return message.react("❌");
if(active === null){
active = {};
let modrole = guild.roles.cache.get(config.roles.mod);
let everyone = guild.roles.cache.get(guild.roles.everyone.id);
let bot = guild.roles.cache.get(config.roles.bot);
await dbTable.add("ticket", 1)
let actualticket = await dbTable.get("ticket");
channel = await guild.channels.create(`${message.author.username}-${message.author.discriminator}`, { type: 'text', reason: `Modmail created ticket #${actualticket}.` });
channel.setParent(config.ticketCategory);
channel.setTopic(`#${actualticket} (Open) | ${config.prefix}complete to close this ticket | Modmail for ${message.author.username}`)
channel.createOverwrite(modrole, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true,
READ_MESSAGE_HISTORY: true
});
channel.createOverwrite(everyone, {
VIEW_CHANNEL: false
});
channel.createOverwrite(bot, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true,
READ_MESSAGE_HISTORY: true,
MANAGE_MESSAGES: true
})
let author = message.author;
const newTicket = new Discord.MessageEmbed()
.setColor("GREEN").setAuthor(author.tag, author.avatarURL({dynamic: true}))
.setTitle("New ticket created")
.addField("Ticket no.", actualticket, true)
.addField("Channel", `<#${channel.id}>`, true)
const embed10 = new Discord.MessageEmbed()
.setColor('e827db')
.setTitle("Command help (> prefix)")
.setDescription(`Pause, Aliases: [p] used to suspend chat between you and the user\n
Continue, Aliases: [c] used to continue a suspended chat\n
Complete, Aliases: [done, end] used to end the chat entireley\n
Reply, Aliases: [r] used to reply to the user\n
Areply, Aliases: [ar] used to reply anonymously to the user\n
Block, stops the user from opening more tickets\n
Unblock, allows the user from opening tickets (use the id of the user)\n
Id, get the id of the user`)
.setTimestamp()
if(config.log){
client.channels.cache.get(config.log).send({embed: newTicket})
}
const newChannel = new Discord.MessageEmbed()
.setColor("BLUE").setAuthor(author.tag, author.avatarURL())
.setDescription(`Ticket #${actualticket} created.\nUser: ${author}\nID: ${author.id}`)
.setTimestamp()
await client.channels.cache.get(channel.id).send({embed:newChannel});
await client.channels.cache.get(channel.id).send({embed:embed10});
message.author.send(`Hello ${author.username}, your ticket #${actualticket} has been created.`)
active.channelID = channel.id;
active.targetID = author.id;
}
channel = client.channels.cache.get(active.channelID);
var msg = message.content;
var whatWeWant = msg.replace("@everyone", "[everyone]").replace("@here", `[here]`) // idk if that's useful since we're blocking mentions
// fix (#6)
var isPaused = await dbTable.get(`suspended${message.author.id}`);
var isBlocked = await dbTable.get(`isBlocked${message.author.id}`);
if(isPaused === true){
return message.channel.send("Sorry, but your ticket is currently paused. I'll message you back when the support team unpause it.")
}
if(isBlocked === true) return; // the user is blocked, so we're just gonna move on.
if(message.attachments.size > 0){
let attachment = new Discord.MessageAttachment(message.attachments.first().url)
client.channels.cache.get(active.channelID).send(`${message.author.username} > ${whatWeWant}`, {files: [message.attachments.first().url]})
} else {
client.channels.cache.get(active.channelID).send(`${message.author.username} > ${whatWeWant}`);
}
await dbTable.set(`support_${message.author.id}`, active);
await dbTable.set(`supportChannel_${active.channelID}`, message.author.id);
return;
}
if(message.author.bot) return;
var table = new db.table("Tickets");
var support = await table.get(`supportChannel_${message.channel.id}`);
if(support){
var support = await table.get(`support_${support}`);
let supportUser = client.users.cache.get(support.targetID);
if(!supportUser) return message.channel.delete();
// reply (with user and role)
if(message.content.startsWith(`${config.prefix}reply`) || message.content.startsWith(`${config.prefix}r`)) {
var isPause = await table.get(`suspended${support.targetID}`);
let isBlock = await table.get(`isBlocked${support.targetID}`);
if(isPause === true) return message.channel.send("This ticket already paused. Unpause it to continue.")
if(isBlock === true) return message.channel.send("The user is blocked. Unblock them to continue or close the ticket.")
var args = message.content.split(" ").slice(1)
let msg = args.join(" ");
message.react("✅");
if(message.attachments.size > 0){
let attachment = new Discord.MessageAttachment(message.attachments.first().url)
return supportUser.send(`${message.author.username} > ${msg}`, {files: [message.attachments.first().url]})
} else {
return supportUser.send(`${message.author.username} > ${msg}`);
}
};
// anonymous reply
if(message.content.startsWith(`${config.prefix}areply`) || message.content.startsWith(`${config.prefix}ar`)) {
var isPause = await table.get(`suspended${support.targetID}`);
let isBlock = await table.get(`isBlocked${support.targetID}`);
if(isPause === true) return message.channel.send("This ticket already paused. Unpause it to continue.")
if(isBlock === true) return message.channel.send("The user is blocked. Unblock them to continue or close the ticket.")
var args = message.content.split(" ").slice(1)
let msg = args.join(" ");
message.react("✅");
return supportUser.send(`Support Team > ${msg}`);
};
// print user ID
if(message.content === `${config.prefix}id`){
return message.channel.send(`User's ID is **${support.targetID}**.`);
};
// suspend a thread
if(message.content === `${config.prefix}pause` || message.content === `${config.prefix}p`){
var isPause = await table.get(`suspended${support.targetID}`);
if(isPause === true || isPause === "true") return message.channel.send("This ticket already paused. Unpause it to continue.")
await table.set(`suspended${support.targetID}`, true);
var suspend = new Discord.MessageEmbed()
.setDescription(`⏸️ This thread has been **locked** and **suspended**. Do \`${config.prefix}continue\` to cancel.`)
.setTimestamp()
.setColor("YELLOW")
message.channel.send({embed: suspend});
return client.users.cache.get(support.targetID).send("Your ticket has been paused. We'll send you a message when we're ready to continue.")
};
// continue a thread
if(message.content === `${config.prefix}continue` || message.content === `${config.prefix}c`){
var isPause = await table.get(`suspended${support.targetID}`);
if(isPause === null || isPause === false) return message.channel.send("This ticket was not paused.");
await table.delete(`suspended${support.targetID}`);
var c = new Discord.MessageEmbed()
.setDescription("▶️ This thread has been **unlocked**.")
.setColor("BLUE").setTimestamp()
message.channel.send({embed: c});
return client.users.cache.get(support.targetID).send("Hi! Your ticket isn't paused anymore. We're ready to continue!");
}
// block a user
if(message.content.startsWith(`${config.prefix}block`)){
var args = message.content.split(" ").slice(1)
let reason = args.join(" ");
if(!reason) reason = `Unspecified.`
let user = client.users.fetch(`${support.targetID}`); // djs want a string here
const blocked = new Discord.MessageEmbed()
.setColor("RED").setAuthor(user.tag)
.setTitle("User blocked")
.addField("Channel", `<#${message.channel.id}>`, true)
.addField("Reason", reason, true)
if(config.logs){
client.channels.cache.get(config.log).send({embed: blocked})
}
let isBlock = await table.get(`isBlocked${support.targetID}`);
if(isBlock === true) return message.channel.send("The user is already blocked.")
await table.set(`isBlocked${support.targetID}`, true);
var c = new Discord.MessageEmbed()
.setDescription("⏸️ The user has been blocked from the modmail. You may now close the ticket or unblock them to continue.")
.setColor("RED").setTimestamp()
message.channel.send({embed: c});
return;
}
// complete
if(message.content.toLowerCase() === `${config.prefix}complete` || message.content === `${config.prefix}done` || message.content === `${config.prefix}end`){
var embed = new Discord.MessageEmbed()
.setDescription(`This ticket will be deleted in **10** seconds...\n:lock: This thread has been locked and closed.`)
.setColor("RED").setTimestamp()
message.channel.send({embed: embed})
var timeout = 10000
setTimeout(() => {end(support.targetID);}, timeout)
}
async function end(userID){
table.delete(`support_${userID}`);
let actualticket = await table.get("ticket");
message.channel.delete()
return client.users.cache.get(support.targetID).send(`Your ticket #${actualticket} has been closed! If you wish to open a new ticket, feel free to message me.`)
}
};
})
client.on("message", async message => {
if(message.content.startsWith(`${config.prefix}unblock`)){
if(message.guild.member(message.author).roles.cache.has(config.roles.mod)){
var args = message.content.split(" ").slice(1);
client.users.fetch(`${args[0]}`).then(async user => {
let data = await table.get(`isBlocked${args[0]}`);
if(data === true){
await table.delete(`isBlocked${args[0]}`);
return message.channel.send(`Successfully unblocked ${user.username} (${user.id}) from the modmail service.`);
} else {
return message.channel.send(`${user.username} (${user.id}) is not blocked from the modmail at the moment.`)
}
}).catch(err => {
if(err) return message.channel.send("Unknown user.");
})
} else {
return message.channel.send("You can not use that.");
}
}
})
client.login(process.env.TOKEN)
const http = require('http');
const express = require('express');
const app = express();
app.get("/", (request, response) => {
console.log(Date.now() + " Ping Received");
response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);