vd-plugins/Commands/index.js

9 lines
26 KiB
JavaScript
Raw Normal View History

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