-
Notifications
You must be signed in to change notification settings - Fork 2
/
embeds.js
143 lines (124 loc) · 5.01 KB
/
embeds.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
const helpers = require('./helpers.js');
const Discord = require('discord.js');
const api = require('mangadex-full-api');
module.exports = {
// embed for a specific scanlation group
groupEmbed(group, channel) {
const title = group.name.substr(0, 256);
const url = `https://mangadex.org/group/${group.id}`;
const fields = [
{ name: 'ID', value: group.id, inline: true },
];
if (group.createdAt != null) {
fields.push({ name: 'Created', value: group.createdAt, inline: true });
}
if (group.leader != null) {
fields.push({ name: 'Leader', value: group.leader.username.substr(0, 1024), inline: true });
}
if (group.members.length > 0) {
fields.push({ name: 'Members', value: group.members.map(m => m.username).join(', ').substr(0, 1024), inline: true });
}
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(title)
.setURL(url)
.setAuthor('MangaDex', 'https://www.saashub.com/images/app/service_logos/86/ced2d3e2ea0d/large.png', url)
.addFields(fields)
.setTimestamp()
.setFooter('MangaMirror by Darude#8096', 'https://i.imgur.com/FXZSEhP.jpg');
channel.send(embed);
},
// embed for a specific chapter
async chapterEmbed(chap, mangaName, channel, files = []) {
const title = `${mangaName}: Chapter ${chap.chapter}`.substr(0, 256);
const url = `https://mangadex.org/chapter/${chap.id}`;
// scanlation groups responsible for the chapter
const groupObjs = await api.resolveArray(chap.groups);
const groups = groupObjs.map(g => `${g.name} (${g.id})`).join(', ').substr(0, 1024);
const fields = [
{ name: 'ID', value: chap.id, inline: true },
{ name: 'Pages', value: chap.pageNames.length, inline: true },
{ name: 'Language', value: chap.translatedLanguage, inline: true },
{ name: (groups.length == 1 ? 'Group' : 'Groups'), value: groups, inline: true },
{ name: 'Date', value: chap.createdAt, inline: true },
];
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(title)
.setURL(url)
.setAuthor('MangaDex', 'https://www.saashub.com/images/app/service_logos/86/ced2d3e2ea0d/large.png', url)
.addFields(fields)
.setTimestamp()
.setFooter('MangaMirror by Darude#8096', 'https://i.imgur.com/FXZSEhP.jpg');
channel.send(embed).then(() => {
if (files.length > 0) {
helpers.sendFiles(channel, files);
}
else {
channel.send('to read this chapter, use:');
channel.send(`!read ${chap.id}`);
}
});
},
// embed for a manga object
async mangaEmbed(manga, channel) {
const title = manga.title.substr(0, 256);
// url of the manga's page on MangaDex
const url = `https://mangadex.org/title/${manga.id}`;
// get and simplify the english description on MD
const desc = helpers.decode(manga.localizedDescription.en).substr(0, 2048);
// comma-separated list of the manga's genre tags
const tags = manga.tags.map(t => t.name).join(', ').substr(0, 1024);
// comma-separated list of the manga's authors
const authorObjs = await api.resolveArray(manga.authors);
const authors = authorObjs.map(a => a.name).join(', ').substr(0, 1024);
// comma-separated list of the manga's artists
const artistObjs = await api.resolveArray(manga.artists);
const artists = artistObjs.map(a => a.name).join(', ').substr(0, 1024);
// input embed content into multiple named fields
const fields = [];
switch (manga.tags.length) {
case 0:
break;
default:
fields.push({ name: 'Tags', value: tags, inline: false });
}
switch (manga.authors.length) {
case 0:
break;
default:
fields.push({ name: (manga.artists.length == 1 ? 'Author' : 'Authors'), value: authors, inline: true });
}
switch (manga.artists.length) {
case 0:
break;
default:
fields.push({ name: (manga.artists.length == 1 ? 'Artist' : 'Artists'), value: artists, inline: true });
}
fields.push({ name: 'Demographic', value: manga.publicationDemographic, inline: true });
// loop through all chapters of the manga to get the latest chapter number
// TODO: replace this workaround with manga.lastChapter once MD updates\
const chapterObjs = await manga.getFeed({ order: { chapter: 'desc' } }, false);
if (chapterObjs.length > 0) {
fields.push({ name: 'Latest Chapter', value: chapterObjs[0].chapter, inline: true });
}
fields.push({ name: 'ID', value: manga.id, inline: true });
// main cover art of the manga on MD
const coverObj = await manga.mainCover.resolve();
const coverUrl = coverObj.imageSource;
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(title)
.setURL(url)
.setAuthor('MangaDex', 'https://www.saashub.com/images/app/service_logos/86/ced2d3e2ea0d/large.png', manga.url)
.setDescription(desc)
.addFields(fields)
.setImage(coverUrl)
.setTimestamp()
.setFooter('MangaMirror by Darude#8096', 'https://i.imgur.com/FXZSEhP.jpg', 'https://github.com/chenmasterandrew/manga-mirror');
channel.send(embed).then(() => {
channel.send('to check for a specific chapter of this manga, use:');
channel.send(`!search chapter ${title} <chapter #>`);
});
},
};