(function(exports,_vendetta,metro,common,plugin,storage,assets,components,toasts){'use strict';constConstants={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]};constAssetManager=metro.findByProps("getAssetIds");asyncfunctionfetchLatestScrobble(){constparams=newURLSearchParams({"method":"user.getrecenttracks","user":currentSettings.username,"api_key":Constants.LFM_API_KEY,"format":"json","limit":"1","extended":"1"}).toString();constresult=awaitfetch(`https://ws.audioscrobbler.com/2.0/?${params}`);if(!result.ok)thrownewError(`Failed to fetch the latest scrobble: ${result.statusText}`);constinfo=awaitresult.json();constlastTrack=info?.recenttracks?.track?.[0];if(!lastTrack)throwinfo;return{name:lastTrack.name,artist:lastTrack.artist.name,album:lastTrack.album["#text"],albumArt:awaithandleAlbumCover(lastTrack.image[3]["#text"]),url:lastTrack.url,date:lastTrack.date?.["#text"]??"now",nowPlaying:Boolean(lastTrack["@attr"]?.nowplaying),loved:lastTrack.loved==="1"}}asyncfunctionhandleAlbumCover(cover){if(Constants.LFM_DEFAULT_COVER_HASHES.some(function(x){returncover.includes(x)})){returnnull}returncover}functionclearActivity(){global.lastActivity&&verboseLog("--> Clearing activity...");returnsendRequest(null)}functionsendRequest(activity){if(global.pluginStopped){console.log("--> Plugin is unloaded, aborting...");global.updateInterval&&clearInterval(global.updateInterval);activity=null;}global.lastActivity=activity;common.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:activity});}asyncfunctionfetchAsset(asset){letappId=arguments.length>1&&arguments[1]!==void0?arguments[1]:Constants.APPLICATION_ID;if(!asset)returnnull;if(typeofasset==="string"){constassetId=awaitAssetManager.getAssetIds(appId,[asset]);returnassetId[0]}returnawaitAssetManager.getAssetIds(appId,asset)}asyncfunctionupdate(){verboseLog("--> Fetching last track...");if(!currentSettings.username){toasts.showToast("Last.fm username is not set!",assets.getAssetIDByName("Small"));flush();thrownewError("Username is not set")}constlastTrack=awaitfetchLatestScrobble().catch(asyncfunction(err){verboseLog("--> An error occurred while fetching the last track, aborting...");clearActivity();throwerr});if(!lastTrack.nowPlaying){verboseLog("--> Last track is not currently playing, aborting...");clearActivity();return}verboseLog("--> Track fetched!");if(global.lastTrackUrl===lastTrack.url){verboseLog("--> Last track is the same as the previous one, aborting...");return}constactivity={name:currentSettings.appName||Constants.DEFAULT_APP_NAME,flags:0,type:currentSettings.listeningTo?2:0,details:lastTrack.name,state:`by ${lastTrack.artist}`,application_id:Constants.APPLICATION_ID};global.lastTrackUrl=lastTrack.url;if(activity.name.includes("{{")){for(constkeyinlastTrack){activity.name=activity.name.replace(`{{${key}}}`,lastTrack[key]);}}if(currentSettings.showTimestamp){activity.timestamps={start:Date.now()/1e3|0};}if(lastTrack.album){activity.assets={large_image:awaitfetchAsset(lastTrack.albumArt),large_text:`on ${lastTrack.album}`};}verboseLog("--> Setting activity...");verboseLog(activity);try{sendRequest(activity);}catch(err){verboseLog("--> An error occurred while setting the activity");clearActivity();throwerr}verboseLog("--> Successfully set activity!");}functionflush(){console.log("--> Flushing...");global.lastActivity=null;global.lastTrackUrl=null;global.updateInterval&&clearInterval(global.updateInterval);clearActivity();}asyncfunctioninitialize(){console.log("--> Initializing...");if(global.pluginStopped){thrownewError("Plugin is already stopped!")}flush();lettries=0;awaitupdate().catch(function(err){console.error(err);tries++;});global.updateInterval=setInterval(function(){returnupdate().then(function(){tries=0;}).catch(function(err){console.error(err);if(++tries>3){console.error("Failedtofetch/setactivity3times,abor
const{ScrollView,TouchableOpacity,Text}=common.ReactNative;const{FormInput,FormDivider,FormSwitchRow,FormText,FormIcon}=components.Forms;functionUpdateButton(){asyncfunctiononPressCallback(){for(constkeyinplugin.storage){if(plugin.storage[key]===false||plugin.storage[key]){currentSettings[key]=plugin.storage[key];}}console.log("Applying settings...");awaitinitialize();toasts.showToast("Settings updated!",assets.getAssetIDByName("Check"));}returncommon.React.createElement(TouchableOpacity,{onPress:onPressCallback},common.React.createElement(FormText,{style:{marginRight:12}},"UPDATE"))}functionSettings(){constsettings=storage.useProxy(plugin.storage);constnavigation=common.NavigationNative.useNavigation();common.React.useEffect(function(){navigation.setOptions({title:"Last.fm Configuration",headerRight:UpdateButton});},[]);returncommon.React.createElement(ScrollView,null,common.React.createElement(FormInput,{value:settings.appName||undefined,onChangeText:function(value){returnsettings.appName=value.trim()},title:"Discord Application Name",placeholder:Constants.DEFAULT_APP_NAME,returnKeyType:"done"}),common.React.createElement(FormDivider,null),common.React.createElement(FormInput,{required:true,value:settings.username||undefined,onChangeText:function(value){returnsettings.username=value.trim()},title:"Last.fm username",helpText:!settings.username&&common.React.createElement(Text,{style:{color:"#FF0000"}},"This field is required!"),placeholder:"wumpus123",returnKeyType:"done"}),common.React.createElement(FormDivider,null),common.React.createElement(FormInput,{value:settings.timeInterval,onChangeText:function(value){returnsettings.timeInterval=Number(value)},title:"Update interval (in seconds)",placeholder:Constants.DEFAULT_TIME_INTERVAL.toString(),keyboardType:"numeric",returnKeyType:"done"}),common.React.createElement(FormDivider,null),common.React.createElement(FormSwitchRow,{label:"Show time elapsed",subLabel:"Show the time elapsed since the song started playing",leading:common.React.createElement(FormIcon,{source:assets.getAssetIDByName("clock")}),value:settings.showTimestamp,onValueChange:function(value){returnsettings.showTimestamp=value}}),common.React.createElement(FormDivider,null),common.React.createElement(FormSwitchRow,{label:"Set status as listening",subLabel:'Set your status as "Listening to" instead of "Playing"',leading:common.React.createElement(FormIcon,{source:assets.getAssetIDByName("ic_headset_neutral")}),value:settings.listeningTo,onValueChange:function(value){returnsettings.listeningTo=value}}),common.React.createElement(FormDivider,null),common.React.createElement(FormSwitchRow,{label:"Verbose logging",subLabel:"Log more information to the console for debugging purposes",leading:common.React.createElement(FormIcon,{source:assets.getAssetIDByName("pencil")}),value:settings.verboseLogging,onValueChange:function(value){returnsettings.verboseLogging=value}}))}function_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function")}}constglobal={};constcurrentSettings={..._vendetta.plugin.storage};constUserStore=metro.findByStoreName("UserStore");constSET_ACTIVITY=metro.findByProps("SET_ACTIVITY").SET_ACTIVITY;constverboseLog=function(){for(var_len=arguments.length,message=newArray(_len),_key=0;_key<_len;_key++){message[_key]=arguments[_key];}returncurrentSettings.verboseLogging&&console.log(...message)};varindex=new(function(){functionLastFM(){_classCallCheck(this,LastFM);this.settings=Settings;}var_proto=LastFM.prototype;_proto.onLoad=functiononLoad(){console.log("Starting last.fm plugin..");global.pluginStopped=false;if(UserStore.getCurrentUser()){console.log("User is already logged in, initializing...");initialize().catch(console.error);}common.FluxDispatcher.subscribe("CONNECTION_OPEN",function(){initialize().catch(console.error);});};_proto.onUnload=functiononUnload(){console.log("Stopping last.fm...");global.pluginStopped=true;flush();};returnLastFM}());exports.SET_ACTIVITY=SET_ACTIVITY;exports.