|
@@ -10,6 +10,9 @@ export async function handleHistoryCommand(ctx: Context, env: any) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Check if "all" argument is provided
|
|
|
|
|
+ const showAll = ctx.match?.trim() === 'all';
|
|
|
|
|
+
|
|
|
// Retrieve stored credentials for this user
|
|
// Retrieve stored credentials for this user
|
|
|
const credentials = await env.COSMOE_CREDENTIALS.get(userId.toString());
|
|
const credentials = await env.COSMOE_CREDENTIALS.get(userId.toString());
|
|
|
if (!credentials) {
|
|
if (!credentials) {
|
|
@@ -18,11 +21,11 @@ export async function handleHistoryCommand(ctx: Context, env: any) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const credentialsObj = JSON.parse(credentials);
|
|
const credentialsObj = JSON.parse(credentials);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Initialize Cosmoe client and set stored credentials
|
|
// Initialize Cosmoe client and set stored credentials
|
|
|
const cosmoeClient = new CosmoeClient();
|
|
const cosmoeClient = new CosmoeClient();
|
|
|
cosmoeClient.setCredentials(credentialsObj.user_id, credentialsObj.token);
|
|
cosmoeClient.setCredentials(credentialsObj.user_id, credentialsObj.token);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!cosmoeClient.isAuthenticated()) {
|
|
if (!cosmoeClient.isAuthenticated()) {
|
|
|
await ctx.reply("无效的凭证,请尝试使用 /login 命令重新登录");
|
|
await ctx.reply("无效的凭证,请尝试使用 /login 命令重新登录");
|
|
|
return;
|
|
return;
|
|
@@ -30,26 +33,30 @@ export async function handleHistoryCommand(ctx: Context, env: any) {
|
|
|
|
|
|
|
|
// Get booking history
|
|
// Get booking history
|
|
|
const bookingsResult = await cosmoeClient.getMyBookings();
|
|
const bookingsResult = await cosmoeClient.getMyBookings();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (bookingsResult.code !== 200 || !bookingsResult.data) {
|
|
if (bookingsResult.code !== 200 || !bookingsResult.data) {
|
|
|
await ctx.reply("获取预约记录失败");
|
|
await ctx.reply("获取预约记录失败");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const bookings = bookingsResult.data;
|
|
|
|
|
|
|
+ // Filter out completed and cancelled bookings unless "all" is specified
|
|
|
|
|
+ let bookings = bookingsResult.data;
|
|
|
|
|
+ if (!showAll) {
|
|
|
|
|
+ bookings = bookings.filter((b: any) => b.status !== '已完成' && b.status !== '已取消');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (bookings.length === 0) {
|
|
if (bookings.length === 0) {
|
|
|
- await ctx.reply("你的预约记录为空");
|
|
|
|
|
|
|
+ await ctx.reply(showAll ? "你的预约记录为空" : "没有进行中的预约记录,使用 /history all 查看全部");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Format and send booking history
|
|
// Format and send booking history
|
|
|
- let historyMessage = `*预约记录*\n\n`;
|
|
|
|
|
-
|
|
|
|
|
- // Sort bookings by booking_date in descending order (most recent first) and take only the latest 10
|
|
|
|
|
|
|
+ let historyMessage = showAll ? `*预约记录(全部)*\n\n` : `*预约记录*\n\n`;
|
|
|
|
|
+
|
|
|
|
|
+ // Sort bookings by booking_date in descending order (most recent first)
|
|
|
const sortedBookings = [...bookings]
|
|
const sortedBookings = [...bookings]
|
|
|
.sort((a, b) => new Date(b.booking_date).getTime() - new Date(a.booking_date).getTime())
|
|
.sort((a, b) => new Date(b.booking_date).getTime() - new Date(a.booking_date).getTime())
|
|
|
- .slice(0, 8);
|
|
|
|
|
|
|
+ .slice(0, showAll ? 50 : 8);
|
|
|
|
|
|
|
|
for (let i = 0; i < sortedBookings.length; i++) {
|
|
for (let i = 0; i < sortedBookings.length; i++) {
|
|
|
const booking = sortedBookings[i];
|
|
const booking = sortedBookings[i];
|