58 lines
1.5 KiB
JavaScript
Executable file
58 lines
1.5 KiB
JavaScript
Executable file
const axios = require('axios');
|
|
const db = require('quick.db');
|
|
const backend = new db.table('backend');
|
|
const Servers = new db.table('servers');
|
|
let md5 = new RegExp(
|
|
'((?:!)?https?://static[0-9]*.(?:e621|e926).net/data/(?:sample/|preview/|)[0-9a-f]{2}/[0-9a-f]{2}/([0-9a-f]{32}).([0-9a-z]+))',
|
|
'igm'
|
|
);
|
|
|
|
let search_md5 = 'https://e621.net/post/show.json?md5=';
|
|
let e6 = 'https://e621.net/post/show/';
|
|
let e9 = 'https://e926.net/post/show/';
|
|
|
|
const version = '0.1.0';
|
|
|
|
module.exports = async function SourceFynnder(enabled, msg) {
|
|
if (!enabled || enabled === null || enabled === undefined) return;
|
|
res = msg.content.match(md5);
|
|
if (!res) return;
|
|
|
|
let Sources = [];
|
|
for (const m in res) {
|
|
let URL = res[m];
|
|
let hash = URL.split(md5)[2];
|
|
|
|
let { data } = await axios.get(search_md5 + hash, {
|
|
headers: { 'user-agent': `SourceFynnder/${version} (ry / codepupper)` }
|
|
});
|
|
if (data.rating === 's') {
|
|
Source = e9 + data.id;
|
|
} else {
|
|
Source = e6 + data.id;
|
|
}
|
|
Sources.push(`:link::mag: ${Source}`);
|
|
}
|
|
msg.channel.send(Sources);
|
|
await backend.add('SourceFynnder.found', Sources.length);
|
|
await Servers.add(`${msg.guild.id}.foundSources`, Sources.length);
|
|
};
|
|
/* url = msg.content.split(md5);
|
|
hash = url[2];
|
|
|
|
if (hash === undefined) return;
|
|
|
|
let res = await axios.get(search_md5 + hash);
|
|
|
|
let data = res.data;
|
|
let Source;
|
|
if (data.rating === "s") {
|
|
Source = e9 + data.id;
|
|
} else {
|
|
Source = e6 + data.id;
|
|
}
|
|
|
|
|
|
|
|
console.log(Source);
|
|
return msg.channel.send(Source); */
|