i have to push all changes this doesnt work on my machine
This commit is contained in:
parent
c633fd8ab7
commit
9923a4f8eb
|
@ -172,39 +172,78 @@ class DiscordDataClient(discord.Client):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error processing user {user.name}: {e}")
|
self.logger.error(f"Error processing user {user.name}: {e}")
|
||||||
|
|
||||||
async def _get_user_bio(self, user) -> Optional[str]:
|
async def get_user_bio(self, user) -> Optional[str]:
|
||||||
"""Get user bio/about me section."""
|
"""Get user bio/about me section."""
|
||||||
if not self.config.collect_bio:
|
if not self.config.collect_bio:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Multiple approaches to get bio data
|
bio = None
|
||||||
bio = None
|
|
||||||
|
|
||||||
# Method 1: Check if user object already has bio
|
# Method 1: Check if user object already has bio (for ClientUser)
|
||||||
if hasattr(user, 'bio') and user.bio:
|
if hasattr(user, 'bio') and user.bio:
|
||||||
bio = user.bio
|
bio = user.bio
|
||||||
self.logger.debug(f"Found bio via user.bio for {user.name}")
|
self.logger.debug(f"Found bio via user.bio for {user.name}")
|
||||||
|
return bio[:500] if bio else None
|
||||||
|
|
||||||
# Method 2: User clients can't fetch other user profiles (403 error)
|
# Method 2: Try to fetch user profile specifically
|
||||||
# Skip profile fetching for user clients
|
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)
|
||||||
|
|
||||||
# Method 3: Check for activities that might contain bio-like info
|
if hasattr(profile, 'bio') and profile.bio:
|
||||||
if not bio and hasattr(user, 'activities'):
|
bio = profile.bio
|
||||||
for activity in user.activities:
|
self.logger.debug(f"Found bio via profile fetch for {user.name}")
|
||||||
if hasattr(activity, 'name') and activity.name and len(activity.name) > 20:
|
elif hasattr(profile, 'display_bio') and profile.display_bio:
|
||||||
bio = f"Activity: {activity.name}"
|
bio = profile.display_bio
|
||||||
self.logger.debug(f"Using activity as bio for {user.name}: {activity.name}")
|
self.logger.debug(f"Found display_bio via profile fetch for {user.name}")
|
||||||
break
|
else:
|
||||||
|
self.logger.debug(f"No bio found in profile for {user.name}")
|
||||||
|
|
||||||
if not bio:
|
except discord.Forbidden:
|
||||||
self.logger.debug(f"No bio found for user {user.name}")
|
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}")
|
||||||
|
|
||||||
return bio[:500] if bio else None # Limit bio length
|
# 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}")
|
||||||
|
|
||||||
except Exception as e:
|
# Method 4: Fallback to activities (last resort)
|
||||||
self.logger.debug(f"Could not fetch bio for user {user.name}: {e}")
|
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
|
return None
|
||||||
|
|
||||||
def _get_user_status(self, user) -> Optional[str]:
|
def _get_user_status(self, user) -> Optional[str]:
|
||||||
|
|
Loading…
Reference in a new issue