-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAnswer.lua
More file actions
51 lines (43 loc) · 1.15 KB
/
Answer.lua
File metadata and controls
51 lines (43 loc) · 1.15 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
-- 搜题
local log = require("log")
local Api = require("coreApi")
local http = require("http")
function stringStarts(str, Start)
return string.sub(str, 1, string.len(Start)) == Start
end
function urlEncode(s)
s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
return string.gsub(s, " ", "%%20")
end
function ReceiveFriendMsg(CurrentQQ, data)
return 1
end
function ReceiveEvents(CurrentQQ, data, extData)
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if data.FromUserId == tonumber(CurrentQQ) then
return 1
end
if not stringStarts(data.Content, "搜题") or data.Content == "搜题" then
return 1
end
-- print('Running..answer')
q = data.Content:gsub("搜题", "")
rep, _ = http.request(
"GET",
"http://127.0.0.1:8080/course/?q="..urlEncode(q)
)
Api.Api_SendMsg(
CurrentQQ,
{
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "TextMsg",
groupid = 0,
content = '\n'..rep.body,
atUser = data.FromUserId
}
)
return 1
end