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 2
/
图片-色图.lua
264 lines (253 loc) · 9.99 KB
/
图片-色图.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
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
local log = require("log")
local Api = require("coreApi")
local json = require("json")
local http = require("http")
local mysql = require("mysql")
function ReceiveFriendMsg(CurrentQQ, data)
if data.MsgType ~= "TempSessionMsg" then
if string.find(data.Content, "来点色图") == 1 then
local strJson = setu(1, 0)
local img_url =
"https://images.weserv.nl/?url=" .. strJson["url"] ..
"&output=webp"
local img_url = strJson["url"]
log.notice("the img_url is %s", img_url)
local str = "标题:" .. strJson["title"] ..
"\nhttps://www.pixiv.net/artworks/" ..
strJson["pid"] .. "\n作者:" .. strJson["author"] ..
"\nhttps://www.pixiv.net/users/" .. strJson["uid"] ..
"\n原图:" .. strJson["url"]
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = data.FromUin,
SendToType = 1,
SendMsgType = "PicMsg",
Content = str,
PicUrl = img_url
})
end
if string.find(data.Content, "来点r18色图") == 1 then
local strJson = setu(1, 1)
local img_url =
"https://images.weserv.nl/?url=" .. strJson["url"] ..
"&output=webp"
local img_url = strJson["url"]
log.notice("the img_url is %s", img_url)
local str = "标题:" .. strJson["title"] ..
"\nhttps://www.pixiv.net/artworks/" ..
strJson["pid"] .. "\n作者:" .. strJson["author"] ..
"\nhttps://www.pixiv.net/users/" .. strJson["uid"] ..
"\n原图:" .. strJson["url"]
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = data.FromUin,
SendToType = 1,
SendMsgType = "PicMsg",
Content = str,
PicUrl = img_url
})
end
end
if data.MsgType == "TempSessionMsg" and data.ToUin == tonumber(CurrentQQ) then
if string.find(data.Content, "来点色图") == 13 then
local strJson = setu(1, 0)
local img_url =
"https://images.weserv.nl/?url=" .. strJson["url"] ..
"&output=webp"
local img_url = strJson["url"]
log.notice("the img_url is %s", img_url)
local str = "标题:" .. strJson["title"] ..
"\nhttps://www.pixiv.net/artworks/" ..
strJson["pid"] .. "\n作者:" .. strJson["author"] ..
"\nhttps://www.pixiv.net/users/" .. strJson["uid"] ..
"\n原图:" .. strJson["url"]
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = data.FromUin,
GroupID = data.TempUin,
SendToType = 3,
SendMsgType = "PicMsg",
Content = str,
PicUrl = img_url
})
end
if string.find(data.Content, "来点r18色图") == 13 then
local strJson = setu(1, 1)
local img_url =
"https://images.weserv.nl/?url=" .. strJson["url"] ..
"&output=webp"
local img_url = strJson["url"]
log.notice("the img_url is %s", img_url)
local str = "标题:" .. strJson["title"] ..
"\nhttps://www.pixiv.net/artworks/" ..
strJson["pid"] .. "\n作者:" .. strJson["author"] ..
"\nhttps://www.pixiv.net/users/" .. strJson["uid"] ..
"\n原图:" .. strJson["url"]
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = data.FromUin,
GroupID = data.TempUin,
SendToType = 3,
SendMsgType = "PicMsg",
Content = str,
PicUrl = img_url
})
end
end
return 1
end
function ReceiveGroupMsg(CurrentQQ, data)
if string.find(data.Content, "来.*色图") then
if data.FromUserId == tonumber(CurrentQQ) then
threshold = "ok"
else
threshold = setu_threshold(data)
end
if threshold == "ok" then
if string.find(data.Content, "来点色图") == 1 or
string.find(data.Content, "来张色图") == 1 or
string.find(data.Content, "来份色图") == 1 then
local strJson = setu(1, 0)
local img_url = "https://images.weserv.nl/?url=" ..
setu_json["url"] .. "&output=webp"
send_pic_to_group(CurrentQQ, data.FromGroupId, "", img_url)
end
if string.find(data.Content, "来点r18色图") == 1 or
string.find(data.Content, "来张r18色图") == 1 then
setu_json = setu(1, 1)
local img_url = "https://images.weserv.nl/?url=" ..
setu_json["url"] .. "&output=webp"
local img_url = setu_json["url"]
local str = "30s后销毁该条消息,请快点冲,谢谢"
send_pic_to_group(CurrentQQ, data.FromGroupId, str, img_url)
end
if string.find(data.Content, "来(%d+)张色图") == 1 then
num = tonumber(data.Content:match("来(%d+)张色图"))
if num > 10 and data.FromUserId ~= tonumber(CurrentQQ) then
send_to_group(CurrentQQ, data.FromGroupId,
"要这么多色图你怎么不冲死呢?")
else
send_to_group(CurrentQQ, data.FromGroupId,
"正在发送ing[表情178][表情67]")
setu_json = setu(num, 0)
len = #setu_json
i = 1
while i <= len do
os.execute('sleep 0.8')
send_pic_to_group(CurrentQQ, data.FromGroupId, "",
setu_json[i])
i = i + 1
end
end
end
else
if threshold == "user_is_locked" then
send_to_group(CurrentQQ, data.FromGroupId,
"要这么多色图你怎么不冲死呢?")
end
if threshold == "group_is_locked" then
send_to_group(CurrentQQ, data.FromGroupId,
"淦 你们身体这么好的吗?")
end
end
end
return 1
end
function ReceiveEvents(CurrentQQ, data, extData) return 1 end
function setu(num, r)
local f, _ = io.open('./Plugins/data/setu.json', "r")
if r == 1 then
f, _ = io.open('./Plugins/data/setu_r18.json', "r")
end
local content = f:read("*all")
f:close()
local setu_data = json.decode(content)
if num == 1 then
math.randomseed(os.time())
setu_json = setu_data[math.random(1, #setu_data)]
else
setu_json = {}
for i = 1, num, 1 do
math.randomseed(os.time()*i)
setu_json[i] = setu_data[math.random(1, #setu_data)]["url"]
end
end
return setu_json
end
function send_to_group(CurrentQQ, toUid, content)
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = toUid,
SendToType = 2,
SendMsgType = "TextMsg",
Content = content
})
end
function send_pic_to_group(CurrentQQ, toUid, str, img_url)
log.notice("the setu_img_url is %s", img_url)
Api.Api_SendMsgV2(CurrentQQ, {
ToUserUid = toUid,
SendToType = 2,
SendMsgType = "PicMsg",
Content = str,
PicUrl = img_url
})
end
-- 读取数据函数
function Read(url)
file = io.open(url, "r")
if (file == nil) then
return nil
else
file:seek("set")
str = file:read("*a")
file:close()
return str
end
end
-- 写入数据函数
function Wirte(url, msg)
file = io.open(url, "w+")
file:write(msg)
file:close()
return "ok"
end
function setu_threshold(data)
os.execute("mkdir -p ./Plugins/cache/色图限制/" .. data.FromGroupId)
user_lock_file =
"./Plugins/cache/色图限制/" .. data.FromGroupId .. "/" ..
data.FromUserId .. ".txt"
group_lock_file = "./Plugins/cache/色图限制/" .. data.FromGroupId ..
"/1.txt"
msg = Read(user_lock_file)
if (msg ~= nil) then
os.execute('flock -xn /tmp/' .. data.FromGroupId .. '-' ..
data.FromGroupId ..
'-setu.lock -c "sleep 10 && echo 0 >| ' .. user_lock_file ..
'" &')
os.execute('flock -xn /tmp/' .. data.FromGroupId ..
'-setu.lock -c "sleep 10 && echo 0 >| ' ..
group_lock_file .. '" &')
if tonumber(msg) >= 3 then
os.execute('flock -xn /tmp/' .. data.FromGroupId .. '-' ..
data.FromGroupId ..
'-setu.lock -c "sleep 10 && echo 0 >| ' ..
user_lock_file .. '" &')
return "user_is_locked"
end
Wirte(user_lock_file, tonumber(msg) + 1)
msg = Read(group_lock_file)
if (msg ~= nil) then
if tonumber(msg) >= 5 then
os.execute('flock -xn /tmp/' .. data.FromGroupId .. '-' ..
data.FromGroupId ..
'-setu.lock -c "sleep 10 && echo 0 >| ' ..
group_lock_file .. '" &')
return "group_is_locked"
else
Wirte(group_lock_file, tonumber(msg) + 1)
end
else
Wirte(group_lock_file, 0)
end
else
Wirte(group_lock_file, 0) -- 群限制
Wirte(user_lock_file, 0) -- 群成员限制
end
return "ok"
end