-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACG图.js
296 lines (285 loc) · 11.1 KB
/
ACG图.js
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
284
285
286
287
288
289
290
291
292
293
294
295
296
import {segment} from "oicq";
import fetch from "node-fetch";
import plugin from "../../lib/plugins/plugin.js";
let CD_Time = 60 //使用CD
let CDT_Time = 150 //使用CD
let Cd = false //CD开关
let CD = {}; //CD容器,不用管
let maxNum = 10//最大请求图片数量
//第一个为撤回,第二个为获取CD,ture为开启,false为关闭
//关键词已禁用,可搜索打开。
let Groupon = false;
// let withdraw = false;
// let timeout = 7000; //撤回CD单位毫秒
// let Cos_on = false;
let r18 = 0;
//上面的为图片r18开关,0为非R18,1为R18,2为混合
//false为关闭,使用前在resources文件夹创建acg文件夹,acg文件夹会有下载好的图片
// let LocalImg = false;
//是否开启概率回复“过会再chong吧欧尼酱>m<...”
let PrivateSwitch = true;
let Black = [123456789] //黑名单QQ
//是否禁用私聊
export class SearchACG extends plugin {
constructor() {
super({
name: 'Acg_Search',
dsc: 'Search',
event: 'message',
// 优先级(数值越小优先度越高)
priority: 1299,
// 消息匹配规则
rule: [
{
reg: "^#图图$",//#图图
fnc: 'ACG',
},
{
reg: '^#搜索(.*)$', //#搜索刻晴
fnc: 'ACG_Sc'
}
]
})
}
async ACG(e) {
if (Black.includes(e.user_id)) {
e.reply("不看图恶意请求,已被拉黑~")
return true
}
if (e.isGroup && Groupon === false && !e.isMaster) {
e.reply("暂时禁用了噢qwq...");
return true;
}
/**禁用私聊,主人除外*/
if (!e.isGroup && !e.isMaster) {
e.reply("禁止私聊!")
return true;
}
/**如果打开了CD开关,获取CD并发送*/
if (CD[e.user_id] && !e.isMaster && Cd === true) {
e.reply(`CD:${CD_Time}s...>_<...`)
return true;
}
/**处理获取的图片数*/
// let requestNum=e.msg.replace(/张|个|图|来|#|/g, '').trim() //替换词语并去掉替换后的空格
// if(isNaN(requestNum)===true){
// e.reply("baka!用数字啊,打数字没有打字轻松吗!")
// return true
// }
// let requestSum=parseInt(requestNum)
// console.log(requestSum) //测试一下获取的数量
//请求为负时
// if(requestSum<0){
// e.reply("敲你!请求一个负数很好玩吗q_q...")
// return true;
// }
//判断一下最大请求的数量(0-20之间)
// if(requestSum>0 && requestSum>maxNum){//最大请求数量
// e.reply("虽然我知道你是lsp,但是也要有个限度!")
// return true;
// }
/**处理url*/
let url = `https://iw233.cn/api.php?&type=json&num=${maxNum}&sort=random`
const response = await fetch(url);
let res = await response.json();
if (res) {
console.log(res.pic[0])//获取一下第一张图的地址看看有没有
e.reply(`请求成功${maxNum},张,loading.....`)
CD[e.user_id] = true;
let acgList = []
let bot
if (e.isPrivate) {
bot = {nickname: Bot.nickname, user_id: Bot.uin}
} else {
console.log("请求者e.member.card:" + `${e.member.card}`)
bot = {nickname: e.member.card || e.member.nickname, user_id: e.user_id}
}
acgList.push(
{
message: [
segment.at(e.user_id), "\n",
"RequestNum:", 15,
"\n", segment.image(res.pic[0]),
"\n", segment.image(res.pic[1]),
"\n", segment.image(res.pic[2]),
"\n", segment.image(res.pic[3]),
"\n", segment.image(res.pic[4]),
"\n", segment.image(res.pic[5]),
"\n", segment.image(res.pic[6]),
"\n", segment.image(res.pic[7]),
"\n", segment.image(res.pic[8]),
"\n", segment.image(res.pic[9]),
],
...bot,
},
)
console.log("装载完毕!")
try {
if (e.isGroup)
res = await e.group.sendMsg([await e.group.makeForwardMsg(acgList)], false, {anonymous: true, recallMsg: 15 })
else
res = await e.reply([await e.friend.makeForwardMsg(acgList)])
CD[e.user_id] = setTimeout(() => {
if (CD[e.user_id]) {
delete CD[e.user_id];
}
}, (CDT_Time) * 1000);
console.log("发送完成")
if (!res) {
e.reply("太那个了...没发出来,CD重置,>_<....", false, { at: true, recallMsg: 8 })
delete CD[e.user_id]
}
return true
} catch (err) {
let Ni = await e.reply([await e.group.makeForwardMsg(acgList)])
if (!Ni) {
e.reply("太那个了...没发出来,CD重置,>_<....", false, { at: true, recallMsg: 8 })
delete CD[e.user_id]
}
}
} else {
e.reply("获取失败了,让管理看一下后台吧qwq")
delete CD[e.user_id]
}
}
//搜索模块
async ACG_Sc(e) {
if (Black.includes(e.user_id)) {
e.reply("不看图恶意请求,已被拉黑~")
return true
}
if (e.isGroup && Groupon === false && !e.isMaster) {
e.reply("暂时禁用了噢qwq...");
return true;
}
/**如果打开了CD开关,获取CD并发送*/
if (CD[e.user_id] && !e.isMaster && Cd === true) {
e.reply(`CD:${CD_Time}s...>_<...`)
return true;
}
/**禁用私聊,主人除外*/
if (e.isPrivate && !e.isMaster && PrivateSwitch === true) {
return;
}
/**解析url*/
console.log("用户命令:", e.msg);
let keyword = e.msg.replace("#", "");
keyword = keyword.replace("搜索", "");
let url = `https://api.lolicon.app/setu/v2?tag=${keyword}&proxy=i.pixiv.re&r18=${r18}`;
console.log(url);
const response = await fetch(url);
let res = await response.json();
if (res.data.length === 0) {
e.reply("没有搜到哦!换个关键词试试吧!", false, { at: true, recallMsg: 8 });
delete CD[e.user_id];
return true;
}
console.log("pid:" + res.data[0].pid)
let pid = res.data[0].pid
// let Img_url = `https://pixiv.re/${pid}.jpg`
let Img_url=res.data[0].urls.original
// {"error":"","data":[{"pid":90849486,"p":0,"uid":512849,"title":"夏の思い出♪","author":"刃天","r18":false,"width":2940,"height":1654,"tags":["原神","Genshin Impact","パイモン(原神)","派蒙(原神)","蛍(原神)","萤(原神)","アンバー(原神)","安柏(原神)","ノエル(原神)","诺艾尔(原神)","フィッシュル(原神)","菲谢尔(原神)","尻神様","尻神样","裸足","赤脚","水着","泳装"],"ext":"png","aiType":0,"uploadDate":1624787144000,"urls":{"original":"https://i.pixiv.re/img-original/img/2021/06/27/18/45/44/90849486_p0.png"}}]}
/**图片描述*/
let TagNumber = res.data[0].tags.length;
let tags, tags_two
let number = 0;
while (TagNumber--) {
tags = res.data[0].tags[TagNumber];
if (number === 0) {
tags_two = "";
}
tags_two = tags_two + " " + tags;
number++;
}
console.log(tags_two);
/**开始封装消息*/
e.reply("已获取到图片,loading...", false, { at: true, recallMsg: 8 })
/**将消息封装进合并消息*/
let msgList = []
let bot
if (e.isPrivate) {
bot = {nickname: Bot.nickname, user_id: Bot.uin}
} else {
console.log("请求者e.member.card:" + `${e.member.card}`)
// const bot = { nickname: Bot.nickname, user_id: Bot.uin }
bot = {nickname: e.member.card || e.member.nickname, user_id: e.user_id}
}
CD[e.user_id] = true;
CD[e.user_id] = setTimeout(() => {
if (CD[e.user_id]) {
delete CD[e.user_id];
}
}, CD_Time * 1000);
msgList.push(
{
message: [
segment.at(e.user_id), "\n",
"Title:", res.data[0].title,
"\nAuthor:", res.data[0].author,
"\nKeyWords:", tags_two,
"\n", "Website:", Img_url,
"\n", segment.image(Img_url),
],
...bot,
},
)
if (e.isGroup)
res = await e.reply([await e.group.makeForwardMsg(msgList)])
else
res = await e.reply([await e.friend.makeForwardMsg(msgList)])
if (!res) {
e.reply("可能太那个了...没发出来,再试一下吧>_<....", false, { at: true, recallMsg: 8 })
delete CD[e.user_id];
}
return true
// if (withdraw === true) {
// let msgRes = await e.reply(msg);
// await this.Che(msgRes, e, Img_url)
// } else {
// await e.reply(msg);
// }
}
//添加CD
// async SetCD(e){
// let nowTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
// let lastTime = await redis.get(`Yz:wcplus:${this.e.group_id}`);
// if (lastTime && (!e.isMaster || (e.isMaster && masterCD))) {
// let seconds = moment(nowTime).diff(moment(lastTime), 'seconds')
// this.e.reply(`cd中,请等待${ACG_CD - seconds}秒后再使用`)
// }
// }
//剩余CD
// async RemainCD(e){
// nowTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
// await redis.set(`Yz:ACG_CD:${this.e.group_id}`, currentTime, {
// EX: ACG_CD
// })
// }
}
//撤回模块
// async Che(msgRes, e, imgurl) {
// let msg = [
// segment.at(e.user_id),
// "\n",
// imgurl, "\n",
// "感兴趣请复制去浏览器Open",
// ];
// if (timeout !== 0 && msgRes && msgRes.message_id) {
// let target = null;
// if (e.isGroup) {
// target = e.group;
// } else {
// target = e.friend;
// }
// if (target != null) {
// setTimeout(() => {
// target.recallMsg(msgRes.message_id);
// e.reply(msg);
// }, timeout);
// }
// }
// }
// st:"获取随机二次元图片(涩一点)"
// acgs:"搜索随机二次元图片"
// acg:"获取随机二次元图片"
// cos:"获取随机cos"