lintonxue00's picture
Upload sign.js
2b65ba8
raw
history blame
5.41 kB
import plugin from '../../../lib/plugins/plugin.js'
import fs from "fs";
import lodash from "lodash";
import { Config } from '../components/index.js'
import { YamlReader, puppeteer, common } from '../model/index.js';
import fetch from "node-fetch";
export class example extends plugin {
constructor() {
super({
name: "小月签到",
event: "message",
priority: 500,
rule: [
{
reg: '^#?(小月)?签到$',
fnc: 'sign',
},
{
reg: '^#?(小月)?(积分排行|积分排名)$',
fnc: 'rankIntegral',
},
{
reg: '^#?(小月)?(积分查询|查询积分)',
fnc: 'queryRank',
}
],
});
}
async sign(e) {
let res = await fetch(`https://yxyapi.sesepic.top/sign?user=${e.user_id}`).catch((err) => logger.error(err))
if (!res?.ok) return e.reply('接口请求失败')
res = await res.json()
let keyres = await fetch(`https://yxyapi.sesepic.top/keys?user=${e.user_id}`).catch(err => { })
if (keyres?.ok) keyres = await keyres.text()
if (keyres == 'true')
keyres = '已激活'
else
keyres = '未激活'
let tgres = await fetch('https://ovooa.com/API/tgrj/api.php?type=json').catch((err) => { })
if (tgres?.ok) tgres = await tgres.json()
let ylres = await fetch('https://v1.hitokoto.cn/?c=a').catch((err) => { })
if (ylres?.ok) ylres = await ylres.json()
let xzName = ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
let num = Math.floor(Math.random() * xzName.length)
let xz = await fetch(`https://xiaoapi.cn/API/xzys.php?msg=${encodeURI(xzName[num])}`).catch((err) => { })
if (xz?.ok) {
xz = await xz.text()
xz = xz.split('\n')
}
if (res.data.endExperience >= 99999) res.data.endExperience = 99999
let { dj, ex } = await getExperience(res.data.endExperience)
let name = e.sender.card || e.sender.nickname
name = name.substring(0, 12)
//签到数据
let signdata = {
//头像
tx: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.user_id}`,
//名字
name,
//等级
dj,
//经验
ex,
//密钥激活状态
keyres,
//签到状态
msg: res.msg,
//积分
integral: res.data.integral,
//经验
experience: res.data.experience,
//积分排名
rank: res.data.rank,
//累计签到次数
time: res.data.time,
//最后签到时间
endTime: res.data.endTime,
//总积分
endIntegral: res.data.endIntegral,
//总经验
endExperience: res.data.endExperience,
//舔狗文案
tg: tgres?.text ?? '我给你打了几通电话,你终于接了。听到了你发出啊啊啊啊的声音,你说你肚子痛,我想你一定是很难受吧。电话还有个男的对你说“来换个姿势”,一定是在做理疗了。期待你早日康复,我好担心。',
//动漫语录
yl: ylres?.hitokoto ?? '只要轻唤你的名字,我们的羁绊就永远不会消逝',
//出自动漫
ylfrom: ylres?.from ?? '紫罗兰永恒花园',
//星座运势
xz_xz: xz?.[0] ?? '水瓶座',
xz_sz: xz?.[3] ?? '9',
xz_color: xz?.[4] ?? '玛瑙黑',
xz_zt: xz?.[5] ?? '今天适合约恋人到欧式风味的餐厅喝咖啡,咖啡的香浓能让两人之间弥漫着浪漫的气味;花点钱施舍给需要帮助的人,可提升你的财运;谦和的态度才能更好的树立你在客户心中的形象,对你今天的洽谈工作非常有利。 ',
//随机底图
bg: await rodom()
}
await puppeteer.render('sign/index', {
...signdata
}, {
e,
scale: 2.0,
})
}
async rankIntegral(e) {
let res = await fetch(`https://yxyapi.sesepic.top/signrank`).catch(err => { })
if (res?.ok) res = await res.json()
for (let i = 0; i < 100; i++) {
res.rank[i].tx = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${res.rank[i].qq}`
}
let arrQQ = []
let arrTx = []
let arrJf = []
for (let i of res.rank) {
arrQQ.push(i.qq)
arrTx.push(i.tx)
arrJf.push(i.value)
}
arrQQ = arrQQ.toString()
arrTx = arrTx.toString()
let data = {
arrQQ,
arrTx,
arrJf,
bg: await rodom()
}
await puppeteer.render('sign/rank', {
...data
}, {
e,
scale: 2.0
})
}
async queryRank(e) {
let res = await fetch(`https://test-1.peterliangaaa.repl.co/signrank`).catch(err => { })
if (res?.ok) res = await res.json()
if (!res) return e.reply('接口失效')
let qq = e.at ?? e.msg.match(/\d+/)?.[0]
if (!qq) return e.reply('未在消息内找到查询者QQ')
for (let i = 0; i < res.rank.length; i++) {
if (res.rank[i].qq == qq) {
return e.reply(`QQ:${qq}\n积分:${res.rank[i].value}\n排名:${i+1}\n总人数:${res.rank.length}`,true)
}
}
e.reply('未在积分榜上查询到此玩家')
}
}
//随机底图
const rodom = async function () {
var image = fs.readdirSync(`./plugins/xiaoyue-plugin/resources/sign/imgs`);
var list_img = [];
for (let val of image) {
list_img.push(val)
}
var imgs = list_img.length == 1 ? list_img[0] : list_img[lodash.random(0, list_img.length - 1)];
return imgs;
}
//返回等级,经验
const getExperience = async function (experience) {
let dj = {}
let res = {}
for (let i = 1; i <= 100; i++) {
dj['LV' + i] = 1000 * i
}
dj['LV100'] = 99999
for (let ex in dj) {
if (dj[ex] >= experience) {
res = { "dj": ex, "ex": `${experience}/${dj[ex]}` }
return res
}
}
}