This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
184 lines (180 loc) · 9.26 KB
/
bot.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
const { Client, Intents, Permissions, MessageEmbed } = require("discord.js");
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS
],
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 pastebin = require("sourcebin");
const db = require("quick.db");
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setStatus('idle')
client.user.setActivity('Mails to the Support Team!', {type: "WATCHING"})
})
client.on("messageCreate", async message => {
if(message.author.bot) return;
if(message.content.includes("@everyone") || message.content.includes("@here")) return message.author.send({content: "You're not allowed to use those mentions."});
// Used a new table so it doesn't get messed up with the old one
const table = new 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}`);
let hold = await table.get(`hold_${message.author.id}`);
// if(config.dmUsers === false) return message.author.send("Hey! Sorry, but the modmail is currently closed.")
if(block === true) return message.author.send("You are not allowed to use modmail.");
if(hold === true) return message.author.send("The support team put your ticket on hold. Please wait until they get back to you.")
let guild = await client.guilds.fetch(config.guild);
let tc = await guild.channels.fetch(config.ticketCategory);
let channel, found = true;
if(active === null){
await table.add("Tickets", 1);
let ticket = await table.get("Tickets");
channel = await guild.channels.create(`${message.author.username}`, {
type: "GUILD_TEXT",
topic: `#${ticket} | From ${message.author.username}`,
parent: tc,
reason: `${message.author.id} opened a ticket through the modmail service.`,
// permissionOverwrites: [
// {id: guild.roles.everyone, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
// {id: guild.roles.fetch(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.roles.fetch(config.roles.bot), allow: [
// Permissions.FLAGS.VIEW_CHANNEL,
// Permissions.FLAGS.SEND_MESSAGES,
// Permissions.FLAGS.ATTACH_FILES,
// Permissions.FLAGS.EMBED_LINKS,
// Permissions.FLAGS.READ_MESSAGE_HISTORY
// ]}
// ]
});
let author = message.author;
const newTicketLog = new MessageEmbed()
.setAuthor(author.tag, author.avatarURL())
.setDescription(`Opened ticket #${ticket}.`)
.setTimestamp()
.setColor("0x6666ff")
let logs = await client.channels.fetch(config.log); // set the log channel id here
logs.send({embeds: [newTicketLog]});
message.author.send(`Hello! Thanks for getting in touch. Our support team will get back to you ASAP.`);
await table.set(`support_${author.id}`, {channel: channel.id, target: message.author.id, ticket: ticket});
await table.set(`channel_${channel.id}`, {author: message.author.id})
let support = await table.get(`support_${message.author.id}`);
let supportchannel = await table.get(`channel_${channel.id}`);
let text = message.content;
let embed = new MessageEmbed()
.setAuthor(author.tag, author.avatarURL())
.setDescription(`${message.author.tag} opened this ticket.`)
.setTimestamp()
.setColor("0x6666ff")
await channel.send({embeds: [embed]})
await channel.send({content: text});
return;
};
channel = guild.channels.cache.get(active.channel);
let text = message.content;
channel.send({content: text});
}
let activechannel = await table.get(`channel_${message.channel.id}`)
if(activechannel === null) return; // if no channel is binded, nothing happens
let activeuser = await table.get(`support_${activechannel.author}`);
let user = await client.users.fetch(activechannel.author);
let text = message.content;
let args = text.split(" ").slice(1);
let pending = args.join(" ");
let blocked = await table.get(`blocked_${activechannel.author}`);
let onHold = await table.get(`hold_${activechannel.author}`);
if(message.content.startsWith(`-r`) || message.content.startsWith(`-reply`)){
if(blocked === true) return message.channel.send({content: "This user is blocked."});
await user.send(`${message.author.username}: ${pending}`);
return;
};
if(message.content === `${config.prefix}help`){
return message.channel.send({content: `Commands: \n
-reply - Replies to a user in a ticket\n
id - Get a ticket owner ID\n
p / hold - Holds a ticket\n
up / unhold - Unholds a ticket\n
b / block - Blocks a user from creating tickets\n
c / complete - Completes and Closes a ticket\n`});
};
if(message.content === `${config.prefix}id`){
return message.channel.send({content: `Ticket owner's ID is **${activechannel.author}**.`});
};
if(message.content === `${config.prefix}p` || message.content === `${config.prefix}hold`){
if(blocked === true) return message.channel.send({content: "This user is blocked."});
if(onHold === true) return message.channel.send({content: "This thread is already on hold."});
await table.set(`hold_${activechannel.author}`, true);
message.channel.send(`This thread has been put on hold.`);
await user.send(`Hi! Your ticket has been put on hold.`);
return;
}
if(message.content === `${config.prefix}up` || message.content === `${config.prefix}unhold`){
if(blocked === true) return message.channel.send({content: "This user is blocked."});
if(onHold === true) return message.channel.send({content: "This thread is not on hold."});
await table.delete(`hold_${activechannel.author}`);
message.channel.send(`This thread isn't on hold anymore.`);
await user.send(`Hi! Your ticket isn't on hold anymore.`);
return;
}
if(message.content === `${config.prefix}b` || message.content === `${config.prefix}block`){
await table.set(`blocked_${activechannel.author}`, true);
await user.send(`You can not use modmail until further notice.`)
message.channel.send(`This user has been blocked from modmail, and other forms of contribution.`);
return;
};
if(message.content === `${config.prefix}c` || message.content === `${config.prefix}complete`){
let text = `Ticket #${activeuser.ticket}\n\nAuthor: ${user.username}#${user.discriminator} (${user.id})\n\n`;
let mmap = message.channel.messages.cache.map(m => {
text += `From ${m.author.username} - ID: ${m.id}\n${m.content}\n\n`
});
pastebin.create([{content: text, language: 'text'},], {title: `ModMail-${activeuser.ticket}-${message.author.username}`, description: `The modmail content for user ${message.author.username}`}).then(async url => {
const newTicketLog = new MessageEmbed()
.setAuthor(user.tag, user.avatarURL())
.setDescription(`Closed ticket #${activeuser.ticket}.\n[Thread](${url.short})`)
.setTimestamp()
.setColor("0x666666")
.setFooter(`Author ID: ${user.id}`)
await client.channels.cache.get(config.log).send({embeds: [newTicketLog]});
await user.send({content: `Thanks for getting in touch! If you wish to open a new ticket, feel free to DM me.\n\nHere's the link to the thread: ${url.url}`})
});
await table.delete(`channel_${message.channel.id}`);
await table.delete(`support_${activechannel.author}`);
await message.channel.delete();
};
})
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.");
}
}
})
client.login("ODczMzMwMjQwMzA5NTcxNjQ1.YQ22Kg.a-xmACPZrd8r-AI3PTHidParXhU"); // if it can't, replace process.env.TOKEN with "TOKEN"