node-karin 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # 更新日志
2
2
 
3
+ ## [1.9.7](https://github.com/KarinJS/Karin/compare/core-v1.9.6...core-v1.9.7) (2025-05-23)
4
+
5
+
6
+ ### ⚡️ Performance
7
+
8
+ * 优化事件工具 新增`hasPermission` ([fb1d693](https://github.com/KarinJS/Karin/commit/fb1d693c0af1b90fbf2b9e417ac45ff54a7dab07))
9
+
3
10
  ## [1.9.6](https://github.com/KarinJS/Karin/compare/core-v1.9.5...core-v1.9.6) (2025-05-22)
4
11
 
5
12
 
package/dist/index.d.ts CHANGED
@@ -5425,6 +5425,13 @@ declare abstract class BaseEvent<T extends EventParent> {
5425
5425
  get isGroupTemp(): boolean;
5426
5426
  /** 是否为频道私信场景 */
5427
5427
  get isDirect(): boolean;
5428
+ /**
5429
+ * 传入目标权限,返回当前事件触发者是否拥有该权限
5430
+ * @param permission - 目标权限
5431
+ * @param isUpper - 是否向上检查 例如`group:admin`向上检查到`master` 默认`true`
5432
+ * @returns 是否拥有该权限
5433
+ */
5434
+ hasPermission(permission: Permission, isUpper?: boolean): boolean;
5428
5435
  }
5429
5436
 
5430
5437
  /**
package/dist/index.mjs CHANGED
@@ -6111,6 +6111,55 @@ var init_base2 = __esm({
6111
6111
  get isDirect() {
6112
6112
  return this.#contact.scene === "direct";
6113
6113
  }
6114
+ /**
6115
+ * 传入目标权限,返回当前事件触发者是否拥有该权限
6116
+ * @param permission - 目标权限
6117
+ * @param isUpper - 是否向上检查 例如`group:admin`向上检查到`master` 默认`true`
6118
+ * @returns 是否拥有该权限
6119
+ */
6120
+ hasPermission(permission, isUpper = true) {
6121
+ if (permission === "all") {
6122
+ return true;
6123
+ }
6124
+ if (permission === "master") {
6125
+ return this.isMaster;
6126
+ }
6127
+ if (permission === "admin") {
6128
+ if (isUpper) return this.isMaster || this.isAdmin;
6129
+ return this.isAdmin;
6130
+ }
6131
+ const permissionConfig = {
6132
+ "group.owner": {
6133
+ sceneCheck: () => this.isGroup,
6134
+ roleValue: "owner",
6135
+ includeAdmin: true
6136
+ },
6137
+ "group.admin": {
6138
+ sceneCheck: () => this.isGroup,
6139
+ roleValue: "admin",
6140
+ includeAdmin: true
6141
+ },
6142
+ "guild.owner": {
6143
+ sceneCheck: () => this.isGuild,
6144
+ roleValue: "owner",
6145
+ includeAdmin: true
6146
+ },
6147
+ "guild.admin": {
6148
+ sceneCheck: () => this.isGuild,
6149
+ roleValue: "admin"
6150
+ }
6151
+ };
6152
+ const config3 = permissionConfig[permission];
6153
+ if (!config3) {
6154
+ throw new Error(`\u4E0D\u652F\u6301\u7684\u6743\u9650: ${permission}`);
6155
+ }
6156
+ if (!config3.sceneCheck()) return false;
6157
+ const role = this.sender?.role || "unknown";
6158
+ if (isUpper && config3.includeAdmin) {
6159
+ return this.isMaster || this.isAdmin || role === config3.roleValue;
6160
+ }
6161
+ return role === config3.roleValue;
6162
+ }
6114
6163
  };
6115
6164
  }
6116
6165
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "Lightweight, efficient, concise, and stable robot framework.",
5
5
  "keywords": [
6
6
  "node",