vd-plugins/Commands/index.js

9 lines
25 KiB
JavaScript
Raw Normal View History

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