Your personal intelligence agent. Watches the world from multiple data sources and pings you when something changes.
fix(discord): bound actionable idea alerts
calesthioe2dc87285f51
diff --git a/lib/alerts/discord.mjs b/lib/alerts/discord.mjsindex f0d9564..8e3ec1b 100644--- a/lib/alerts/discord.mjs+++ b/lib/alerts/discord.mjs@@ -11,6 +11,14 @@ const TIER_CONFIG = {ROUTINE: { color: 0x3498DB, label: 'ROUTINE', cooldownMs: 60 * 60 * 1000, maxPerHour: 2 },};+const ACTIONABLE_IDEA_TIER = 'PRIORITY';+const ACTIONABLE_IDEA_MAX_PER_SWEEP = 2;+const EMBED_LIMITS = {+ title: 256,+ description: 3600,+ fieldValue: 1024,+};+// Slash command definitions for Discord's APIconst SLASH_COMMANDS = [{ name: 'status', description: 'System health, last sweep time, source status' },@@ -440,6 +448,11 @@ export class DiscordAlerter {if (actionable.length === 0) return;+ if (!this._checkRateLimit(ACTIONABLE_IDEA_TIER)) {+ console.log(`[Discord] Rate limited for actionable ideas (${ACTIONABLE_IDEA_TIER})`);+ return false;+ }+// Dedup: don't re-alert the same idea title within 6 hoursconst now = Date.now();if (!this._alertedIdeas) this._alertedIdeas = new Map();@@ -447,35 +460,37 @@ export class DiscordAlerter {const key = idea.title.toLowerCase().replace(/\s+/g, '-');const last = this._alertedIdeas.get(key);if (last && (now - last) < 6 * 60 * 60 * 1000) return false;- this._alertedIdeas.set(key, now);+ idea._alertKey = key;return true;- });+ }).slice(0, ACTIONABLE_IDEA_MAX_PER_SWEEP);if (fresh.length === 0) return;+ let sentAny = false;for (const idea of fresh) {const typeEmoji = { LONG: 'π', SHORT: 'π', HEDGE: 'π‘οΈ' }[idea.type] || 'ποΈ';const horizonEmoji = { Intraday: 'β‘', Days: 'π ', Weeks: 'ποΈ' }[idea.horizon] || 'β³';const embed = this._embed(- `${typeEmoji} ACTIONABLE: ${idea.title}`,- `**${idea.type}** ${idea.ticker} Β· Confidence: π’ HIGH Β· Horizon: ${horizonEmoji} ${idea.horizon}\n\n` ++ this._truncate(`${typeEmoji} ACTIONABLE: ${idea.title}`, EMBED_LIMITS.title),+ this._truncate(`**${idea.type}** ${idea.ticker} Β· Confidence: π’ HIGH Β· Horizon: ${horizonEmoji} ${idea.horizon}\n\n` +`${idea.rationale}\n\n` +- `β οΈ **Risk:** ${idea.risk}`,+ `β οΈ **Risk:** ${idea.risk}`, EMBED_LIMITS.description),idea.type === 'SHORT' ? 0xE74C3C : idea.type === 'HEDGE' ? 0x95A5A6 : 0x2ECC71);const fields = [- { name: 'Ticker', value: idea.ticker || 'β', inline: true },- { name: 'Direction', value: idea.type, inline: true },- { name: 'Horizon', value: idea.horizon, inline: true },+ { name: 'Ticker', value: this._truncate(idea.ticker || 'β', EMBED_LIMITS.fieldValue), inline: true },+ { name: 'Direction', value: this._truncate(idea.type, EMBED_LIMITS.fieldValue), inline: true },+ { name: 'Horizon', value: this._truncate(idea.horizon, EMBED_LIMITS.fieldValue), inline: true },];if (idea.signals?.length) {- fields.push({ name: 'Supporting Signals', value: idea.signals.join('\n'), inline: false });+ const signals = idea.signals.map(s => String(s)).filter(Boolean).slice(0, 8).join('\n');+ fields.push({ name: 'Supporting Signals', value: this._truncate(signals, EMBED_LIMITS.fieldValue), inline: false });}- fields.push({ name: 'π― Prediction Market Angle', value: this._kalshiAngle(idea), inline: false });+ fields.push({ name: 'π― Prediction Market Angle', value: this._truncate(this._kalshiAngle(idea), EMBED_LIMITS.fieldValue), inline: false });if (embed.setFields) {embed.setFields(fields);@@ -485,9 +500,18 @@ export class DiscordAlerter {embed.footer = { text: `Crucix Actionable Ideas Β· ${new Date().toISOString().replace('T', ' ').substring(0, 19)} UTC` };}- await this.sendMessage(null, [embed]);- console.log(`[Discord] Actionable idea sent: ${idea.type} ${idea.ticker} (${idea.horizon})`);+ const sent = await this.sendMessage(null, [embed]);+ if (sent) {+ this._alertedIdeas.set(idea._alertKey, now);+ sentAny = true;+ console.log(`[Discord] Actionable idea sent: ${idea.type} ${idea.ticker} (${idea.horizon})`);+ } else {+ console.warn(`[Discord] Actionable idea send failed: ${idea.type} ${idea.ticker} (${idea.horizon})`);+ }}++ if (sentAny) this._recordAlert(ACTIONABLE_IDEA_TIER);+ return sentAny;}/**@@ -534,6 +558,13 @@ export class DiscordAlerter {return `Look for event contracts related to ${ticker || 'this sector'} directional moves`;}+ _truncate(value, max, fallback = 'β') {+ const text = String(value ?? '').trim();+ if (!text) return fallback;+ if (text.length <= max) return text;+ return `${text.slice(0, Math.max(0, max - 1))}β¦`;+ }+// βββ Rule-Based Fallback (same logic as Telegram) βββββββββββββββββββββββ_ruleBasedEvaluation(signals, delta) {