[ OPENED SOURCED ] Simple Object Oriented Programming Discord logging with Game Jobid

Information

:happy3: Thank you for taking your time and reading this, this is a simple Objected Oriented Programming Discord Logging system, this system simply just logs every player that joins with the game JobId along with the epoch time on the bottom of the embed, Overall this is my first “Open sourced” system I have made, let me know your feedback and more things I should open source

Preview:
image

Source Code
Script: Location: ServerScriptService

local Player = game:GetService("Players")

-- // Module
local Module = require(script.ModuleScript)

-- //
Player.PlayerAdded:Connect(function(plr)
	local GetPlayerInfo = Module.AddPlayer(plr)
	GetPlayerInfo:SendInfo()
end)

Module Script: Location: Inside the parent of the Script Above :smiley:

--[[
    - Thigbr
    - 03/25/21
    - Open Sourced [03/25/21]
    - Simple Object Oriented Programming, Logging system
]]

-- // Services
local http = game:GetService("HttpService")

-- // Configuration
local DiscordWebhook = "https://discord.com/api/webhooks/823719482911883265/clBrrx2sC_EfB0bAiI-CFt-v9btSnWsg8j4Tpssrp6ygEnGya2ONK7240Ni2I3SLwOg0"

-- //
local module = {}
module.__index = module

function getRealTime(Time)
    local ExactTime     = os.date("!*t",Time)
    local Hr, min, sec, day, mnth, year = ExactTime.hour,  ExactTime.min, ExactTime.sec, ExactTime.day, ExactTime.month, ExactTime.year
    return ("%0.0f-%0.0f-%0.0fT%0.0f:%0.0f:%0.0fZ"):format(year, mnth, day, Hr, min, sec)
end

function module.AddPlayer(plr)
    local self = setmetatable({
        Player = plr.Name;
        UserId = plr.UserId;
    }, module)

    return self
end

function module:SendInfo()    
    local data = {
        embeds = {
            {
                author = {name = "Player Joined!"},
                title = "Server: "..game.JobId,
                description = self.Player..":"..self.UserId..' Has joined the server',
                timestamp = getRealTime(tick()),
                color = "2053964",        
                type = "rich",
            }
        }
    }    
    local newdata = http:JSONEncode(data)
    http:PostAsync(DiscordWebhook,newdata)
end

return module

Credits
@thigbr - Creator

:smiley:

4 Likes

Discord isn’t a logging service and your code doesn’t have any rate limit checks when using the webhook (which can lead to several negative outcomes).

Hmm, why would rate limit checks be needed?

If a lot of players join a server at once, rate limits will be hit frequently. If the limit is reached too often, Discord can disable your webhook and/or terminate your Discord account. If they can’t control the abuse of webhooks, they may block Roblox entirely (for the 2nd time).

I can just add a debounce and a queue system, or would there be a more ideal way of doing it?

That’s not a very effective way to prevent hitting rate limits.

IIRC, the current limit is 200 webhook requests per minute. This can vary since a game can have several servers. There’s a way to get the number of requests a webhook can receive before getting limited with HttpService, but I don’t remember how exactly.

Related Post:

3 Likes

Hey why are you putting your webhook in your code?

The webhook is removed, however it’s there if someone doesn’t know what to put there!

1 Like