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 return
|
|
22 end
|
71
|
23 local html = chat.ai_add(input)
|
5
|
24 %>
|
71
|
25 askAi2(<%=json_string(html)%>);
|
5
|
26 <%
|
|
27 end
|