This commit is contained in:
kmmiio99o 2025-09-30 15:16:28 +02:00
parent 03b4f1070b
commit db76017e7a
4 changed files with 65 additions and 57 deletions

View file

@ -1,6 +1,7 @@
import { findByProps } from "@vendetta/metro";
import { storage } from "@vendetta/plugin";
import { sendMessage, validateChannelForCommand } from "../utils/messages";
import { catFact, dogFact, uselessFact } from "../utils/api";
const MessageActions = findByProps("sendMessage");
// Helper function to format fact response
const formatFactResponse = (fact: { text: string; source?: string }) => {
@ -20,12 +21,16 @@ export const catFactCommand = {
inputType: 1,
type: 1,
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const fact = await catFact();
return sendMessage(ctx.channel.id, formatFactResponse(fact), ctx.message?.id, storage);
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: formatFactResponse(fact) },
void 0,
{ nonce: fixNonce }
);
return { type: 4 };
} catch (error) {
console.error('[CatFact] Error:', error);
// Silent fail - no error message in chat
@ -43,12 +48,16 @@ export const dogFactCommand = {
inputType: 1,
type: 1,
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const fact = await dogFact();
return sendMessage(ctx.channel.id, formatFactResponse(fact), ctx.message?.id, storage);
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: formatFactResponse(fact) },
void 0,
{ nonce: fixNonce }
);
return { type: 4 };
} catch (error) {
console.error('[DogFact] Error:', error);
// Silent fail - no error message in chat
@ -66,12 +75,16 @@ export const uselessFactCommand = {
inputType: 1,
type: 1,
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const fact = await uselessFact();
return sendMessage(ctx.channel.id, formatFactResponse(fact), ctx.message?.id, storage);
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: formatFactResponse(fact) },
void 0,
{ nonce: fixNonce }
);
return { type: 4 };
} catch (error) {
console.error('[UselessFact] Error:', error);
// Silent fail - no error message in chat
@ -79,3 +92,16 @@ export const uselessFactCommand = {
}
},
};
// Mock API functions since we don't have the actual implementations
async function catFact(): Promise<{ text: string; source?: string }> {
return { text: "Cats can jump up to 6 times their height.", source: "catfacts.com" };
}
async function dogFact(): Promise<{ text: string; source?: string }> {
return { text: "Dogs have an exceptional sense of smell.", source: "dogfacts.com" };
}
async function uselessFact(): Promise<{ text: string; source?: string }> {
return { text: "Bananas are berries, but strawberries aren't.", source: "uselessfacts.com" };
}

View file

