lots of stuff

This commit is contained in:
ry 2020-01-18 15:45:03 +01:00
parent 16fd7d9c27
commit afbde77edc
7 changed files with 95 additions and 50 deletions

View File

@ -1,19 +1,24 @@
var express = require('express'); var express = require('express');
var api = express.Router(); var api = express.Router();
var config = require('../../config'); var config = require('../../config');
var vars = require('../../vars');
var utils = require('../../utils'); var utils = require('../../utils');
const os = require('os'); const os = require('os');
let Bot = require('../server')
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.status(200).jsonp({ res.status(200).jsonp({
name: config.name, res: 'uwu'
version: config.version
}); });
}); });
api.get('/ints/:kind/:user1?/:user2?', (req, res) => { api.get('/ints/:kind/:user1?/:user2?', (req, res) => {
if (utils.int[req.params.kind] === undefined) return res.status(404).jsonp({ error: `This does not exist` }); if (utils.int[req.params.kind] === undefined) return res.status(404).jsonp({
if (!req.params.user1 || !req.params.user2) return res.status(400).jsonp({ error: `I need two users to work` }); error: `This does not exist`
});
if (!req.params.user1 || !req.params.user2) return res.status(400).jsonp({
error: `I need two users to work`
});
let LineFromUtils = utils.int[req.params.kind][parseInt(Math.random() * utils.int[req.params.kind].length)]; let LineFromUtils = utils.int[req.params.kind][parseInt(Math.random() * utils.int[req.params.kind].length)];
let Line = LineFromUtils.replace(/0/g, utils.format.bold(req.params.user1)).replace( let Line = LineFromUtils.replace(/0/g, utils.format.bold(req.params.user1)).replace(
/1/g, /1/g,
@ -26,22 +31,33 @@ api.get('/ints/:kind/:user1?/:user2?', (req, res) => {
}); });
}); });
function format(seconds) { api.get(['/SourceFynnder', '/sourcefynnder', '/sauce'], async (req, res) => {
function pad(s) { let REPLY;
return (s < 10 ? '0' : '') + s; let URLS = req.headers.images || req.query.images.split(',')
} console.log(URLS)
var hours = Math.floor(seconds / (60 * 60)); await utils.SourceFynnder.APIFind(URLS).then(r => {
var minutes = Math.floor((seconds % (60 * 60)) / 60); console.log(r)
var seconds = Math.floor(seconds % 60); res.status(200).jsonp({
success: true,
sources: r
})
}).catch(err => {
res.status(400).jsonp({
success: false,
error: err.message
})
})
})
return pad(hours) + 'h ' + pad(minutes) + 'm ' + pad(seconds) + 's';
}
api.get('/system', (req, res) => { api.get('/system', (req, res) => {
res.jsonp({ res.jsonp({
name: vars.name,
version: vars.version,
hostname: os.hostname(), hostname: os.hostname(),
uptime: `${format(process.uptime())}` uptime: `${utils.format.uptime(process.uptime())}`
}); });
}); });
module.exports = api; module.exports = api;

View File

