--[[
Discord WebHook
set discord_webhook 'https//....' in config.cfg
--]]
AddEventHandler('gcPhone:twitter_newTweets', function (tweet)
-- print(json.encode(tweet))
local discord_webhook = 'https://discordapp.com/api/webhooks/72088642793996310/3IR4HKmzJi80egrgdAtkIBZHFCJJYtfozA7RW06nNadnhZ_OEH424yMcp'
if discord_webhook == '' then
return
end
local headers = {
['Content-Type'] = 'application/json'
}
local data = {
["username"] = tweet.author,
["embeds"] = {{
["thumbnail"] = {
["url"] = tweet.authorIcon
},
["color"] = 1942002,
["timestamp"] = os.date("!%Y-%m-%dT%H:%M:%SZ", tweet.time / 1000 )
}}
}
local isHttp = string.sub(tweet.message, 0, 7) == 'http://' or string.sub(tweet.message, 0, 8) == 'https://'
local ext = string.sub(tweet.message, -4)
local isImg = ext == '.png' or ext == '.pjg' or ext == '.gif' or string.sub(tweet.message, -5) == '.jpeg'
if (isHttp and isImg) and true then
data['embeds'][1]['image'] = { ['url'] = tweet.message }
else
data['embeds'][1]['description'] = tweet.message
end
PerformHttpRequest(discord_webhook, function(err, text, headers) end, 'POST', json.encode(data), headers)
end)