Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/OmegaBot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# .github/workflows/OmegaBot.yml
name: 🔍 Lint · Typecheck · Format
name: 🤖 OmegaBot

on:
pull_request:
Expand Down
72 changes: 0 additions & 72 deletions scripts copy/precheck.sh

This file was deleted.

56 changes: 39 additions & 17 deletions src/commands/history/history.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {
SlashCommandBuilder,
AttachmentBuilder,
MessageFlags,
type ChatInputCommandInteraction,
} from "discord.js";

/**
* /history command
* Returns the last N raw messages (no summarization).
* Returns the last N raw user messages as a DM to the requester.
* MVP version for chat playback feature (F1).
*/
export const data = new SlashCommandBuilder()
.setName("history")
.setDescription("Show the most recent messages in plain text")
.setDescription("DMs you the most recent messages in this channel")
.addIntegerOption((opt) =>
opt
.setName("count")
Expand All @@ -23,53 +24,74 @@ export const data = new SlashCommandBuilder()
export async function execute(
interaction: ChatInputCommandInteraction,
): Promise<void> {
// Use the requested count, or default to 50 messages.
// Default to 50 messages if no count is provided.
const count = interaction.options.getInteger("count") ?? 50;

await interaction.deferReply();
// Ephemeral: only the caller sees the acknowledgment message.
await interaction.deferReply({ flags: MessageFlags.Ephemeral });

// Fetch messages from the current channel.
const messages = await interaction.channel?.messages.fetch({ limit: count });
if (!messages) {
await interaction.editReply("Could not fetch messages for this channel.");
return;
}

/**
* Filter out bots so playback only includes real user messages.
* Sort oldest→newest so the playback follows the conversation flow.
* Filter user messages only (exclude bots),
* oldest first so playback reads correctly.
*/
const userMessages = messages
.filter((m) => !m.author.bot && m.content)
.sort((a, b) => a.createdTimestamp - b.createdTimestamp);

/**
* Nothing to show.
*/
if (userMessages.size === 0) {
await interaction.editReply("No history found.");
return;
}

/**
* Combine messages into a simple “username: content” transcript, one per line.
* Build a readable transcript.
*/
const text = userMessages
.map((m) => `${m.author.username}: ${m.content}`)
.join("\n");

/**
* If the history exceeds Discord’s 2000-character limit, send it as a text file instead of a normal message.
* If too large for a normal DM, send as a file.
*/
if (text.length > 2000) {
const file = new AttachmentBuilder(Buffer.from(text), {
const file = new AttachmentBuilder(Buffer.from(text, "utf8"), {
name: "history.txt",
});
await interaction.editReply({
content: "History was too long to display, so I attached it as a file.",
files: [file],
});

try {
await interaction.user.send({
content: "Here is your recent chat history:",
files: [file],
});

await interaction.editReply("History sent to your DMs.");
} catch (err) {
console.error("[history] DM file send failed", err);
await interaction.editReply(
"I generated the history, but your DMs appear to be closed.",
);
}

return;
}

await interaction.editReply(text);
/**
* Normal-length transcript → DM it as text.
*/
try {
await interaction.user.send(text);
await interaction.editReply("History sent to your DMs.");
} catch (err) {
console.error("[history] DM text send failed", err);
await interaction.editReply(
"I generated the history, but could not DM you. Your DMs may be closed.",
);
}
}