vd-plugins/Commands/index.js

9 lines
26 KiB
JavaScript
Raw Normal View History

(function(P,se,s,f,L,b,A,o,re,oe,ie){"use strict";const ce=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}},le=async function(){return{text:(await(await fetch("https://dogapi.dog/api/v2/facts?limit=1")).json()).data[0].attributes.body}},de=async function(){const t=await(await fetch("https://catfact.ninja/fact")).json();return{text:t.fact,length:t.length}},ue=async function(t){return await(await fetch(`https://api.obamabot.me/v2/image/petpet?image=${t.replace("webp","png")}`)).json()},ye=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(a){return console.error(`[Gary API] Error fetching image from ${t}:`,a),null}},B=f.findByProps("sendMessage"),U=function(t){let a=t.text;return s.storage.factSettings?.includeCitation&&t.source&&(a+=`
2025-09-27 19:17:53 +02:00
Source: ${t.source}`),a},pe={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,a){try{const e=await de(),r=Date.now().toString();return B.sendMessage(a.channel.id,{content:U(e)},void 0,{nonce:r}),{type:4}}catch(e){return console.error("[CatFact] Error:",e),{type:4}}}},fe={name:"dogfact",displayName:"dogfact",description:"Sends a dog fact.",displayDescription:"Sends a dog fact.",applicationId:"-1",inputType:1,type:1,execute:async function(t,a){try{const e=await le(),r=Date.now().toString();return B.sendMessage(a.channel.id,{content:U(e)},void 0,{nonce:r}),{type:4}}catch(e){return console.error("[DogFact] Error:",e),{type:4}}}},me={name:"useless",displayName:"useless",description:"Sends a useless fact.",displayDescription:"Sends a useless fact.",applicationId:"-1",inputType:1,type:1,execute:async function(t,a){try{const e=await ce(),r=Date.now().toString();return B.sendMessage(a.channel.id,{content:U(e)},void 0,{nonce:r}),{type:4}}catch(e){return console.error("[UselessFact] Error:",e),{type:4}}}},w={CONTENT:"This list is over 2000 characters. Send anyway?",CONFIRM:"Send",CANCEL:"Cancel"},ge={DETAILED:"detailed"},O="",D={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."},x={SEMICOL:"; ",NEW_LINE:`
`},he="Nothing to see here, huh...",j="github.com/fres621/vendetta-plugins",C={ENABLED:"\u2705",DISABLED:"\u274C",SELECTED:"\u2705",NOT_SELECTED:"\u274C"},be=f.findByProps("sendMessage","receiveMessage"),S=f.findByProps("sendBotMessage"),V=function(){try{return f.findByStoreName("UserStore").getCurrentUser()?.premiumType===2?4e3:2e3}catch{return 2e3}}(),G=function(t){return Object.keys(t).includes(j)},F=function(t){return Object.values(t).find(function(a){return a.id==j})?.enabled},K=function(t){return t.find(function(a){return a.name===ge.DETAILED})?.value??!1},N=function(t){return!t||!Array.isArray(t)||t.length===0?"Unknown":t.filter(function(a){return a&&(typeof a=="string"||typeof a=="object"&&a.name)}).map(function(a){return typeof a=="string"?a:a.name||"Unknown"}).join(x.SEMICOL)||"Unknown"},W=function(t){return t.join(x.NEW_LINE).trimEnd()},k=function(t){return W(t).length},$=async function(t,a){const e=Date.now().toString();await be.sendMessage(t,{content:W(a)},void 0,{nonce:e})},q=function(t,a){return[`**My ${t} List | ${a} ${t}s**`,O]};async function Ce(t,a){try{const e=K(t),r=s.storage.themeListAlwaysDetailed??!1;if(!L.themes||typeof L.themes!="object"){const p=a.channel.id;return S.sendBotMessage(p,"No themes found or themes not loaded yet."),{type:4}}const n=Object.values(L.themes),c=a.channel.id,i=q("Theme",Object.keys(L.themes).length);if(n.length)for(const p of n){if(!p||typeof p!="object")continue;const{selected:l,data:d,id:m}=p,E=d?.name||"Unknown Theme",v=d?.description||"No description",I=d?.authors;e||r?i.push(`> **Name**: ${E}`,`> **Selected**: ${l?C.SELECTED:C.NOT_SELECTED}`,`> **Description**: ${v}`,`> **Authors**: ${N(I)}`,`> **[Install!](${m||"unknown"})**`,O):i.push(`> ${l?C.SELECTED:C.NOT_SELECTED} **${E}** by ${N(I)}`)}else i.push(he);const y=k(i)>V;if(y&&!G(b.plugins))S.sendBotMessage(c,D.SLM_NOT_INSTALLED);else if(y&&!F(b.plugins))S.sendBotMessage(c,D.SLM_NOT_ENABLED);else{if(k(i)>2e3)return A.alerts.showConfirmationAlert({content:w.CONTENT,confirmText:w.CONFIRM,cancelText:w.CANCEL,onConfirm:async function(){return await $(c,i)}});await $(c,i)}}catch(e){return console.error("[ThemeList] Error:",e),{type:4}}}async function we(t,a){try{const e=K(t),r=s.storage.pluginListAlwaysDetailed??!1,n=a.channel.id;if(!b.plugins||typeof b.plugins!="object")return S.sendBotMessage(n,"No plugins found or plugins not loaded yet."),{type:4};const c=q("Plugin",Object.keys(b.plugins).length);for(const y of Object.values(b.plugins)){if(!y||typeof y!="object")continue;const{enabled:p,manifest:l,id:d}=y,m=l?.name||"Unknown Plugin",E=l?.description||"No description",v=l?.authors;e||r?c.push(`> **Name**: ${m}`,`> **Status**: ${p?C.ENABLED:C.DISABLED}`,`> **Description**: ${E}`,`> **Authors**: ${N(v)}`,`> **[Install!](${d||"unknown"})**`,O):c.push(`> ${p?C.ENABLED:C.DISABLED} **${m}** by ${N(v)}`)}const i=k(c)>V;if(i&&!G(b.plugins))S.sendBotMessage(n,D.SLM_NOT_INSTALLED);else if(i&&!F(b.plugins))S.sendBotMessage(n,D.SLM_NOT_ENABLED);else{if(k(c)>2e3)return A.alerts.showConfirmationAlert({content:w.CONTENT,confirmText:w.CONFIRM,cancelText:w.CANCEL,onConfirm:async function(){return await $(n,c)}});await $(n,c)}}catch(e){return console.error("[PluginList] Error:",e),{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:we,applicationId:"-1",inputType:1,type:1},Ee={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:Ce,applicationId:"-1",inputType:1,type:1
`];const r=Oe();Object.keys(r).forEach(function(i){const y=s.storage[i.toLowerCase()],p=t.find(function(l){return l.name==i.toLowerCase()})?.value??y;(p||y)&&!(y&&!p)&&(e.push(`[**${i}**]`),Object.keys(r[i]).forEach(function(l){e.push(`> ${l}: ${r[i][l]}`)}))});const n=s.storage.ephemeral,c=t.find(function(i){return i.name=="ephemeral"})?.value??n;if((c||n)&&!(n&&!c))return Me.sendBotMessage(a.channel.id,e.join(`
`)),{type:4};{const i=Date.now().toString();return Ie.sendMessage(a.channel.id,{content:e.join(`
`)},void 0,{nonce:i}),{type:4}}}catch(e){return console.error("[Sysinfo] Error:",e),{type:4}}}const xe={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},...J.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:_e,applicationId:"-1",inputType:1,type:1},Q=f.findByProps("sendMessage","receiveMessage"),je=f.findByStoreName("SpotifyStore");async function Ve(t,a){return s.storage.enabledCommands?.spotifyTrack?R(a,function(e){return`https://open.spotify.com/track/${e.id}`}):{type:4}}async function Ge(t,a){return s.storage.enabledCommands?.spotifyAlbum?R(a,function(e){return`https://open.spotify.com/album/${e.album.id}`}):{type:4}}async function Fe(t,a){return s.storage.enabledCommands?.spotifyArtists?R(a,function(e){return e.artists.map(function(r){return`[${r.name}](${r.external_urls.spotify})`}).join(`
`)}):{type:4}}async function Ke(t,a){return s.storage.enabledCommands?.spotifyCover?R(a,function(e){return e.album.image.url}):{type:4}}async function R(t,a){try{const e=t.channel.id,r=je?.getTrack?.();if(!r){const i=Date.now().toString();return Q.sendMessage(e,{content:"You are not listening to any track."},void 0,{nonce:i}),{type:4}}const n=a(r),c=Date.now().toString();return Q.sendMessage(e,{content:n},void 0,{nonce:c}),{type:4}}catch(e){return console.error("[Spotify Command] Error:",e),{type:4}}}const We={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:Ve},qe={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:Ge},He={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:Fe},Ye={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:Ke},ze=f.findByProps("sendMessage"),Xe={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,a){try{let e="gary";s.storage.garySettings?.useCatAPI?e="catapi":s.storage.garySettings?.useMinkerAPI?e="minker":s.storage.garySettings?.useGooberAPI&&(e="goober");const r=await ye(e);if(!r)return{type:4};const n=Date.now().toString();return ze.sendMessage(a.channel.id,{content:r},void 0,{nonce:n}),{type:4}}catch(e){return console.error("[Gary] Error:",e),{type:4}}},applicationId:"-1",inputType:1,type:1},{ScrollView:Ze}=f.findByProps("ScrollView"),{TableRowGroup:g,TableSwitchRow:u,Stack:Je,TableRow:h}=f.findByProps("TableSwitchRow","TableRowGroup","Stack","TableRow");s.storage.factSettings||(s.storage.factSettings={sendAsReply:!0,includeCitation:!1}),s.storage.listSettings||(s.storage.listSettings={pluginListAlwaysDetailed:!1,themeListAlwaysDetailed:!1}),s.storage.garySettings||(s.storage.garySettings={useGaryAPI:!0,useCatAPI:!1,useMinkerAPI:!1,useGooberAPI:!1}),s.storage.enabledCommands||(s.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}),s.storage.pendingRestart||(s.storage.pendingRestart=!1);function Qe(){oe.useProxy(s.storage);const[t,a]=o.React.useReducer(function(n){return n+1},0);o.React.useEffect(function(){return function(){s.storage.pendingRestart&&(s.storage.pendingRestart=!1,A.alerts.showConfirmationAlert({title:"Restart Required",content:"You have made changes to commands. Please restart Discord to apply these changes.",confirmText:"Okay",cancelText:null}))}},[]);const e=function(n,c){s.storage.enabledCommands[n]=c,s.storage.pendingRestart=!0,a()},r=function(n,c){c&&(s.storage.garySettings.useGaryAPI=n==="gary",s.storage.garySettings.useCatAPI=n==="catapi",s.storage.garySettings.useMinkerAPI=n==="minker",s.storage.garySettings.useGooberAPI=n==="goober"),a()};return o.React.createElement(ie.View,{style:{flex:1}},o.React.createElement(Ze,{style:{flex:1},contentContainerStyle:{paddingBottom:38}},o.React.createElement(Je,{spacing:8},o.React.createElement(g,{title:"Facts Commands"},o.React.createElement(u,{label:"Send as Reply",subLabel:"Send facts as a reply to the command message",value:s.storage.factSettings?.sendAsReply??!0,onValueChange:function(n){s.storage.factSettings.sendAsReply=n,a()}}),o.React.createElement(u,{label:"Include Source Citation",subLabel:"Include the source of facts when available",value:s.storage.factSettings?.includeCitation??!1,onValueChange:function(n){s.storage.factSettings.includeCitatio