Advertisement
ERROR_CODE

joke bot

Dec 7th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. -- Создаём ScreenGui
  2. local screenGui = Instance.new("ScreenGui")
  3. screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  4.  
  5. -- Создаём Frame
  6. local frame = Instance.new("Frame")
  7. frame.Size = UDim2.new(0, 300, 0, 200)
  8. frame.Position = UDim2.new(0.5, -150, 0.5, -100)
  9. frame.Parent = screenGui
  10.  
  11. -- Создаём TextLabel
  12. local textLabel = Instance.new("TextLabel")
  13. textLabel.Size = UDim2.new(1, 0, 0.5, 0)
  14. textLabel.Position = UDim2.new(0, 0, 0, 0)
  15. textLabel.Text = "Ответ бота появится здесь"
  16. textLabel.Parent = frame
  17.  
  18. -- Создаём TextBox
  19. local textBox = Instance.new("TextBox")
  20. textBox.Size = UDim2.new(1, 0, 0.5, 0)
  21. textBox.Position = UDim2.new(0, 0, 0.5, 0)
  22. textBox.PlaceholderText = "Введите тему шутки и нажмите Enter"
  23. textBox.Parent = frame
  24.  
  25. -- Функция для отправки запроса к JokeAPI
  26. local function getJoke(keyword)
  27.     local httpService = game:GetService("HttpService")
  28.     local url = "https://v2.jokeapi.dev/joke/Any?contains=" .. httpService:UrlEncode(keyword)
  29.     local response = httpService:JSONDecode(game:HttpGetAsync(url))
  30.  
  31.     if response and not response.error then
  32.         if response.type == "single" then
  33.             return response.joke
  34.         elseif response.type == "twopart" then
  35.             return response.setup .. " " .. response.delivery
  36.         end
  37.     else
  38.         return "Извините, СЏ РЅРµ нашел шутки РЅР° эту тему."
  39.     end
  40. end
  41.  
  42. -- Обработчик события FocusLost для TextBox
  43. textBox.FocusLost:Connect(function(enterPressed)
  44.     if enterPressed then
  45.         local botResponse = getJoke(textBox.Text)
  46.         textLabel.Text = botResponse
  47.     end
  48. end)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement