5
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Parsers = require "luan:Parsers.luan"
|
|
4 local json_string = Parsers.json_string or error()
|
|
5 local Io = require "luan:Io.luan"
|
|
6 local Http = require "luan:http/Http.luan"
|
|
7 local User = require "site:/lib/User.luan"
|
|
8 local current_user = User.current or error()
|
|
9 local Chat = require "site:/lib/Chat.luan"
|
|
10 local get_chat_by_id = Chat.get_by_id or error()
|
|
11
|
|
12
|
|
13 return function()
|
|
14 Io.stdout = Http.response.text_writer()
|
|
15 local parameters = Http.request.parameters
|
|
16 local chat = parameters.chat or error()
|
|
17 chat = get_chat_by_id(chat) or error()
|
|
18 chat.user_id == current_user().id or error()
|
|
19 local input = parameters.input or error()
|
|
20 if input == "" then
|
|
21 %>
|
|
22 hideWaitingAiIcon();
|
|
23 <%
|
|
24 return
|
|
25 end
|
|
26 local html = chat.ask(input)
|
|
27 %>
|
|
28 updateAi(<%=json_string(html)%>);
|
|
29 <%
|
|
30 end
|