mirror of
https://gitlab.com/pancakes1234/wdiscordbotserver.git
synced 2025-06-16 07:14:21 -06:00
added a manual data set command because of fuckass discord API
This commit is contained in:
parent
2570f6c124
commit
9fbe200c73
152
cogs/userinfo.py
152
cogs/userinfo.py
@ -2,10 +2,142 @@ import discord
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
from typing import Optional
|
||||
import json
|
||||
import os
|
||||
|
||||
class UserInfoCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.user_data_file = "user_data.json"
|
||||
self.user_data = self._load_user_data()
|
||||
self.developer_id = 1141746562922459136 # The developer's ID
|
||||
|
||||
def _load_user_data(self):
|
||||
"""Load user data from JSON file"""
|
||||
if os.path.exists(self.user_data_file):
|
||||
try:
|
||||
with open(self.user_data_file, 'r') as f:
|
||||
return json.load(f)
|
||||
except Exception as e:
|
||||
print(f"Error loading user data: {e}")
|
||||
return {}
|
||||
return {}
|
||||
|
||||
def _save_user_data(self):
|
||||
"""Save user data to JSON file"""
|
||||
try:
|
||||
with open(self.user_data_file, 'w') as f:
|
||||
json.dump(self.user_data, f, indent=4)
|
||||
except Exception as e:
|
||||
print(f"Error saving user data: {e}")
|
||||
|
||||
@app_commands.command(name="setuser", description="Set custom data for a user")
|
||||
@app_commands.describe(
|
||||
user="The user to set data for",
|
||||
nickname="Custom nickname",
|
||||
pronouns="User's pronouns",
|
||||
bio="Short biography",
|
||||
birthday="User's birthday (YYYY-MM-DD)",
|
||||
location="User's location",
|
||||
custom_field="Name of custom field",
|
||||
custom_value="Value for custom field"
|
||||
)
|
||||
async def setuser(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
user: discord.Member,
|
||||
nickname: Optional[str] = None,
|
||||
pronouns: Optional[str] = None,
|
||||
bio: Optional[str] = None,
|
||||
birthday: Optional[str] = None,
|
||||
location: Optional[str] = None,
|
||||
custom_field: Optional[str] = None,
|
||||
custom_value: Optional[str] = None
|
||||
):
|
||||
"""Set custom data for a user - only works for the developer"""
|
||||
# Check if the command user is the developer
|
||||
if interaction.user.id != self.developer_id:
|
||||
await interaction.response.send_message("This command is only available to the bot developer.", ephemeral=True)
|
||||
return
|
||||
|
||||
# Initialize user data if not exists
|
||||
user_id = str(user.id)
|
||||
if user_id not in self.user_data:
|
||||
self.user_data[user_id] = {}
|
||||
|
||||
# Update fields if provided
|
||||
fields_updated = []
|
||||
|
||||
if nickname is not None:
|
||||
self.user_data[user_id]["nickname"] = nickname
|
||||
fields_updated.append("Nickname")
|
||||
|
||||
if pronouns is not None:
|
||||
self.user_data[user_id]["pronouns"] = pronouns
|
||||
fields_updated.append("Pronouns")
|
||||
|
||||
if bio is not None:
|
||||
self.user_data[user_id]["bio"] = bio
|
||||
fields_updated.append("Bio")
|
||||
|
||||
if birthday is not None:
|
||||
self.user_data[user_id]["birthday"] = birthday
|
||||
fields_updated.append("Birthday")
|
||||
|
||||
if location is not None:
|
||||
self.user_data[user_id]["location"] = location
|
||||
fields_updated.append("Location")
|
||||
|
||||
if custom_field is not None and custom_value is not None:
|
||||
if "custom_fields" not in self.user_data[user_id]:
|
||||
self.user_data[user_id]["custom_fields"] = {}
|
||||
self.user_data[user_id]["custom_fields"][custom_field] = custom_value
|
||||
fields_updated.append(f"Custom field '{custom_field}'")
|
||||
|
||||
# Save data
|
||||
self._save_user_data()
|
||||
|
||||
# Create response embed
|
||||
embed = discord.Embed(
|
||||
title=f"User Data Updated",
|
||||
description=f"Updated data for {user.mention}",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
|
||||
if fields_updated:
|
||||
embed.add_field(name="Fields Updated", value=", ".join(fields_updated), inline=False)
|
||||
|
||||
# Show current values
|
||||
embed.add_field(name="Current Values", value="User's current data:", inline=False)
|
||||
for field, value in self.user_data[user_id].items():
|
||||
if field != "custom_fields":
|
||||
embed.add_field(name=field.capitalize(), value=value, inline=True)
|
||||
|
||||
# Show custom fields if any
|
||||
if "custom_fields" in self.user_data[user_id] and self.user_data[user_id]["custom_fields"]:
|
||||
custom_fields_text = "\n".join([f"**{k}**: {v}" for k, v in self.user_data[user_id]["custom_fields"].items()])
|
||||
embed.add_field(name="Custom Fields", value=custom_fields_text, inline=False)
|
||||
else:
|
||||
embed.description = "No fields were updated."
|
||||
|
||||
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||
|
||||
@app_commands.command(name="clearuserdata", description="Clear custom data for a user")
|
||||
@app_commands.describe(user="The user to clear data for")
|
||||
async def clearuserdata(self, interaction: discord.Interaction, user: discord.Member):
|
||||
"""Clear all custom data for a user - only works for the developer"""
|
||||
# Check if the command user is the developer
|
||||
if interaction.user.id != self.developer_id:
|
||||
await interaction.response.send_message("This command is only available to the bot developer.", ephemeral=True)
|
||||
return
|
||||
|
||||
user_id = str(user.id)
|
||||
if user_id in self.user_data:
|
||||
del self.user_data[user_id]
|
||||
self._save_user_data()
|
||||
await interaction.response.send_message(f"All custom data for {user.mention} has been cleared.", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message(f"No custom data found for {user.mention}.", ephemeral=True)
|
||||
|
||||
@app_commands.command(name="aboutuser", description="Display info about a user or yourself.")
|
||||
@app_commands.describe(user="The user to get info about (optional)")
|
||||
@ -96,7 +228,7 @@ class UserInfoCog(commands.Cog):
|
||||
if getattr(user_flags, flag, False):
|
||||
badges.append(badge_map[flag])
|
||||
badge_str = ", ".join(badges) if badges else ""
|
||||
if member.id == 1141746562922459136:
|
||||
if member.id == self.developer_id:
|
||||
badge_str = (badge_str + ", " if badge_str else "") + "Bot Developer 🛠️"
|
||||
# Embed
|
||||
embed = discord.Embed(
|
||||
@ -133,9 +265,23 @@ class UserInfoCog(commands.Cog):
|
||||
# Nitro status (public flag)
|
||||
if user_flags and getattr(user_flags, 'premium', False):
|
||||
embed.add_field(name="Nitro", value="Yes", inline=True)
|
||||
|
||||
# Add custom user data if available
|
||||
user_id = str(member.id)
|
||||
if user_id in self.user_data:
|
||||
# Add custom data fields
|
||||
for field, value in self.user_data[user_id].items():
|
||||
if field != "custom_fields":
|
||||
embed.add_field(name=field.capitalize(), value=value, inline=True)
|
||||
|
||||
# Add custom fields if any
|
||||
if "custom_fields" in self.user_data[user_id] and self.user_data[user_id]["custom_fields"]:
|
||||
custom_fields_text = "\n".join([f"**{k}**: {v}" for k, v in self.user_data[user_id]["custom_fields"].items()])
|
||||
embed.add_field(name="Custom Fields", value=custom_fields_text, inline=False)
|
||||
|
||||
# Pronouns (if available)
|
||||
pronouns = getattr(user_obj, 'pronouns', None)
|
||||
if pronouns:
|
||||
if pronouns and user_id not in self.user_data: # Only show Discord's pronouns if we don't have custom ones
|
||||
embed.add_field(name="Pronouns", value=pronouns, inline=True)
|
||||
# Locale/language (if available)
|
||||
locale = getattr(user_obj, 'locale', None)
|
||||
@ -154,4 +300,4 @@ class UserInfoCog(commands.Cog):
|
||||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(UserInfoCog(bot))
|
||||
await bot.add_cog(UserInfoCog(bot)
|
Loading…
x
Reference in New Issue
Block a user