tech/game

21/07/27 ROBLOX httpservice 활용하여 http get/post이용 잔디 웹훅연결

tech-lover 2021. 7. 27. 23:32

-- ServerScriptService

 

```

-- RoHook Created By LuaScape

 

local HTTP = game:GetService("HttpService")

local webhookurl = "잔디 Webhook(incoming) URL 주소" -- This can be found by going into your discord server settings then going to integrations then going to webhooks

 

local function SendReport(player)

    

    -- local character = player.Character

    -- local hmndrootpart = character:FindFirstChild("HumanoidRootPart")

 

    local data = {

        ["body"] = "[[Alert]](http://url_to_text) 새로운 방문자가 들어왔습니다.",

        ["connectColor"] = "#FAC11B",

        ["connectInfo"] = {{

                ["title"] = player.Name,

                ["description"] = "play started"

            },

            {

                ["title"] = 'Location',

                ["description"] = "Empire State Building, 5th Ave, New York",

                ["imageUrl"] = "http://url_to_text"

            }

        }

    }

        

 

    local response = HTTP:RequestAsync(

        {

            Url = webhookurl,  -- This website helps debug HTTP requests

            Method = "POST",

            Headers = {

                ["Accept"] = "application/vnd.tosslab.jandi-v2+json",

                ["Content-Type"] = "application/json"  -- When sending JSON, set this!

            },

            Body = HTTP:JSONEncode(data)

        }

    )

 

    -- Inspect the response table

    if response.Success then

        print("Status code:", response.StatusCode, response.StatusMessage)

        print("Response body:\n", response.Body)

    else

        print("The request failed:", response.StatusCode, response.StatusMessage)

    end

end



-- This is just an EXAMPLE you should not log everytime a player joins

game.Players.PlayerAdded:Connect(function(player)

    wait(5)

    SendReport(player)

end)

```

 

-- jandi message screen capture

 

References

- https://support.jandi.com/hc/ko/articles/210952203-%EC%9E%94%EB%94%94-%EC%BB%A4%EB%84%A5%ED%8A%B8-%EC%9D%B8%EC%BB%A4%EB%B0%8D-%EC%9B%B9%ED%9B%85-Incoming-Webhook-%EC%9C%BC%EB%A1%9C-%EC%99%B8%EB%B6%80-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%A5%BC-%EC%9E%94%EB%94%94-%EB%A9%94%EC%8B%9C%EC%A7%80%EB%A1%9C-%EC%88%98%EC%8B%A0%ED%95%98%EA%B8%B0

 

잔디 커넥트 인커밍 웹훅(Incoming Webhook)으로 외부 데이터를 잔디 메시지로 수신하기

Webhook이란? 웹훅(Webhook)이란 잔디에 잔디가 정한 포맷에 일치하는 데이터를 수신하여 지정된 대화에 메시지 형태로 전송해주는 기능을 말합니다. 현재 잔디 커넥트에서 지원하지 않고 있는 서비

support.jandi.com

- https://developer.roblox.com/en-us/api-reference/function/HttpService/RequestAsync

 

HttpService:RequestAsync

This Platform uses cookies to offer you a better experience, to personalize content, to provide social media features and to analyse the traffic on our site. For further information, including information on how to prevent or manage the use of cookies on t

developer.roblox.com

 

- How To Send Information To Discord Webhooks From Roblox

https://youtu.be/KNR0DwNxCQ4

 

-- discord webhook lua script (discord windows 설치 오류 빈번하여 잔디 webhook 사용으로 변경)

-- discord webhook example

```

-- RoHook Created By LuaScape

 

local HTTP = game:GetService("HttpService")

 

local webhookurl = "URL HERE" -- This can be found by going into your discord server settings then going to integrations then going to webhooks

 

local function SendReport(playerreason)

    local data = {

        ["embeds"] = {{

 

            ["author"] = {

                ["name"] = player.Name,

                ["icon_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&username="..player.Name

            },

            ["description"] = "Kicked For: " .. reason,

            ["color"] = tonumber(0xFFFAFA),

            ["fields"] = {

                {

                    ["name"] = "Account Age:",

                    ["value"] = player.AccountAge,

                    ["inline"] = true

                },

                {

                    ["name"] = "User ID:",

                    ["value"] = player.UserId,

                    ["inline"] = true

                }

            }

        }},

 

    }

    local finaldata = HTTP:JSONEncode(data)

    HTTP:PostAsync(webhookurl, finaldata)

end

 

--[[

This is just an EXAMPLE you should not log everytime a player joins

game.Players.PlayerAdded:Connect(function(p)

    wait(5)

    SendReport(p, "Doing Bad Stuff")

end)]]

```