-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPicSearch.lua
More file actions
283 lines (258 loc) · 9.88 KB
/
Copy pathPicSearch.lua
File metadata and controls
283 lines (258 loc) · 9.88 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
function ReceiveFriendMsg(CurrentQQ, data)
if data.FromUin ==2986807981 then--防止自我复读
return 1 end
if string.find(data.MsgType, "PicMsg") then
str = json.decode(data.Content)
log.notice("str.Content---> %s", str.Content)
if str.Content == nil then
return 1
end
if string.find(str.Content, "搜图") and data.Content:gsub("搜图", "")=="" then
loadingF(CurrentQQ,data)
img_url = str.FriendPic[1].Url--私聊搜图是FriendPic
log.notice("MsgType---> %s", data.MsgType)
log.notice("img_url---> %s", img_url)
response, error_message =
http.request(
"GET",
"https://saucenao.com/search.php?",
{
query = "api_key=f765018e40a010d6a01c58e39cab46afde4738df&db=999&output_type=2&testmode=1&numres=1&url=" ..
img_url,
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 re = json.decode(html)
-- log.notice("re---> %s", re)
--[[for k, v in pairs(re.results[1].data) do --遍历结果测试用
print(k, v)
end]]--
local similarity = re.results[1].header.similarity --相似度
local thumbnail_url = re.results[1].header.thumbnail --缩略图地址
local title = re.results[1].data.title --标题
local pixiv_id = re.results[1].data.pixiv_id --p站id
--##处理作者名开始########
local member_name = re.results[1].data.member_name
local data_creator = ""
if type(re.results[1].data.creator)=="table" then --data.creator可能是个string也可能是个table
data_creator = re.results[1].data.creator[1]
else
data_creator = re.results[1].data.creator
end
if member_name == nil then
member_name = data_creator
if member_name == nil then
member_name = re.results[1].data.artist
if member_name == nil then
member_name = re.results[1].data.author
end
end
end
if member_name ==nil then --上面三个字段全都没有就认命了 给个空字符串
member_name =""
--log.notice("member_name= %s", member_name)
end
--##处理作者名结束##########
--###处理其他信息开始,有时是地址有时是作品信息(data.source)##########
local data_source = ""
if type(re.results[1].data.source)=="table" then --data.source可能是个string也可能是个table
data_source = re.results[1].data.source[1]
else
data_source = re.results[1].data.source
end
if data_source==nil then --api返回的结果可能没有source字段
data_source = ""
--log.notice("data_source= %s", data_source)
end
--####处理其他信息开始结束###########
--###处理插画链接开始###########
local ext_urls=""
if type(re.results[1].data.ext_urls)=="table" then --data.ext_urls可能是个string也可能是个table
ext_urls = re.results[1].data.ext_urls[1]
else
ext_urls = re.results[1].data.ext_urls
end
--log.notice("ext_urls = %s", ext_urls)
--###处理插画链接结束#########
luaRes =
Api.Api_SendMsg(--调用发消息的接口
CurrentQQ,
{
toUser = data.FromUin, --回复当前消息的来源群ID
sendToType = 1, --2发送给群1发送给好友3私聊
sendMsgType = "PicMsg", --进行文本复读回复
content = string.format(
"\n相似度:%s\n标题:%s\nPixiv_ID:%d\n插画家昵称:%s \n插画链接:%s\n其他信息:%s ",
similarity,
title,
pixiv_id,
member_name,
ext_urls,
data_source
), --回复内容
picUrl = thumbnail_url,
picBase64Buf = "",
fileMd5 = ""
}
)
-- log.notice("From Lua SendMsg Ret-->%d", luaRes.Ret)
end
end
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if data.FromUserId ==2986807981 then--防止自我复读
return 1 end
if string.find(data.MsgType, "PicMsg") then
str = json.decode(data.Content)
log.notice("str.Content---> %s", str.Content)
if str.Content == nil then
return 1
end
if string.find(str.Content, "搜图") and (str.Content:gsub("搜图", "")=="" or str.Content:gsub("搜图", "")=="\r") then --避免误触发
loadingG(CurrentQQ,data)
img_url = str.GroupPic[1].Url
log.notice("MsgType---> %s", data.MsgType)
log.notice("img_url---> %s", img_url)
response, error_message =
http.request(
"GET",
"https://saucenao.com/search.php?",
{
query = "api_key=f765018e40a010d6a01c58e39cab46afde4738df&db=999&output_type=2&testmode=1&numres=1&url=" ..
img_url,
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 re = json.decode(html)
-- log.notice("re---> %s", re)
--[[for k, v in pairs(re.results[1].data) do --遍历结果测试用
print(k, v)
end]]--
local similarity = re.results[1].header.similarity --相似度
local thumbnail_url = re.results[1].header.thumbnail --缩略图地址
local title = re.results[1].data.title --标题
local pixiv_id = re.results[1].data.pixiv_id --p站id
--##处理作者名开始########
local member_name = re.results[1].data.member_name
local data_creator = ""
if type(re.results[1].data.creator)=="table" then --data.creator可能是个string也可能是个table
data_creator = re.results[1].data.creator[1]
else
data_creator = re.results[1].data.creator
end
if member_name == nil then
member_name = data_creator
if member_name == nil then
member_name = re.results[1].data.artist
if member_name == nil then
member_name = re.results[1].data.author
end
end
end
if member_name ==nil then --上面三个字段全都没有就认命了 给个空字符串
member_name =""
--log.notice("member_name= %s", member_name)
end
--##处理作者名结束##########
--###处理其他信息开始,有时是地址有时是作品信息(data.source)##########
local data_source = ""
if type(re.results[1].data.source)=="table" then --data.source可能是个string也可能是个table
data_source = re.results[1].data.source[1]
else
data_source = re.results[1].data.source
end
if data_source==nil then --api返回的结果可能没有source字段
data_source = ""
--log.notice("data_source= %s", data_source)
end
--####处理其他信息开始结束###########
--###处理插画链接开始###########
local ext_urls=""
if type(re.results[1].data.ext_urls)=="table" then --data.ext_urls可能是个string也可能是个table
ext_urls = re.results[1].data.ext_urls[1]
else
ext_urls = re.results[1].data.ext_urls
end
--log.notice("ext_urls = %s", ext_urls)
--###处理插画链接结束#########
luaRes =
Api.Api_SendMsg(--调用发消息的接口
CurrentQQ,
{
toUser = data.FromGroupId, --回复当前消息的来源群ID
sendToType = 2, --2发送给群1发送给好友3私聊
sendMsgType = "PicMsg", --进行文本复读回复
content = string.format(
"\n相似度:%s\n标题:%s\nPixiv_ID:%d\n插画家昵称:%s \n插画链接:%s\n其他信息:%s ",
similarity,
title,
pixiv_id,
member_name,
ext_urls,
data_source
),
picUrl = thumbnail_url,
picBase64Buf = "",
fileMd5 = ""
}
)
-- log.notice("From Lua SendMsg Ret-->%d", luaRes.Ret)
end
end
return 1
end
function ReceiveEvents(CurrentQQ, data, extData)
return 1
end
function loadingG(CurrentQQ,data)
luaMsg =
Api.Api_SendMsg(--调用发消息的接口
CurrentQQ,
{
toUser = data.FromGroupId, --回复当前消息的来源群ID
sendToType = 2, --2发送给群1发送给好友3私聊
sendMsgType = "TextMsg", --进行文本复读回复
groupid = 0, --不是私聊自然就为0咯
content = "正在查询saucenao(只上传推特的大概率搜不到)[表情67]", --回复内容
atUser = 0 --是否 填上data.FromUserId就可以复读给他并@了
}
)
end
function loadingF(CurrentQQ,data)
luaMsg =
Api.Api_SendMsg(--调用发消息的接口
CurrentQQ,
{
toUser = data.FromUin, --回复当前消息的来源群ID
sendToType = 1, --2发送给群1发送给好友3私聊
sendMsgType = "TextMsg", --进行文本复读回复
groupid = 0, --不是私聊自然就为0咯
content = "正在查询saucenao(只上传推特的大概率搜不到)[表情67]", --回复内容
atUser = 0 --是否 填上data.FromUserId就可以复读给他并@了
}
)
end
function table.kIn(tbl, key)--判断表中是否存在给定的Key值
if tbl == nil then
return false
end
for k, v in pairs(tbl) do
if k == key then
return true
end
end
return false
end