From afbde77edc0d7e3ee6ec3713dc0665e60bce9e3e Mon Sep 17 00:00:00 2001 From: ry Date: Sat, 18 Jan 2020 15:45:03 +0100 Subject: [PATCH] lots of stuff --- Dashboard/routes/api.js | 46 +++++++++++++++------- Dashboard/server.js | 3 +- DiscordEvents/MessageSourceFynnder.js | 5 ++- package-lock.json | 14 ++----- package.json | 2 +- utils/src/format.js | 19 +++++++-- utils/src/sourceFynnder.js | 56 ++++++++++++++++++--------- 7 files changed, 95 insertions(+), 50 deletions(-) diff --git a/Dashboard/routes/api.js b/Dashboard/routes/api.js index b02726f..433cfc1 100644 --- a/Dashboard/routes/api.js +++ b/Dashboard/routes/api.js @@ -1,19 +1,24 @@ var express = require('express'); var api = express.Router(); var config = require('../../config'); +var vars = require('../../vars'); var utils = require('../../utils'); const os = require('os'); +let Bot = require('../server') api.get('/', (req, res) => { res.status(200).jsonp({ - name: config.name, - version: config.version + res: 'uwu' }); }); 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 (!req.params.user1 || !req.params.user2) return res.status(400).jsonp({ error: `I need two users to work` }); + if (utils.int[req.params.kind] === undefined) return res.status(404).jsonp({ + 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 Line = LineFromUtils.replace(/0/g, utils.format.bold(req.params.user1)).replace( /1/g, @@ -26,22 +31,33 @@ api.get('/ints/:kind/:user1?/:user2?', (req, res) => { }); }); -function format(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); +api.get(['/SourceFynnder', '/sourcefynnder', '/sauce'], async (req, res) => { + let REPLY; + let URLS = req.headers.images || req.query.images.split(',') + console.log(URLS) + await utils.SourceFynnder.APIFind(URLS).then(r => { + console.log(r) + 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) => { res.jsonp({ + name: vars.name, + version: vars.version, hostname: os.hostname(), - uptime: `${format(process.uptime())}` + uptime: `${utils.format.uptime(process.uptime())}` }); }); -module.exports = api; +module.exports = api; \ No newline at end of file diff --git a/Dashboard/server.js b/Dashboard/server.js index 9084b41..da0b387 100755 --- a/Dashboard/server.js +++ b/Dashboard/server.js @@ -54,9 +54,10 @@ app.use( }) ); -app.use('/api', require('./routes/api')); let support = 'https://discord.gg/' + Backend.get('Info.invite'); +app.use('/api', require('./routes/api')); module.exports = (client) => { + clientInfo: client, app.get('/', async (req, res) => { res.status(200).render('index', { layout: 'main', diff --git a/DiscordEvents/MessageSourceFynnder.js b/DiscordEvents/MessageSourceFynnder.js index f3338fb..cc9437e 100755 --- a/DiscordEvents/MessageSourceFynnder.js +++ b/DiscordEvents/MessageSourceFynnder.js @@ -3,7 +3,9 @@ const { db } = require("../utils/index"); const { - SourceFynnder, + SourceFynnder: { + SourceFynnder + }, topic } = require("../utils"); const { @@ -13,6 +15,7 @@ const Servers = new table("servers"); const Users = new table("users"); const Backend = new table("backend"); + module.exports = { name: "message", run: async (client, Message) => { diff --git a/package-lock.json b/package-lock.json index 67df120..869d65e 100755 --- a/package-lock.json +++ b/package-lock.json @@ -122,12 +122,11 @@ "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" }, "axios": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz", - "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==", + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.1.tgz", + "integrity": "sha512-Yl+7nfreYKaLRvAvjNPkvfjnQHJM1yLBY3zhqAwcJSwR/6ETkanUgylgtIvkvz0xJ+p/vZuNw8X7Hnb7Whsbpw==", "requires": { - "follow-redirects": "1.5.10", - "is-buffer": "^2.0.2" + "follow-redirects": "1.5.10" } }, "balanced-match": { @@ -1813,11 +1812,6 @@ "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": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz", diff --git a/package.json b/package.json index b59952c..36fce3e 100755 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "private": true, "dependencies": { - "axios": "^0.19.0", + "axios": "^0.19.1", "blapi": "^1.2.3", "chalk": "^2.4.2", "compression": "*", diff --git a/utils/src/format.js b/utils/src/format.js index 136c2cc..2e2dad4 100755 --- a/utils/src/format.js +++ b/utils/src/format.js @@ -1,11 +1,22 @@ module.exports = { - bold: function(str) { + bold: function (str) { return `**${str}**`; }, - italic: function(str) { + italic: function (str) { return `*${str}*`; }, - code: function(str) { + code: function (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'; } -}; + +}; \ No newline at end of file diff --git a/utils/src/sourceFynnder.js b/utils/src/sourceFynnder.js index a5fbd57..953d79a 100755 --- a/utils/src/sourceFynnder.js +++ b/utils/src/sourceFynnder.js @@ -13,7 +13,7 @@ let e9 = 'https://e926.net/post/show/'; const version = '0.1.0'; -module.exports = async function SourceFynnder(enabled, msg) { +async function SourceFynnderBot(enabled, msg) { if (!enabled || enabled === null || enabled === undefined) return; res = msg.content.match(md5); if (!res) return; @@ -23,8 +23,12 @@ module.exports = async function SourceFynnder(enabled, msg) { 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)` } + let { + data + } = await axios.get(search_md5 + hash, { + headers: { + 'user-agent': `SourceFynnder/${version} (ry / codepupper)` + } }); if (data.rating === 's') { Source = e9 + data.id; @@ -35,24 +39,40 @@ module.exports = async function SourceFynnder(enabled, msg) { } 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); }; -/* 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 Source; - if (data.rating === "s") { - Source = e9 + data.id; - } else { - Source = e6 + data.id; - } + 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 +}; - - - console.log(Source); - return msg.channel.send(Source); */ +module.exports = { + SourceFynnder: SourceFynnderBot, + APIFind: SourceFynnderAPI +} \ No newline at end of file