加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pix搜图无涩图版群cd.js 3.95 KB
一键复制 编辑 原始数据 按行查看 历史
玉玉了 提交于 2023-05-28 12:38 . V3
import fetch from "node-fetch";
import plugin from '../../lib/plugins/plugin.js'
let cooldowns = new Map();
let mb = 300; //撤回时间
let cdtime = 60; // 冷却时间秒
let NumReg = '[一壹二两三四五六七八九十百千万亿\\d]+'
export class pixiv extends plugin {
constructor() {
super({
/** 功能名称 */
name: "pixiv",
/** 功能描述 */
dsc: "pixiv",
/** https://oicqjs.github.io/oicq/#events */
event: "message",
/** 优先级,数字越小等级越高 */
priority: 5000,
rule: [
{
reg: "^#?pix搜图(.*)$",
fnc: 'tags'
},
]
});
}
async tags(e) {
if (!e.isMaster && !e.isGroup) {
e.reply('不可以私聊瑟瑟哦~')
return;
}
if (!e.isMaster ) {
let groupId = e.group_id; // 获取群聊号
const cooldown = cooldowns[groupId];
if (cooldown && cooldown > Date.now()) {
const remainingTime = Math.ceil((cooldown - Date.now()) / 1000);
e.reply("当前群聊共享cd,还有" + remainingTime + "秒~");
return;
}
cooldowns[groupId] = Date.now() + cdtime * 1000;
}
logger.info('[用户命令]', e.msg);
let msg = e.msg.replace(/#|pix搜图/g, '').trim()
msg = msg.replace("pix搜图","").trim()
let string = msg
let stringlist = string.split(" ")
let tag = stringlist[0]
let key = stringlist[1]
let num = [];
if (!tag) {
tag = "";
}
if (!key) {
num = 1;
} else {
num = (key - 1) * 20;
if (isNaN(num)) {
e.reply('请输入阿拉伯数字');
return;
}
}
let url = `https://www.vilipix.com/api/v1/picture/public?&tags=${tag}&limit=20&sort=new&offset=${num}`;
let response = ""; //调用接口获取数据
let res = ""; //结果json字符串转对象
let msgRes = [];
let pd = [];
let bt = [];
let tg = [];
let zs = [];
let img = [];
let ffmsg = [];
try {
response = await fetch(url);
res = await response.json();
for (let i = 0; i < res.data.rows.length; i++) {
img[i] = res.data.rows[i].original_url
pd[i] = res.data.rows[i].picture_id
bt[i] = res.data.rows[i].title
tg[i] = res.data.rows[i].tags.split(",")
zs = res.data.count
}
} catch {
e.reply('对不起,没有搜索到' + tag )
return
}
console.log(img)
if (res.data.count == 0) {
e.reply("暂时没有搜到哦!换个关键词试试吧!");
return true;
}
//发送消息
let page = Math.ceil(zs / 20);
let ab = Math.floor(num / 20) + 1;
let abc = ab + 1;
if (key > page) {
e.reply('伦家只有这么多了!不可以翻到那页!>_<');
return true;
}
e.reply("别急,伦家这就去给你找图片了~")
for (let i = 0; i < img.length; i++) {
msgRes[i] = [
`标题:${bt[i]}\n`,
`pid:${pd[i]}\n`,
`tags:${tg[i]}\n`,
segment.image(img[i])
];
msgRes[0]=[
`图片总张数:${zs}\n`,
`总页数:${page},当前页数 ${ab},可以用指令 #pix搜图${tag} 2 进行翻页`
];
ffmsg.push({
message: msgRes[i],
nickname: e.nickname,
user_id: e.user_id
});
}
let ForwardMsg;
if (e.isGroup) {
ForwardMsg = await e.group.makeForwardMsg(ffmsg);
}
let abmsg = e.reply(ForwardMsg,true,{ recallMsg: mb });//回复消息
if (abmsg == undefined) {
e.reply("消息被风控了,图被吞掉了捏");
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化