-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
31 lines (29 loc) · 860 Bytes
/
server.lua
File metadata and controls
31 lines (29 loc) · 860 Bytes
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
local url <const> = 'https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit';
local function getJoke()
local p = promise.new();
PerformHttpRequest(url, function(statusCode, body, headers)
if statusCode == 200 and not body.error then
p:resolve(body);
end
end)
return Citizen.Await(p);
end
RegisterCommand('joke', function(source)
local result = json.decode(getJoke())
if result.error or not result.setup or not result.delivery then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
multiline = true,
args = {
'^1Joke API Error:',
'^2' .. result.error
}
})
return;
end
local message = result.setup .. ' ' .. result.delivery;
TriggerClientEvent('chat:addMessage', -1, {
multiline = true,
args = {"Joke", message}
})
end)