Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Jul 17, 2024
1 parent 52b8ee4 commit e2d7fdc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand Down
72 changes: 68 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
})
Expand All @@ -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
})
Expand All @@ -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)
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
15 changes: 1 addition & 14 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
IR8 = {}

------------------------------------------------------------
-- Blip Configuration
-- Ticket Manager Configuration
------------------------------------------------------------
IR8.Config = {

Expand Down Expand Up @@ -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 = {

Expand Down
44 changes: 0 additions & 44 deletions shared/utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2d7fdc

Please sign in to comment.