vd-plugins/Commands/index.js

13 lines
40 KiB
JavaScript
Raw Normal View History

(function($,ie,r,h,D,b,l,e,ce,G,c,le){"use strict";const de=async function(){const t=await(await fetch("https://uselessfacts.jsph.pl/api/v2/facts/random")).json();return{text:t.text,source:t.source,language:t.language}},ue=async function(){return{text:(await(await fetch("https://dogapi.dog/api/v2/facts?limit=1")).json()).data[0].attributes.body}},ge=async function(){const t=await(await fetch("https://catfact.ninja/fact")).json();return{text:t.fact,length:t.length}},ye=async function(t){return await(await fetch(`https://api.obamabot.me/v2/image/petpet?image=${t.replace("webp","png")}`)).json()},pe=async function(t="gary"){try{switch(t){case"gary":return(await(await fetch("https://api.garythe.cat/gary")).json()).url;case"goober":return(await(await fetch("https://api.garythe.cat/goober")).json()).url;case"catapi":return(await(await fetch("https://api.thecatapi.com/v1/images/search")).json())[0].url;case"minker":return"https://minky.materii.dev/";default:throw new Error("Invalid Gary image source value")}}catch(n){return console.error(`[Gary API] Error fetching image from ${t}:`,n),null}},_=h.findByProps("sendMessage"),O=function(t){let n=t.text;return r.storage.factSettings?.includeCitation&&t.source&&(n+=`
2025-09-27 19:17:53 +02:00
Source: ${t.source}`),n},fe={name:"catfact",displayName:"catfact",description:"Sends a random cat fact.",displayDescription:"Sends a random cat fact.",applicationId:"-1",inputType:1,type:1,execute:async function(t,n){try{const a=await ge(),o=Date.now().toString();return _.sendMessage(n.channel.id,{content:O(a)},void 0,{nonce:o}),{type:4}}catch(a){return console.error("[CatFact] Error:",a),{type:4}}}},me={name:"dogfact",displayName:"dogfact",description:"Sends a dog fact.",displayDescription:"Sends a dog fact.",applicationId:"-1",inputType:1,type:1,execute:async function(t,n){try{const a=await ue(),o=Date.now().toString();return _.sendMessage(n.channel.id,{content:O(a)},void 0,{nonce:o}),{type:4}}catch(a){return console.error("[DogFact] Error:",a),{type:4}}}},he={name:"useless",displayName:"useless",description:"Sends a useless fact.",displayDescription:"Sends a useless fact.",applicationId:"-1",inputType:1,type:1,execute:async function(t,n){try{const a=await de(),o=Date.now().toString();return _.sendMessage(n.channel.id,{content:O(a)},void 0,{nonce:o}),{type:4}}catch(a){return console.error("[UselessFact] Error:",a),{type:4}}}},S={CONTENT:"This list is over 2000 characters. Send anyway?",CONFIRM:"Send",CANCEL:"Cancel"},Ce={DETAILED:"detailed"},U="",v={SLM_NOT_INSTALLED:"This list is over 2000 characters. Install the Split Large Messages plugin to send it.",SLM_NOT_ENABLED:"This list is over 2000 characters. Enable the Split Large Messages plugin to send it."},F={SEMICOL:"; ",NEW_LINE:`
`},Re="Nothing to see here, huh...",j="github.com/fres621/vendetta-plugins",I={ENABLED:"\u2705",DISABLED:"\u274C",SELECTED:"\u2705",NOT_SELECTED:"\u274C"},be=h.findByProps("sendMessage","receiveMessage"),N=h.findByProps("sendBotMessage"),K=function(){try{return h.findByStoreName("UserStore").getCurrentUser()?.premiumType===2?4e3:2e3}catch{return 2e3}}(),z=function(t){return Object.keys(t).includes(j)},W=function(t){return Object.values(t).find(function(n){return n.id==j})?.enabled},H=function(t){return t.find(function(n){return n.name===Ce.DETAILED})?.value??!1},T=function(t){return!t||!Array.isArray(t)||t.length===0?"Unknown":t.filter(function(n){return n&&(typeof n=="string"||typeof n=="object"&&n.name)}).map(function(n){return typeof n=="string"?n:n.name||"Unknown"}).join(F.SEMICOL)||"Unknown"},X=function(t){return t.join(F.NEW_LINE).trimEnd()},B=function(t){return X(t).length},L=async function(t,n){const a=Date.now().toString();await be.sendMessage(t,{content:X(n)},void 0,{nonce:a})},Y=function(t,n){return[`**My ${t} List | ${n} ${t}s**`,U]};async function Ie(t,n){try{const a=H(t),o=r.storage.themeListAlwaysDetailed??!1;if(!D.themes||typeof D.themes!="object"){const f=n.channel.id;return N.sendBotMessage(f,"No themes found or themes not loaded yet."),{type:4}}const s=Object.values(D.themes),u=n.channel.id,i=Y("Theme",Object.keys(D.themes).length);if(s.length)for(const f of s){if(!f||typeof f!="object")continue;const{selected:y,data:p,id:R}=f,A=p?.name||"Unknown Theme",w=p?.description||"No description",M=p?.authors;a||o?i.push(`> **Name**: ${A}`,`> **Selected**: ${y?I.SELECTED:I.NOT_SELECTED}`,`> **Description**: ${w}`,`> **Authors**: ${T(M)}`,`> **[Install!](${R||"unknown"})**`,U):i.push(`> ${y?I.SELECTED:I.NOT_SELECTED} **${A}** by ${T(M)}`)}else i.push(Re);const g=B(i)>K;if(g&&!z(b.plugins))N.sendBotMessage(u,v.SLM_NOT_INSTALLED);else if(g&&!W(b.plugins))N.sendBotMessage(u,v.SLM_NOT_ENABLED);else{if(B(i)>2e3)return l.alerts.showConfirmationAlert({content:S.CONTENT,confirmText:S.CONFIRM,cancelText:S.CANCEL,onConfirm:async function(){return await L(u,i)}});await L(u,i)}}catch(a){return console.error("[ThemeList] Error:",a),{type:4}}}async function Ee(t,n){try{const a=H(t),o=r.storage.pluginListAlwaysDetailed??!1,s=n.channel.id;if(!b.plugins||typeof b.plugins!="object")return N.sendBotMessage(s,"No plugins found or plugins not loaded yet."),{type:4};const u=Y("Plugin",Object.keys(b.plugins).length);for(const g of Object.values(b.plugins)){if(!g||typeof g!="object")continue;const{enabled:f,manifest:y,id:p}=g,R=y?.name||"Unknown Plugin",A=y?.description||"No description",w=y?.authors;a||o?u.push(`> **Name**: ${R}`,`> **Status**: ${f?I.ENABLED:I.DISABLED}`,`> **Description**: ${A}`,`> **Authors**: ${T(w)}`,`> **[Install!](${p||"unknown"})**`,U):u.push(`> ${f?I.ENABLED:I.DISABLED} **${R}** by ${T(w)}`)}const i=B(u)>K;if(i&&!z(b.plugins))N.sendBotMessage(s,v.SLM_NOT_INSTALLED);else if(i&&!W(b.plugins))N.sendBotMessage(s,v.SLM_NOT_ENABLED);else{if(B(u)>2e3)return l.alerts.showConfirmationAlert({content:S.CONTENT,confirmText:S.CONFIRM,cancelText:S.CANCEL,onConfirm:async function(){return await L(s,u)}});await L(s,u)}}catch(a){return console.error("[PluginList] Error:",a),{type:4}}}const Se={name:"plugin-list",displayName:"plugin list",description:"Send your plugin list to the current channel",displayDescription:"Send your plugin list to the current channel",options:[{name:"detailed",description:"Whether to send a list with detailed information.",type:5,required:!1,displayName:"detailed",displayDescription:"Whether to send a list with detailed information."}],execute:Ee,applicationId:"-1",inputType:1,type:1},Ne={name:"theme-list",displayName:"theme list",description:"Send your theme list to the current channel",displayDescription:"Send your theme list to the current channel",options:[{name:"detailed",description:"Whether to send a list with detailed information.",type:5,required:!1,displayName:"detailed",displayDescription:"Whether to send a list with detailed information."}],execute:Ie,applicationId:"-1",inputType:1,type:1
`];const o=Ue();Object.keys(o).forEach(function(i){const g=r.storage[i.toLowerCase()],f=t.find(function(y){return y.name==i.toLowerCase()})?.value??g;(f||g)&&!(g&&!f)&&(a.push(`[**${i}**]`),Object.keys(o[i]).forEach(function(y){a.push(`> ${y}: ${o[i][y]}`)}))});const s=r.storage.ephemeral,u=t.find(function(i){return i.name=="ephemeral"})?.value??s;if((u||s)&&!(s&&!u))return xe.sendBotMessage(n.channel.id,a.join(`
`)),{type:4};{const i=Date.now().toString();return Me.sendMessage(n.channel.id,{content:a.join(`
`)},void 0,{nonce:i}),{type:4}}}catch(a){return console.error("[Sysinfo] Error:",a),{type:4}}}const Ge={name:"sysinfo",displayName:"sysinfo",description:"Display system information",displayDescription:"Display system information",options:[{name:"ephemeral",displayName:"ephemeral",description:"Keep sysinfo ephemeral (default: true)",displayDescription:"Keep sysinfo ephemeral (default: true)",type:5,required:!1},...te.slice(0,-1).map(function(t){return{name:t,displayName:t,description:`Display the ${t} section. Set default in settings.`,displayDescription:`Display the ${t} section. Set default in settings.`,type:5,required:!1}})],execute:Ve,applicationId:"-1",inputType:1,type:1},ae=h.findByProps("sendMessage","receiveMessage"),Fe=h.findByStoreName("SpotifyStore");async function je(t,n){return r.storage.enabledCommands?.spotifyTrack?P(n,function(a){return`https://open.spotify.com/track/${a.id}`}):{type:4}}async function Ke(t,n){return r.storage.enabledCommands?.spotifyAlbum?P(n,function(a){return`https://open.spotify.com/album/${a.album.id}`}):{type:4}}async function ze(t,n){return r.storage.enabledCommands?.spotifyArtists?P(n,function(a){return a.artists.map(function(o){return`[${o.name}](${o.external_urls.spotify})`}).join(`
`)}):{type:4}}async function We(t,n){return r.storage.enabledCommands?.spotifyCover?P(n,function(a){return a.album.image.url}):{type:4}}async function P(t,n){try{const a=t.channel.id,o=Fe?.getTrack?.();if(!o){const i=Date.now().toString();return ae.sendMessage(a,{content:"You are not listening to any track."},void 0,{nonce:i}),{type:4}}const s=n(o),u=Date.now().toString();return ae.sendMessage(a,{content:s},void 0,{nonce:u}),{type:4}}catch(a){return console.error("[Spotify Command] Error:",a),{type:4}}}const He={name:"spotify track",displayName:"spotify track",description:"Sends your current Spotify track",displayDescription:"Sends your current Spotify track",applicationId:"-1",inputType:1,type:1,execute:je},Xe={name:"spotify album",displayName:"spotify album",description:"Sends your current track's album",displayDescription:"Sends your current track's album",applicationId:"-1",inputType:1,type:1,execute:Ke},Ye={name:"spotify artists",displayName:"spotify artists",description:"Sends your current track's artists",displayDescription:"Sends your current track's artists",applicationId:"-1",inputType:1,type:1,execute:ze},qe={name:"spotify cover",displayName:"spotify cover",description:"Sends your current track's cover",displayDescription:"Sends your current track's cover",applicationId:"-1",inputType:1,type:1,execute:We},Ze=h.findByProps("sendMessage"),Je={name:"gary",displayName:"gary",description:"Send a random Gary image to the channel.",displayDescription:"Send a random Gary image to the channel.",options:[],execute:async function(t,n){try{r.storage.garySettings||(r.storage.garySettings={imageSource:"gary"});const a=r.storage.garySettings.imageSource||"gary";console.log(`[Gary Command] Using image source: ${a}`);const o=await pe(a);if(!o)return console.log("[Gary Command] No image URL received"),{type:4};console.log(`[Gary Command] Sending image: ${o}`);const s=Date.now().toString();return Ze.sendMessage(n.channel.id,{content:o},void 0,{nonce:s}),{type:4}}catch(a){return console.error("[Gary] Error:",a),{type:4}}},applicationId:"-1",inputType:1,type:1},{ScrollView:E}=h.findByProps("ScrollView"),{FormRow:d,FormSwitchRow:m}=le.Forms;function C({title:t,icon:n,children:a,padding:o=!1}){const s=e.stylesheet.createThemedStyleSheet({main:{backgroundColor:l.semanticColors.CARD_PRIMARY_BG,borderColor:l.semanticColors.BORDER_FAINT,borderWidth:1,borderRadius:16,overflow:"hidden",flex:1},titleContainer:{marginBottom:8,marginHorizontal:0,marginTop:8,gap:4,flexDirection:"row",alignItems:"center"},icon:{width:16,height:16,marginTop:1.5,tintColor:l.semanticColors.TEXT_MUTED},titleText:{fontSize:14,fontWeight:"600",color:l.semanticColors.TEXT_MUTED}});return e.React.createElement(e.ReactNative.View,{style:{marginHorizontal:16,marginTop:16}},t&&e.React.createElement(e.ReactNative.View,{style:s.titleContainer},n&&e.React.createElement(e.ReactNative.Image,{style:s.icon,source:n,resizeMode:"cover"}),e.React.createElement(e.ReactNative.Text,{style:s.titleText},t.toUpperCase())),e.React.createElement(e.ReactNative.View,{style:s.main},o?e.React.createElement(e.ReactNative.View,{style:{paddingHorizontal:16,paddingVertical:16}},a):a))}function Qe(){const t=e.stylesheet.createThemedStyleSheet({container:{flexDirection:"column",alignItems:"center",paddingVertical:24,paddingHorizontal:16},title:{fontSize:28,fontWeight:"700",color:l.semanticColors.TEXT_NORMAL,marginBottom:4},subtitle:{fontSize:16,fontWeight:"500",color:l.semanticColors.TEXT_MUTED},iconContainer:{backgroundColor:l.semanticColors.BACKGROUND_SECONDARY,borderRadius:16,padding:12,marginBottom:16},icon:{width:32,height:32,tintColor:l.semanticColors.TEXT_NORMAL}});return e.React.createElement(e.ReactNative.View,{style:t.container},e.React.createElement(e.ReactNative.View,{style:t.iconContainer},e.React.createElement(e.ReactNative.Image,{source:c.getAssetIDByName("SettingsIcon"),style:t.icon})),e.React.createElement(e.ReactNative.Text,{style:t.title},"Commands"),e.React.createElement(e.ReactNative.Text,{style:t.subtitle},"A collection of useful commands"))}function et({forceRerender:t}){con
`,"Tap on any contributor to visit their GitHub profile.")),n.map(function(o,s){return e.React.createElement(e.ReactNative.Pressable,{key:s,style:t.creditItem,onPress:function(){return a(o.github)},android_ripple:{color:l.semanticColors.ANDROID_RIPPLE,radius:200}},e.React.createElement(e.ReactNative.Image,{source:{uri:o.avatar},style:t.avatar}),e.React.createElement(e.ReactNative.View,{style:t.textContainer},e.React.createElement(e.ReactNative.Text,{style:t.commandText},o.command),e.React.createElement(e.ReactNative.Text,{style:t.authorText},"by ",o.author),e.React.createElement(e.ReactNative.Text,{style:t.linkText},o.github.replace("https://github.com/","@"))))}),e.React.createElement(C,{title:"About",icon:c.getAssetIDByName("InfoIcon"),padding:!0},e.React.createElement(e.ReactNative.Text,{style:t.versionText},"Commands Plugin Collection",`
`,"Version 1.0.0",`
`,"Built on ",new Date().toLocaleDateString(),`
`,"Made with \u2764\uFE0F for the community"))))}r.storage.factSettings||(r.storage.factSettings={sendAsReply:!0,includeCitation:!1}),r.storage.listSettings||(r.storage.listSettings={pluginListAlwaysDetailed:!1,themeListAlwaysDetailed:!1}),r.storage.garySettings||(r.storage.garySettings={imageSource:"gary"}),r.storage.enabledCommands||(r.storage.enabledCommands={catfact:!0,dogfact:!0,useless:!0,petpet:!0,pluginList:!0,themeList:!0,konoself:!0,konosend:!0,firstmessage:!0,sysinfo:!0,spotifyTrack:!0,spotifyAlbum:!0,spotifyArtists:!0,spotifyCover:!0,gary:!0}),r.storage.pendingRestart||(r.storage.pendingRestart=!1);function it(){G.useProxy(r.storage);const[t,n]=e.React.useReducer(function(u){return u+1},0),a=e.NavigationNative.useNavigation(),o=e.stylesheet.createThemedStyleSheet({container:{flex:1,backgroundColor:l.semanticColors.BACKGROUND_PRIMARY}});e.React.useEffect(function(){return function(){r.storage.pendingRestart&&(r.storage.pendingRestart=!1,l.alerts.showConfirmationAlert({title:"Restart Required",content:"You have made changes to commands. Please restart Discord to apply these changes.",confirmText:"Okay",cancelText:null}))}},[]);const s=function(u,i){a.push("VendettaCustomPage",{title:u,render:function(){return e.React.createElement(i,{forceRerender:n})}})};return e.React.createElement(e.ReactNative.View,{style:o.container},e.React.createElement(E,{style:{flex:1},contentContainerStyle:{paddingBottom:38},showsVerticalScrollIndicator:!1},e.React.createElement(Qe,null),e.React.createElement(C,{title:"Command Categories",icon:c.getAssetIDByName("ChannelListIcon")},e.React.createElement(d,{label:"Facts Commands",subLabel:"Cat facts, dog facts, and useless facts",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("BookmarkIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Facts Commands",et)}}),e.React.createElement(d,{label:"List Commands",subLabel:"Plugin lists and theme lists",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("ListViewIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("List Commands",at)}}),e.React.createElement(d,{label:"Image Commands",subLabel:"PetPet, KonoChan, and image utilities",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("ImageIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Image Commands",nt)}}),e.React.createElement(d,{label:"Gary Commands",subLabel:`Gary images - Current: ${r.storage.garySettings?.imageSource==="gary"?"Gary API":r.storage.garySettings?.imageSource==="catapi"?"Cat API":r.storage.garySettings?.imageSource==="minker"?"Minker API":r.storage.garySettings?.imageSource==="goober"?"Goober API":"Gary API"}`,leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("CameraIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Gary Commands",tt)}}),e.React.createElement(d,{label:"Spotify Commands",subLabel:"Share your Spotify activity",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("SpotifyNeutralIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Spotify Commands",rt)}}),e.React.createElement(d,{label:"Other Commands",subLabel:"System info and miscellaneous",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("MoreHorizontalIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Other Commands",ot)}})),e.React.createElement(C,{title:"More Options",icon:c.getAssetIDByName("SettingsIcon")},e.React.createElement(d,{label:"Credits",subLabel:"View plugin authors and contributors",leading:e.React.createElement(d.Icon,{source:c.getAssetIDByName("HeartIcon")}),trailing:e.React.createElement(d.Arrow,null),onPress:function(){return s("Credits",st)}}))))}r.storage.factSettings||(r.storage.factSettings={sendAsReply:!0,includeCitation:!1}),r.storage.listSettings||(r.storage.listSettings={pluginListAlwaysDetailed:!1,themeListAlwaysDetailed:!1}),r.storage.garySettings||(r.storage.garySettings={imageSource:"gary"}),r.storage.enabledCom