Skip to content

Commit

Permalink
Added Webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncion committed Nov 29, 2024
1 parent b365fff commit 0170b1c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ All settings are customizable in the script. Here are a few examples:
- **Christmas Tree & Present Rewards:** Configure cooldowns and prizes.

# ToDo
[ ] Christmas Lootdrop \
[ ] QBCore Bridge \
[ ] Webhooks
[] Christmas Lootdrop \
[] QBCore Bridge \
[x] Webhooks

## Support
For assistance, reporting bugs, or sharing suggestions, you can:
Expand Down
108 changes: 108 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ lib.callback.register('dream_christmas:server:rewardRandomProp', function(source

TriggerClientEvent('dream_christmas:client:removeRandomProp', -1, PropId)

if DreamCore.Webhooks.Enabled then
local WebhookReward = 'Unknown Reward'
if RewardData.type == 'item' then
WebhookReward = ('**📦 Item:** `%s` (`%s`)\n**🔢 Amount:** `%s`'):format(DreamFramework.InventoryManagement(src, { type = 'label', item = RewardData.item }), RewardData.item, RewardData.amount)
elseif RewardData.type == 'weapon' then
WebhookReward = ('**🔫 Weapon:** `%s` (`%s`)\n**🔢 Ammo:** `%s`'):format(Locales['Weapons'][RewardData.weapon] or Locales['Weapons']['unknown'], RewardData.weapon, lib.math.groupdigits(RewardData.ammo))
elseif RewardData.type == 'money' then
WebhookReward = ('**🪙 Wallet:** `%s` (`%s`)\n**💸 Amount:** `%s$`'):format(Locales['MoneyAccount'][RewardData.account] or Locales['MoneyAccount']['unknown'], RewardData.account, lib.math.groupdigits(RewardData.amount))
end

SendDiscordWebhook({
link = DreamCore.Webhooks.RandomPropReward,
color = DreamCore.Webhooks.Color,
thumbnail = DreamCore.Webhooks.IconURL,
author = {
name = DreamCore.Webhooks.Author,
icon_url = DreamCore.Webhooks.IconURL
},
title = "☃️ Prop Reward",
description = ("%s\n**⚙️ Player:** `%s` (`%s`)\n**🏷️ Name:** `%s`"):format(WebhookReward, GetPlayerName(source), source, DreamFramework.getPlayerName(source)),
footer = {
text = "Made with ❤️ by Dream Development",
icon_url = DreamCore.Webhooks.IconURL
},
})
end

return { success = true, message = NotifyMessage }
else
return { success = false, message = Locales['RandomProp']['Error']['RandomPropAlreadyClaimed'] }
Expand Down Expand Up @@ -154,6 +181,26 @@ lib.callback.register('dream_christmas:server:decorateChristmasTree', function(s
}
local MoneyAmount = math.random(DreamCore.ChristmasTreeRewards.decorate.amount.min, DreamCore.ChristmasTreeRewards.decorate.amount.max)
DreamFramework.addPlayerMoney(src, DreamCore.ChristmasTreeRewards.decorate.account, MoneyAmount)

if DreamCore.Webhooks.Enabled then
local WebhookReward = ('**🆔 Id:** `%s`\n**🪙 Wallet:** `%s` (`%s`)\n**💸 Amount:** `%s$`'):format(TreeId, Locales['MoneyAccount'][DreamCore.ChristmasTreeRewards.decorate.account] or Locales['MoneyAccount']['unknown'], DreamCore.ChristmasTreeRewards.decorate.account, lib.math.groupdigits(MoneyAmount))
SendDiscordWebhook({
link = DreamCore.Webhooks.DecorateChristmasTree,
color = DreamCore.Webhooks.Color,
thumbnail = DreamCore.Webhooks.IconURL,
author = {
name = DreamCore.Webhooks.Author,
icon_url = DreamCore.Webhooks.IconURL
},
title = "🎄 Decorate Christmas Tree",
description = ("%s\n**⚙️ Player:** `%s` (`%s`)\n**🏷️ Name:** `%s`"):format(WebhookReward, GetPlayerName(source), source, DreamFramework.getPlayerName(source)),
footer = {
text = "Made with ❤️ by Dream Development",
icon_url = DreamCore.Webhooks.IconURL
},
})
end

return { success = true, message = Locales['ChristmasTree']['Success']['ChristmasTreeDecorate']:format(lib.math.groupdigits(MoneyAmount)) }
else
return { success = false, message = Locales['ChristmasTree']['Error']['ChristmasTreeAlreadyDecorated'] }
Expand Down Expand Up @@ -196,6 +243,33 @@ lib.callback.register('dream_christmas:server:claimChristmasPresent', function(s
NotifyMessage = Locales['ChristmasPresent']['Success']['ChristmasPresentMoney']:format(lib.math.groupdigits(RewardData.amount), Locales['MoneyAccount'][RewardData.account] or Locales['MoneyAccount']['unknown'])
end

if DreamCore.Webhooks.Enabled then
local WebhookReward = 'Unknown Reward'
if RewardData.type == 'item' then
WebhookReward = ('**🆔 Id:** `%s`\n**📦 Item:** `%s` (`%s`)\n**🔢 Amount:** `%s`'):format(PresentId, DreamFramework.InventoryManagement(src, { type = 'label', item = RewardData.item }), RewardData.item, RewardData.amount)
elseif RewardData.type == 'weapon' then
WebhookReward = ('**🆔 Id:** `%s`\n**🔫 Weapon:** `%s` (`%s`)\n**🔢 Ammo:** `%s`'):format(PresentId, Locales['Weapons'][RewardData.weapon] or Locales['Weapons']['unknown'], RewardData.weapon, lib.math.groupdigits(RewardData.ammo))
elseif RewardData.type == 'money' then
WebhookReward = ('**🆔 Id:** `%s`\n**🪙 Wallet:** `%s` (`%s`)\n**💸 Amount:** `%s$`'):format(PresentId, Locales['MoneyAccount'][RewardData.account] or Locales['MoneyAccount']['unknown'], RewardData.account, lib.math.groupdigits(RewardData.amount))
end

SendDiscordWebhook({
link = DreamCore.Webhooks.ChristmasPresent,
color = DreamCore.Webhooks.Color,
thumbnail = DreamCore.Webhooks.IconURL,
author = {
name = DreamCore.Webhooks.Author,
icon_url = DreamCore.Webhooks.IconURL
},
title = "🎁 Christmas Present",
description = ("%s\n**⚙️ Player:** `%s` (`%s`)\n**🏷️ Name:** `%s`"):format(WebhookReward, GetPlayerName(source), source, DreamFramework.getPlayerName(source)),
footer = {
text = "Made with ❤️ by Dream Development",
icon_url = DreamCore.Webhooks.IconURL
},
})
end

return { success = true, message = NotifyMessage }
else
return { success = false, message = Locales['ChristmasPresent']['Error']['ChristmasPresentAlreadyClaimed'] }
Expand All @@ -222,3 +296,37 @@ function GiveRandomRewardToPlayer(src, RewardsPool)
end
return RandomReward
end

function SendDiscordWebhook(WebhookData)
local EmbedDataArray = {}
local EmbedData = {}

EmbedData.color = WebhookData.color

if WebhookData.author then
EmbedData.author = {}
EmbedData.author.name = WebhookData.author.name
EmbedData.author.icon_url = WebhookData.author.icon_url
end

if WebhookData.title then
EmbedData.title = WebhookData.title
end

if WebhookData.thumbnail then
EmbedData.thumbnail = {}
EmbedData.thumbnail.url = WebhookData.thumbnail
end

EmbedData.description = WebhookData.description

if WebhookData.footer then
EmbedData.footer = {}
EmbedData.footer.text = WebhookData.footer.text
EmbedData.footer.icon_url = WebhookData.footer.icon_url
end

table.insert(EmbedDataArray, EmbedData)

PerformHttpRequest(WebhookData.link, function(err, text, headers) end, 'POST', json.encode({ embeds = EmbedDataArray }), { ['Content-Type'] = 'application/json' })
end
2 changes: 1 addition & 1 deletion settings/DreamCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DreamFramework = {} -- Do not touch this!!!
DreamCore = {} -- Do not touch this!!!

-- Dream Christmas Settings
DreamCore.Language = 'at'
DreamCore.Language = 'en'
DreamCore.GiveCredits = true -- Set to false if you don't want to give credits

-- Snow System (Snowballs)
Expand Down
5 changes: 4 additions & 1 deletion settings/DreamCoreExt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ DreamCore.Webhooks = {
IconURL = 'https://i.ibb.co/KNS96CM/dreamservices-round.png', -- Change the IconURL of the Webhook

-- Webhook URLs
XY = 'https://discord.com/api/webhooks/XXX/XXX',
RandomPropReward = 'https://discord.com/api/webhooks/XXX/XXX',
DecorateChristmasTree = 'https://discord.com/api/webhooks/XXX/XXX',
ChristmasPresent = 'https://discord.com/api/webhooks/XXX/XXX',

}

0 comments on commit 0170b1c

Please sign in to comment.