This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
index.js
191 lines (177 loc) · 7.46 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
const { Client, GatewayIntentBits, Partials, Permissions, EmbedBuilder } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
partials: [Partials.Channel]
}) // not sure about intents, though
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const config = require("./config.json");
const strings = require("./strings.json");
const { paste } = require("ubuntu-pastebin");
const { QuickDB } = require("quick.db");
const db = new QuickDB();
// If you store your database somewhere else, uncomment & edit the following:
// const db = new QuickDB({filePath: "/path/to/db.sqlite"});
// Notify once logged in
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}.`);
})
// Log in
client.login(config.token);
// If that doesn't work, uncomment & edit this:
// client.login("PUT YOUR TOKEN HERE");
client.on("messageCreate", async message => {
const author = message.author;
if(author.bot) return;
let guild = await client.guilds.fetch(config.id.server);
if(guild.members.fetch(author.id).communicationDisabledUntilTimestamp !== null && config.permissions.disableOnTimeout === true) return message.author.send(strings.disableOnTimeout);
if(guild.members.fetch(author.id).pending) return message.author.send(strings.pending);
let text = message.content.replace(/[`]|@everyone|@here/g, '');
// Use table from 1.1.9
const table = db.table("Support13")
if(message.channel.type === "DM"){
let active = await table.get(`support_${message.author.id}`);
let block = await table.get(`blocked_${message.author.id}`);
if(config.enabled === false) return message.author.send(strings.disabled);
if(block === true) return message.author.send(strings.blocked);
let ticketcategory = await guild.channels.fetch(config.id.ticketCategory);
let channel, found = true;
// NEW TICKET
if(active === null){
await table.add("Tickets", 1);
let ticket = await table.get("Tickets");
channel = await guild.channels.create({
name: `${message.author.username}`,
topic: `#${ticket} | From ${message.author.username}`,
parent: ticketcategory,
reason: `${message.author.id} opened a ticket through the modmail service.`,
permissionOverwrites: [
{id: guild.roles.everyone, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
{id: guild.roles.resolve(config.roles.mod), allow: [
Permissions.FLAGS.VIEW_CHANNEL,
Permissions.FLAGS.SEND_MESSAGES,
Permissions.FLAGS.ATTACH_FILES,
Permissions.FLAGS.EMBED_LINKS,
Permissions.FLAGS.READ_MESSAGE_HISTORY
]},
{id: guild.members.resolve(client.user.id), allow: [
Permissions.FLAGS.VIEW_CHANNEL,
Permissions.FLAGS.SEND_MESSAGES,
Permissions.FLAGS.ATTACH_FILES,
Permissions.FLAGS.EMBED_LINKS,
Permissions.FLAGS.READ_MESSAGE_HISTORY
]}
]
});
try {
let logs = await client.channels.fetch(config.id.logchannel);
if(config.permissions.rawLogs){
const newTicketLog = new EmbedBuilder()
.setAuthor(author.tag, author.avatarURL())
.setDescription(`Ticket ${ticket} opened\nUser ID: ${author.id}`)
.setTimestamp().setColor("0x6666ff")
logs.send({embeds: [newTicketLog]});
} else {
logs.send(`#**${ticket}** | Opened by ${author.tag} (${author.id})`);
}
} catch(e) {
console.warn("Could not send log message. Ignoring...");
}
message.author.send(strings.welcome);
await table.set(`support_${author.id}`, {channel: channel.id, target: author.id, ticket: ticket});
await table.set(`channel_${channel.id}`, author.id);
await channel.send(`**New ticket (#${ticket})**\nAuthor: ${author.tag}`);
await channel.send(`${author.username}: ${text}`);
} // End of new ticket
let data = await table.get(`support_${author.id}`);
active.channel = data.channel;
active.targetID = data.target;
channel = guild.channels.cache.get(active.channel);
channel.send(`${message.author.username}: ${text}`);
}
let activechannel = await table.get(`channel_${message.channel.id}`);
if(activechannel === null) return; // Otherwise it's gonna spam all channels
const userID = activechannel;
let activeuser = await table.get(`support_${userID}`);
let user = await client.users.fetch(userID);
let args = text.split(" ").slice(1); // use "text" var here
let pending = args.join(" ");
let blocked = await table.get(`blocked_${userID}`);
const prefix = config.prefix;
let member = message.guild.members.fetch(user);
// Reply
if(message.content.startsWith(`${prefix}r`) || message.content.startsWith(`${prefix}reply`)){
if(blocked) return message.channel.send(strings.thread.blocked)
if(member.communicationDisabledUntilTimestamp !== null && config.permissions.disableOnTimeout === true) return message.channel.send(strings.thread.timeout);
await user.send(`${author.username}: ${pending}`);
return;
}
// Get the ID
if(message.content === `${prefix}id`){
return message.channel.send(`The ID of this thread's author is ${userID}.`);
}
// Block the user
if(message.content === `${prefix}block`){
await table.set(`blocked_${userID}`, true);
if(config.permissions.notifyUserOnBlock) await user.send(strings.nowBlocked);
return message.channel.send(strings.thread.nowBlocked);
}
// Close the ticket
// TODO: Fix the paste feature
if(message.content === `${prefix}close`){
let text = `Ticket #${activeuser.ticket}\n\nAuthor: ${user.tag} (${user.id})\n\n`;
let list = message.channel.messages.cache.map(m => {
text += `${m.author.tag} (message ${m.id})\n${m.content}\n\n`
})
//paste(text).then(async url => {
// Send log
try {
let logs = await client.channels.fetch(config.id.logchannel);
if(config.permissions.rawLogs){
const oldTicketLog = new EmbedBuilder()
.setAuthor(author.tag, author.avatarURL())
.setDescription(`Ticket ${ticket} closed\nUser ID: ${author.id}`)
.setTimestamp().setColor("0x666666")
// [Message log](${url})
logs.send({embeds: [oldTicketLog]});
} else {
logs.send(`#**${ticket}** | Closed. Author was ${author.tag} (${author.id}).`);
}
} catch(e) {
console.warn("Could not send log embed. Ignoring...");
}
// Notify user
await user.send(strings.nowClosed.replace("{{URL}}", ""));
//})
await table.delete(`channel_${message.channel.id}`);
await table.delete(`support_${activechannel.author}`);
}
})
// Unblock feature
client.on("messageCreate", 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 => {
const dbTable3 = new db.table("Support13");
let data = await dbTable3.get(`blocked_${args[0]}`);
if(data === true){
await dbTable3.delete(`blocked_${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.");
}
}
})