koishi-plugin-zanwo
Version:
QQ 名片赞点赞插件,支持对指定 QQ 号点赞,支持指定点赞次数
159 lines (145 loc) • 6.46 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/locales/zh_CN.yml
var require_zh_CN = __commonJS({
"src/locales/zh_CN.yml"(exports2, module2) {
module2.exports = { commands: { zanwo: { description: "给自己点个赞", usage: "直接输入命令即可为自己点赞\n", examples: "zanwo\n", messages: { success: "已为你点赞,记得也给朋友点个赞哦~", failure: "点赞失败欸,请稍后再试" } }, zan: { description: "为他人点赞", usage: "命令后接 @用户名 或 @QQ号\n", examples: "zan @114514\nzan @小明\n", messages: { success: "已成功完成点赞操作", failure: "无法为该用户点赞,请检查目标是否有效", noarg: "请提供要点赞的对象" } } } };
}
});
// src/index.ts
var src_exports = {};
__export(src_exports, {
Config: () => Config,
apply: () => apply,
name: () => name,
usage: () => usage
});
module.exports = __toCommonJS(src_exports);
var import_koishi = require("koishi");
var Sentry = __toESM(require("@sentry/node-core/light"));
var name = "zanwo";
var usage = `
[](https://www.npmjs.com/package/koishi-plugin-zanwo)
[](https://www.npmjs.com/package/koishi-plugin-zanwo)
QQ 点赞插件,支持为自己或他人点赞,支持设置点赞数量。
> 💡 点赞数量限制在 1-50 之间,超出范围会自动调整
## 本地化配置
插件支持自定义成功/失败提示语句,可在控制台 **本地化** 部分手动配置
## 常见问题
### Q: 为什么点赞失败?
A: 可能的原因:
1. 对方未启用陌生人点赞
2. 网络连接问题
### Q: 使用 @ 提及不生效?
A: 确保:
1. 使用正确的格式:\`zan @用户名\`
2. 在支持 @ 提及的平台使用
3. 或直接使用 QQ 号:\`zan @123456789\`
## 反馈
- 启用「上报错误数据」配置项将自动上报错误给 Sentry,需要配置 Sentry DSN
- 开发路线 [Roadmap](https://git.xmsl.im/liuzhen932/koishi-plugin-zanwo/issues)
`;
var logger = new import_koishi.Logger(name);
var Config = import_koishi.Schema.object({
debug: import_koishi.Schema.boolean().description("是否开启调试模式").default(false).experimental(),
sentryDsn: import_koishi.Schema.string().description("Sentry DSN,用于错误报告。留空则不发送错误数据。").default("").experimental()
});
function apply(ctx, config) {
ctx.i18n.define("zh-CN", require_zh_CN());
const dsn = config.sentryDsn || process.env.SENTRY_DSN || "";
if (dsn) {
Sentry.init({
dsn,
tracesSampleRate: 1
});
if (config.debug) {
logger.info("Sentry 已初始化");
}
}
async function sendLikes(session, userId, totalCount, commandName) {
const clampedCount = Math.max(1, Math.min(50, totalCount));
const batchSize = 10;
const rounds = Math.ceil(clampedCount / batchSize);
let successfulRounds = 0;
try {
for (let i = 0; i < rounds; i++) {
const currentBatch = i === rounds - 1 ? clampedCount - i * batchSize : batchSize;
await session.bot.internal.sendLike(userId, currentBatch);
successfulRounds++;
if (config.debug) {
logger.info(`为 ${userId} 点赞了第 ${successfulRounds} 轮 (${currentBatch} 个)`);
}
}
return session.text(".success");
} catch (e) {
if (dsn) {
Sentry.withScope((scope) => {
scope.setFingerprint([commandName]);
scope.setTag("command", commandName);
scope.setContext("like", { count: clampedCount, successfulRounds });
Sentry.captureException(e);
});
}
if (config.debug) {
logger.warn(`为 ${userId} 点赞失败:${e.message}`);
}
if (successfulRounds > 0) {
return session.text(".success");
}
return session.text(".failure");
}
}
__name(sendLikes, "sendLikes");
ctx.command("zanwo").alias("赞我").option("count", "-c <count:posint> 点赞数量 (1-50)", { fallback: 50 }).action(async ({ session, options }) => {
const count = Math.min(options.count ?? 50, 50);
return sendLikes(session, session.userId, count, "zanwo");
});
ctx.command("zan <target:user>").option("count", "-c <count:posint> 点赞数量 (1-50)", { fallback: 50 }).action(async ({ session, options }, target) => {
if (!target) {
return session.text(".noarg");
}
const uid = target.split(":")[1] || target;
if (config.debug) {
logger.info(`从 ${target} 解析到 UID: ${uid}`);
}
const count = Math.min(options.count ?? 50, 50);
return sendLikes(session, uid, count, "zan");
});
}
__name(apply, "apply");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Config,
apply,
name,
usage
});