husteno-o feat: issue management, standup, full PR review, webhooks, news digest Β· 9/10/2026
967bdc7
208 lines Β· 7.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { db, standups, users } from "@devpulse/database";
import { SlashCommandBuilder } from "discord.js";
import { and, eq } from "drizzle-orm";
import { BrandColors } from "../ui/colors.js";
import { createBaseEmbed, createErrorEmbed } from "../ui/embeds.js";
import { NF } from "../ui/icons.js";
import type { Command } from "./types.js";

export const standupCommand: Command = {
  data: new SlashCommandBuilder()
    .setName("standup")
    .setDescription("Daily Standup: log what you did, what you'll do, and any blockers")
    .addSubcommand((sub) =>
      sub
        .setName("submit")
        .setDescription("Submit your daily standup update")
        .addStringOption((opt) =>
          opt
            .setName("yesterday")
            .setDescription("What you did yesterday (comma-separated list)")
            .setRequired(true),
        )
        .addStringOption((opt) =>
          opt
            .setName("today")
            .setDescription("What you plan to do today")
            .setRequired(true),
        )
        .addStringOption((opt) =>
          opt
            .setName("blockers")
            .setDescription("Any blockers or issues (optional)")
            .setRequired(false),
        ),
    )
    .addSubcommand((sub) =>
      sub
        .setName("view")
        .setDescription("View today's standup for the team")
        .addStringOption((opt) =>
          opt
            .setName("date")
            .setDescription("Date to view (YYYY-MM-DD, defaults to today)")
            .setRequired(false),
        ),
    )
    .addSubcommand((sub) =>
      sub
        .setName("history")
        .setDescription("View your recent standup history")
        .addIntegerOption((opt) =>
          opt
            .setName("days")
            .setDescription("Number of days to look back (default 7)")
            .setRequired(false),
        ),
    ),

  async execute(interaction) {
    if (!interaction.guildId) {
      await interaction.reply({
        content: `${NF.cross} This command can only be used in a Discord server.`,
        ephemeral: true,
      });
      return;
    }

    await interaction.deferReply();
    const subcommand = interaction.options.getSubcommand();
    const guildId = interaction.guildId;
    const today = new Date().toISOString().split("T")[0];

    try {
      if (subcommand === "submit") {
        const yesterdayStr = interaction.options.getString("yesterday", true);
        const todayPlan = interaction.options.getString("today", true);
        const blockers = interaction.options.getString("blockers") || null;

        const yesterdayItems = yesterdayStr
          .split(",")
          .map((s) => s.trim())
          .filter(Boolean);

        // Upsert standup
        const existing = await db.query.standups.findFirst({
          where: and(
            eq(standups.guildId, guildId),
            eq(standups.userId, interaction.user.id),
            eq(standups.date, today),
          ),
        });

        if (existing) {
          await db
            .update(standups)
            .set({
              yesterdayActivity: yesterdayItems,
              todayPlan,
              blockers,
            })
            .where(eq(standups.id, existing.id));
        } else {
          await db.insert(standups).values({
            id: crypto.randomUUID(),
            guildId,
            userId: interaction.user.id,
            date: today,
            yesterdayActivity: yesterdayItems,
            todayPlan,
            blockers,
          });
        }

        const embed = createBaseEmbed(`${NF.check} Standup Submitted`)
          .setColor(BrandColors.success)
          .setDescription(
            `**Standup for ${today}** submitted by ${interaction.user.toString()}\n\n` +
              `**πŸ“‹ Yesterday:**\n${yesterdayItems.map((i) => `β€’ ${i}`).join("\n")}\n\n` +
              `**🎯 Today:**\nβ€’ ${todayPlan}\n\n` +
              (blockers ? `**🚧 Blockers:**\nβ€’ ${blockers}\n\n` : "") +
              `_Use /standup view to see the team's standups._`,
          );

        await interaction.editReply({ embeds: [embed] });
        return;
      }

      if (subcommand === "view") {
        const date = interaction.options.getString("date") || today;

        const dayStandups = await db.query.standups.findMany({
          where: and(eq(standups.guildId, guildId), eq(standups.date, date)),
        });

        if (dayStandups.length === 0) {
          await interaction.editReply({
            embeds: [
              createBaseEmbed(`${NF.clipboard} Standup: ${date}`).setDescription(
                `No standups submitted for **${date}**.\n\nUse \`/standup submit\` to log your update.`,
              ),
            ],
          });
          return;
        }

        const lines: string[] = [];
        for (const s of dayStandups) {
          const user = await db.query.users.findFirst({
            where: eq(users.id, s.userId),
          });
          const name = user?.username || s.userId;
          const yesterday = (s.yesterdayActivity as string[]) || [];
          lines.push(
            `**@${name}**\n` +
              `β€’ Yesterday: ${yesterday.join(", ") || "N/A"}\n` +
              `β€’ Today: ${s.todayPlan}\n` +
              (s.blockers ? `β€’ 🚧 Blockers: ${s.blockers}` : ""),
          );
        }

        const embed = createBaseEmbed(`${NF.clipboard} Team Standup: ${date}`)
          .setDescription(lines.join("\n\n"))
          .setFooter({ text: `${dayStandups.length} standup(s) submitted` });

        await interaction.editReply({ embeds: [embed] });
        return;
      }

      if (subcommand === "history") {
        const days = interaction.options.getInteger("days") || 7;
        const userId = interaction.user.id;

        const history = await db.query.standups.findMany({
          where: and(eq(standups.guildId, guildId), eq(standups.userId, userId)),
          orderBy: (s, { desc }) => [desc(s.date)],
          limit: days,
        });

        if (history.length === 0) {
          await interaction.editReply({
            embeds: [
              createBaseEmbed(`${NF.clipboard} Your Standup History`).setDescription(
                "No standups found. Use `/standup submit` to get started!",
              ),
            ],
          });
          return;
        }

        const lines = history.map((s) => {
          const yesterday = (s.yesterdayActivity as string[]) || [];
          return `**${s.date}**\nβ€’ Yesterday: ${yesterday.slice(0, 3).join(", ") || "N/A"}\nβ€’ Today: ${s.todayPlan.slice(0, 80)}${s.todayPlan.length > 80 ? "..." : ""}${s.blockers ? `\nβ€’ 🚧 ${s.blockers}` : ""}`;
        });

        const embed = createBaseEmbed(`${NF.clipboard} Your Standup History`)
          .setDescription(lines.join("\n\n"))
          .setFooter({ text: `Last ${history.length} standups` });

        await interaction.editReply({ embeds: [embed] });
        return;
      }
    } catch (err: unknown) {
      await interaction.editReply({
        embeds: [createErrorEmbed(err instanceof Error ? err : new Error(String(err)))],
      });
    }
  },
};