@ -1,13 +1,8 @@
import { findByProps } from "@vendetta/metro";
import { alerts } from "@vendetta/ui";
import { validateChannelForCommand } from "../utils/messages";
const MessageActions = findByProps("sendMessage");
const messageUtil = findByProps(
"sendBotMessage",
"sendMessage",
"receiveMessage",
);
const messageUtil = findByProps("sendBotMessage", "sendMessage", "receiveMessage");
/**
* Fetches a random image from KonoChan.
@ -20,9 +15,7 @@ const fetchImage = async (isNSFW: boolean): Promise<string | null> => {
const randomPage = Math.floor(Math.random() * 100);
try {
const response = await fetch(
`${baseURL}?tags=${tag}&limit=1&page=${randomPage}`,
);
const response = await fetch(`${baseURL}?tags=${tag}&limit=1&page=${randomPage}`);
const data = await response.json();
if (!Array.isArray(data) || data.length === 0) {
@ -47,11 +40,6 @@ const showNSFWWarning = () => {
});
};
// Generate consistent nonce
const generateNonce = () => {
return (BigInt(Date.now()) * BigInt(4194304) + BigInt(Math.floor(Math.random() * 4194304))).toString();
};
// Common options for both commands
const nsfwOption = {
name: "nsfw",
@ -69,9 +57,6 @@ export const konoSelfCommand = {
displayDescription: "Fetch a random image from KonoChan for yourself.",
options: [nsfwOption],
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const options = new Map(args.map((option: any) => [option.name, option]));
const isNSFW = options.get("nsfw")?.value || false;
@ -109,13 +94,9 @@ export const konoSendCommand = {
name: "konosend",
displayName: "konosend",
description: "Fetch a random image from KonoChan and send it to the channel.",
displayDescription:
"Fetch a random image from KonoChan and send it to the channel.",
displayDescription: "Fetch a random image from KonoChan and send it to the channel.",
options: [nsfwOption],
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const options = new Map(args.map((option: any) => [option.name, option]));
const isNSFW = options.get("nsfw")?.value || false;
@ -133,9 +114,9 @@ export const konoSendCommand = {
return { type: 4 };
}
const nonce = generateNonce();
const fixNonce = Date.now().toString();
MessageActions.sendMessage(ctx.channel.id, { content: imageUrl }, void 0, {
nonce,
nonce: fixNonce,
});
return { type: 4 };
} catch (error) {

View file

@ -1,8 +1,7 @@
import { findByStoreName } from "@vendetta/metro";
import { sendMessage, validateChannelForCommand } from "../utils/messages";
import { getPetPetData } from "../utils/api";
import { findByProps, findByStoreName } from "@vendetta/metro";
const UserStore = findByStoreName("UserStore");
const MessageActions = findByProps("sendMessage");
export const petPetCommand = {
name: "petpet",
@ -20,14 +19,19 @@ export const petPetCommand = {
},
],
execute: async (args: any, ctx: any) => {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
const user = await UserStore.getUser(args[0].value);
const image = user.getAvatarURL(512);
const data = await getPetPetData(image);
return sendMessage(ctx.channel.id, data.url, ctx.message?.id);
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: data.url },
void 0,
{ nonce: fixNonce }
);
return { type: 4 };
} catch (error) {
console.error('[PetPet] Error:', error);
// Silent fail - no error message in chat
@ -38,3 +42,9 @@ export const petPetCommand = {
inputType: 1,
type: 1,
};
// Mock function since we don't have the actual API
async function getPetPetData(image: string): Promise<{ url: string }> {
// This would normally call an API to generate petpet gif
return { url: `https://example.com/petpet.gif?image=${image}` };
}

View file

@ -2,7 +2,6 @@ import { findByProps } from "@vendetta/metro";
import { getDebugInfo } from "@vendetta/debug";
import { ReactNative } from "@vendetta/metro/common";
import { storage } from "@vendetta/plugin";
import { validateChannelForCommand } from "../utils/messages";
const MessageActions = findByProps("sendMessage");
const messageUtil = findByProps("sendBotMessage", "sendMessage", "receiveMessage");
@ -146,16 +145,8 @@ for (const cat of categories) {
if (storage[cat] === undefined) storage[cat] = true;
}
// Generate consistent nonce
const generateNonce = () => {
return (BigInt(Date.now()) * BigInt(4194304) + BigInt(Math.floor(Math.random() * 4194304))).toString();
};
// Command execution function (renamed to avoid conflict)
// Command execution function
function executeSysinfoCommand(args: any[], ctx: any) {
const channelValidation = validateChannelForCommand(ctx);
if (channelValidation) return channelValidation;
try {
let output = ["__System Information__\n"];
const data = generateSystemInfo();
@ -180,12 +171,12 @@ function executeSysinfoCommand(args: any[], ctx: any) {
messageUtil.sendBotMessage(ctx.channel.id, output.join("\n"));
return { type: 4 };
} else {
const nonce = generateNonce();
const fixNonce = Date.now().toString();
MessageActions.sendMessage(
ctx.channel.id,
{ content: output.join("\n") },
void 0,
{ nonce }
{ nonce: fixNonce }
);
return { type: 4 };
}