-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
75 lines (59 loc) · 2.79 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
const { APIMessage, Structures } = require("discord.js");
class Message extends Structures.get("Message") {
async lineReply(content, options) {
let mentionRepliedUser = typeof ((options || content || {}).allowedMentions || {}).repliedUser === "undefined" ? true : ((options || content).allowedMentions).repliedUser;
const apiMessage = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this.channel, content, options).resolveData();
Object.assign(apiMessage.data, { message_reference: { message_id: this.id } });
if (!apiMessage.data.allowed_mentions || Object.keys(apiMessage.data.allowed_mentions).length === 0) {
apiMessage.data.allowed_mentions = {
parse: ["users", "roles", "everyone"]
}
}
if (typeof apiMessage.data.allowed_mentions.replied_user === "undefined") {
Object.assign(apiMessage.data.allowed_mentions, { replied_user: mentionRepliedUser });
}
if (Array.isArray(apiMessage.data.content)) {
return Promise.all(apiMessage.split().map(x => {
x.data.allowed_mentions = apiMessage.data.allowed_mentions;
return x;
}).map(this.lineReply.bind(this)));
}
const { data, files } = await apiMessage.resolveFiles();
return this.client.api.channels[this.channel.id].messages
.post({ data, files })
.then(d => this.client.actions.MessageCreate.handle(d).message);
}
async lineReplyNoMention(content, options) {
/*if (!options) {
options = {
allowedMentions: {
repliedUser: false
}
}
}
if (options.allowedMentions) {
if (options.allowedMentions.repliedUser !== false) {
options.allowedMentions.repliedUser = false;
}
}*/
const apiMessage = content instanceof APIMessage ? content.resolveData() : APIMessage.create(this.channel, content, options).resolveData();
Object.assign(apiMessage.data, { message_reference: { message_id: this.id } });
if (!apiMessage.data.allowed_mentions || Object.keys(apiMessage.data.allowed_mentions).length === 0) {
apiMessage.data.allowed_mentions = {
parse: ["users", "roles", "everyone"]
}
}
Object.assign(apiMessage.data.allowed_mentions, { replied_user: false });
if (Array.isArray(apiMessage.data.content)) {
return Promise.all(apiMessage.split().map(x => {
x.data.allowed_mentions = apiMessage.data.allowed_mentions;
return x;
}).map(this.lineReply.bind(this)));
}
const { data, files } = await apiMessage.resolveFiles();
return this.client.api.channels[this.channel.id].messages
.post({ data, files })
.then(d => this.client.actions.MessageCreate.handle(d).message);
}
}
Structures.extend("Message", () => Message);