From e2d7fdca4a79433aa15aa9c1e79b4b913c6b395a Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 17 Jul 2024 16:40:00 -0400 Subject: [PATCH] Updates --- README.md | 17 +++-------- server/main.lua | 72 +++++++++++++++++++++++++++++++++++++++++--- shared/config.lua | 15 +-------- shared/utilities.lua | 44 --------------------------- 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 6c369c2..ec62f9f 100644 --- a/README.md +++ b/README.md @@ -114,19 +114,6 @@ IR8.Config = { TicketsDescription = "View ticket system", }, - -- Send discord notifications when blips are created / updated / deleted - Discord = { - - -- Only sends webhooks if this is true - WebhookEnabled = false, - - -- The webhook url to send the request to - WebhookUrl = 'url', - - -- The author name of the webhook - AuthorName = 'IR8 Ticket Manager' - }, - -- Customize NUI Theme Theme = { @@ -147,6 +134,10 @@ IR8.Config = { } ``` +### Webhook Configuration + +You can set your webhook configuration from server/main.lua at the top of the file. + ### Renaming the Resource If you rename the resource folder, make sure you set the following configuration variables to match the folder name: diff --git a/server/main.lua b/server/main.lua index 6cf2833..8a88c99 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,3 +1,22 @@ +------------------------------------------------- +-- +-- DISCORD WEBHOOK CONFIGURATION +-- +------------------------------------------------- + +-- Send discord notifications when tickets are created / updated +Discord = { + + -- Only sends webhooks if this is true + WebhookEnabled = true, + + -- The webhook url to send the request to + WebhookUrl = 'url', + + -- The author name of the webhook + AuthorName = 'IR8 Ticket Manager' +} + ------------------------------------------------- -- -- COMMANDS @@ -71,7 +90,7 @@ lib.callback.register(IR8.Config.ServerCallbackPrefix .. "Ticket_UpdateStatus", -- Send discord webhook IR8.Utilities.DebugPrint("Sending discord notification for created ticket.") - IR8.Utilities.SendDiscordEmbed({ + SendDiscordEmbed({ title = "Ticket Status Update", message = "A ticket status was updated to " .. data.status .. " by " .. name .. " for Ticket #" .. data.id .. " - " .. ticketData.title }) @@ -95,7 +114,7 @@ lib.callback.register(IR8.Config.ServerCallbackPrefix .. "Ticket_CreateReply", f -- Send discord webhook IR8.Utilities.DebugPrint("Sending discord notification for created ticket.") - IR8.Utilities.SendDiscordEmbed({ + SendDiscordEmbed({ title = "New Ticket Reply", message = "A ticket was replied to by " .. name .. " for Ticket #" .. data.ticket_id .. " - " .. ticketData.title }) @@ -114,11 +133,56 @@ lib.callback.register(IR8.Config.ServerCallbackPrefix .. "Ticket_Create", functi -- Send discord webhook IR8.Utilities.DebugPrint("Sending discord notification for created ticket.") - IR8.Utilities.SendDiscordEmbed({ + SendDiscordEmbed({ title = "Ticket Created", message = "A ticket was created with title: " .. data.title .. " by " .. name }) end return res -end) \ No newline at end of file +end) + +----------------------------------------------------------- +-- +-- DISCORD WEBHOOK +-- +----------------------------------------------------------- + +function SendDiscordEmbed (options) + + if not Discord.WebhookEnabled then return end + if Discord.WebhookUrl == "url" then return end + + if type(options) ~= "table" then + return false + end + + if not options.title then + return false + end + + if not options.message then + return false + end + + local embed = { + { + ["title"] = "**".. options.title .."**", + ["description"] = options.message, + } + } + + if options.color then + embed[1].color = options.color + end + + if options.footer then + embed[1].footer = { + ["text"] = options.footer + } + end + + PerformHttpRequest(Discord.WebhookUrl, function(err, text, headers) + print(err) + end, 'POST', json.encode({username = Discord.AuthorName, embeds = embed}), { ['Content-Type'] = 'application/json' }) +end \ No newline at end of file diff --git a/shared/config.lua b/shared/config.lua index 306a392..f91c668 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -2,7 +2,7 @@ IR8 = {} ------------------------------------------------------------ --- Blip Configuration +-- Ticket Manager Configuration ------------------------------------------------------------ IR8.Config = { @@ -77,19 +77,6 @@ IR8.Config = { TicketsDescription = "View ticket system", }, - -- Send discord notifications when blips are created / updated / deleted - Discord = { - - -- Only sends webhooks if this is true - WebhookEnabled = false, - - -- The webhook url to send the request to - WebhookUrl = 'url', - - -- The author name of the webhook - AuthorName = 'IR8 Ticket Manager' - }, - -- Customize NUI Theme Theme = { diff --git a/shared/utilities.lua b/shared/utilities.lua index 1b77aa6..bbe128e 100644 --- a/shared/utilities.lua +++ b/shared/utilities.lua @@ -54,50 +54,6 @@ IR8.Utilities = { return hasPermission end, - ----------------------------------------------------------- - -- - -- DISCORD WEBHOOK - -- - ----------------------------------------------------------- - - SendDiscordEmbed = function (options) - - if not IR8.Config.Discord.WebhookEnabled then return end - - if type(options) ~= "table" then - return false - end - - if not options.title then - return false - end - - if not options.message then - return false - end - - local embed = { - { - ["title"] = "**".. options.title .."**", - ["description"] = options.message, - } - } - - if options.color then - embed[1].color = options.color - end - - if options.footer then - embed[1].footer = { - ["text"] = options.footer - } - end - - PerformHttpRequest(IR8.Config.Discord.WebhookUrl, function(err, text, headers) - print(err) - end, 'POST', json.encode({username = IR8.Config.Discord.AuthorName, embeds = embed}), { ['Content-Type'] = 'application/json' }) - end, - --------------------------------------------------------- -- -- NOTIFICATIONS