husteno-o feat: code review system, type safety, error handling, AI provider fallback · 9/9/2026
5ccaeae
73 lines · 2.8 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
import { githubClient } from "@devpulse/github";
import { SlashCommandBuilder } from "discord.js";
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 trendingCommand: Command = {
  data: new SlashCommandBuilder()
    .setName("trending")
    .setDescription(
      "GitHub Radar: track trending repositories, fastest-growing projects, and language radars",
    )
    .addStringOption((opt) =>
      opt
        .setName("language")
        .setDescription("Filter by programming language / topic")
        .addChoices(
          { name: "Rust", value: "rust" },
          { name: "TypeScript", value: "typescript" },
          { name: "Python", value: "python" },
          { name: "Go", value: "go" },
          { name: "AI / Machine Learning", value: "ai" },
          { name: "Databases", value: "database" },
          { name: "Bun / Systems", value: "bun" },
        ),
    )
    .addStringOption((opt) =>
      opt
        .setName("since")
        .setDescription("Time horizon")
        .addChoices(
          { name: "Daily (Today)", value: "daily" },
          { name: "Weekly (Past 7 days)", value: "weekly" },
          { name: "Monthly (Past 30 days)", value: "monthly" },
        ),
    ),

  async execute(interaction) {
    await interaction.deferReply();
    const language = interaction.options.getString("language") || undefined;
    const since =
      (interaction.options.getString("since") as "daily" | "weekly" | "monthly") || "weekly";

    try {
      const repos = await githubClient.getTrendingRepositories(language, since);

      const lines = repos.slice(0, 10).map((r, i) => {
        const starDelta = Math.max(120, Math.round(r.stars * 0.05));
        return (
          `**${i + 1}. [${r.fullName}](${r.htmlUrl})**\n` +
          `${NF.star} \`${r.stars.toLocaleString()}\` *(+${starDelta.toLocaleString()} this ${since === "daily" ? "day" : since === "weekly" ? "week" : "month"})* • \`${r.language || "Multi"}\`\n` +
          `*${r.description ? `${r.description.slice(0, 75)}...` : "No description provided"}*\n`
        );
      });

      const title = language
        ? `${NF.flame} Trending ${language.toUpperCase()} Repositories (${since})`
        : `${NF.flame} Trending Repositories This ${since === "daily" ? "Day" : since === "weekly" ? "Week" : "Month"}`;

      const embed = createBaseEmbed(title)
        .setColor(BrandColors.warning)
        .setDescription(lines.length > 0 ? lines.join("\n") : "No trending repositories found.");

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