aboutsummaryrefslogtreecommitdiff
path: root/index.ts
blob: ea436336329e8ccbfe5d1919d95ee2579cb92883 (plain)
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
import * as dotenv from 'dotenv';
import axios from 'axios';
import { Client, MessageEmbed } from 'discord.js';
import { load } from 'cheerio';

dotenv.config();
var client = new Client();

client.on("message", msg => {
	// hard-coded channel id to prevent mess
	if (msg.channel.id != "833644027681177620") return;
	if (msg.author.bot) return;

	// check for codes
	var codes = msg.content.match(/\d{5,6}(?!\d)/g);
	if (!codes) return;

	codes.forEach(code => {
		var url = `https://nhentai.net/g/${code}/`
		axios({ url, method: "get" })
		.then(response => {
			if(response.status != 200) return;

			var reply = "I've found an nhentai code in your message:\n> " + msg.content;
			reply += "\n\n" + url;

			var $ = load(response.data);
			var tagArr = [];
			var tags = $('#tags .tag-container .tags a.tag[href^="/tag"] span.name').each((i, el) => {
				tagArr.push($(el).text());
			});
			
			msg.reply(reply, new MessageEmbed()
					  .setColor("#EC2854")
					  .setTitle("nHentai")
					 .setURL(url)
					 .setDescription("tags:\n\n" + tagArr.join(", ")))
		})
		.catch(() => console.log("request error'd out :("));

	})
});

client.login(process.env.DISCORD_TOKEN);