Update Code

This commit is contained in:
Jyotirmoy Bandyopadhayaya 2021-07-26 15:39:06 +05:30
parent b6aaf1c600
commit 5d121e91c0
2 changed files with 178 additions and 94 deletions

178
bot.js
View File

@ -4,109 +4,193 @@ const {token,prefix} = require('./config.json')
client.once('ready', () => { client.once('ready', () => {
console.log('Ready!'); console.log('Ready!');
}); });
const { API } = require('nhentai-api'); const { API } = require("nhentai-api");
const log = console.log;
const api = new API(); const api = new API();
const { MessageEmbed } = require('discord.js'); const pagination = require("discord.js-pagination");
const pagination = require('discord.js-pagination');
client.on('message', message => { client.on("message", (message) => {
if (message.content === 'h&nhentai') { if (message.content === "n&help") {
// send back "Pong." to the channel the message was sent in const coverEmbed = new Discord.MessageEmbed()
message.channel.send('Lesss Goo !!'); .setColor("#f04668")
.setTitle(`Sin's Bot`)
.setDescription(`All available commands for Sin's bot`)
.addFields(
{
name: "n&cover xxxxxx",
value: `Get the Image of the Cover of Doujinshi`,
inline: true,
},
{
name: "n&read xxxxxx",
value: `Get the Entire Doujinshi in forms of Embedded messages`,
inline: true,
},
{
name: "n&about",
value: `To know About of Sin's Bot`,
}
)
.setTimestamp();
message.channel.send(coverEmbed);
}
});
client.on("message", (message) => {
if (message.content === "n&about") {
const coverEmbed = new Discord.MessageEmbed()
.setColor("#9b42f5")
.setTitle(`Sin's Bot`)
.setImage(
`https://cdn.discordapp.com/avatars/${client.user.id}/${client.user.avatar}.png`
)
.setDescription(
`An Discord by which Connects to nHentai and Returns images to You.`
)
.addFields(
{
name: "Invite",
value: `https://discord.com/oauth2/authorize?client_id=862307032002854912&scope=bot&permissions=117824`,
inline: true,
},
{
name: "Github",
value: `https://github.com/BRAVO68WEB/sins-bot`,
inline: true,
}
)
.setAuthor("Bravo68web")
.setFooter("Build by Bravo68web")
.setThumbnail(`https://avatars.githubusercontent.com/u/41448663?s=60&v=4`)
.setTimestamp();
message.channel.send(coverEmbed);
} }
}); });
client.on('message', message => { client.on("message", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return; if (!message.content.startsWith(prefix) || message.author.bot) return;
if(!message.channel.nsfw){ message.channel.send("This command can only be used in channels marked nsfw."); return; } if (!message.channel.nsfw) {
const args = message.content.slice(prefix.length).trim().split(' '); message.channel.send(
"This command can only be used in channels marked nsfw."
);
return;
}
const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
if (command === 'cover') { if (command === "cover") {
api.getBook(args[0]).then(book => { console.log(message.author.username + " requested cover for " + args[0]);
api.getBook(args[0]).then((book) => {
const coverEmbed = new Discord.MessageEmbed() const coverEmbed = new Discord.MessageEmbed()
.setColor("#fc0388") .setColor("#fc0388")
.setTitle(`${book.title.english}`) .setTitle(`${book.title.english}`)
.setDescription(`${book.tags[0].name}, ${book.tags[1].name}, ${book.tags[2].name}, ${book.tags[3].name}`) .setDescription(
`${book.tags[0].name}, ${book.tags[1].name}, ${book.tags[2].name}, ${book.tags[3].name}`
)
.setURL(`https://nhentai.net/g/${book.id}`) .setURL(`https://nhentai.net/g/${book.id}`)
.setImage(`${api.getImageURL(book.cover)}`, "\u200B") .setImage(`${api.getImageURL(book.cover)}`, "\u200B")
.addFields({ name: '❤️ *Favorites*', value: `${book.favorites}` }) .addFields(
.setTimestamp() { name: "❤️ *Favorites*", value: `${book.favorites}`, inline: true },
{
name: "🧾 *Pages*",
value: `${book.pages.length}`,
inline: true,
}
)
.setFooter(
client.user.username,
`https://cdn.discordapp.com/avatars/${client.user.id}/${client.user.avatar}.png`
)
.setTimestamp();
message.channel.send(coverEmbed); message.channel.send(coverEmbed);
}); });
} }
}); });
client.on('message', message => { client.on("message", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return; if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(' '); const args = message.content.slice(prefix.length).trim().split(" ");
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
if (command === 'readall') {
api.getBook(args[0]).then(book => { if (command === "read") {
console.log(
message.author.username + " requested entire Doujinshi for " + args[0]
);
api.getBook(args[0]).then((book) => {
for (var i = 0; i < book.pages.length; i++) { for (var i = 0; i < book.pages.length; i++) {
const mangaEmbed = new Discord.MessageEmbed() const mangaEmbed = new Discord.MessageEmbed()
.setColor("#057435") .setColor("#057435")
.setTitle(`${book.title.english}`) .setTitle(`${book.title.english}`)
.setDescription(`${book.tags[0].name}, ${book.tags[1].name}, ${book.tags[2].name}, ${book.tags[3].name}`) .setDescription(
.setURL(`https://nhentai.net/g/${book.id}`) `${book.tags[0].name}, ${book.tags[1].name}, ${book.tags[2].name}, ${book.tags[3].name}`
)
.setURL(`https://nhentai.net/g/${book.id}/${i + 1}`)
.setImage(`${api.getImageURL(book.pages[i])}`, "\u200B") .setImage(`${api.getImageURL(book.pages[i])}`, "\u200B")
.addField(`❤️ *Favorites* ${book.favorites}`) .addFields(
.setTimestamp() {
name: "❤️ *Favorites*",
value: `${book.favorites}`,
inline: true,
},
{
name: "🧾 *Page*",
value: `${i + 1} of ${book.pages.length}`,
inline: true,
}
)
.setTimestamp();
message.channel.send(mangaEmbed); message.channel.send(mangaEmbed);
} }
}); });
console.log(
message.author.username +
"'s requested entire Doujinshi for " +
args[0] +
" was sent successfully!!"
);
} }
}); });
client.on('message', message => { client.on("message", (message) => {
if (message.author.bot) return; if (message.author.bot) return;
if (message.content.startsWith('emb2')){ if (message.content.startsWith("emb2")) {
const Hebergeur = new Discord.MessageEmbed() const Hebergeur = new Discord.MessageEmbed()
.setColor("#057435") .setColor("#057435")
.setTitle("Name") .setTitle("Name")
.addField("**__Image Post : __**", "\u200B") .addField("**__Image Post : __**", "\u200B")
.setTimestamp() .setTimestamp();
const Invisible = new Discord.MessageEmbed() const Invisible = new Discord.MessageEmbed()
.setColor("#057435") .setColor("#057435")
.setTitle("Ok It works !") .setTitle("Ok It works !")
.addField("**__👻 : __**", "\u200B") .addField("**__👻 : __**", "\u200B")
.setTimestamp() .setTimestamp();
const InfoBot = new Discord.MessageEmbed() const InfoBot = new Discord.MessageEmbed()
.setColor("#0E4396") .setColor("#0E4396")
.setTitle("F") .setTitle("F")
.addField("**__Create By Paimon__**", "\u200B") .addField("**__Create By Paimon__**", "\u200B")
.setTimestamp() .setTimestamp();
const pages = [ const pages = [Hebergeur, Invisible, InfoBot];
Hebergeur,
Invisible,
InfoBot
]
const emojiList = ["◀️", "▶️"]; const emojiList = ["◀️", "▶️"];
const timeout = '120000'; const timeout = "120000";
pagination(message, pages, emojiList, timeout) pagination(message, pages, emojiList, timeout);
} }
}) });
client.on("messageReactionAdd", async (reaction, user) => {
client.on('messageReactionAdd', async (reaction, user) => {
// When a reaction is received, check if the structure is partial
if (reaction.partial) { if (reaction.partial) {
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
try { try {
await reaction.fetch(); await reaction.fetch();
} catch (error) { } catch (error) {
console.error('Something went wrong when fetching the message: ', error); console.error("Something went wrong when fetching the message: ", error);
// Return as `reaction.message.author` may be undefined/null
return; return;
} }
} }
// Now the message has been cached and is fully available console.log(
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`); `${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`
// The reaction is now also fully available and the properties will be reflected accurately: );
console.log(`${reaction.count} user(s) have given the same reaction to this message!`); console.log(
`${reaction.count} user(s) have given the same reaction to this message!`
);
}); });
client.login(token); client.login(token);