Skip to content
This repository was archived by the owner on Nov 22, 2020. It is now read-only.

Commit ce42d9f

Browse files
committed
Messages being delivered back and fourth
1 parent cb43b34 commit ce42d9f

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

events/message.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
const Discord = require("discord.js"); // eslint-disable-line no-unused-vars
22
const cooldowns = new Discord.Collection();
3+
const Threading = require("../modules/threading.js");
34

45
module.exports = class {
56
constructor (client) {
67
this.client = client;
78
}
89

910
async run (message) {
11+
Threading.message(this.client, message);
12+
1013
if (message.author.bot) return;
1114

1215
const reply = (c) => message.channel.send(c);

models/message.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const Schema = new mongoose.Schema({
88
content: { type: String },
99
author: { type: String },
1010
attachments: { type: Array },
11-
timestamp: { type: Number }
11+
timestamp: { type: Number },
12+
anonymous: { type: Boolean, default: false }
1213
});
1314

1415
module.exports = mongoose.model("messages", Schema);

modules/threading.js

+49-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Threading {
1212
if (!recipientThread) return;
1313

1414
this.dm(client, message, recipientThread);
15-
} else if (message.chanenl.type === "text") {
15+
} else if (message.channel.type === "text") {
1616
const recipientThread = await Thread.findOne({ channel: message.channel.id, closed: false });
1717
if (!recipientThread) return;
1818

@@ -22,7 +22,7 @@ class Threading {
2222

2323
static async dm (client, message, thread) {
2424
const channel = client.channels.get(thread.channel);
25-
if (!channel) console.log(`Channel for thread ${thread.id} can not be found.`);
25+
if (!channel) message.channel.send(`Channel for thread ${thread.id} can not be found.`);
2626

2727
const contentEmbed = new Discord.MessageEmbed()
2828
.setAuthor(message.author.tag, message.author.displayAvatarURL())
@@ -52,10 +52,56 @@ class Threading {
5252
attachments: message.attachments.map(a => a.proxyURL),
5353
timestamp: Date.now()
5454
}).save());
55+
56+
await message.react(client.config.emojis.greenTick);
5557
}
5658

5759
static async channel (client, message, thread, isAnonymous) {
58-
// In case dm appears to come from a channel thread. (Support)
60+
const user = client.users.get(thread.recipient);
61+
const channel = client.channels.get(thread.channel);
62+
if (!user) message.chamnel.send(`Recipient for thread ${thread.id} can not be found.`);
63+
64+
let contentEmbed = new Discord.MessageEmbed()
65+
.setColor("YELLOW")
66+
.setTimestamp()
67+
.setFooter("Support Assistant");
68+
69+
if (isAnonymous) {
70+
contentEmbed.setDescription(message.content.slice(2));
71+
} else {
72+
contentEmbed.setAuthor(message.author.tag, message.author.displayAvatarURL());
73+
contentEmbed.setDescription(message.content);
74+
}
75+
76+
user.send(contentEmbed).catch(e => {});
77+
channel.send(contentEmbed).catch(e => {});
78+
message.attachments.forEach(attachment => {
79+
let embed = new Discord.MessageEmbed()
80+
.setColor("ORANGE")
81+
.setImage(attachment.proxyURL)
82+
.setFooter("Support Assistant");
83+
if (!isAnonymous) {
84+
embed.setAuthor(message.author.tag, message.author.displayAvatarURL());
85+
}
86+
user.send(embed).catch(e => {});
87+
channel.send(embed).catch(e => {});
88+
});
89+
90+
const messageID = (await Message.countDocuments({ thread: thread.id })) + 1;
91+
92+
await (new Message({
93+
thread: thread.id,
94+
message: messageID,
95+
recipient: thread.recipient,
96+
channel: message.channel.id,
97+
content: message.content,
98+
author: message.author.id,
99+
attachments: message.attachments.map(a => a.proxyURL),
100+
anonymous: isAnonymous,
101+
timestamp: Date.now()
102+
}).save());
103+
104+
await message.react(client.config.emojis.greenTick);
59105
}
60106
}
61107

0 commit comments

Comments
 (0)