From 0170b1c1652546adc63732879930edeef834ce0b Mon Sep 17 00:00:00 2001 From: Tuncion Date: Fri, 29 Nov 2024 18:18:23 +0100 Subject: [PATCH] Added Webhooks --- ReadMe.md | 6 +-- server/main.lua | 108 ++++++++++++++++++++++++++++++++++++++ settings/DreamCore.lua | 2 +- settings/DreamCoreExt.lua | 5 +- 4 files changed, 116 insertions(+), 5 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index fdd0dd2..ee4ce9b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -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: diff --git a/server/main.lua b/server/main.lua index 150b049..961a9e5 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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'] } @@ -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'] } @@ -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'] } @@ -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 diff --git a/settings/DreamCore.lua b/settings/DreamCore.lua index 3053ffa..80808aa 100644 --- a/settings/DreamCore.lua +++ b/settings/DreamCore.lua @@ -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) diff --git a/settings/DreamCoreExt.lua b/settings/DreamCoreExt.lua index b584f60..01cbe47 100644 --- a/settings/DreamCoreExt.lua +++ b/settings/DreamCoreExt.lua @@ -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', + }