From 2a7fd97092ca7997569402d867432bedb74354f7 Mon Sep 17 00:00:00 2001 From: rhearmas <34490428+qu-ota@users.noreply.github.com> Date: Sat, 21 Dec 2019 17:15:44 -0500 Subject: [PATCH] more functions woo yeah --- modules/functions.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/modules/functions.js b/modules/functions.js index 1cd336c..1a4d1f2 100644 --- a/modules/functions.js +++ b/modules/functions.js @@ -1,4 +1,5 @@ const Discord = require("discord.js"); +const got = require("got"); module.exports = (client) => { client.permlevel = message => { @@ -310,4 +311,56 @@ module.exports = (client) => { }, delay * i); }); }; + + client.textUpload = (text, options) => { + options = options || {}; + let method = (options.method || uploadMethods.ix).toLowerCase(); + + if (method === uploadMethods.ix) { + return ixUpload(text); + } else if (method === uploadMethods.hastebin) { + return hastebinUpload(text); + } + }; + + const uploadMethods = { + hastebin: 'hastebin', + ix: 'ix.io' + }; + + const hastebinUpload = text => { + return got('https://hastebin.com/documents', { body: { 'contents': text }, form: true }) + .then(res => { + if (res && res.body && res.body.key) { + const key = res.body.key; + return { + key: key, + success: true, + url: `https://hastebin.com/${key}`, + rawUrl: `https://hastebin.com/raw/${key}` + }; + } else { + return { + success: false + }; + } + }); + }; + + const ixUpload = text => { + return got('http://ix.io', { body: { 'f:1': text }, form: true }) + .then(res => { + if (res && res.body) { + return { + success: true, + url: res.body, + rawUrl: res.body + }; + } else { + return { + success: false + }; + } + }); + }; }; \ No newline at end of file