koishi-plugin-maple-points 0.0.2 → 0.0.3

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/lib/index.js CHANGED
@@ -74,48 +74,25 @@ function apply(ctx) {
74
74
  ctx.on("ready", () => {
75
75
  initItems().catch(console.error);
76
76
  });
77
- const root = ctx.command("积分");
78
- ctx.command("积分/重置积分 <points:number>").usage("重置积分 <积分数量> - 将群内所有人的积分设置为指定值").example("重置积分 1000").action(async ({ session }, points) => {
79
- if (!points) return "格式错误!请输入积分数量\n例如:重置积分 1000";
77
+ const root = ctx.command("积分", "固定队装备分配助手");
78
+ ctx.command("积分/重置积分 <points:number>", "重置所有用户积分").usage("重置积分 <积分数量> - 将用户表中所有人的积分设置为指定值").example("重置积分 1000").action(async ({ session }, points) => {
79
+ if (points === void 0 || points === null) {
80
+ return "格式错误!请使用:重置积分 积分数量";
81
+ }
80
82
  try {
81
- const memberList = await session.bot.getGuildMemberList(session.guildId);
82
- const botId = session.bot.selfId;
83
- let processedCount = 0;
84
- let members = [];
85
- if (Array.isArray(memberList)) {
86
- members = memberList;
87
- } else if (memberList.data && Array.isArray(memberList.data)) {
88
- members = memberList.data;
89
- } else if (typeof memberList === "object") {
90
- members = Object.values(memberList);
91
- }
92
- console.log("处理成员数量:", members.length);
93
- for (const member of members) {
94
- if (!member || member.userId === botId) continue;
95
- const userId = String(member.userId);
96
- const userName = member.nickname || member.username || userId;
97
- const existingUser = await ctx.database.get("maple-points-user", { userid: userId });
98
- if (existingUser.length === 0) {
99
- await ctx.database.create("maple-points-user", {
100
- userid: userId,
101
- name: userName,
102
- points
103
- });
104
- } else {
105
- await ctx.database.set("maple-points-user", { userid: userId }, {
106
- name: userName,
107
- points
108
- });
109
- }
110
- processedCount++;
83
+ const users = await ctx.database.get("maple-points-user", {});
84
+ for (const user of users) {
85
+ await ctx.database.set("maple-points-user", { id: user.id }, {
86
+ points
87
+ });
111
88
  }
112
- return `已将 ${processedCount} 名用户的积分重置为 ${points}`;
89
+ return `已将 ${users.length} 名用户的积分重置为 ${points}`;
113
90
  } catch (error) {
114
91
  console.error("重置积分失败:", error);
115
- return "重置积分失败,请检查机器人权限";
92
+ return "重置积分失败";
116
93
  }
117
94
  });
118
- ctx.command("积分/查询积分", "查询积分").usage("查询群内所有人的积分排行").example("查询积分").action(async ({ session }) => {
95
+ ctx.command("积分/查询积分", "查询所有用户积分").usage("查询群内所有人的积分排行").example("查询积分").action(async ({ session }) => {
119
96
  const users = await ctx.database.get("maple-points-user", {});
120
97
  const sortedUsers = users.sort((a, b) => b.points - a.points);
121
98
  let output = "【用户积分表】\n";
@@ -131,7 +108,7 @@ function apply(ctx) {
131
108
  output += `您的积分:${userPoints}`;
132
109
  return output;
133
110
  });
134
- ctx.command("积分/分配积分").usage("将装备总价值平均分配给所有用户").example("分配积分").action(async ({ session }) => {
111
+ ctx.command("积分/分配积分", "结算装备积分,开始新一轮装备需求").usage("将装备总价值平均分配给所有用户").example("分配积分").action(async ({ session }) => {
135
112
  const items = await ctx.database.get("maple-points-items", {});
136
113
  const totalValue = items.reduce((sum, item) => sum + item.currentPrice, 0);
137
114
  const users = await ctx.database.get("maple-points-user", {});
@@ -149,7 +126,7 @@ function apply(ctx) {
149
126
  }
150
127
  return `已将 ${totalValue} 积分平均分配给 ${users.length} 名用户,每人获得 ${perUser} 积分`;
151
128
  });
152
- ctx.command("积分/查询装备").usage("查看所有装备需求情况").example("查询装备").action(async ({ session }) => {
129
+ ctx.command("积分/查询装备", "查询装备需求情况").usage("查看所有装备需求情况").example("查询装备").action(async ({ session }) => {
153
130
  const items = await ctx.database.get("maple-points-items", {});
154
131
  const sortedItems = items.sort((a, b) => b.currentPrice - a.currentPrice);
155
132
  let output = "【装备需求表】\n";
@@ -179,7 +156,7 @@ function apply(ctx) {
179
156
  }
180
157
  __name(getUserName, "getUserName");
181
158
  });
182
- ctx.command("积分/需求 <itemName:string> [price:number]").usage("需求 <装备名> [价格] - 对指定装备出价").example("需求 自选武器").example("需求 项链 300").action(async ({ session }, itemName, price) => {
159
+ ctx.command("积分/需求 <itemName:string> [price:number]", "需求装备").usage("需求 <装备名> [价格] - 对指定装备出价").example("需求 自选武器").example("需求 项链 300").action(async ({ session }, itemName, price) => {
183
160
  if (!itemName) return "格式错误!请输入装备名\n例如:需求 自选武器\n例如:需求 项链 300";
184
161
  const items = await ctx.database.get("maple-points-items", { name: itemName });
185
162
  if (items.length === 0) {
@@ -233,7 +210,7 @@ function apply(ctx) {
233
210
  });
234
211
  return `需求【${itemName}】成功!扣除${price}积分,当前积分:${user.points - price}`;
235
212
  });
236
- ctx.command("积分/分配装备 <itemName:string> <userName:string>").usage("分配装备 <装备名> <用户名> - 以底价将装备分配给指定用户").example("分配装备 自选武器 张三").action(async ({ session }, itemName, userName) => {
213
+ ctx.command("积分/分配装备 <itemName:string> <userName:string>", "分配装备给用户").usage("分配装备 <装备名> <用户名> - 以底价将装备分配给指定用户").example("分配装备 自选武器 张三").action(async ({ session }, itemName, userName) => {
237
214
  if (!itemName || !userName) {
238
215
  return "格式错误!请输入完整参数\n例如:分配装备 自选武器 张三 1000";
239
216
  }
@@ -255,7 +232,7 @@ function apply(ctx) {
255
232
  });
256
233
  return `分配【${itemName}】成功!扣除【${userName}】${price}积分,当前积分:${user.points - price}`;
257
234
  });
258
- ctx.command("积分/增加积分 <userName:string> <points:number>").usage('增加积分 <用户名> <积分> - 增加或扣除用户积分\n用户名可以是具体用户名或"全部"').example("增加积分 张三 100").example("增加积分 全部 50").example("增加积分 李四 -50").action(async ({ session }, userName, points) => {
235
+ ctx.command("积分/增加积分 <userName:string> <points:number>", "增减用户积分").usage('增加积分 <用户名> <积分> - 增加或扣除用户积分\n用户名可以是具体用户名或"全部"').example("增加积分 张三 100").example("增加积分 全部 50").example("增加积分 李四 -50").action(async ({ session }, userName, points) => {
259
236
  if (!userName || points === void 0) {
260
237
  return "格式错误!请输入完整参数\n例如:增加积分 全部 100\n例如:增加积分 李四 -50";
261
238
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-maple-points",
3
3
  "description": "-",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/lib/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { Context, Schema } from 'koishi';
2
- export declare const name = "maple-points";
3
- export declare const using: readonly ["database"];
4
- export interface Config {
5
- }
6
- export declare const Config: Schema<Config>;
7
- interface User {
8
- id: number;
9
- userid: string;
10
- name: string;
11
- points: number;
12
- }
13
- interface Item {
14
- name: string;
15
- minPrice: number;
16
- lastBidder: string | null;
17
- currentPrice: number;
18
- }
19
- declare module 'koishi' {
20
- interface Tables {
21
- 'maple-points-user': User;
22
- 'maple-points-items': Item;
23
- }
24
- }
25
- export declare function apply(ctx: Context): void;
26
- export {};