From 9923a4f8eb45933fa0020e3b3bdd2890435f8aa7 Mon Sep 17 00:00:00 2001 From: Xargana Date: Mon, 14 Jul 2025 10:42:32 +0300 Subject: [PATCH] i have to push all changes this doesnt work on my machine --- src/client.py | 105 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/src/client.py b/src/client.py index ac67c46..3e9f243 100644 --- a/src/client.py +++ b/src/client.py @@ -172,41 +172,80 @@ class DiscordDataClient(discord.Client): except Exception as e: self.logger.error(f"Error processing user {user.name}: {e}") - async def _get_user_bio(self, user) -> Optional[str]: - """Get user bio/about me section.""" - if not self.config.collect_bio: - return None - - try: - # Multiple approaches to get bio data - bio = None - - # Method 1: Check if user object already has bio - if hasattr(user, 'bio') and user.bio: - bio = user.bio - self.logger.debug(f"Found bio via user.bio for {user.name}") - - # Method 2: User clients can't fetch other user profiles (403 error) - # Skip profile fetching for user clients - - # Method 3: Check for activities that might contain bio-like info - if not bio and hasattr(user, 'activities'): - for activity in user.activities: - if hasattr(activity, 'name') and activity.name and len(activity.name) > 20: - bio = f"Activity: {activity.name}" - self.logger.debug(f"Using activity as bio for {user.name}: {activity.name}") - break - - if not bio: - self.logger.debug(f"No bio found for user {user.name}") - - return bio[:500] if bio else None # Limit bio length - - except Exception as e: - self.logger.debug(f"Could not fetch bio for user {user.name}: {e}") - +async def get_user_bio(self, user) -> Optional[str]: + """Get user bio/about me section.""" + if not self.config.collect_bio: return None + try: + bio = None + + # Method 1: Check if user object already has bio (for ClientUser) + if hasattr(user, 'bio') and user.bio: + bio = user.bio + self.logger.debug(f"Found bio via user.bio for {user.name}") + return bio[:500] if bio else None + + # Method 2: Try to fetch user profile specifically + if hasattr(user, 'id'): + try: + # Use fetch_user_profile instead of fetch_user + # This is the key change - you need the profile endpoint + profile = await self.fetch_user_profile(user.id) + + if hasattr(profile, 'bio') and profile.bio: + bio = profile.bio + self.logger.debug(f"Found bio via profile fetch for {user.name}") + elif hasattr(profile, 'display_bio') and profile.display_bio: + bio = profile.display_bio + self.logger.debug(f"Found display_bio via profile fetch for {user.name}") + else: + self.logger.debug(f"No bio found in profile for {user.name}") + + except discord.Forbidden: + self.logger.debug(f"Access denied to profile for {user.name} - user may have privacy settings enabled") + return None + except discord.NotFound: + self.logger.debug(f"Profile not found for {user.name}") + return None + except Exception as e: + self.logger.debug(f"Profile fetch failed for {user.name}: {e}") + + # Method 3: Try member profile if in a guild context + if not bio and hasattr(user, 'guild') and user.guild: + try: + member_profile = await user.guild.fetch_member_profile(user.id) + if hasattr(member_profile, 'bio') and member_profile.bio: + bio = member_profile.bio + self.logger.debug(f"Found bio via member profile for {user.name}") + elif hasattr(member_profile, 'display_bio') and member_profile.display_bio: + bio = member_profile.display_bio + self.logger.debug(f"Found display_bio via member profile for {user.name}") + elif hasattr(member_profile, 'guild_bio') and member_profile.guild_bio: + bio = member_profile.guild_bio + self.logger.debug(f"Found guild_bio via member profile for {user.name}") + except discord.Forbidden: + self.logger.debug(f"Access denied to member profile for {user.name}") + except Exception as e: + self.logger.debug(f"Member profile fetch failed for {user.name}: {e}") + + # Method 4: Fallback to activities (last resort) + if not bio and hasattr(user, 'activities'): + for activity in user.activities: + if hasattr(activity, 'name') and activity.name and len(activity.name) > 20: + bio = f"Activity: {activity.name}" + self.logger.debug(f"Using activity as bio for {user.name}: {activity.name}") + break + + if not bio: + self.logger.debug(f"No bio found for user {user.name}") + + return bio[:500] if bio else None + + except Exception as e: + self.logger.debug(f"Could not fetch bio for user {user.name}: {e}") + return None + def _get_user_status(self, user) -> Optional[str]: """Get user status with better handling.""" if not self.config.collect_status: