DNS server (add NS record)
This commit is contained in:
@@ -2,16 +2,11 @@ use serenity::async_trait;
|
||||
use serenity::all::*;
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub struct DiscordBot {
|
||||
pub pool: PgPool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DomainRegistration {
|
||||
pub id: i32,
|
||||
pub domain_name: String,
|
||||
pub tld: String,
|
||||
pub ip: String,
|
||||
pub user_id: i32,
|
||||
pub username: String,
|
||||
}
|
||||
@@ -40,31 +35,61 @@ impl EventHandler for BotHandler {
|
||||
}
|
||||
};
|
||||
|
||||
// Update domain status to approved
|
||||
match sqlx::query("UPDATE domains SET status = 'approved' WHERE id = $1")
|
||||
.bind(domain_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("✅ Domain approved!")
|
||||
.ephemeral(true)
|
||||
);
|
||||
|
||||
if let Err(e) = component.create_response(&ctx.http, response).await {
|
||||
log::error!("Error responding to interaction: {}", e);
|
||||
// Get domain info for the updated embed
|
||||
let domain: Option<(String, String, String)> = sqlx::query_as(
|
||||
"SELECT d.name, d.tld, u.username FROM domains d JOIN users u ON d.user_id = u.id WHERE d.id = $1"
|
||||
)
|
||||
.bind(domain_id)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
if let Some((name, tld, username)) = domain {
|
||||
// Update domain status to approved
|
||||
match sqlx::query("UPDATE domains SET status = 'approved' WHERE id = $1")
|
||||
.bind(domain_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
// First, send ephemeral confirmation
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("✅ Domain approved!")
|
||||
.ephemeral(true)
|
||||
);
|
||||
|
||||
if let Err(e) = component.create_response(&ctx.http, response).await {
|
||||
log::error!("Error responding to interaction: {}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then edit the original message with green color and no buttons
|
||||
let updated_embed = CreateEmbed::new()
|
||||
.title("✅ Domain Registration - APPROVED")
|
||||
.field("Domain", format!("{}.{}", name, tld), true)
|
||||
.field("User", username, true)
|
||||
.field("Status", "Approved", true)
|
||||
.color(0x00ff00); // Green color
|
||||
|
||||
let edit_message = EditMessage::new()
|
||||
.embed(updated_embed)
|
||||
.components(vec![]); // Remove buttons
|
||||
|
||||
let mut message = component.message.clone();
|
||||
if let Err(e) = message.edit(&ctx.http, edit_message).await {
|
||||
log::error!("Error updating original message: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error approving domain: {}", e);
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Error approving domain")
|
||||
.ephemeral(true)
|
||||
);
|
||||
let _ = component.create_response(&ctx.http, response).await;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error approving domain: {}", e);
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Error approving domain")
|
||||
.ephemeral(true)
|
||||
);
|
||||
let _ = component.create_response(&ctx.http, response).await;
|
||||
}
|
||||
}
|
||||
} else if custom_id.starts_with("deny_") {
|
||||
@@ -116,32 +141,66 @@ impl EventHandler for BotHandler {
|
||||
})
|
||||
.unwrap_or("No reason provided");
|
||||
|
||||
// Update domain status to denied with reason
|
||||
match sqlx::query("UPDATE domains SET status = 'denied', denial_reason = $1 WHERE id = $2")
|
||||
.bind(reason)
|
||||
.bind(domain_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Domain denied!")
|
||||
.ephemeral(true)
|
||||
);
|
||||
|
||||
if let Err(e) = modal_submit.create_response(&ctx.http, response).await {
|
||||
log::error!("Error responding to modal: {}", e);
|
||||
// Get domain info for the updated embed
|
||||
let domain: Option<(String, String, String)> = sqlx::query_as(
|
||||
"SELECT d.name, d.tld, u.username FROM domains d JOIN users u ON d.user_id = u.id WHERE d.id = $1"
|
||||
)
|
||||
.bind(domain_id)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.unwrap_or(None);
|
||||
|
||||
if let Some((name, tld, username)) = domain {
|
||||
// Update domain status to denied with reason
|
||||
match sqlx::query("UPDATE domains SET status = 'denied', denial_reason = $1 WHERE id = $2")
|
||||
.bind(reason)
|
||||
.bind(domain_id)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
// First, send ephemeral confirmation
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Domain denied!")
|
||||
.ephemeral(true)
|
||||
);
|
||||
|
||||
if let Err(e) = modal_submit.create_response(&ctx.http, response).await {
|
||||
log::error!("Error responding to modal: {}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then edit the original message with red color and no buttons
|
||||
let updated_embed = CreateEmbed::new()
|
||||
.title("❌ Domain Registration - DENIED")
|
||||
.field("Domain", format!("{}.{}", name, tld), true)
|
||||
.field("User", username, true)
|
||||
.field("Status", "Denied", true)
|
||||
.field("Reason", reason, false)
|
||||
.color(0xff0000); // Red color
|
||||
|
||||
let edit_message = EditMessage::new()
|
||||
.embed(updated_embed)
|
||||
.components(vec![]); // Remove buttons
|
||||
|
||||
if let Some(mut message) = modal_submit.message.clone() {
|
||||
if let Err(e) = message.edit(&ctx.http, edit_message).await {
|
||||
log::error!("Error updating original message: {}", e);
|
||||
}
|
||||
} else {
|
||||
log::error!("Original message not found for editing");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error denying domain: {}", e);
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Error denying domain")
|
||||
.ephemeral(true)
|
||||
);
|
||||
let _ = modal_submit.create_response(&ctx.http, response).await;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error denying domain: {}", e);
|
||||
let response = CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content("❌ Error denying domain")
|
||||
.ephemeral(true)
|
||||
);
|
||||
let _ = modal_submit.create_response(&ctx.http, response).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,12 +221,12 @@ pub async fn send_domain_approval_request(
|
||||
let http = serenity::http::Http::new(bot_token);
|
||||
|
||||
let embed = CreateEmbed::new()
|
||||
.title("New Domain Registration")
|
||||
.title("Domain request")
|
||||
.field("Domain", format!("{}.{}", registration.domain_name, registration.tld), true)
|
||||
.field("IP", ®istration.ip, true)
|
||||
.field("User", ®istration.username, true)
|
||||
.field("User ID", registration.user_id.to_string(), true)
|
||||
.color(0x00ff00);
|
||||
.field("Status", "Pending Review", true)
|
||||
.color(0x808080); // Gray color for pending
|
||||
|
||||
let approve_button = CreateButton::new(format!("approve_{}", registration.id))
|
||||
.style(ButtonStyle::Success)
|
||||
|
||||
Reference in New Issue
Block a user