From ad3dacea00b59735331b64f78cbeb41c027d9c04 Mon Sep 17 00:00:00 2001 From: amsyarasyiq Date: Mon, 13 Feb 2023 01:06:09 +0000 Subject: [PATCH] deploy: 4abc0c5f59b102167c918bee3ea643913bd213c6 --- Last.fm/index.js | 2 +- Last.fm/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Last.fm/index.js b/Last.fm/index.js index 0f209b6..6bff114 100644 --- a/Last.fm/index.js +++ b/Last.fm/index.js @@ -1 +1 @@ -(function(c,m,T,n,d,L,o,S,b){"use strict";const u={DEFAULT_APP_NAME:"Music",APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]};async function P(){const e=new URLSearchParams({method:"user.getrecenttracks",user:s.username,api_key:u.LFM_API_KEY,format:"json",limit:"1",extended:"1"}).toString(),r=await fetch(`https://ws.audioscrobbler.com/2.0/?${e}`).then(i=>{if(!i.ok)throw new Error(`Failed to fetch latest scrobble: ${i.status} ${i.statusText}`);return i.json()}),t=r.recenttracks?.track?.[0]||Promise.reject(r);return{name:t.name,artist:t.artist.name,album:t.album["#text"],albumArt:R(t.image[3]["#text"]),url:t.url,date:t.date?.["#text"]??"now",nowPlaying:Boolean(t["@attr"]?.nowplaying),loved:t.loved==="1"}}function R(e){return u.LFM_DEFAULT_COVER_HASHES.some(r=>e.includes(r))?null:e}async function A(e){return a.stopped&&(console.log("--> Plugin is unloaded, aborting..."),a.updateInterval&&clearInterval(a.updateInterval),e=null),a.lastActivity=e,await _.handler({isSocketConnected:()=>!0,socket:{id:120,application:{id:u.APPLICATION_ID,name:e?.name||"RichPresence"},transport:"ipc"},args:{pid:120,activity:e&&{...e}||null}})}function g(){return a.lastActivity&&l("--> Clearing activity..."),A(null)}async function w(){if(l("--> Fetching last track..."),!s.username)throw b.showToast("Last.fm username is not set!",o.getAssetIDByName("Small")),await h(),new Error("Username is not set");const e=await P().catch(async function(i){throw l("--> An error occurred while fetching the last track, aborting..."),await g().catch(),i});if(!e.nowPlaying)return l("--> Last track is not currently playing, aborting..."),await g();if(l("--> Track fetched! Setting activity..."),a.lastTrackUrl===e.url){l("--> Last track is the same as the previous one, aborting...");return}const r={name:s.appName||u.DEFAULT_APP_NAME,type:s.listeningTo?2:0,details:e.name,state:`by ${e.artist}`};a.lastTrackUrl=e.url,s.showTimestamp&&(r.timestamps={start:Date.now()/1e3|0}),e.album&&(r.assets={large_image:e.albumArt,large_text:`on ${e.album}`});const t=await A(r).catch(async function(i){throw l("--> An error occurred while setting the activity"),await g().catch(),i});return l("--> Successfully set activity!"),l(t),t}function h(){return console.log("--> Flushing..."),a.lastActivity=null,a.updateInterval&&clearInterval(a.updateInterval),g()}async function y(){if(console.log("--> Initializing..."),a.stopped)throw new Error("Plugin is already stopped!");a.lastTrackUrl=null,a.updateInterval&&clearInterval(a.updateInterval),a.lastActivity&&await g();let e=0;w().catch(r=>{console.error(r),e++}),a.updateInterval=setInterval(()=>w().then(()=>e=0).catch(r=>{console.error(r),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),clearInterval(a.updateInterval),a.stopped=!0)}),s.timeInterval)}function F(){a.activityTypeUnpatch&&(console.warn("This is weird... activity type override is already defined?"),a.activityTypeUnpatch()),console.log("Patching activity type...");const e=Object.values(n.FluxDispatcher._actionHandlers._dependencyGraph.nodes),{actionHandler:r}=e.find(t=>t.name==="LocalActivityStore");return m.patcher.before("LOCAL_ACTIVITY_UPDATE",r,([{activity:t}])=>{t&&t.name===a.lastActivity.name&&(t.type=a.lastActivity.type)})}const{ScrollView:N,TouchableOpacity:U,Text:C}=n.ReactNative,{FormInput:E,FormDivider:p,FormSwitchRow:v,FormText:D,FormIcon:f}=S.Forms;function k(){const e=L.useProxy(d.storage),r=n.NavigationNative.useNavigation();return n.React.useEffect(()=>{r.setOptions({title:"Last.fm Configuration",headerRight:()=>{async function t(){for(const i in d.storage)(typeof d.storage[i]=="boolean"||d.storage[i])&&(s[i]=e[i]);console.log("Applying settings..."),await h(),await y(),b.showToast("Settings updated!",o.getAssetIDByName("Check"))}return n.React.createElement(U,{onPress:t},n.React.createElement(D,{style:{marginRight:12}},"UPDATE"))}})},[]),n.React.createElement(N,null,n.React.createElement(E,{value:e.appName||void 0,onChangeText:t=>e.appName=t.trim(),title:"Discord Application Name",placeholder:u.DEFAULT_APP_NAME,returnKeyType:"done"}),n.React.createElement(p,null),n.React.createElement(E,{required:!0,value:e.username||void 0,onChangeText:t=>e.username=t.trim(),title:"Last.fm username",helpText:!e.username&&n.React.createElement(C,{style:{color:"#FF0000"}},"This field is required!"),placeholder:"wumpus123",returnKeyType:"done"}),n.React.createElement(p,null),n.React.createElement(v,{label:"Show time elapsed",subLabel:"Show the time elapsed since the song started playing",leading:n.React.createElement(f,{source:o.getAssetIDByName("clock")}),value:e.showTimestamp,onValueChange:t=>e.showTimestamp=t}),n.React.createElement(p,null),n.React.createElement(v,{label:"Set status as listening",subLabel:'Set your status as "Listening to" instead of "Playing"',leading:n.React.createElement(f,{source:o.getAssetIDByName("ic_headset_neutral")}),value:e.listeningTo,onValueChange:t=>e.listeningTo=t}),n.React.createElement(p,null),n.React.createElement(v,{label:"Verbose logging",subLabel:"Log more information to the console for debugging purposes",leading:n.React.createElement(f,{source:o.getAssetIDByName("icon-qs-files")}),value:e.verboseLogging,onValueChange:t=>e.verboseLogging=t}))}const a={},s={...m.plugin.storage},I=T.findByStoreName("UserStore"),_=T.findByProps("SET_ACTIVITY").SET_ACTIVITY,l=(...e)=>s.verboseLogging&&console.log(...e);var O={onLoad:()=>{console.log("Starting last.fm plugin.."),a.activityTypeUnpatch=F(),a.stopped=!1,I.getCurrentUser()&&(console.log("User is already logged in, initializing..."),y().catch(console.error)),n.FluxDispatcher.subscribe("CONNECTION_OPEN",()=>{y().catch(console.error)})},onUnload:()=>{console.log("Stopping last.fm..."),a.stopped=!0,h(),a.activityTypeUnpatch?.(),a.activityTypeUnpatch=null},settings:k};return c.SET_ACTIVITY=_,c.UserStore=I,c.currentSettings=s,c.default=O,c.global=a,c.verboseLog=l,Object.defineProperty(c,"__esModule",{value:!0}),c})({},vendetta,vendetta.metro,vendetta.metro.common,vendetta.plugin,vendetta.storage,vendetta.ui.assets,vendetta.ui.components,vendetta.ui.toasts); +(function(c,f,m,n,d,L,u,S,A){"use strict";const o={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]};async function P(){const e=new URLSearchParams({method:"user.getrecenttracks",user:s.username,api_key:o.LFM_API_KEY,format:"json",limit:"1",extended:"1"}).toString(),r=await fetch(`https://ws.audioscrobbler.com/2.0/?${e}`).then(i=>{if(!i.ok)throw new Error(`Failed to fetch latest scrobble: ${i.status} ${i.statusText}`);return i.json()}),t=r.recenttracks?.track?.[0]||Promise.reject(r);return{name:t.name,artist:t.artist.name,album:t.album["#text"],albumArt:R(t.image[3]["#text"]),url:t.url,date:t.date?.["#text"]??"now",nowPlaying:Boolean(t["@attr"]?.nowplaying),loved:t.loved==="1"}}function R(e){return o.LFM_DEFAULT_COVER_HASHES.some(r=>e.includes(r))?null:e}async function b(e){return a.stopped&&(console.log("--> Plugin is unloaded, aborting..."),a.updateInterval&&clearInterval(a.updateInterval),e=null),a.lastActivity=e,await _.handler({isSocketConnected:()=>!0,socket:{id:120,application:{id:o.APPLICATION_ID,name:e?.name||"RichPresence"},transport:"ipc"},args:{pid:120,activity:e&&{...e}||null}})}function g(){return a.lastActivity&&l("--> Clearing activity..."),b(null)}async function E(){if(l("--> Fetching last track..."),!s.username)throw A.showToast("Last.fm username is not set!",u.getAssetIDByName("Small")),await h(),new Error("Username is not set");const e=await P().catch(async function(i){throw l("--> An error occurred while fetching the last track, aborting..."),await g().catch(),i});if(!e.nowPlaying)return l("--> Last track is not currently playing, aborting..."),await g();if(l("--> Track fetched! Setting activity..."),a.lastTrackUrl===e.url){l("--> Last track is the same as the previous one, aborting...");return}const r={name:s.appName||o.DEFAULT_APP_NAME,type:s.listeningTo?2:0,details:e.name,state:`by ${e.artist}`};a.lastTrackUrl=e.url,s.showTimestamp&&(r.timestamps={start:Date.now()/1e3|0}),e.album&&(r.assets={large_image:e.albumArt,large_text:`on ${e.album}`});const t=await b(r).catch(async function(i){throw l("--> An error occurred while setting the activity"),await g().catch(),i});return l("--> Successfully set activity!"),l(t),t}function h(){return console.log("--> Flushing..."),a.lastActivity=null,a.updateInterval&&clearInterval(a.updateInterval),g()}async function y(){if(console.log("--> Initializing..."),a.stopped)throw new Error("Plugin is already stopped!");a.lastTrackUrl=null,a.updateInterval&&clearInterval(a.updateInterval),a.lastActivity&&await g();let e=0;E().catch(r=>{console.error(r),e++}),a.updateInterval=setInterval(()=>E().then(()=>e=0).catch(r=>{console.error(r),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),clearInterval(a.updateInterval),a.stopped=!0)}),(s.timeInterval||o.DEFAULT_TIME_INTERVAL)*1e3)}function F(){a.activityTypeUnpatch&&(console.warn("This is weird... activity type override is already defined?"),a.activityTypeUnpatch()),console.log("Patching activity type...");const e=Object.values(n.FluxDispatcher._actionHandlers._dependencyGraph.nodes),{actionHandler:r}=e.find(t=>t.name==="LocalActivityStore");return f.patcher.before("LOCAL_ACTIVITY_UPDATE",r,([{activity:t}])=>{t&&t.name===a.lastActivity.name&&(t.type=a.lastActivity.type)})}const{ScrollView:N,TouchableOpacity:U,Text:C}=n.ReactNative,{FormInput:I,FormDivider:p,FormSwitchRow:v,FormText:D,FormIcon:T}=S.Forms;function k(){const e=L.useProxy(d.storage),r=n.NavigationNative.useNavigation();return n.React.useEffect(()=>{r.setOptions({title:"Last.fm Configuration",headerRight:()=>{async function t(){for(const i in d.storage)(typeof d.storage[i]=="boolean"||d.storage[i])&&(s[i]=e[i]);console.log("Applying settings..."),await h(),await y(),A.showToast("Settings updated!",u.getAssetIDByName("Check"))}return n.React.createElement(U,{onPress:t},n.React.createElement(D,{style:{marginRight:12}},"UPDATE"))}})},[]),n.React.createElement(N,null,n.React.createElement(I,{value:e.appName||void 0,onChangeText:t=>e.appName=t.trim(),title:"Discord Application Name",placeholder:o.DEFAULT_APP_NAME,returnKeyType:"done"}),n.React.createElement(p,null),n.React.createElement(I,{required:!0,value:e.username||void 0,onChangeText:t=>e.username=t.trim(),title:"Last.fm username",helpText:!e.username&&n.React.createElement(C,{style:{color:"#FF0000"}},"This field is required!"),placeholder:"wumpus123",returnKeyType:"done"}),n.React.createElement(p,null),n.React.createElement(v,{label:"Show time elapsed",subLabel:"Show the time elapsed since the song started playing",leading:n.React.createElement(T,{source:u.getAssetIDByName("clock")}),value:e.showTimestamp,onValueChange:t=>e.showTimestamp=t}),n.React.createElement(p,null),n.React.createElement(v,{label:"Set status as listening",subLabel:'Set your status as "Listening to" instead of "Playing"',leading:n.React.createElement(T,{source:u.getAssetIDByName("ic_headset_neutral")}),value:e.listeningTo,onValueChange:t=>e.listeningTo=t}),n.React.createElement(p,null),n.React.createElement(v,{label:"Verbose logging",subLabel:"Log more information to the console for debugging purposes",leading:n.React.createElement(T,{source:u.getAssetIDByName("icon-qs-files")}),value:e.verboseLogging,onValueChange:t=>e.verboseLogging=t}))}const a={},s={...f.plugin.storage},w=m.findByStoreName("UserStore"),_=m.findByProps("SET_ACTIVITY").SET_ACTIVITY,l=(...e)=>s.verboseLogging&&console.log(...e);var V={onLoad:()=>{console.log("Starting last.fm plugin.."),a.activityTypeUnpatch=F(),a.stopped=!1,w.getCurrentUser()&&(console.log("User is already logged in, initializing..."),y().catch(console.error)),n.FluxDispatcher.subscribe("CONNECTION_OPEN",()=>{y().catch(console.error)})},onUnload:()=>{console.log("Stopping last.fm..."),a.stopped=!0,h(),a.activityTypeUnpatch?.(),a.activityTypeUnpatch=null},settings:k};return c.SET_ACTIVITY=_,c.UserStore=w,c.currentSettings=s,c.default=V,c.global=a,c.verboseLog=l,Object.defineProperty(c,"__esModule",{value:!0}),c})({},vendetta,vendetta.metro,vendetta.metro.common,vendetta.plugin,vendetta.storage,vendetta.ui.assets,vendetta.ui.components,vendetta.ui.toasts); diff --git a/Last.fm/manifest.json b/Last.fm/manifest.json index 58de85f..27c4290 100644 --- a/Last.fm/manifest.json +++ b/Last.fm/manifest.json @@ -1 +1 @@ -{"name":"Last.fm","description":"Show off your last.fm status on your Discord profile.","authors":[{"name":"amsyarasyiq","id":"492949202121261067"}],"main":"index.js","vendetta":{"icon":"ic_stage_music"},"hash":"5bed0b7722dc5beda4f1e5d674f4dd8ea9efdc789bcf1b05cdc18c042ca8fde4"} \ No newline at end of file +{"name":"Last.fm","description":"Show off your last.fm status on your Discord profile.","authors":[{"name":"amsyarasyiq","id":"492949202121261067"}],"main":"index.js","vendetta":{"icon":"ic_stage_music"},"hash":"28d29dfafae57f75123f3c69d8e127f271e48eb21c6b6a29bf28d6d39c03e59c"} \ No newline at end of file