-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.lua
More file actions
176 lines (156 loc) · 6.07 KB
/
webhook.lua
File metadata and controls
176 lines (156 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
local httpRequest =
(syn and syn.request) or
(http and http.request) or
(http_request) or
(fluxus and fluxus.request) or
(request)
if not httpRequest then
warn("[WARN] HTTP Support not found.")
return
end
local player = game.Players.LocalPlayer
local httpService = game:GetService("HttpService")
local runService = game:GetService("RunService")
local fallbackImage = "https://static.wikia.nocookie.net/bgs-infinity/images/6/67/Playtime_Icon.png/revision/latest/scale-to-width-down/100?cb=20250502035843"
local recentFrames = {}
local function isRecentFrame(frame)
local id = tostring(frame)
if recentFrames[id] and tick() - recentFrames[id] < 5 then
return true
end
recentFrames[id] = tick()
return false
end
local function sendWebhook(name, rarity, shiny, chance)
if not getgenv().Config.Webhook_enabled then
return
end
if chance and not string.find(chance, " in ", 1, true) then
return
end
local rarityLower = (rarity and rarity:lower()) or ""
local time = os.time()
local totalHatches = "N/A"
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local hatches = leaderstats:FindFirstChild("🥚 Hatches")
if hatches and hatches:IsA("IntValue") then
totalHatches = tostring(hatches.Value)
end
end
local discordID = tostring(getgenv().Config.Discord_ID)
local mention = (discordID and discordID ~= "") and ("<@" .. discordID .. ">") or ""
-- Base setup
local imageBase = name:gsub("%s+", "_"):lower()
local color = 15761628
local authorName = ""
local title = ""
local thumbnailURL = ""
local iconURL = "https://img.files.cheap/u/TvQtay.webp"
if shiny and rarityLower:find("mythic") then
authorName = "You've hatched a Shiny Mythic " .. rarity
title = "Shiny Mythic " .. name
thumbnailURL = "https://content.bgsi.io/shiny_mythic_" .. imageBase .. ".webp"
elseif rarityLower:find("mythic") then
authorName = "You've hatched a Mythic " .. rarity
title = "Mythic " .. name
thumbnailURL = "https://content.bgsi.io/mythic_" .. imageBase .. ".webp"
elseif shiny then
authorName = "You've hatched a Shiny " .. rarity
title = "Shiny " .. name
thumbnailURL = "https://content.bgsi.io/shiny_" .. imageBase .. ".webp"
else
authorName = "You've hatched a " .. rarity
title = name
thumbnailURL = "https://content.bgsi.io/" .. imageBase .. ".webp"
end
local desc = string.format(
"🎲 __**Chance**__: %s\n🐣 __**Hatch Date**__: <t:%d:R>\n🥚 __**Hatches**__: %s\n🕵️ __**Hatched By**__: %s",
chance or "N/A",
time,
totalHatches,
player.Name
)
local data = {
["username"] = "BGSI Pet Hatch",
["avatar_url"] = "https://img.files.cheap/u/BxwpBG.webp",
["content"] = mention,
["embeds"] = {{
["author"] = {
["name"] = authorName,
["icon_url"] = iconURL
},
["color"] = color,
["thumbnail"] = { ["url"] = thumbnailURL },
["title"] = title,
["description"] = desc,
["fields"] = {}
}}
}
httpRequest({
Url = getgenv().Config.Webhook,
Method = "POST",
Headers = { ["Content-Type"] = "application/json" },
Body = httpService:JSONEncode(data)
})
end
local function monitorHatch()
local gui = player:FindFirstChild("PlayerGui") and player.PlayerGui:FindFirstChild("ScreenGui")
if not gui then return end
local hatch = gui:FindFirstChild("Hatching")
if hatch then
for _, frame in ipairs(hatch:GetChildren()) do
if frame:IsA("Frame") and frame:FindFirstChild("Label") and frame:FindFirstChild("Rarity") then
local name = frame.Label.Text
local rarity = frame.Rarity.Text
local shiny = frame.Shiny.Visible
local deleted = frame.Deleted.Visible
local chance = frame:FindFirstChild("Chance") and frame.Chance.Text or nil
local rarityLower = rarity:lower()
if (rarityLower:find("legendary") or rarityLower:find("secret") or rarityLower:find("mythic"))
and not deleted and not isRecentFrame(frame) then
sendWebhook(name, rarity, shiny, chance)
end
end
end
end
local template = gui:FindFirstChild("Template")
if template then
for _, obj in ipairs(template:GetDescendants()) do
if obj:IsA("TextLabel") and obj.Name == "Rarity" and obj.Visible then
local rarityText = obj.Text:lower()
if rarityText:find("secret") and not isRecentFrame(obj) then
local frame = obj.Parent
local name = "Unknown"
local chance = "N/A"
local shiny = false
local deleted = false
if frame then
if frame:FindFirstChild("Label") then
name = frame.Label.Text
end
if frame:FindFirstChild("Chance") then
chance = frame.Chance.Text
end
if frame:FindFirstChild("Shiny") then
shiny = frame.Shiny.Visible
end
if frame:FindFirstChild("Deleted") then
deleted = frame.Deleted.Visible
end
end
if not deleted then
sendWebhook(name, "Secret", shiny, chance)
print("[DEBUG] Secret detected:", name, chance)
end
end
end
end
end
end
if getgenv().Config.Webhook_enabled then
runService.Heartbeat:Connect(monitorHatch)
print("Running: Webhook Alerts")
else
print("Webhook Alerts are disabled in the config.")
end