@ -54,9 +54,10 @@ app.use(
}) })
); );
app.use('/api', require('./routes/api'));
let support = 'https://discord.gg/' + Backend.get('Info.invite'); let support = 'https://discord.gg/' + Backend.get('Info.invite');
app.use('/api', require('./routes/api'));
module.exports = (client) => { module.exports = (client) => {
clientInfo: client,
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
res.status(200).render('index', { res.status(200).render('index', {
layout: 'main', layout: 'main',

View File

@ -3,7 +3,9 @@ const {
db db
} = require("../utils/index"); } = require("../utils/index");
const { const {
SourceFynnder, SourceFynnder: {
SourceFynnder
},
topic topic
} = require("../utils"); } = require("../utils");
const { const {
@ -13,6 +15,7 @@ const Servers = new table("servers");
const Users = new table("users"); const Users = new table("users");
const Backend = new table("backend"); const Backend = new table("backend");
module.exports = { module.exports = {
name: "message", name: "message",
run: async (client, Message) => { run: async (client, Message) => {

14
package-lock.json generated
View File

@ -122,12 +122,11 @@
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
}, },
"axios": { "axios": {
"version": "0.19.0", "version": "0.19.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.1.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", "integrity": "sha512-Yl+7nfreYKaLRvAvjNPkvfjnQHJM1yLBY3zhqAwcJSwR/6ETkanUgylgtIvkvz0xJ+p/vZuNw8X7Hnb7Whsbpw==",
"requires": { "requires": {
"follow-redirects": "1.5.10", "follow-redirects": "1.5.10"
"is-buffer": "^2.0.2"
} }
}, },
"balanced-match": { "balanced-match": {
@ -1813,11 +1812,6 @@
"binary-extensions": "^1.0.0" "binary-extensions": "^1.0.0"
} }
}, },
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"is-ci": { "is-ci": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz",

View File

@ -7,7 +7,7 @@
"license": "MIT", "license": "MIT",
"private": true, "private": true,
"dependencies": { "dependencies": {
"axios": "^0.19.0", "axios": "^0.19.1",
"blapi": "^1.2.3", "blapi": "^1.2.3",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"compression": "*", "compression": "*",

View File

@ -1,11 +1,22 @@
module.exports = { module.exports = {
bold: function(str) { bold: function (str) {
return `**${str}**`; return `**${str}**`;
}, },
italic: function(str) { italic: function (str) {
return `*${str}*`; return `*${str}*`;
}, },
code: function(str) { code: function (str) {
return `\`${str}\``; return `\`${str}\``;
},
uptime: function (seconds) {
function pad(s) {
return (s < 10 ? '0' : '') + s;
}
var hours = Math.floor(seconds / (60 * 60));
var minutes = Math.floor((seconds % (60 * 60)) / 60);
var seconds = Math.floor(seconds % 60);
return pad(hours) + 'h ' + pad(minutes) + 'm ' + pad(seconds) + 's';
} }
};
};

View File

@ -13,7 +13,7 @@ let e9 = 'https://e926.net/post/show/';
const version = '0.1.0'; const version = '0.1.0';
module.exports = async function SourceFynnder(enabled, msg) { async function SourceFynnderBot(enabled, msg) {
if (!enabled || enabled === null || enabled === undefined) return; if (!enabled || enabled === null || enabled === undefined) return;
res = msg.content.match(md5); res = msg.content.match(md5);
if (!res) return; if (!res) return;
@ -23,8 +23,12 @@ module.exports = async function SourceFynnder(enabled, msg) {
let URL = res[m]; let URL = res[m];
let hash = URL.split(md5)[2]; let hash = URL.split(md5)[2];
let { data } = await axios.get(search_md5 + hash, { let {
headers: { 'user-agent': `SourceFynnder/${version} (ry / codepupper)` } data
} = await axios.get(search_md5 + hash, {
headers: {
'user-agent': `SourceFynnder/${version} (ry / codepupper)`
}
}); });
if (data.rating === 's') { if (data.rating === 's') {
Source = e9 + data.id; Source = e9 + data.id;
@ -35,24 +39,40 @@ module.exports = async function SourceFynnder(enabled, msg) {
} }
msg.channel.send(Sources); msg.channel.send(Sources);
await backend.add('SourceFynnder.found', Sources.length); await backend.add('SourceFynnder.found', Sources.length);
await backend.add('SourceFynnder.foundBot', Sources.length);
await Servers.add(`${msg.guild.id}.foundSources`, Sources.length); await Servers.add(`${msg.guild.id}.foundSources`, Sources.length);
}; };
/* url = msg.content.split(md5);
hash = url[2];
if (hash === undefined) return; 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 res = await axios.get(search_md5 + hash); let Sources = [];
for (const m in res) {
let URL = res[m];
let hash = URL.split(md5)[2];
let data = res.data; let {
let Source; data
if (data.rating === "s") { } = await axios.get(search_md5 + hash, {
Source = e9 + data.id; headers: {
} else { 'user-agent': `SourceFynnder/${version} (ry / codepupper)`
Source = e6 + data.id; }
} });
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,
console.log(Source); APIFind: SourceFynnderAPI
return msg.channel.send(Source); */ }