Update 0BDFDB.plugin.js
This commit is contained in:
parent
fbd63a9184
commit
761ae7beeb
|
@ -2,7 +2,7 @@
|
|||
* @name BDFDB
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 3.0.1
|
||||
* @version 3.0.2
|
||||
* @description Required Library for DevilBro's Plugins
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -4050,6 +4050,25 @@ module.exports = (_ => {
|
|||
};
|
||||
|
||||
BDFDB.DiscordUtils = {};
|
||||
BDFDB.DiscordUtils.requestFileData = function (...args) {
|
||||
let {url, uIndex} = args[0] && typeof args[0] == "string" ? {url: args[0], uIndex: 0} : (args[1] && typeof args[1] == "object" && typeof args[1].url == "string" ? {url: args[1], uIndex: 1} : {url: null, uIndex: -1});
|
||||
if (!url || typeof url != "string") return;
|
||||
let {callback, cIndex} = args[1] && typeof args[1] == "function" ? {callback: args[1], cIndex: 1} : (args[2] && typeof args[2] == "function" ? {callback: args[2], cIndex: 2} : {callback: null, cIndex: -1});
|
||||
if (typeof callback != "function") return;
|
||||
|
||||
let config = args[0] && typeof args[0] == "object" ? args[0] : (args[1] && typeof args[1] == "object" && args[1]);
|
||||
|
||||
let timeoutMs = config && !isNaN(parseInt(config.timeout)) && config.timeout > 0 ? config.timeout : 600000;
|
||||
let timedout = false, timeout = BDFDB.TimeUtils.timeout(_ => {
|
||||
timedout = true;
|
||||
callback(`Request Timeout after ${timeoutMs}ms`, null)
|
||||
}, timeoutMs);
|
||||
Internal.LibraryModules.FileRequestUtils.getFileData(url).then(buffer => {
|
||||
BDFDB.TimeUtils.clear(timeout);
|
||||
if (timedout) return;
|
||||
callback(null, buffer);
|
||||
});
|
||||
};
|
||||
BDFDB.DiscordUtils.getSetting = function (category, key) {
|
||||
if (!category || !key) return;
|
||||
return BDFDB.LibraryStores.UserSettingsProtoStore && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category] && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category][key] && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category][key].value;
|
||||
|
|
Loading…
Reference in New Issue