Browse Source

fix sourcefynnder

master
ry 1 month ago
parent
commit
376f4be631
2 changed files with 102 additions and 100 deletions
  1. +62
    -64
      utils/src/sourceFynnder.js
  2. +40
    -36
      vars.js

+ 62
- 64
utils/src/sourceFynnder.js View File

@@ -1,78 +1,76 @@
const axios = require('axios');
const db = require('quick.db');
const backend = new db.table('backend');
const Servers = new db.table('servers');
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'
"((?:!)?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/';
let search_md5 = "https://e621.net/posts.json?md5=";
let e6 = "https://e621.net/posts/";
let e9 = "https://e926.net/posts/";

const version = '0.1.0';
const version = "0.2.0";

async function SourceFynnderBot(enabled, msg) {
if (!enabled || enabled === null || enabled === undefined) return;
res = msg.content.match(md5);
if (!res) return;
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 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 backend.add('SourceFynnder.foundBot', Sources.length);
await Servers.add(`${msg.guild.id}.foundSources`, Sources.length);
};
let { data } = await axios.get(search_md5 + hash, {
headers: {
"user-agent": `SourceFynnder/${version} (ry on e621)`
}
});
//console.log(data);
if (data.rating === "s") {
Source = e9 + data.post.id;
} else {
Source = e6 + data.post.id;
}
Sources.push(`:link::mag: <${Source}>`);
}
msg.channel.send(Sources);
await backend.add("SourceFynnder.found", Sources.length);
await backend.add("SourceFynnder.foundBot", Sources.length);
await Servers.add(`${msg.guild.id}.foundSources`, Sources.length);
}

async function SourceFynnderAPI(url) {
url = url.toString().replace(/\,/g, ' ')
res = url.match(md5);
if (!res) throw new Error('Not a Valid e621/e926 URL');
url = url.toString().replace(/\,/g, " ");
res = url.match(md5);
if (!res) throw new Error("Not a Valid e621/e926 URL");

let Sources = [];
for (const m in res) {
let URL = res[m];
let hash = URL.split(md5)[2];
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(`${Source}`);
}
await backend.add('SourceFynnder.found', Sources.length);
await backend.add('SourceFynnder.foundAPI', Sources.length);
return Sources
};
let { data } = await axios.get(search_md5 + hash, {
headers: {
"user-agent": `SourceFynnder/${version} (ry on e621)`
}
});
if (data.post.rating === "s") {
Source = e9 + data.post.id;
} else {
Source = e6 + data.post.id;
}
Sources.push(`${Source}`);
}
await backend.add("SourceFynnder.found", Sources.length);
await backend.add("SourceFynnder.foundAPI", Sources.length);
return Sources;
}

module.exports = {
SourceFynnder: SourceFynnderBot,
APIFind: SourceFynnderAPI
}
SourceFynnder: SourceFynnderBot,
APIFind: SourceFynnderAPI
};

+ 40
- 36
vars.js View File

@@ -1,38 +1,42 @@
module.exports = {
name: 'Thaldrin',
version: '3.6.4',
color: '#ff995d',
hostname: '127.2.11.1',
//hostname: 'localhost',
port: '8080',
type: {
beta: true,
prod: false
},
prefixes: ["'", `<@434662676547764244> `, '<@!434662676547764244> '],
developers: [{
id: '318044130796109825',
nick: 'ry'
}],
logs: {
usage: '663740167684620318'
},
contributors: [{
id: '150745989836308480',
nick: 'Cyn',
reason: 'Shortlink Code :3'
},
{
id: '356323373443448843',
nick: 'Twiggy',
reason: 'Letting me use his Sona as the Mascot <3'
},
{
id: '289947794142396427',
nick: 'Fynn',
reason: 'Letting me use his name for `SourceFynnder` <3'
}
],
source: 'https://werewolf.codes/t/thaldrin',
invite: 'https://discordapp.com/oauth2/authorize?client_id=434662676547764244&scope=bot&permissions=379968'
name: "Thaldrin",
version: "3.6.4",
color: "#ff995d",
hostname: "127.2.11.1",
//hostname: 'localhost',
port: "8080",
type: {
beta: true,
prod: false
},
prefixes: ["''", `<@434662676547764244> `, "<@!434662676547764244> "],
developers: [
{
id: "318044130796109825",
nick: "ry"
}
],
logs: {
usage: "663740167684620318"
},
contributors: [
{
id: "150745989836308480",
nick: "Cyn",
reason: "Shortlink Code :3"
},
{
id: "356323373443448843",
nick: "Twiggy",
reason: "Letting me use his Sona as the Mascot <3"
},
{
id: "289947794142396427",
nick: "Fynn",
reason: "Letting me use his name for `SourceFynnder` <3"
}
],
source: "https://werewolf.codes/t/thaldrin",
invite:
"https://discordapp.com/oauth2/authorize?client_id=434662676547764244&scope=bot&permissions=379968"
};

Loading…
Cancel
Save