This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
chatBot.lua
109 lines (108 loc) · 2.88 KB
/
chatBot.lua
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function ReceiveFriendMsg(CurrentQQ, data)
if string.find(data.Content, "$") == 1 then
keyWord = data.Content:gsub("*", "")
log.notice("keyWord --> %s",keyWord)
if keyWord == nil then
return 1
end
response, error_message =
http.request(
"GET",
"http://api.qingyunke.com/api.php?",
{
query = "key=free&appid=0&msg=" ..
keyWord,
headers = {
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
}
)
local html = response.body
log.notice("html --> %s",html)
local msg = json.decode(html)
local content = msg.content:gsub("{br}","\n")
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
local randomNum = math.random(1,120)
-- 图片路径
local path = "/root/img/mm/"..randomNum..".jpg"
res = readImg(path)
base64 = PkgCodec.EncodeBase64(res)
Api.Api_SendMsg(
CurrentQQ,
{
toUser = data.FromUin,
sendToType = 1,
sendMsgType = "PicMsg",
groupid = 0,
content = "\n"..content,
picUrl = "",
picBase64Buf = base64,
fileMd5 = "",
atUser = 0
}
)
end
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if string.find(data.Content, "#") == 1 then
keyWord = data.Content:gsub("#", "")
log.notice("keyWord --> %s",keyWord)
if keyWord == nil then
return 1
end
response, error_message =
http.request(
"GET",
"http://api.qingyunke.com/api.php",
{
query = "key=free&appid=0&msg=" ..
keyWord,
headers = {
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
}
)
local html = response.body
log.notice("html --> %s",tostring(response))
local msg = json.decode(html)
local content = msg.content:gsub("{br}","\n")
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
local randomNum = math.random(1,120)
-- 图片路径
local path = "/root/img/mm/"..randomNum..".jpg"
res = readImg(path)
base64 = PkgCodec.EncodeBase64(res)
Api.Api_SendMsg(
CurrentQQ,
{
toUser = data.FromGroupId,
sendToType = 2,
sendMsgType = "PicMsg",
groupid = 0,
content = "\n"..content,
picUrl = "",
picBase64Buf = base64,
fileMd5 = "",
atUser = 0
}
)
end
return 1
end
function ReceiveEvents(CurrentQQ, data, extData)
return 1
end
function readImg(filePath)
local f, err = io.open(filePath, "rb")
if err ~= nil then
return nil, err
end
local content = f:read("*all")
f:close()
return content, err
end