sure buddy :333
This commit is contained in:
parent
ccd155e0b8
commit
8ed7e03205
2 changed files with 451 additions and 1036 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -3,75 +3,193 @@ import { findByProps } from "@vendetta/metro";
|
|||
const MessageActions = findByProps("sendMessage");
|
||||
|
||||
interface RedditPost {
|
||||
kind: string;
|
||||
data: {
|
||||
title: string;
|
||||
url: string;
|
||||
is_video: boolean;
|
||||
over_18: boolean;
|
||||
thumbnail: string;
|
||||
thumbnail_width?: number;
|
||||
thumbnail_height?: number;
|
||||
preview?: {
|
||||
images: Array<{
|
||||
source: {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
resolutions: Array<{
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}>;
|
||||
}>;
|
||||
};
|
||||
secure_media?: {
|
||||
oembed?: {
|
||||
thumbnail_url: string;
|
||||
type: string;
|
||||
};
|
||||
};
|
||||
media_embed?: {
|
||||
content: string;
|
||||
};
|
||||
url_overridden_by_dest?: string;
|
||||
domain: string;
|
||||
post_hint?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RedditResponse {
|
||||
kind: string;
|
||||
data: {
|
||||
children: RedditPost[];
|
||||
after: string;
|
||||
dist: number;
|
||||
};
|
||||
}
|
||||
|
||||
async function getFemboyImage(includeNsfw: boolean = false): Promise<string | null> {
|
||||
function isValidImageUrl(url: string): boolean {
|
||||
if (!url) return false;
|
||||
|
||||
const lowerUrl = url.toLowerCase();
|
||||
|
||||
// Check for direct image URLs
|
||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.webp'];
|
||||
if (imageExtensions.some(ext => lowerUrl.includes(ext))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Known image hosting domains
|
||||
const imageHosts = [
|
||||
'i.redd.it',
|
||||
'i.imgur.com',
|
||||
'preview.redd.it'
|
||||
];
|
||||
|
||||
return imageHosts.some(host => lowerUrl.includes(host));
|
||||
}
|
||||
|
||||
function extractImageUrl(post: RedditPost): string | null {
|
||||
const postData = post.data;
|
||||
|
||||
// Skip videos and GIFs from redgifs/etc
|
||||
if (postData.is_video || postData.domain.includes('redgifs.com') || postData.domain.includes('gfycat.com')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check post hint for image types
|
||||
if (postData.post_hint && !['image', 'hosted:video'].includes(postData.post_hint)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try the main URL first
|
||||
const mainUrl = postData.url;
|
||||
if (isValidImageUrl(mainUrl)) {
|
||||
return mainUrl;
|
||||
}
|
||||
|
||||
// Try preview images
|
||||
if (postData.preview?.images?.[0]) {
|
||||
const previewImage = postData.preview.images[0];
|
||||
|
||||
// Try source image first (highest quality)
|
||||
if (previewImage.source?.url) {
|
||||
const sourceUrl = previewImage.source.url.replace(/&/g, '&');
|
||||
if (isValidImageUrl(sourceUrl)) {
|
||||
return sourceUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// Try highest resolution preview
|
||||
if (previewImage.resolutions?.length > 0) {
|
||||
const highestRes = previewImage.resolutions[previewImage.resolutions.length - 1];
|
||||
if (highestRes?.url) {
|
||||
const resUrl = highestRes.url.replace(/&/g, '&');
|
||||
if (isValidImageUrl(resUrl)) {
|
||||
return resUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try secure_media oembed thumbnail for some cases
|
||||
if (postData.secure_media?.oembed?.thumbnail_url && postData.secure_media.oembed.type === 'photo') {
|
||||
const thumbUrl = postData.secure_media.oembed.thumbnail_url;
|
||||
if (isValidImageUrl(thumbUrl)) {
|
||||
return thumbUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// Try regular thumbnail as last resort (but only if it's not a default thumbnail)
|
||||
if (postData.thumbnail &&
|
||||
postData.thumbnail !== 'self' &&
|
||||
postData.thumbnail !== 'default' &&
|
||||
postData.thumbnail !== 'nsfw' &&
|
||||
postData.thumbnail.startsWith('http')) {
|
||||
if (isValidImageUrl(postData.thumbnail)) {
|
||||
return postData.thumbnail;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async function getFemboyImage(includeNsfw: boolean = false): Promise<{ url: string; isNsfw: boolean; title: string } | null> {
|
||||
try {
|
||||
const response = await fetch('https://reddit.com/r/femboys.json');
|
||||
console.log(`[LoveFemboys] Fetching images, includeNsfw: ${includeNsfw}`);
|
||||
|
||||
// Fetch more posts to increase chances of finding images
|
||||
const response = await fetch('https://reddit.com/r/femboys.json?limit=100&raw_json=1');
|
||||
if (!response.ok) {
|
||||
console.log('[LoveFemboys] Failed to fetch from Reddit API');
|
||||
console.log('[LoveFemboys] Failed to fetch from Reddit API:', response.status, response.statusText);
|
||||
return null;
|
||||
}
|
||||
|
||||
const data: RedditResponse = await response.json();
|
||||
console.log(`[LoveFemboys] Fetched ${data.data.children.length} posts`);
|
||||
|
||||
// Filter posts that are images and match NSFW preference
|
||||
const imagePosts = data.data.children.filter(post => {
|
||||
const validPosts = [];
|
||||
|
||||
for (const post of data.data.children) {
|
||||
const postData = post.data;
|
||||
|
||||
// Skip videos
|
||||
if (postData.is_video) return false;
|
||||
console.log(`[LoveFemboys] Checking post: "${postData.title}" (NSFW: ${postData.over_18}, Domain: ${postData.domain})`);
|
||||
|
||||
// Check NSFW filter
|
||||
if (!includeNsfw && postData.over_18) return false;
|
||||
// Filter by NSFW preference first
|
||||
if (!includeNsfw && postData.over_18) {
|
||||
console.log(`[LoveFemboys] Skipping NSFW post: ${postData.title}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if it's an image URL
|
||||
const url = postData.url_overridden_by_dest || postData.url;
|
||||
return url && (
|
||||
url.includes('.jpg') ||
|
||||
url.includes('.jpeg') ||
|
||||
url.includes('.png') ||
|
||||
url.includes('.gif') ||
|
||||
url.includes('i.redd.it') ||
|
||||
url.includes('i.imgur.com')
|
||||
);
|
||||
});
|
||||
// Try to extract image URL
|
||||
const imageUrl = extractImageUrl(post);
|
||||
if (imageUrl) {
|
||||
console.log(`[LoveFemboys] Found valid image: ${imageUrl}`);
|
||||
validPosts.push({
|
||||
url: imageUrl,
|
||||
isNsfw: postData.over_18,
|
||||
title: postData.title
|
||||
});
|
||||
} else {
|
||||
console.log(`[LoveFemboys] No valid image URL found for: ${postData.title}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (imagePosts.length === 0) {
|
||||
console.log(`[LoveFemboys] Found ${validPosts.length} valid image posts (includeNsfw: ${includeNsfw})`);
|
||||
|
||||
if (validPosts.length === 0) {
|
||||
console.log('[LoveFemboys] No suitable images found');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get random image
|
||||
const randomPost = imagePosts[Math.floor(Math.random() * imagePosts.length)];
|
||||
const imageUrl = randomPost.data.url_overridden_by_dest || randomPost.data.url;
|
||||
const randomPost = validPosts[Math.floor(Math.random() * validPosts.length)];
|
||||
console.log(`[LoveFemboys] Selected: ${randomPost.title} - ${randomPost.url}`);
|
||||
|
||||
// Handle Reddit preview images
|
||||
if (imageUrl.includes('reddit.com') && randomPost.data.preview?.images?.[0]?.source?.url) {
|
||||
return randomPost.data.preview.images[0].source.url.replace(/&/g, '&');
|
||||
}
|
||||
|
||||
return imageUrl;
|
||||
return randomPost;
|
||||
} catch (error) {
|
||||
console.error('[LoveFemboys] Error fetching image:', error);
|
||||
return null;
|
||||
|
|
@ -106,10 +224,14 @@ export const lovefemboysCommand = {
|
|||
const includeNsfw = args.find((arg: any) => arg.name === "nsfw")?.value || false;
|
||||
const isEphemeral = args.find((arg: any) => arg.name === "ephemeral")?.value || false;
|
||||
|
||||
const imageUrl = await getFemboyImage(includeNsfw);
|
||||
console.log(`[LoveFemboys] Command executed with nsfw: ${includeNsfw}, ephemeral: ${isEphemeral}`);
|
||||
|
||||
const result = await getFemboyImage(includeNsfw);
|
||||
|
||||
if (!imageUrl) {
|
||||
const errorMessage = "❌ Failed to fetch femboy image. Try again later!";
|
||||
if (!result) {
|
||||
const errorMessage = includeNsfw
|
||||
? "❌ Failed to fetch femboy image. Reddit might be having issues or no images available."
|
||||
: "❌ No SFW femboy images found. Try with `nsfw:true` or try again later.";
|
||||
|
||||
if (isEphemeral) {
|
||||
return {
|
||||
|
|
@ -128,7 +250,9 @@ export const lovefemboysCommand = {
|
|||
}
|
||||
}
|
||||
|
||||
const content = `💖 **Femboy Image** ${includeNsfw ? '(NSFW included)' : '(SFW only)'}\n${imageUrl}`;
|
||||
const nsfwTag = result.isNsfw ? " 🔞" : " ✅";
|
||||
const modeTag = includeNsfw ? " (NSFW allowed)" : " (SFW only)";
|
||||
const content = `💖 **Femboy Image**${nsfwTag}${modeTag}\n*${result.title}*\n${result.url}`;
|
||||
|
||||
if (isEphemeral) {
|
||||
return {
|
||||
|
|
@ -147,7 +271,7 @@ export const lovefemboysCommand = {
|
|||
}
|
||||
} catch (error) {
|
||||
console.error('[LoveFemboys] Command error:', error);
|
||||
const errorMessage = "❌ An error occurred while fetching femboy image.";
|
||||
const errorMessage = "❌ An error occurred while fetching femboy image. Check console for details.";
|
||||
|
||||
const isEphemeral = args.find((arg: any) => arg.name === "ephemeral")?.value || false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue