generated from nhcarrigan/template
wip: commands
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { MessageFlags } from "discord.js";
|
||||
import { ids } from "../config/ids.js";
|
||||
import { anthropic } from "../utils/anthropic.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { ChatInputCommandInteraction } from "discord.js";
|
||||
|
||||
interface LeantimeResponse {
|
||||
error?: { message: string };
|
||||
result?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param interaction
|
||||
*/
|
||||
export const createTask = async(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
): Promise<void> => {
|
||||
if (interaction.user.id !== ids.users.naomi) {
|
||||
await interaction.reply({
|
||||
content: "This command is restricted to Naomi.",
|
||||
flags: [ MessageFlags.Ephemeral ],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const title = interaction.options.getString("title", true);
|
||||
const description = interaction.options.getString("description") ?? "";
|
||||
const priority = interaction.options.getInteger("priority") ?? 3;
|
||||
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const aiResponse = await anthropic.messages.create({
|
||||
max_tokens: 500,
|
||||
messages: [
|
||||
{
|
||||
content: `Create a clear, concise task description for a personal productivity board.\n\nTask title: ${title}${description
|
||||
? `\nAdditional context: ${description}`
|
||||
: ""}`,
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
model: "claude-haiku-4-5-20251001",
|
||||
system: "You are a helpful assistant that creates well-structured task descriptions. Be concise and actionable. Return only the description text with no extra formatting or headers.",
|
||||
});
|
||||
|
||||
const firstContent = aiResponse.content[0];
|
||||
const augmentedDesc = firstContent.type === "text"
|
||||
? firstContent.text
|
||||
: description;
|
||||
|
||||
const response = await fetch("https://board.nhcarrigan.com/api/jsonrpc", {
|
||||
body: JSON.stringify({
|
||||
id: `amari-task-${Date.now().toString()}`,
|
||||
jsonrpc: "2.0",
|
||||
method: "leantime.rpc.tickets.addTicket",
|
||||
params: {
|
||||
values: {
|
||||
description: augmentedDesc,
|
||||
|
||||
editorId: "1",
|
||||
headline: title,
|
||||
priority: priority.toString(),
|
||||
|
||||
projectId: "1",
|
||||
type: "task",
|
||||
},
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": process.env.LEANTIME_KEY ?? "",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
const data: LeantimeResponse = await response.json();
|
||||
|
||||
if (data.error !== undefined) {
|
||||
await interaction.editReply({
|
||||
content: `❌ Failed to create task: ${data.error.message}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const taskId = data.result;
|
||||
const taskUrl = taskId !== undefined
|
||||
? `https://board.nhcarrigan.com/dashboard/home#/tickets/showTicket/${taskId.toString()}`
|
||||
: "https://board.nhcarrigan.com";
|
||||
|
||||
await logger.metric("created_task", 1, { title });
|
||||
await interaction.editReply({
|
||||
content: `✅ Task created: **${title}**\n${taskUrl}`,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user