-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.lua
More file actions
113 lines (99 loc) · 3.25 KB
/
server.lua
File metadata and controls
113 lines (99 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--Made by Jijamik, feel free to modify
local cityid = "5368361" -- Los Angeles
local apikey = "Ici votre clé openweathermap"
local GetWeather = "http://api.openweathermap.org/data/2.5/weather?id="..cityid.."&lang=fr&units=metric&APPID="..apikey
function sendToDiscordMeteo (type, name,message,color)
local DiscordWebHook = "Webhook Discord"
local avatar = "Url de l'image"
local embeds = {
{
["title"]=message,
["type"]="rich",
["color"] =color,
["footer"]= {
["text"]= "-------------------------------------------------------------------------------------------------------------------",
},
}
}
if message == nil or message == '' then return FALSE end
PerformHttpRequest(DiscordWebHook, function(err, text, headers) end, 'POST', json.encode({ username = name,embeds = embeds,avatar_url = avatar}), { ['Content-Type'] = 'application/json' })
end
function checkMeteo(err,response)
local data = json.decode(response)
local type = data.weather[1].main
local id = data.weather[1].id
local description = data.weather[1].description
local wind = math.floor(data.wind.speed)
local windrot = data.wind.deg
local meteo = "EXTRASUNNY"
local ville = data.name
local temp = math.floor(data.main.temp)
local tempmini = math.floor(data.main.temp_min)
local tempmaxi = math.floor(data.main.temp_max)
local emoji = ":white_sun_small_cloud:"
if type == "Thunderstorm" then
meteo = "THUNDER"
emoji = ":cloud_lightning:"
end
if type == "Rain" then
meteo = "RAIN"
emoji = ":cloud_snow:"
end
if type == "Drizzle" then
meteo = "CLEARING"
emoji = ":clouds:"
if id == 608 then
meteo = "OVERCAST"
end
end
if type == "Clear" then
meteo = "CLEAR"
emoji = ":sun_with_face:"
end
if type == "Clouds" then
meteo = "CLOUDS"
emoji = ":clouds:"
if id == 804 then
meteo = "OVERCAST"
end
end
if type == "Snow" then
meteo = "SNOW"
emoji = ":cloud_snow:"
if id == 600 or id == 602 or id == 620 or id == 621 or id == 622 then
meteo = "XMAS"
end
end
Data = {
["Meteo"] = meteo,
["VitesseVent"] = wind,
["DirVent"] = windrot
}
TriggerClientEvent("meteo:actu", -1, Data)
sendToDiscordMeteo(1,('Météo'), emoji.." La météo à "..ville.." est "..description..". \n:thermometer: Il fait actuellement "..temp.."°C avec des minimales à "..tempmini.."°C et des maximales à "..tempmaxi.."°C. \n:wind_blowing_face: Des vents de "..wind.."m/s sont à prévoir.",16711680)
SetTimeout(60*60*1000, checkMeteoHTTPRequest)
end
function checkMeteoHTTPRequest()
PerformHttpRequest(GetWeather, checkMeteo, "GET")
end
checkMeteoHTTPRequest()
RegisterServerEvent("meteo:sync")
AddEventHandler("meteo:sync",function()
TriggerClientEvent("meteo:actu", source, Data)
end)
--[[
"EXTRASUNNY"
"SMOG"
"CLEAR"
"CLOUDS"
"FOGGY"
"OVERCAST"
"RAIN"
"THUNDER"
"CLEARING"
"NEUTRAL"
"SNOW"
"BLIZZARD"
"SNOWLIGHT"
"XMAS"
]]