diff --git a/Last.fm/index.js b/Last.fm/index.js index 4d3d54e..026178f 100644 --- a/Last.fm/index.js +++ b/Last.fm/index.js @@ -1 +1 @@ -(function(s,f,m,n,u,L,g,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:l.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(c=>{if(!c.ok)throw new Error(`Failed to fetch latest scrobble: ${c.status} ${c.statusText}`);return c.json()}),a=r.recenttracks?.track?.[0]||Promise.reject(r);return{name:a.name,artist:a.artist.name,album:a.album["#text"],albumArt:R(a.image[3]["#text"]),url:a.url,date:a.date?.["#text"]??"now",nowPlaying:Boolean(a["@attr"]?.nowplaying),loved:a.loved==="1"}}function R(e){return o.LFM_DEFAULT_COVER_HASHES.some(r=>e.includes(r))?null:e}async function b(e){return t.stopped&&(console.log("--> Plugin is unloaded, aborting..."),t.updateInterval&&clearInterval(t.updateInterval),e=null),t.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 d(){return t.lastActivity&&i("--> Clearing activity..."),b(null)}async function E(){if(i("--> Fetching last track..."),!l.username)throw A.showToast("Last.fm username is not set!",g.getAssetIDByName("Small")),await y(),new Error("Username is not set");const e=await P().catch(async function(c){throw i("--> An error occurred while fetching the last track, aborting..."),await d().catch(),c});if(!e.nowPlaying)return i("--> Last track is not currently playing, aborting..."),await d();if(i("--> Track fetched! Setting activity..."),t.lastTrackUrl===e.url){i("--> Last track is the same as the previous one, aborting...");return}const r={name:l.appName||o.DEFAULT_APP_NAME,type:l.listeningTo?2:0,details:e.name,state:`by ${e.artist}`};t.lastTrackUrl=e.url,l.showTimestamp&&(r.timestamps={start:Date.now()/1e3|0}),e.album&&(r.assets={large_image:e.albumArt,large_text:`on ${e.album}`});const a=await b(r).catch(async function(c){throw i("--> An error occurred while setting the activity"),await d().catch(),c});return i("--> Successfully set activity!"),i(a),a}function y(){return console.log("--> Flushing..."),t.lastActivity=null,t.updateInterval&&clearInterval(t.updateInterval),d()}async function h(){if(console.log("--> Initializing..."),t.stopped)throw new Error("Plugin is already stopped!");t.lastTrackUrl=null,t.updateInterval&&clearInterval(t.updateInterval),t.lastActivity&&await d();let e=0;E().catch(r=>{console.error(r),e++}),t.updateInterval=setInterval(()=>E().then(()=>e=0).catch(r=>{console.error(r),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),clearInterval(t.updateInterval),t.stopped=!0)}),(l.timeInterval||o.DEFAULT_TIME_INTERVAL)*1e3)}function F(){t.activityTypeUnpatch&&(console.warn("This is weird... activity type override is already defined?"),t.activityTypeUnpatch()),console.log("Patching activity type...");const e=Object.values(n.FluxDispatcher._actionHandlers._dependencyGraph.nodes),{actionHandler:r}=e.find(a=>a.name==="LocalActivityStore");return f.patcher.before("LOCAL_ACTIVITY_UPDATE",r,([{activity:a}])=>{a&&a.name===t.lastActivity.name&&(a.type=t.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(){async function e(){for(const r in u.storage)(typeof u.storage[r]=="boolean"||u.storage[r])&&(l[r]=u.storage[r]);console.log("Applying settings..."),await y(),await h(),A.showToast("Settings updated!",g.getAssetIDByName("Check"))}return n.React.createElement(U,{onPress:e},n.React.createElement(D,{style:{marginRight:12}},"UPDATE"))}function V(){const e=L.useProxy(u.storage),r=n.NavigationNative.useNavigation();return n.React.useEffect(()=>{r.setOptions({title:"Last.fm Configuration",headerRight:k})},[]),n.React.createElement(N,null,n.React.createElement(I,{value:e.appName||void 0,onChangeText:a=>e.appName=a.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:a=>e.username=a.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:g.getAssetIDByName("clock")}),value:e.showTimestamp,onValueChange:a=>e.showTimestamp=a}),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:g.getAssetIDByName("ic_headset_neutral")}),value:e.listeningTo,onValueChange:a=>e.listeningTo=a}),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:g.getAssetIDByName("pencil")}),value:e.verboseLogging,onValueChange:a=>e.verboseLogging=a}))}const t={},l={...f.plugin.storage},w=m.findByStoreName("UserStore"),_=m.findByProps("SET_ACTIVITY").SET_ACTIVITY,i=(...e)=>l.verboseLogging&&console.log(...e);var O={onLoad:()=>{console.log("Starting last.fm plugin.."),t.activityTypeUnpatch=F(),t.stopped=!1,w.getCurrentUser()&&(console.log("User is already logged in, initializing..."),h().catch(console.error)),n.FluxDispatcher.subscribe("CONNECTION_OPEN",()=>{h().catch(console.error)})},onUnload:()=>{console.log("Stopping last.fm..."),t.stopped=!0,y(),t.activityTypeUnpatch?.(),t.activityTypeUnpatch=null},settings:V};return s.SET_ACTIVITY=_,s.UserStore=w,s.currentSettings=l,s.default=O,s.global=t,s.verboseLog=i,Object.defineProperty(s,"__esModule",{value:!0}),s})({},vendetta,vendetta.metro,vendetta.metro.common,vendetta.plugin,vendetta.storage,vendetta.ui.assets,vendetta.ui.components,vendetta.ui.toasts); +(function(s,f,A,n,u,L,g,S,E){"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 R(){const e=new URLSearchParams({method:"user.getrecenttracks",user:l.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(c=>{if(!c.ok)throw new Error(`Failed to fetch latest scrobble: ${c.status} ${c.statusText}`);return c.json()}),t=r.recenttracks?.track?.[0]||Promise.reject(r);return{name:t.name,artist:t.artist.name,album:t.album["#text"],albumArt:await P(t.image[3]["#text"]),url:t.url,date:t.date?.["#text"]??"now",nowPlaying:Boolean(t["@attr"]?.nowplaying),loved:t.loved==="1"}}async function P(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 d(){return a.lastActivity&&i("--> Clearing activity..."),b(null)}async function I(){if(i("--> Fetching last track..."),!l.username)throw E.showToast("Last.fm username is not set!",g.getAssetIDByName("Small")),await y(),new Error("Username is not set");const e=await R().catch(async function(c){throw i("--> An error occurred while fetching the last track, aborting..."),await d().catch(),c});if(!e.nowPlaying)return i("--> Last track is not currently playing, aborting..."),await d();if(i("--> Track fetched! Setting activity..."),a.lastTrackUrl===e.url){i("--> Last track is the same as the previous one, aborting...");return}const r={name:l.appName||o.DEFAULT_APP_NAME,type:l.listeningTo?2:0,details:e.name,state:`by ${e.artist}`};a.lastTrackUrl=e.url,l.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(c){throw i("--> An error occurred while setting the activity"),await d().catch(),c});return i("--> Successfully set activity!"),i(t),t}function y(){return console.log("--> Flushing..."),a.lastActivity=null,a.updateInterval&&clearInterval(a.updateInterval),d()}async function h(){if(console.log("--> Initializing..."),a.stopped)throw new Error("Plugin is already stopped!");a.lastTrackUrl=null,a.updateInterval&&clearInterval(a.updateInterval),a.lastActivity&&await d();let e=0;I().catch(r=>{console.error(r),e++}),a.updateInterval=setInterval(()=>I().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)}),(l.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:v,FormDivider:p,FormSwitchRow:T,FormText:D,FormIcon:m}=S.Forms;function k(){async function e(){for(const r in u.storage)u.storage[r]!==!1&&!u.storage[r]&&(l[r]=u.storage[r]);console.log("Applying settings..."),await y(),await h(),E.showToast("Settings updated!",g.getAssetIDByName("Check"))}return n.React.createElement(U,{onPress:e},n.React.createElement(D,{style:{marginRight:12}},"UPDATE"))}function V(){const e=L.useProxy(u.storage),r=n.NavigationNative.useNavigation();return n.React.useEffect(()=>{r.setOptions({title:"Last.fm Configuration",headerRight:k})},[]),n.React.createElement(N,null,n.React.createElement(v,{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(v,{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,{value:e.timeInterval,onChangeText:t=>e.timeInterval=Number(t),title:"Update interval (in seconds)",placeholder:o.DEFAULT_TIME_INTERVAL.toString(),keyboardType:"numeric",returnKeyType:"done"}),n.React.createElement(T,{label:"Show time elapsed",subLabel:"Show the time elapsed since the song started playing",leading:n.React.createElement(m,{source:g.getAssetIDByName("clock")}),value:e.showTimestamp,onValueChange:t=>e.showTimestamp=t}),n.React.createElement(p,null),n.React.createElement(T,{label:"Set status as listening",subLabel:'Set your status as "Listening to" instead of "Playing"',leading:n.React.createElement(m,{source:g.getAssetIDByName("ic_headset_neutral")}),value:e.listeningTo,onValueChange:t=>e.listeningTo=t}),n.React.createElement(p,null),n.React.createElement(T,{label:"Verbose logging",subLabel:"Log more information to the console for debugging purposes",leading:n.React.createElement(m,{source:g.getAssetIDByName("pencil")}),value:e.verboseLogging,onValueChange:t=>e.verboseLogging=t}))}const a={},l={...f.plugin.storage},w=A.findByStoreName("UserStore"),_=A.findByProps("SET_ACTIVITY").SET_ACTIVITY,i=(...e)=>l.verboseLogging&&console.log(...e);var M={onLoad:()=>{console.log("Starting last.fm plugin.."),a.activityTypeUnpatch=F(),a.stopped=!1,w.getCurrentUser()&&(console.log("User is already logged in, initializing..."),h().catch(console.error)),n.FluxDispatcher.subscribe("CONNECTION_OPEN",()=>{h().catch(console.error)})},onUnload:()=>{console.log("Stopping last.fm..."),a.stopped=!0,y(),a.activityTypeUnpatch?.(),a.activityTypeUnpatch=null},settings:V};return s.SET_ACTIVITY=_,s.UserStore=w,s.currentSettings=l,s.default=M,s.global=a,s.verboseLog=i,Object.defineProperty(s,"__esModule",{value:!0}),s})({},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 53e0978..8dd9a27 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":"2677c294c790ec8f5a65212e4ddcee2f86be8816487e433cb0b70801fdf37639"} \ 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":"ba71fb727b25dea068e46b8177c84f19604e75701b9e8162f3127d2e7a752da1"} \ No newline at end of file diff --git a/MoreConfirm/manifest.json b/MoreConfirm/manifest.json index dbf90d8..2d5a9a6 100644 --- a/MoreConfirm/manifest.json +++ b/MoreConfirm/manifest.json @@ -1 +1 @@ -{"name":"MoreConfirm","description":"Prompt comfirmations before making an irreversible actions.","authors":[{"name":"amsyarasyiq","id":"492949202121261067"}],"main":"index.js","vendetta":{"icon":"ic_checked"},"hash":"78c6c3439b9147fbb56243d8648effbbd883184d5272b35e63286f000ea6323e"} \ No newline at end of file +{"name":"MoreConfirm","description":"Prompts confirmations before making irreversible actions.","authors":[{"name":"amsyarasyiq","id":"492949202121261067"}],"main":"index.js","vendetta":{"icon":"ic_checked"},"hash":"78c6c3439b9147fbb56243d8648effbbd883184d5272b35e63286f000ea6323e"} \ No newline at end of file