This commit is contained in:
ry 2020-02-16 21:04:28 +01:00
parent 26236cf8a5
commit db9b3fda7e
12 changed files with 536 additions and 0 deletions

80
utils/src/Shortlinks.js Executable file
View file

@ -0,0 +1,80 @@
const ShortLinkReg = /(?:\s|^)(gh|gl|gd|owo|aud|sg|ttv|teknik|bb|yt|bc|bcu|sc|bot|sw|tw|npm|xkcd)\/([a-zA-Z0-9-_.#/!]*)/g;
const ShortLinks = {
gh: 'https://github.com/$link$',
gl: 'https://gitlab.com/$link$',
yt: 'https://youtu.be/$link$',
tw: 'https://twitter.com/$link$',
npm: 'https://npm.im/$link$',
ttv: 'https://twitch.tv/$link$',
gd: 'https://gitdab.com/$link$',
owo: 'https://owo.codes/$link$',
sg: 'https://git.supernets.org/$link$',
teknik: 'https://git.teknik.io/$link$',
bb: 'https://bitbucket.org/$link$',
bc: 'https://$link$.bandcamp.com/',
bcu: 'https://bandcamp.com/$link$',
sc: 'https://soundcloud.com/$link$',
aud: 'https://audius.co/$link$',
// aur: 'https://aur.archlinux.org/packages/$link$',
sw: 'https://steamcommunity.com/sharedfiles/filedetails/?id=$link$',
bot: '<https://discordapp.com/oauth2/authorize?client_id=$link$&scope=bot>',
xkcd: 'https://xkcd.com/$link$'
};
const ShortLinkDirs = {
gh: 'Github',
gl: 'Gitlab',
gd: 'Gitdab',
yt: 'Youtube',
tw: 'Twitter',
npm: 'NPM',
ttv: 'TwitchTv',
owo: 'owo_codes',
sg: 'Supernets_Git',
aud: 'Audius',
teknik: 'Teknik_Git',
bb: 'BitBucket',
bc: 'Bandcamp_Band',
bcu: 'Bandcamp_User',
sc: 'Soundcloud',
// aur: 'Arch_Packages',
sw: 'Steam_Workshop',
bot: 'Discord_Bot_Invite',
xkcd: 'xkcd'
};
const db = require('quick.db');
const backend = new db.table('backend');
module.exports = async function Shortlink(enabled, msg) {
if (!enabled || enabled === null || enabled === undefined) return;
let res = msg.content.match(ShortLinkReg);
if (!res) return;
res = res.map((x) => (x.startsWith(' ') ? x.substring(1) : x));
let links = [];
let Amount = [];
for (const m in res) {
for (const x in ShortLinks) {
let url = res[m];
if (!url.startsWith(x)) continue;
url = url.replace(x + '/', '');
if (x == 'gh' || x == 'gl' || x == 'gd') {
url = url.replace('#', '/issues/');
}
if (x == 'gl') {
url = url.replace('!', '/merge_requests/');
} else if (x == 'gd') {
url = url.replace('!', '/pulls/');
} else if (x == 'gh') {
url = url.replace('!', '/pull/');
}
url = ShortLinks[x].replace('$link$', url);
links.push(`${url}`);
await backend.add(`Shortlink.${ShortLinkDirs[x]}`, 1);
await backend.add(`Shortlink.total`, 1);
}
}
msg.channel.send(links.join('\n'));
};

78
utils/src/SourceFynnder.js Executable file
View file

@ -0,0 +1,78 @@
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';
async function SourceFynnderBot(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 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');
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
};
module.exports = {
SourceFynnder: SourceFynnderBot,
APIFind: SourceFynnderAPI
}