Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koishi-plugin-jrys-max

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koishi-plugin-jrys-max - npm Package Compare versions

Comparing version 0.3.2 to 0.3.4

165

lib/index.js

@@ -94,6 +94,6 @@ var __create = Object.create;

// 0:已签到, 1:签到成功, 2:未签到, 3:抽奖
// { "cmd":"get", "status": 1, "getpoint": signpoint, "signTime": signTime, "allpoint": signpoint, "count": 1 };
// { "status": 1, "getpoint": signpoint, "signTime": signTime, "allpoint": signpoint, "count": 1 };
// 参数:session, 返回:json
async callSignin(session) {
var name2;
let name2;
if (this.ctx.database && this.cfg.callme)

@@ -117,3 +117,10 @@ name2 = session.username;

await this.ctx.database.upsert("jrys_max", [{ id: String(session.userId), name: name2, time: signTime, point: Number(signpoint), count: 1, current_point: Number(signpoint) }]);
return { "cmd": "get", "status": 1, "getpoint": signpoint, "signTime": signTime, "allpoint": signpoint, "count": 1 };
return {
"cmd": "get",
"status": 1,
"getpoint": signpoint,
"signTime": signTime,
"allpoint": signpoint,
"count": 1
};
}

@@ -130,3 +137,3 @@ if (Number(time.slice(8, 10)) - Number(signTime.slice(8, 10))) {

return {
"cmd": "get",
// "cmd": "get",
"status": 1,

@@ -145,3 +152,3 @@ // 签到成功

return {
"cmd": "get",
// "cmd": "get",
"status": 0,

@@ -159,14 +166,14 @@ // 签到失败

}
// 参数:session, 返回:json
async signQuery(session) {
let all_point = (await this.ctx.database.get("jrys_max", { id: String(session.userId) }))[0]?.point;
let time = (await this.ctx.database.get("jrys_max", { id: String(session.userId) }))[0]?.time;
let count = (await this.ctx.database.get("jrys_max", { id: String(session.userId) }))[0]?.count;
let current_point = (await this.ctx.database.get("jrys_max", { id: String(session.userId) }))[0]?.current_point;
let nowTime = import_koishi.Time.template("yyyy-MM-dd hh:mm:ss", /* @__PURE__ */ new Date());
if (Number(time.slice(8, 10)) - Number(nowTime.slice(8, 10))) {
return { "cmd": "query", "status": 2, "getpoint": current_point ? current_point : 0, "signTime": time ? time : "暂无数据", "allpoint": all_point ? all_point : 0, "count": count ? count : 0 };
}
return { "cmd": "query", "status": 0, "getpoint": current_point ? current_point : 0, "signTime": time ? time : "暂无数据", "allpoint": all_point ? all_point : 0, "count": count ? count : 0 };
}
// // 参数:session, 返回:json
// async signQuery(session) {
// let all_point = (await this.ctx.database.get('jrys_max', { id: String(session.userId) }))[0]?.point;
// let time = (await this.ctx.database.get('jrys_max', { id: String(session.userId) }))[0]?.time;
// let count = (await this.ctx.database.get('jrys_max', { id: String(session.userId) }))[0]?.count;
// let current_point = (await this.ctx.database.get('jrys_max', { id: String(session.userId) }))[0]?.current_point;
// let nowTime = Time.template('yyyy-MM-dd hh:mm:ss', new Date());
// if (Number(time.slice(8,10)) - Number(nowTime.slice(8,10))) {
// return { "cmd":"query", "status": 2, "getpoint": current_point? current_point:0, "signTime": time? time:"暂无数据", "allpoint": all_point? all_point:0, "count": count? count:0 };
// }
// return { "cmd":"query", "status": 0, "getpoint": current_point? current_point:0, "signTime": time? time:"暂无数据", "allpoint": all_point? all_point:0, "count": count? count:0 };
// }
levelJudge(all_point) {

@@ -197,5 +204,13 @@ for (const levelInfo of levelInfos) {

// src/jrysmax.ts
var import_crypto = __toESM(require("crypto"));
var fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
function fnv1aHash(str) {
let hash = 2166136261;
for (let i = 0; i < str.length; i++) {
hash ^= str.charCodeAt(i);
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
}
return hash >>> 0;
}
__name(fnv1aHash, "fnv1aHash");
var jrysmax = class {

@@ -207,63 +222,40 @@ static {

}
async getJrys(uid, debug) {
const md5 = import_crypto.default.createHash("md5");
const hash = import_crypto.default.createHash("sha256");
let etime = (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0);
async getJrys(uid) {
const etime = (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0).toString();
let userId;
if (!isNaN(Number(uid))) {
userId = uid;
if (typeof uid === "number" || !isNaN(Number(uid))) {
userId = Number(uid);
} else {
if (uid) {
hash.update(uid + String(etime));
let hashhexDigest = hash.digest("hex");
userId = Number(parseInt(hashhexDigest, 16)) % 1000000001;
const hashInput = uid + etime;
userId = fnv1aHash(hashInput) % 1000000001;
} else {
md5.update("Default Jrys" + String(etime));
let hexDigest = md5.digest("hex");
userId = parseInt(hexDigest, 16) % 1000000001;
const defaultInput = "Default Jrys" + etime;
userId = fnv1aHash(defaultInput) % 1000000001;
}
}
let todayJrys = etime / 1e5 * userId % 1000001 * 2333 % 512;
if (debug)
return { "jrys": todayJrys, "etime": etime / 1e5 };
else
return todayJrys;
}
async generateUserRandom(uid) {
const md5 = import_crypto.default.createHash("md5");
const hash = import_crypto.default.createHash("sha256");
let etime = (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0);
let userId;
if (!isNaN(Number(uid))) {
userId = uid;
} else {
if (uid) {
hash.update(uid + String(etime));
let hashhexDigest = hash.digest("hex");
userId = Number(parseInt(hashhexDigest, 16)) % 1000000001;
} else {
md5.update("Default Jrys" + String(etime));
let hexDigest = md5.digest("hex");
userId = parseInt(hexDigest, 16) % 1000000001;
}
}
let todayJrys = etime / 1e5 * userId % 1000001 * 2333 % 512;
const todaySeed = userId * parseInt(etime) % 1000000001;
const randomFactor = Math.sin(todaySeed) * 1e4;
const todayJrys = Math.floor((randomFactor - Math.floor(randomFactor)) * 512);
return todayJrys;
}
seededRandom(seed) {
const x = Math.sin(seed) * 1e4;
return x - Math.floor(x);
}
// 抽取四个宜不宜
async getRandomObjects(jsonObject, uid) {
const seed = await this.generateUserRandom(uid);
if (!Array.isArray(jsonObject) || jsonObject.length < 4) {
throw new Error("输入必须是一个包含至少四个对象的数组");
}
const seed = await this.getJrys(uid);
const randomIndexes = /* @__PURE__ */ new Set();
let counter = 0;
while (randomIndexes.size < 4) {
const randomIndex = Math.floor(seed * randomIndexes.size % 2333 % jsonObject.length);
const randomIndex = Math.floor(this.seededRandom(seed + counter) * jsonObject.length);
randomIndexes.add(randomIndex);
counter++;
}
return Array.from(randomIndexes).map((index) => jsonObject[index]);
}
async getFolderImg(folder) {
let imgfilename = this.readFilenames(folder);
const filteredArr = imgfilename.filter((filename) => {
return /\.(png|jpg|jpeg|ico|svg)$/i.test(filename);
});
return filteredArr;
}
// 递归获取文件夹内所有文件的文件名

@@ -295,3 +287,3 @@ async readFilenames(dirPath) {

"good": "一次性过",
"bad": '"谁说话这么难懂"'
"bad": "谁说话这么难懂"
},

@@ -825,14 +817,5 @@ {

var Config = import_koishi2.Schema.object({
// superuser: Schema.array(String)
// .description('超级用户id'),
imgurl: import_koishi2.Schema.string().role("link").description("随机横图api"),
imgurl: import_koishi2.Schema.string().role("link").description("随机横图api").required(),
signpointmin: import_koishi2.Schema.number().default(1).description("签到积分随机最小值"),
signpointmax: import_koishi2.Schema.number().default(100).description("签到积分随机最大值")
// textfont: Schema.string().description("`请填写.ttf 字体文件的绝对路径`").default(path.join(__dirname, '/font/pixel.ttf')),
// lotteryOdds: Schema.percent().default(0.6)
// .description('抽奖指令中倍率的概率(默认0.6)'),
// callme: Schema.boolean().default(false)
// .description("启用callme(需要安装callme插件)"),
// waittip: Schema.boolean().default(false)
// .description("启用渲染提示"),
});

@@ -875,4 +858,4 @@ var inject = ["database", "puppeteer"];

} catch (error) {
console.error("An error occurred while fetching hitokoto:", error);
return "Failed to fetch hitokoto";
console.error("获取 hitokoto 时出错:", error);
return "无法获取 hitokoto";
}

@@ -883,9 +866,9 @@ }

const signin = new Signin(ctx, config);
const jrys = new jrysmax();
const date = /* @__PURE__ */ new Date();
ctx.command("jrysmax", "今日运势").userFields(["name"]).action(async ({ session, options }) => {
const jrys = new jrysmax();
const date = /* @__PURE__ */ new Date();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const formattedDate = `${month}/${day}`;
const jrysData = await jrys.getJrys(session.userId ? session.userId : 2333);
const jrysData = await jrys.getJrys(session.userId);
const [gooddo1, gooddo2, baddo1, baddo2] = await jrys.getRandomObjects(eventJson, session.userId ? session.userId : 2333);

@@ -945,9 +928,7 @@ let jryslucky = jrysData;

let etime = (/* @__PURE__ */ new Date()).getTime() % 25565;
let filePath = (0, import_path2.resolve)(__dirname, "./index/defaultImg/").replaceAll("\\", "/");
if (!config.imgurl)
bgUrl = (0, import_url.pathToFileURL)((0, import_path2.resolve)(__dirname, filePath + "/" + import_koishi2.Random.pick(await getFolderImg(filePath)))).href;
else if (config.imgurl.match(/http(s)?:\/\/(.*)/gi))
if (config.imgurl.match(/http(s)?:\/\/(.*)/gi)) {
bgUrl = config.imgurl.match(/^http(s)?:\/\/(.*)#e#$/gi) ? config.imgurl.replace("#e#", etime.toString()) : config.imgurl;
else
} else {
bgUrl = (0, import_url.pathToFileURL)((0, import_path2.resolve)(__dirname, config.imgurl + import_koishi2.Random.pick(await getFolderImg(config.imgurl)))).href;
}
const getSigninJson = await signin.callSignin(session);

@@ -1036,5 +1017,13 @@ let lvline = signin.levelJudge(Number(getSigninJson.allpoint)).level_line;

const element = await page.$("#body");
return import_koishi2.h.image(await element.screenshot({
encoding: "binary"
}), "image/png");
let msg;
if (element) {
const imgBuf = await element.screenshot({
encoding: "binary"
});
msg = import_koishi2.h.image(imgBuf, "image/png");
} else {
msg = "Failed to capture screenshot.";
}
await page.close();
return import_koishi2.h.quote(session.event.message.id) + msg;
} catch (err) {

@@ -1041,0 +1030,0 @@ logger.error(`[jrysmax Error]:\r

export declare class jrysmax {
constructor();
getJrys(uid: string | number, debug?: boolean): Promise<number | {
jrys: number;
etime: number;
}>;
generateUserRandom(uid: string | number): Promise<number>;
getJrys(uid: string | number): Promise<number>;
seededRandom(seed: number): number;
getRandomObjects(jsonObject: Array<any>, uid: string | number): Promise<Array<any>>;
getFolderImg(folder: String): Promise<any>;
readFilenames(dirPath: any): Promise<any[]>;
}

@@ -32,5 +32,3 @@ import { Context } from 'koishi';

count: number;
}>;
signQuery(session: any): Promise<{
cmd: string;
} | {
status: number;

@@ -41,2 +39,3 @@ getpoint: number;

count: number;
cmd?: undefined;
}>;

@@ -43,0 +42,0 @@ levelJudge(all_point: number): LevelInfo;

{
"name": "koishi-plugin-jrys-max",
"description": "",
"version": "0.3.2",
"version": "0.3.4",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "typings": "lib/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc