Help With Creating an Item Notifier?

Recently I’ve been trying to create my own item notifier. I am trying to do this with just a proxy and ROBLOX Studio. Now, I could do this with some other programming language and program, maybe even create an extension or something but I am trying to create this with just ROBLOX, my own proxy (to get the catalog API) and discord webhooks (to send the messages there). While trying to create my item notifier, I faced some issues. So I was able to receive the data from the catalog API to the game with no problems, I JSON decoded the data, converted it to a Lua table but then I got stuck. I did not know in which way I could obtain the new items released, updated items (items which go limited for examples, items that get a decrease on their price, items which go for sale for a period of time etc… ), new limited items and so on. Then I came up with a solution. So the way I thought I was going to do this was:
Make a variable which stores the last :GetAsync() request and another variable which stores the current :GetAsync() request and compare the tables with the items. In this way I could compare the differences in the modified table and end up with a conclusion on what happened. Like did a new item get created? Did an item go limited? etc…
And this seemed like a good idea but I got stuck eventually and I couldn’t figure out what was wrong. The code that I wrote was awfully bad also. The script that I wrote sometimes worked but not in the way I desired it to work. I need some help over here, but I am repeating the code I wrote is awfully bad, it handles HttpRequests in a really bad way (to the discord webhook) (e.x if 2 items changed at once the HttpRequest would error because of reaching the rate-limit). I am actually looking for a way to do this and not someone to fix my awfully made script. If someone would do that, I would appreciate that but you do not have to. Anyway here is my script:

--//Scripted by vamik64

--[[
INFO:
"target" is my own private proxy server,.
This won't work if HttpRequest are down, can't do anything about that
unfortunately.
--]]

local target = "my proxy's link here (website)"
local wh= "my webhook link goes here"
local HttpService = game:GetService("HttpService")
local lastRequest = HttpService:JSONDecode(HttpService:GetAsync(target))
local blacklist = {"Favorited"; "Sales"; "Remaining"; "PrivateSales"; "IsServerSideThumbnailLookupInCatalogEnabled"; "ThumbnailUrl"; "IsLargeItem"; "BestPrice"; "PriceView"; "OffSaleDeadline"; "Updated"} --properties, do not remove any

function SendMessage(webhook, message)
   local content = {
       message = message 
   }
    local toBeSent = HttpService:JSONEncode(content)
   local succ, err = pcall(function() HttpService:PostAsync(webhook, toBeSent) end)
    if not succ then
       print(err) 
    end  
end   

function compare(tab1, tab2)
   if tab1 == nil or tab2 == nil then return end
    
--//MainCode
    
    for n, item in pairs(tab1) do
        for property, value in pairs (item) do
                for n2, item2 in pairs(tab2) do
                   for property2, value2 in pairs(item2) do
                       if property == property2 then
							for _, r in pairs(blacklist) do
								if r == property then return end
							end
                            if n == n2 then
								print(property)
                                if value ~= value2 then
									lastRequest = tab1
                                    local message = "New Item!\nItem Name: "..item2["Name"].."\nURL: "..item2["AbsoluteUrl"]
                                    print(message)
                                    SendMessage(wh, message)
									return
                                else
                                    lastRequest = tab1
                                end    
                            end    
                        end    
                    end    
                    
        end         
    end  
end    
end   

function GetInfo(target, decode)
    local result;
    if type(target) ~= "string" then return end
    local succ, err = pcall(function() result = HttpService:GetAsync(target) end)
    if not succ then
          print(err)
    end     
    if #result == 0 then
		repeat local succ, err = pcall(function() result = HttpService:GetAsync(target) end) and wait() until #result ~= 0
end

	if #result ~= 0 then
    if decode == true then
       result = HttpService:JSONDecode(result) 
    end    
	end
    return result
end        
    
while wait(0.2) do
    local currentRequest = GetInfo(target, true)
   compare(lastRequest, currentRequest)     
end        

As I said the code is awful :grimacing:.
I was trying to mess around with and find a solution more than I was trying to get it to work as I expected it to.

7 Likes