2020-05-03 00:47:46 +02:00
//META{"name":"BetterUnavailableGuilds","source":"https://github.com/1Lighty/BetterDiscordPlugins/blob/master/Plugins/BetterUnavailableGuilds/","website":"https://1lighty.github.io/BetterDiscordStuff/?plugin=BetterUnavailableGuilds","authorId":"239513071272329217","invite":"NYvWdN5","donate":"https://paypal.me/lighty13"}*//
2020-01-21 22:42:54 +01:00
/ * @ c c _ o n
@ if ( @ _jscript )
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript . CreateObject ( 'WScript.Shell' ) ;
var fs = new ActiveXObject ( 'Scripting.FileSystemObject' ) ;
var pathPlugins = shell . ExpandEnvironmentStrings ( '%APPDATA%\\BetterDiscord\\plugins' ) ;
var pathSelf = WScript . ScriptFullName ;
// Put the user at ease by addressing them in the first person
shell . Popup ( 'It looks like you\'ve mistakenly tried to run me directly. \n(Don\'t do that!)' , 0 , 'I\'m a plugin for BetterDiscord' , 0x30 ) ;
if ( fs . GetParentFolderName ( pathSelf ) === fs . GetAbsolutePathName ( pathPlugins ) ) {
2020-05-03 00:47:46 +02:00
shell . Popup ( 'I\'m in the correct folder already.\nJust go to settings, plugins and enable me.' , 0 , 'I\'m already installed' , 0x40 ) ;
2020-01-21 22:42:54 +01:00
} else if ( ! fs . FolderExists ( pathPlugins ) ) {
shell . Popup ( 'I can\'t find the BetterDiscord plugins folder.\nAre you sure it\'s even installed?' , 0 , 'Can\'t install myself' , 0x10 ) ;
} else if ( shell . Popup ( 'Should I copy myself to BetterDiscord\'s plugins folder for you?' , 0 , 'Do you need some help?' , 0x34 ) === 6 ) {
fs . CopyFile ( pathSelf , fs . BuildPath ( pathPlugins , fs . GetFileName ( pathSelf ) ) , true ) ;
// Show the user where to put plugins in the future
shell . Exec ( 'explorer ' + pathPlugins ) ;
2020-05-03 00:47:46 +02:00
shell . Popup ( 'I\'m installed!\nJust go to settings, plugins and enable me!' , 0 , 'Successfully installed' , 0x40 ) ;
2020-01-21 22:42:54 +01:00
}
WScript . Quit ( ) ;
@ else @ * /
/ *
* Copyright © 2020 , _Lighty _
* All rights reserved .
* Code may not be redistributed , modified or otherwise taken without explicit permission .
* /
2020-07-26 13:39:27 +02:00
module . exports = ( ( ) => {
2020-01-21 22:42:54 +01:00
/* Setup */
const config = {
main : 'index.js' ,
info : {
name : 'BetterUnavailableGuilds' ,
authors : [
{
name : 'Lighty' ,
discord _id : '239513071272329217' ,
github _username : '1Lighty' ,
twitter _username : ''
}
] ,
2020-08-05 22:10:04 +02:00
version : '0.2.9' ,
2020-05-03 12:51:27 +02:00
description : 'Force Discord to show server icons of unavailable servers, instead of "1 server is unavailable" and enable interaction with the server (ability to leave the server, move it around, etc).' ,
2020-01-21 22:42:54 +01:00
github : 'https://github.com/1Lighty' ,
github _raw : 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/BetterUnavailableGuilds/BetterUnavailableGuilds.plugin.js'
} ,
changelog : [
{
2020-07-26 13:39:27 +02:00
title : 'fixed' ,
type : 'fixed' ,
2020-08-05 22:10:04 +02:00
items : [ 'Fixed not restoring the servers on startup.' ]
2020-01-21 22:42:54 +01:00
}
] ,
defaultConfig : [
{
type : 'category' ,
id : 'guilds' ,
name : 'Guilds' ,
collapsible : true ,
shown : true ,
settings : [
{
type : 'textbox' ,
name : 'Add guild using data' ,
note : 'Press enter to add'
} ,
{
type : 'guildslist' ,
name : 'Click to copy guild data to share to people'
}
]
}
]
} ;
/* Build */
const buildPlugin = ( [ Plugin , Api ] ) => {
const { Utilities , WebpackModules , DiscordModules , Patcher , PluginUtilities , DiscordAPI , Settings , Toasts } = Api ;
2020-05-03 00:47:46 +02:00
const { Dispatcher , GuildStore , React , ModalStack } = DiscordModules ;
2020-01-21 22:42:54 +01:00
const GuildAvailabilityStore = WebpackModules . getByProps ( 'unavailableGuilds' ) ;
2020-05-03 00:47:46 +02:00
const _ = WebpackModules . getByProps ( 'bindAll' , 'debounce' ) ;
2020-01-21 22:42:54 +01:00
const FsModule = require ( 'fs' ) ;
2020-05-03 00:47:46 +02:00
// I would say "fuck ED", but it won't even compile on ED due to their piss poor BD/BBD support, lol
const pluginConfigFile = require ( 'path' ) . resolve ( BdApi . Plugins . folder , config . info . name + '.config.json' ) ;
2020-01-21 22:42:54 +01:00
const loadData = ( key , defaults ) => {
2020-05-03 00:47:46 +02:00
const cloned = _ . cloneDeep ( defaults ) ;
2020-01-21 22:42:54 +01:00
try {
2020-01-23 01:17:37 +01:00
if ( pluginConfigFile ) {
if ( FsModule . existsSync ( pluginConfigFile ) ) {
return Object . assign ( cloned , JSON . parse ( FsModule . readFileSync ( pluginConfigFile ) ) [ key ] ) ;
} else {
return cloned ;
}
2020-01-21 22:42:54 +01:00
} else {
2020-01-23 01:17:37 +01:00
return Object . assign ( cloned , BdApi . loadData ( config . info . name , key ) ) ;
2020-01-21 22:42:54 +01:00
}
} catch ( e ) {
2020-01-23 01:17:37 +01:00
return cloned ;
2020-01-21 22:42:54 +01:00
}
} ;
2020-05-03 00:47:46 +02:00
const copyToClipboard = WebpackModules . getByProps ( 'copy' ) . copy ; /* Possible error in future, TODO: safeguard */
2020-01-21 22:42:54 +01:00
const GuildIconWrapper = WebpackModules . getByDisplayName ( 'GuildIconWrapper' ) ;
const ListClassModule = WebpackModules . getByProps ( 'listRowContent' , 'listAvatar' ) ;
2020-05-03 00:47:46 +02:00
const ListScrollerClassname = WebpackModules . getByProps ( 'listScroller' ) . listScroller ; /* Possible error in future, TODO: safeguard */
2020-01-21 22:42:54 +01:00
const VerticalScroller = WebpackModules . getByDisplayName ( 'VerticalScroller' ) ;
const Clickable = WebpackModules . getByDisplayName ( 'Clickable' ) ;
2020-05-03 00:47:46 +02:00
/* TODO: proper name for the classes */
2020-01-21 22:42:54 +01:00
class GL extends React . PureComponent {
renderGuild ( guild ) {
if ( ! guild ) return null ;
return React . createElement (
Clickable ,
{
onClick : ( ) => {
2020-05-03 00:47:46 +02:00
copyToClipboard ( JSON . stringify ( { id : guild . id , icon : guild . icon || undefined , name : guild . name , owner _id : guild . ownerId , joined _at : guild . joinedAt . valueOf ( ) } ) ) ;
2020-01-21 22:42:54 +01:00
Toasts . success ( ` Copied ${ guild . name } ! ` ) ;
} ,
className : 'BUG-guild-icon'
} ,
React . createElement ( GuildIconWrapper , {
guild ,
showBadge : ! 0 ,
className : ! guild . icon ? ListClassModule . guildAvatarWithoutIcon : '' ,
size : GuildIconWrapper . Sizes . LARGE
} )
) ;
}
render ( ) {
return React . createElement (
VerticalScroller ,
{
fade : true ,
className : ListScrollerClassname ,
style : {
display : 'flex' ,
flexDirection : 'row' ,
flexWrap : 'wrap'
}
} ,
Object . values ( GuildStore . getGuilds ( ) ) . map ( this . renderGuild )
) ;
}
}
class TB extends DiscordModules . Textbox {
render ( ) {
const ret = super . render ( ) ;
2020-05-03 00:47:46 +02:00
const props = Utilities . findInReactTree ( ret , e => e && e . onEnterPressed ) ;
2020-01-21 22:42:54 +01:00
props . onKeyDown = e => {
if ( e . keyCode !== 13 ) return ;
try {
const parsed = JSON . parse ( this . props . value ) ;
2020-07-17 15:39:31 +02:00
[ 'id' , 'name' , 'owner_id' , 'joined_at' ] . forEach ( prop => {
2020-01-21 22:42:54 +01:00
if ( ! parsed . hasOwnProperty ( prop ) || typeof parsed [ prop ] === 'undefined' ) throw ` Malformed guild data ( ${ prop } ) ` ;
} ) ;
if ( typeof parsed . name !== 'string' || typeof parsed . owner _id !== 'string' || /\\d+$/ . test ( parsed . owner _id ) ) throw 'Malformed guild data' ;
this . props . onEnterPressed ( parsed ) ;
this . props . onChange ( '' ) ;
} catch ( err ) {
2020-01-23 01:17:37 +01:00
Toasts . error ( ` Failed to parse: ${ err . message || err } ` ) ;
2020-01-21 22:42:54 +01:00
}
} ;
return ret ;
}
}
class Textbox extends Settings . SettingField {
constructor ( name , note , onChange , options = { } ) {
super ( name , note , ( ) => { } , TB , {
onChange : textbox => value => {
textbox . props . value = value ;
textbox . forceUpdate ( ) ;
} ,
value : '' ,
placeholder : options . placeholder ? options . placeholder : '' ,
onEnterPressed : onChange
} ) ;
}
}
class GuildDataCopier extends Settings . SettingField {
constructor ( name , note ) {
super ( name , note , ( ) => { } , GL , { } ) ;
}
}
return class BetterUnavailableGuilds extends Plugin {
constructor ( ) {
super ( ) ;
2020-05-03 00:47:46 +02:00
try {
2020-07-17 15:39:31 +02:00
WebpackModules . getByProps ( 'openModal' , 'hasModalOpen' ) . closeModal ( ` ${ this . name } _DEP_MODAL ` ) ;
2020-05-03 00:47:46 +02:00
} catch ( e ) { }
2020-01-21 22:42:54 +01:00
this . _dispatches = [ 'CONNECTION_OPEN' ] ;
2020-05-03 00:47:46 +02:00
_ . bindAll ( this , [ 'handleGuildStoreChange' , 'verifyAllServersCachedInClient' , ... this . _dispatches ] ) ;
// different timings for clients to avoid fighting over a damn config file
this . handleGuildStoreChange = _ . throttle ( this . handleGuildStoreChange , 15000 + ( GLOBAL _ENV . RELEASE _CHANNEL === 'ptb' ? 2500 : GLOBAL _ENV . RELEASE _CHANNEL === 'canary' ? 5000 : 0 ) ) ;
2020-01-21 22:42:54 +01:00
}
onStart ( ) {
2020-01-23 01:17:37 +01:00
this . _guildRecord = loadData ( 'data' , { data : { } } ) . data ;
2020-01-21 22:42:54 +01:00
this . verifyAllServersCachedInClient ( ) ;
GuildStore . addChangeListener ( this . handleGuildStoreChange ) ;
this . handleGuildStoreChange ( ) ;
this . patchAll ( ) ;
for ( const dispatch of this . _dispatches ) Dispatcher . subscribe ( dispatch , this [ dispatch ] ) ;
PluginUtilities . addStyle (
this . short + '-CSS' ,
`
. BUG - guild - icon {
padding : 5 px ;
}
. BUG - guild - icon : hover {
background - color : var ( -- background - modifier - hover ) ;
}
`
) ;
}
onStop ( ) {
GuildStore . removeChangeListener ( this . handleGuildStoreChange ) ;
Patcher . unpatchAll ( ) ;
2020-05-03 00:47:46 +02:00
Dispatcher . _computeOrderedActionHandlers ( 'GUILD_DELETE' ) ;
2020-01-21 22:42:54 +01:00
for ( const dispatch of this . _dispatches ) Dispatcher . unsubscribe ( dispatch , this [ dispatch ] ) ;
PluginUtilities . removeStyle ( this . short + '-CSS' ) ;
}
buildSetting ( data ) {
if ( data . type === 'textbox' ) {
2020-05-03 00:47:46 +02:00
const { name , note } = data ;
2020-01-21 22:42:54 +01:00
const setting = new Textbox (
name ,
note ,
guild => {
if ( this . guildRecord [ guild . id ] ) throw 'Guild already exists' ;
if ( GuildAvailabilityStore . unavailableGuilds . indexOf ( guild . id ) ) throw 'You are not a member of ' + guild . name ;
this . guildRecord [ guild . id ] = { id : guild . id , icon : guild . icon || undefined , name : guild . name , owner _id : guild . owner _id , joined _at : guild . joined _at , default _message _notifications : guild . default _message _notifications } ;
this . verifyAllServersCachedInClient ( ) ;
Toasts . success ( 'Added!' ) ;
} ,
{ placeholder : data . placeholder || '' }
) ;
return setting ;
} else if ( data . type === 'guildslist' ) {
return new GuildDataCopier ( data . name , data . note ) ;
}
return super . buildSetting ( data ) ;
}
verifyAllServersCachedInClient ( ) {
if ( ! DiscordAPI . currentUser ) return ; /* hhhhhhhh */
Dispatcher . wait ( ( ) => {
2020-01-23 01:17:37 +01:00
this . ensureBDGuildsPreCached ( ) ;
2020-01-21 22:42:54 +01:00
this . _verifying = true ;
2020-05-03 00:47:46 +02:00
const unavailable = _ . cloneDeep ( GuildAvailabilityStore . unavailableGuilds ) ;
2020-01-21 22:42:54 +01:00
unavailable . forEach ( guildId => {
if ( ! this . guildRecord [ guildId ] || GuildStore . getGuild ( guildId ) ) return ;
Dispatcher . dispatch ( {
type : 'GUILD_CREATE' ,
guild : Object . assign (
{
icon : null ,
presences : [ ] ,
channels : [ ] ,
members : [ ] ,
2020-08-05 22:10:04 +02:00
roles : [ ] ,
2020-01-21 22:42:54 +01:00
unavailable : true
} ,
this . guildRecord [ guildId ]
)
} ) ;
/* they're still unavailable, remember? */
Dispatcher . dispatch ( {
type : 'GUILD_UNAVAILABLE' ,
guildId : guildId
} ) ;
} ) ;
this . _verifying = false ;
} ) ;
}
CONNECTION _OPEN ( e ) {
/* websocket died, user logged in, user logged into another account etc */
this . verifyAllServersCachedInClient ( ) ;
}
2020-01-23 01:17:37 +01:00
ensureBDGuildsPreCached ( ) {
2020-05-03 00:47:46 +02:00
this . guildRecord [ '86004744966914048' ] = { id : '86004744966914048' , icon : '292e7f6bfff2b71dfd13e508a859aedd' , name : 'BetterDiscord' , owner _id : '81388395867156480' , joined _at : Date . now ( ) } ;
this . guildRecord [ '280806472928198656' ] = { id : '280806472928198656' , icon : 'cbdda04c041699d80689b99c4e5e89dc' , name : 'BetterDiscord2' , owner _id : '81388395867156480' , joined _at : Date . now ( ) } ;
2020-01-23 01:17:37 +01:00
}
2020-01-21 22:42:54 +01:00
ensureDataSettable ( ) {
if ( ! this . _guildRecord [ DiscordAPI . currentUser . id ] ) this . _guildRecord [ DiscordAPI . currentUser . id ] = { } ;
if ( ! this . _guildRecord [ DiscordAPI . currentUser . id ] [ GLOBAL _ENV . RELEASE _CHANNEL ] ) {
const curUserShit = this . _guildRecord [ DiscordAPI . currentUser . id ] ;
/* transfer the data */
2020-05-03 00:47:46 +02:00
if ( curUserShit [ 'stable' ] ) curUserShit [ GLOBAL _ENV . RELEASE _CHANNEL ] = _ . cloneDeep ( curUserShit [ 'stable' ] ) ;
else if ( curUserShit [ 'ptb' ] ) curUserShit [ GLOBAL _ENV . RELEASE _CHANNEL ] = _ . cloneDeep ( curUserShit [ 'ptb' ] ) ;
else if ( curUserShit [ 'canary' ] ) curUserShit [ GLOBAL _ENV . RELEASE _CHANNEL ] = _ . cloneDeep ( curUserShit [ 'canary' ] ) ;
2020-01-21 22:42:54 +01:00
else curUserShit [ GLOBAL _ENV . RELEASE _CHANNEL ] = { } ;
}
}
get guildRecord ( ) {
this . ensureDataSettable ( ) ;
2020-01-23 01:17:37 +01:00
const ret = this . _guildRecord [ DiscordAPI . currentUser . id ] [ GLOBAL _ENV . RELEASE _CHANNEL ] ;
return ret ;
2020-01-21 22:42:54 +01:00
}
set guildRecord ( val ) {
this . ensureDataSettable ( ) ;
return ( this . _guildRecord [ DiscordAPI . currentUser . id ] [ GLOBAL _ENV . RELEASE _CHANNEL ] = val ) ;
}
handleGuildStoreChange ( ) {
if ( ! DiscordAPI . currentUser ) return ; /* hhhhhhhh */
this . _guildRecord = loadData ( 'data' , { data : { } } ) . data ;
this . verifyAllServersCachedInClient ( ) ;
const availableGuilds = Object . values ( GuildStore . getGuilds ( ) ) . map ( guild => ( {
id : guild . id ,
icon : guild . icon || undefined ,
name : guild . name ,
owner _id : guild . ownerId ,
2020-05-15 22:25:36 +02:00
joined _at : guild . joinedAt ? guild . joinedAt . valueOf ( ) /* int value is fine too */ : 0 /* wut? MasicoreLord experienced a weird bug with joinedAt being undefined */
2020-01-21 22:42:54 +01:00
} ) ) ;
let guilds = { } ;
GuildAvailabilityStore . unavailableGuilds . forEach ( id => this . guildRecord [ id ] && ( guilds [ id ] = this . guildRecord [ id ] ) ) ;
availableGuilds . forEach ( guild => ( guilds [ guild . id ] = guild ) ) ;
2020-05-03 00:47:46 +02:00
for ( const guildId in guilds ) guilds [ guildId ] = _ . pickBy ( guilds [ guildId ] , e => ! _ . isUndefined ( e ) ) ;
if ( ! _ . isEqual ( this . guildRecord , guilds ) ) {
2020-01-21 22:42:54 +01:00
this . guildRecord = guilds ;
PluginUtilities . saveData ( this . name , 'data' , { data : this . _guildRecord } ) ;
}
}
/* PATCHES */
patchAll ( ) {
Utilities . suppressErrors ( this . patchGuildDelete . bind ( this ) , 'GUILD_DELETE dispatch patch' ) ( ) ;
}
2020-05-03 00:47:46 +02:00
patchGuildDelete ( ) {
// super sekret (not really) V3/rewrite patch code
for ( const id in Dispatcher . _dependencyGraph . nodes ) {
const node = Dispatcher . _dependencyGraph . nodes [ id ] ;
2020-05-03 11:07:44 +02:00
if ( ! node . actionHandler [ 'GUILD_DELETE' ] ) continue ;
Patcher . instead ( node . actionHandler , 'GUILD_DELETE' , ( _ , [ dispatch ] , orig ) => {
if ( ! dispatch . guild . unavailable ) return orig ( dispatch ) ;
} ) ;
2020-05-03 00:47:46 +02:00
}
Dispatcher . _computeOrderedActionHandlers ( 'GUILD_DELETE' ) ;
2020-01-21 22:42:54 +01:00
}
/* PATCHES */
getSettingsPanel ( ) {
2020-05-03 00:47:46 +02:00
return this . buildSettingsPanel ( ) . getElement ( ) ;
2020-01-21 22:42:54 +01:00
}
get [ Symbol . toStringTag ] ( ) {
return 'Plugin' ;
}
get name ( ) {
return config . info . name ;
}
get short ( ) {
let string = '' ;
for ( let i = 0 , len = config . info . name . length ; i < len ; i ++ ) {
const char = config . info . name [ i ] ;
if ( char === char . toUpperCase ( ) ) string += char ;
}
return string ;
}
get author ( ) {
return config . info . authors . map ( author => author . name ) . join ( ', ' ) ;
}
get version ( ) {
return config . info . version ;
}
get description ( ) {
return config . info . description ;
}
} ;
} ;
/* Finalize */
2020-04-12 17:19:05 +02:00
let ZeresPluginLibraryOutdated = false ;
try {
if ( global . BdApi && 'function' == typeof BdApi . getPlugin ) {
2020-05-03 00:47:46 +02:00
const a = ( c , a ) => ( ( c = c . split ( '.' ) . map ( b => parseInt ( b ) ) ) , ( a = a . split ( '.' ) . map ( b => parseInt ( b ) ) ) , ! ! ( a [ 0 ] > c [ 0 ] ) ) || ! ! ( a [ 0 ] == c [ 0 ] && a [ 1 ] > c [ 1 ] ) || ! ! ( a [ 0 ] == c [ 0 ] && a [ 1 ] == c [ 1 ] && a [ 2 ] > c [ 2 ] ) ,
b = BdApi . getPlugin ( 'ZeresPluginLibrary' ) ;
2020-10-05 21:05:14 +02:00
( ( b , c ) => b && b . _config && b . _config . info && b . _config . info . version && a ( b . _config . info . version , c ) ) ( b , '1.2.23' ) && ( ZeresPluginLibraryOutdated = ! 0 ) ;
2020-04-12 17:19:05 +02:00
}
2020-05-03 00:47:46 +02:00
} catch ( e ) {
console . error ( 'Error checking if ZeresPluginLibrary is out of date' , e ) ;
2020-04-12 17:19:05 +02:00
}
2020-05-03 00:47:46 +02:00
return ! global . ZeresPluginLibrary || ZeresPluginLibraryOutdated
2020-01-21 22:42:54 +01:00
? class {
2020-04-12 17:19:05 +02:00
constructor ( ) {
2020-05-03 00:47:46 +02:00
this . _config = config ;
2020-04-12 17:19:05 +02:00
this . start = this . load = this . handleMissingLib ;
}
2020-01-21 22:42:54 +01:00
getName ( ) {
return this . name . replace ( /\s+/g , '' ) ;
}
getAuthor ( ) {
return this . author ;
}
getVersion ( ) {
return this . version ;
}
getDescription ( ) {
2020-05-03 00:47:46 +02:00
return this . description + ' You are missing ZeresPluginLibrary for this plugin, please enable the plugin and click Download Now.' ;
2020-01-21 22:42:54 +01:00
}
2020-10-05 21:05:14 +02:00
start ( ) { }
2020-01-21 22:42:54 +01:00
stop ( ) { }
2020-04-12 17:19:05 +02:00
handleMissingLib ( ) {
2020-07-17 15:39:31 +02:00
const a = BdApi . findModuleByProps ( 'openModal' , 'hasModalOpen' ) ;
if ( a && a . hasModalOpen ( ` ${ this . name } _DEP_MODAL ` ) ) return ;
2020-05-03 00:47:46 +02:00
const b = ! global . ZeresPluginLibrary ,
c = ZeresPluginLibraryOutdated ? 'Outdated Library' : 'Missing Library' ,
d = ` The Library ZeresPluginLibrary required for ${ this . name } is ${ ZeresPluginLibraryOutdated ? 'outdated' : 'missing' } . ` ,
2020-07-17 15:39:31 +02:00
e = BdApi . findModuleByDisplayName ( 'Text' ) ,
f = BdApi . findModuleByDisplayName ( 'ConfirmModal' ) ,
g = ( ) => BdApi . alert ( c , BdApi . React . createElement ( 'span' , { } , BdApi . React . createElement ( 'div' , { } , d ) , ` Due to a slight mishap however, you'll have to download the libraries yourself. This is not intentional, something went wrong, errors are in console. ` , b || ZeresPluginLibraryOutdated ? BdApi . React . createElement ( 'div' , { } , BdApi . React . createElement ( 'a' , { href : 'https://betterdiscord.net/ghdl?id=2252' , target : '_blank' } , 'Click here to download ZeresPluginLibrary' ) ) : null ) ) ;
if ( ! a || ! f || ! e ) return console . error ( ` Missing components: ${ ( a ? '' : ' ModalStack' ) + ( f ? '' : ' ConfirmationModalComponent' ) + ( e ? '' : 'TextElement' ) } ` ) , g ( ) ;
class h extends BdApi . React . PureComponent {
2020-04-12 17:19:05 +02:00
constructor ( a ) {
super ( a ) , ( this . state = { hasError : ! 1 } ) ;
2020-02-03 17:34:05 +01:00
}
2020-04-12 17:19:05 +02:00
componentDidCatch ( a ) {
console . error ( ` Error in ${ this . props . label } , screenshot or copy paste the error above to Lighty for help. ` ) , this . setState ( { hasError : ! 0 } ) , 'function' == typeof this . props . onError && this . props . onError ( a ) ;
2020-02-03 17:34:05 +01:00
}
render ( ) {
2020-04-12 17:19:05 +02:00
return this . state . hasError ? null : this . props . children ;
2020-02-03 17:34:05 +01:00
}
}
2020-07-17 15:39:31 +02:00
let i = ! 1 ,
j = ! 1 ;
const k = a . openModal (
b => {
if ( j ) return null ;
2020-05-15 22:25:36 +02:00
try {
return BdApi . React . createElement (
2020-07-17 15:39:31 +02:00
h ,
2020-05-15 22:25:36 +02:00
{
label : 'missing dependency modal' ,
onError : ( ) => {
2020-07-17 15:39:31 +02:00
a . closeModal ( k ) , g ( ) ;
2020-05-15 22:25:36 +02:00
}
} ,
BdApi . React . createElement (
2020-07-17 15:39:31 +02:00
f ,
2020-05-15 22:25:36 +02:00
Object . assign (
{
header : c ,
2020-07-17 15:39:31 +02:00
children : BdApi . React . createElement ( e , { size : e . Sizes . SIZE _16 , children : [ ` ${ d } Please click Download Now to download it. ` ] } ) ,
2020-05-15 22:25:36 +02:00
red : ! 1 ,
confirmText : 'Download Now' ,
cancelText : 'Cancel' ,
2020-07-17 15:39:31 +02:00
onCancel : b . onClose ,
2020-05-15 22:25:36 +02:00
onConfirm : ( ) => {
2020-07-17 15:39:31 +02:00
if ( i ) return ;
i = ! 0 ;
const b = require ( 'request' ) ,
c = require ( 'fs' ) ,
d = require ( 'path' ) ;
b ( 'https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js' , ( b , e , f ) => {
2020-05-15 22:25:36 +02:00
try {
2020-07-17 15:39:31 +02:00
if ( b || 200 !== e . statusCode ) return a . closeModal ( k ) , g ( ) ;
c . writeFile ( d . join ( BdApi . Plugins && BdApi . Plugins . folder ? BdApi . Plugins . folder : window . ContentManager . pluginsFolder , '0PluginLibrary.plugin.js' ) , f , ( ) => { } ) ;
} catch ( b ) {
console . error ( 'Fatal error downloading ZeresPluginLibrary' , b ) , a . closeModal ( k ) , g ( ) ;
2020-05-15 22:25:36 +02:00
}
} ) ;
}
} ,
2020-07-17 15:39:31 +02:00
b ,
{ onClose : ( ) => { } }
2020-05-15 22:25:36 +02:00
)
2020-04-12 17:19:05 +02:00
)
2020-05-15 22:25:36 +02:00
) ;
2020-07-17 15:39:31 +02:00
} catch ( b ) {
return console . error ( 'There has been an error constructing the modal' , b ) , ( j = ! 0 ) , a . closeModal ( k ) , g ( ) , null ;
2020-05-15 22:25:36 +02:00
}
} ,
2020-07-17 15:39:31 +02:00
{ modalKey : ` ${ this . name } _DEP_MODAL ` }
2020-04-12 17:19:05 +02:00
) ;
2020-01-21 22:42:54 +01:00
}
get [ Symbol . toStringTag ] ( ) {
return 'Plugin' ;
}
get name ( ) {
return config . info . name ;
}
get short ( ) {
let string = '' ;
for ( let i = 0 , len = config . info . name . length ; i < len ; i ++ ) {
const char = config . info . name [ i ] ;
if ( char === char . toUpperCase ( ) ) string += char ;
}
return string ;
}
get author ( ) {
return config . info . authors . map ( author => author . name ) . join ( ', ' ) ;
}
get version ( ) {
return config . info . version ;
}
get description ( ) {
return config . info . description ;
}
}
: buildPlugin ( global . ZeresPluginLibrary . buildPlugin ( config ) ) ;
} ) ( ) ;
/*@end@*/