build-in-public-bot
Version:
AI-powered CLI bot for automating build-in-public tweets with code screenshots
113 lines ⢠5.25 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.historyCommand = historyCommand;
const logger_1 = require("../utils/logger");
const storage_1 = require("../services/storage");
const chalk_1 = __importDefault(require("chalk"));
const prompts_1 = require("../utils/prompts");
async function historyCommand(options) {
const storageService = storage_1.StorageService.getInstance();
const limit = parseInt(options.limit, 10);
try {
const historyType = await (0, prompts_1.select)('What would you like to view?', [
{ value: 'posted', label: 'Posted tweets' },
{ value: 'drafts', label: 'Draft tweets' },
{ value: 'both', label: 'Both posted and drafts' }
]);
let posts = [];
let drafts = [];
if (historyType === 'posted' || historyType === 'both') {
posts = await storageService.getHistory(limit);
}
if (historyType === 'drafts' || historyType === 'both') {
drafts = await storageService.getDrafts();
}
if (historyType === 'posted' || historyType === 'both') {
console.log(chalk_1.default.bold('\nš® Posted Tweets:\n'));
if (posts.length === 0) {
console.log(chalk_1.default.gray('No posted tweets yet.'));
}
else {
posts.forEach((post, index) => {
console.log(chalk_1.default.cyan(`${index + 1}. `) + formatDate(post.createdAt));
console.log(post.text);
if (post.mediaUrls && post.mediaUrls.length > 0) {
console.log(chalk_1.default.gray(` š· ${post.mediaUrls.length} attachment(s)`));
}
console.log();
});
}
}
if (historyType === 'drafts' || historyType === 'both') {
console.log(chalk_1.default.bold('\nš Draft Tweets:\n'));
if (drafts.length === 0) {
console.log(chalk_1.default.gray('No drafts saved.'));
}
else {
drafts.forEach((draft, index) => {
console.log(chalk_1.default.yellow(`${index + 1}. `) + formatDate(draft.createdAt));
console.log(draft.text);
if (draft.includeScreenshot && draft.screenshotPath) {
console.log(chalk_1.default.gray(` š· Screenshot attached`));
}
console.log(chalk_1.default.gray(` ID: ${draft.id}`));
console.log();
});
if (drafts.length > 0) {
const manageDrafts = await (0, prompts_1.confirm)('\nWould you like to manage drafts?');
if (manageDrafts) {
const action = await (0, prompts_1.select)('What would you like to do?', [
{ value: 'post', label: 'Post a draft' },
{ value: 'delete', label: 'Delete a draft' },
{ value: 'cancel', label: 'Cancel' }
]);
if (action === 'post') {
logger_1.logger.info('Draft posting will be available when Twitter integration is complete.');
}
else if (action === 'delete') {
const draftIndex = await (0, prompts_1.select)('Which draft to delete?', drafts.map((d, i) => ({
value: i.toString(),
label: `${i + 1}. ${d.text.substring(0, 50)}...`
})));
const draft = drafts[parseInt(draftIndex, 10)];
await storageService.deleteDraft(draft.id);
logger_1.logger.success('Draft deleted successfully!');
}
}
}
}
}
console.log(chalk_1.default.bold('\nš Summary:'));
console.log(` Posted tweets: ${posts.length}`);
console.log(` Drafts: ${drafts.length}`);
console.log(` Total: ${posts.length + drafts.length}`);
}
catch (error) {
logger_1.logger.error('Failed to fetch history');
throw error;
}
}
function formatDate(date) {
const d = new Date(date);
const now = new Date();
const diffMs = now.getTime() - d.getTime();
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffHours < 1) {
const diffMinutes = Math.floor(diffMs / (1000 * 60));
return chalk_1.default.gray(`${diffMinutes} minutes ago`);
}
else if (diffHours < 24) {
return chalk_1.default.gray(`${diffHours} hours ago`);
}
else if (diffDays < 7) {
return chalk_1.default.gray(`${diffDays} days ago`);
}
else {
return chalk_1.default.gray(d.toLocaleDateString());
}
}
//# sourceMappingURL=history.js.map
;