Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit ea3c1e3

Browse files
committed
1.1.10 READ CHANGES
1 parent ef62720 commit ea3c1e3

5 files changed

Lines changed: 207 additions & 10 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
A modmail with rich features using the latest discord.js version.
44

5-
[![Badge](https://img.shields.io/github/commit-activity/y/Cyanic76/discord-modmail?style=for-the-badge)](https://github.com/Cyanic76/discord-modmail/graphs/commit-activity)
6-
[![License](https://img.shields.io/github/license/Cyanic76/discord-modmail.svg?style=for-the-badge)](https://github.com/Cyanic76/discord-modmail/blob/master/LICENSE)
7-
85
## Links
96

107
- [Get the modmail up & running](https://github.com/Cyanic76/discord-modmail/wiki/Installation)

config.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
2-
"guild": "Your support server ID goes here",
2+
"deleteTicketOnLeave": false,
3+
"enabled": false,
4+
"id": {
5+
"logchannel": "Your modmail log channel ID (will be ignored if none)",
6+
"ticketCategory": "Your support server's TICKET category ID",
7+
"server": "Your support server ID goes here"
8+
},
39
"log": "Your modmail log channel ID",
10+
"permissions": {
11+
"disabledOnTimeout": true,
12+
"notifyUserOnBlock": true
13+
},
414
"prefix": "!",
515
"roles": {
616
"bot": "Your bot role ID",
717
"mod": ["Your moderator/support team role ID"]
8-
},
9-
"ticketCategory": "Your support server's TICKET category ID",
10-
"dmUsers": false,
11-
"deleteTicketOnLeave": false
18+
}
1219
}

index.js

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
const { Client, Intents, Permissions } = require("discord.js");
2+
const client = new Client({
3+
intents: [
4+
Intents.FLAGS.GUILDS,
5+
Intents.FLAGS.GUILD_MEMBERS,
6+
Intents.FLAGS.GUILD_MESSAGES,
7+
Intents.FLAGS.DIRECT_MESSAGES,
8+
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
9+
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS
10+
],
11+
partials: ["CHANNEL"]
12+
}) // not sure about intents, though
13+
const { REST } = require("@discordjs/rest");
14+
const { Routes } = require("discord-api-types/v9");
15+
const config = require("./config.json");
16+
const strings = require("./strings.json");
17+
const { paste } = require("ubuntu-pastebin");
18+
const { QuickDB } = require("quick.db");
19+
const db = new QuickDB();
20+
// If you store your database somewhere else, uncomment & edit the following:
21+
// const db = new QuickDB({filePath: "/path/to/db.sqlite"});
22+
23+
// Notify once logged in
24+
client.once("ready", () => {
25+
console.log(`Logged in as ${client.user.tag}.`);
26+
})
27+
28+
// Log in
29+
client.login(process.env.TOKEN);
30+
// If that doesn't work, uncomment & edit this:
31+
// client.login("PUT YOUR TOKEN HERE");
32+
33+
client.on("messageCreate", async message => {
34+
if(message.author.bot) return;
35+
if(message.guild.member(message.author).communicationDisabledUntilTimestamp !== null && config.permissions.disableOnTimeout === true) return message.author.send(strings.disableOnTimeout);
36+
if(message.guild.member(message.author).pending) return message.author.send(strings.pending);
37+
let text = string.replace(/[`]|@everyone|@here/g, '');
38+
// Use table from 1.1.9
39+
const table = db.table("Support13")
40+
41+
if(message.channel.type === "DM"){
42+
let active = await table.get(`support_${message.author.id}`);
43+
let block = await table.get(`blocked_${message.author.id}`);
44+
if(config.enabled === false) return message.author.send(strings.disabled);
45+
if(block === true) return message.author.send(strings.blocked);
46+
let guild = await client.guilds.fetch(config.id.server);
47+
let ticketcategory = await guild.channels.fetch(config.id.ticketCategory);
48+
let channel, found = true;
49+
50+
// NEW TICKET
51+
if(active === null){
52+
await table.add("Tickets", 1);
53+
let ticket = await table.get("Tickets");
54+
55+
channel = await guild.channels.create(`${message.author.username}`, {
56+
type: "GUILD_TEXT",
57+
topic: `#${ticket} | From ${message.author.username}`,
58+
parent: tc,
59+
reason: `${message.author.id} opened a ticket through the modmail service.`,
60+
permissionOverwrites: [
61+
{id: guild.roles.everyone, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
62+
{id: guild.roles.fetch(config.roles.mod), allow: [
63+
Permissions.FLAGS.VIEW_CHANNEL,
64+
Permissions.FLAGS.SEND_MESSAGES,
65+
Permissions.FLAGS.ATTACH_FILES,
66+
Permissions.FLAGS.EMBED_LINKS,
67+
Permissions.FLAGS.READ_MESSAGE_HISTORY
68+
]},
69+
{id: guild.roles.fetch(config.roles.bot), allow: [
70+
Permissions.FLAGS.VIEW_CHANNEL,
71+
Permissions.FLAGS.SEND_MESSAGES,
72+
Permissions.FLAGS.ATTACH_FILES,
73+
Permissions.FLAGS.EMBED_LINKS,
74+
Permissions.FLAGS.READ_MESSAGE_HISTORY
75+
]}
76+
]
77+
});
78+
79+
let author = message.author;
80+
try {
81+
const newTicketLog = new MessageEmbed()
82+
.setAuthor(author.tag, author.avatarURL())
83+
.setDescription(`Ticket ${ticket} opened`)
84+
.setTimestamp().setColor("0x6666ff")
85+
let logs = await client.channels.fetch(config.id.logchannel); // set the log channel id here
86+
logs.send({embeds: [newTicketLog]});
87+
} catch(e) {
88+
console.warn("Could not send log embed. Ignoring...");
89+
}
90+
91+
message.author.send(strings.welcome);
92+
await table.set(`support_${author.id}`, {channel: channel.id, target: author.id, ticket: ticket});
93+
await table.set(`channel_${channel.id}`, author.id);
94+
await channel.send(`**New ticket (#${ticket})**\nAuthor: ${author.tag}`);
95+
await channel.send(`${author.username}: ${text}`);
96+
97+
} // End of new ticket
98+
channel = guild.channels.cache.get(active.channel);
99+
// TODO: Do something when channel doesn't exists or no permissions
100+
channel.send(`${message.author.username}: ${text}`);
101+
}
102+
const author = message.author;
103+
let activechannel = await table.get(`channel_${message.channel.id}`);
104+
if(activechannel === null) return; // TODO: If no channel is binded, notify mods
105+
const userID = activechannel.author;
106+
let activeuser = await table.get(`support_${userID}`);
107+
let user = await client.users.fetch(userID);
108+
let args = text.split(" ").slice(1); // use "text" var here
109+
let pending = args.join(" ");
110+
let blocked = await table.get(`blocked_${userID}`);
111+
const prefix = config.prefix;
112+
113+
// Reply
114+
if(message.content.startsWith(`${prefix}r`) || message.content.startsWith(`${prefix}reply`)){
115+
if(blocked) return message.channel.send(strings.thread.blocked)
116+
if(message.guild.member(user).communicationDisabledUntilTimestamp !== null && config.permissions.disableOnTimeout === true) return message.channel.send(strings.thread.timeout);
117+
await user.send(`${author.username}: ${pending}`);
118+
return;
119+
}
120+
121+
// Get the ID
122+
if(message.content === `${prefix}id`){
123+
return message.channel.send(`The ID of this thread's author is ${userID}.`);
124+
}
125+
126+
// Block the user
127+
if(message.content === `${prefix}block`){
128+
await table.set(`blocked_${activechannel.author}`, true);
129+
if(config.permissions.notifyUserOnBlock) await user.send(strings.nowBlocked);
130+
return message.channel.send(strings.thread.nowBlocked);
131+
}
132+
133+
// Close the ticket
134+
if(message.content === `${prefix}close`){
135+
let text = `Ticket #${activeuser.ticket}\n\nAuthor: ${user.tag} (${user.id})\n\n`;
136+
let list = message.channel.messages.cache.map(m => {
137+
text += `${m.author.tag} (message ${m.id})\n${m.content}\n\n`
138+
})
139+
paste(text).then(async url => {
140+
// Send log
141+
try {
142+
const oldTicketLog = new MessageEmbed()
143+
.setAuthor(author.tag, author.avatarURL())
144+
.setDescription(`Ticket ${ticket} closed\n[Message log](${url})`)
145+
.setTimestamp().setColor("0x666666")
146+
let logs = await client.channels.fetch(config.id.logchannel); // set the log channel id here
147+
logs.send({embeds: [oldTicketLog]});
148+
} catch(e) {
149+
console.warn("Could not send log embed. Ignoring...");
150+
}
151+
// Notify user
152+
await user.send(strings.nowClosed.replace("{{URL}}", url));
153+
})
154+
await table.delete(`channel_${message.channel.id}`);
155+
await table.delete(`support_${activechannel.author}`);
156+
}
157+
})
158+
159+
// Unblock feature
160+
client.on("messageCreate", async message => {
161+
if(message.content.startsWith(`${config.prefix}unblock`)){
162+
if(message.guild.member(message.author).roles.cache.has(config.roles.mod)){
163+
var args = message.content.split(" ").slice(1);
164+
client.users.fetch(`${args[0]}`).then(async user => {
165+
const dbTable3 = new db.table("Support13");
166+
let data = await dbTable3.get(`blocked_${args[0]}`);
167+
if(data === true){
168+
await dbTable3.delete(`blocked_${args[0]}`);
169+
return message.channel.send(`Successfully unblocked ${user.username} (${user.id}) from the modmail service.`);
170+
} else {
171+
return message.channel.send(`${user.username} (${user.id}) is not blocked from the modmail at the moment.`)
172+
}
173+
}).catch(err => {
174+
if(err) return message.channel.send("Unknown user.");
175+
})
176+
} else {
177+
return message.channel.send("You can not use that.");
178+
}
179+
}
180+
})

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "discord-modmail",
3-
"version": "1.1.9",
3+
"version": "1.1.10",
44
"description": "JavaScript modmail bot with rich features. (using quick.db & mongo)",
55
"main": "bot.js",
66
"scripts": {
7-
"start": "node bot.js"
7+
"start": "node index.js"
88
},
99
"dependencies": {
1010
"express": "^4.18.1",

strings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"disableOnTimeout": "Hello! You are on timeout right now and the modmail is set up in a way that prevent users on timeout to use this service.",
3+
"disabled": "Hello! I'm sorry, but the modmail is currently disabled.",
4+
"nowBlocked": "Hi! The support team has decided to prevent you from using the modmail.",
5+
"nowClosed": "Hi! Thanks for getting in touch. Your ticket has been closed by the support team. If you wish to open a new one, feel free to send a new message here.\nMessage log: {{URL}}",
6+
"pending": "Hello! You must review the support server's guidelines and accept them first.",
7+
"thread": {
8+
"blocked": "The author of this thread has been blocked. You may want to unblock them (`unblock {user ID}`).",
9+
"nowBlocked": "Successfully blocked the author of this thread.",
10+
"timeout": "The author of this thread is on timeout and usage of modmail while on timeout is disabled."
11+
},
12+
"welcome": "Hi! Thanks for getting in touch with the support team. They will quickly get back to you."
13+
}

0 commit comments

Comments
 (0)