-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanga.js
150 lines (148 loc) · 5.67 KB
/
manga.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
const Discord = require('discord.js');
const fetch = require('cross-fetch');
module.exports = {
config: {
name: "manga", // Name of Command
description: "Ask them questions", // Command Description
usage: "" // Command usage
},
permissions: "", // User permissions needed
owner: false, // Owner only?
run: async (client, message, args, prefix, config, db, interaction) => {
let name = args.slice(0).join(' ');
var query = `
query ($id: Int, $page: Int, $perPage: Int, $search: String) {
Page (page: $page, perPage: $perPage) {
pageInfo {
total
currentPage
lastPage
hasNextPage
perPage
}
media (id: $id, search: $search, type: MANGA) {
id
title {
romaji
english
}
description
coverImage{
extraLarge
}
startDate{
year
month
day
}
format
status
chapters
volumes
isAdult
averageScore
source
}
}
}
`;
var variables = {
search: name,
page: 1,
perPage: 25
};
var url = 'https://graphql.anilist.co',
options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query,
variables: variables
})
};
var animedata = await fetch(url, options)
.then(handleResponse)
.catch(handleError);
if (animedata == undefined) return message.channel.send("```If you see this message contact devs```")
var data = animedata.data.Page.media
if (data.length == 0) return message.channel.send(`Could not find anything`)
var page = 0;
var embeds = [];
data.forEach(element => {
if (element.isAdult == true) {
const embed = new Discord.MessageEmbed()
.setTitle("Adult Content")
.setDescription("Feature to see 18+ content coming very soon")
embeds.push(embed)
return
}
var newDescription;
if (element.description != null) {
newDescription = element.description.replace(/(<([^>]+)>)/gi, "");
} else {
newDescription = "No Description"
}
const embed = new Discord.MessageEmbed()
.setTitle(element.title.romaji)
.setThumbnail(element.coverImage.extraLarge)
.setDescription(element.title.english + `\n` + `\n` + newDescription)
.addFields({name: `ID:`,value: element.id, inline: true})
if (element.status != "NOT_YET_RELEASED") {
embed.addFields({name: `Average Score:`, value: element.averageScore + `%`,inline: true})
embed.addFields({name:`Aired:`,value: `(${element.startDate.day}/${element.startDate.month}/${element.startDate.year})`, inline: true})
}
embed.addField(`Status:`, element.status, true)
if (element.status != "NOT_YET_RELEASED") {
embed.addField(`Volumes:`, element.volumes, true)
embed.addField(`Chapters:`, element.chapters, true)
}
embed.addField(`Format:`, element.format, true)
embed.addField(`source:`, element.source, true)
embed.addField(`18+:`, element.isAdult, true)
embed.addField(`Link:`, `https://anilist.co/manga/${element.id}/`, true)
embeds.push(embed)
});
botmsg = await message.channel.send(embeds[page])
await botmsg.react(`⬅️`)
await botmsg.react(`➡️`)
rewait(message, botmsg, embeds, page)
}
}
function rewait(message, botmsg, embeds, page) {
test = 0
botmsg.awaitReactions((reaction, user) => (reaction.emoji.name === `⬅️` || reaction.emoji.name === `➡️`) && user.id === message.author.id, { max: 1 })
.then(r => {
re0 = botmsg.reactions.cache.filter(reaction => reaction.users.cache.has(message.author.id));
for (const re1 of re0.values()) {
re1.users.remove(message.author.id);
}
emote = r.map(r => r.emoji.name).toString()
if (emote === `⬅️`) {
if (page - 1 >= 0) {
page--
embeds[page].setFooter(`Page ${page + 1} of ${embeds.length} || Menhera Chan is Kawaii || www.menhera-chan.in`)
botmsg.edit(embeds[page])
}
}
if (emote === `➡️`) {
if (page + 1 <= embeds.length - 1) {
page++
embeds[page].setFooter(`Page ${page + 1} of ${embeds.length} || Menhera Chan is Kawaii || www.menhera-chan.in`)
botmsg.edit(embeds[page])
}
}
if (test != 1) return rewait(message, botmsg, embeds, page)
})
setTimeout(function () { test = 1 }, 120000)
}
function handleResponse(response) {
return response.json().then(function (json) {
return response.ok ? json : Promise.reject(json);
});
}
function handleError(error) {
console.error(error);
}