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
4 changes: 2 additions & 2 deletions .cursor/rules/discord-bot/RULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Non-`#` → `smartBotResponse.ts`. Channel must be present in active `channels*.

## OpenSea Dual Path

1. **Stream** (`@opensea/stream-js`): primary listings + sales; started only after Discord login succeeds (`startProductionBots` in `index.ts`). Handlers also no-op when `PRODUCTION_MODE` is false.
2. **REST poll** (`OpenSeaEventsPollBot`): sales backfill; starts after Discord ready; registers stream sale IDs to dedupe
1. **Stream** (`@opensea/stream-js`): primary listings + sales. Starts with the process, not after Discord login (`startProductionBots` in `index.ts`). Handlers also no-op when `PRODUCTION_MODE` is false. Discord posts are skipped when the client is not ready; Twitter posts still go out.
2. **REST poll** (`OpenSeaEventsPollBot`): sales backfill; starts alongside the stream; registers stream sale IDs to dedupe.

Activity posts go through `activityTriager.ts` (hardcoded artist/platform → channel mapping + ban list). New sale destinations usually need code there, not only JSON.

Expand Down
10 changes: 5 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ src/index.ts
│ POST /new-mint ← Hasura mint webhook (header: webhook_secret)
│ GET /callback ← Twitter OAuth
│ GET|POST /update ← stub OK responses (not a real health check)
├── Discord client (if PRODUCTION_MODE) — must login before feeds start
├── Discord client (if PRODUCTION_MODE) — login retries in the background
│ MessageCreate → # commands OR smartBotResponse
├── OpenSea WebSocket stream → OpenSeaListBot / OpenSeaSaleBot → activityTriager
├── OpenSeaEventsPollBot (sales backfill, 30s) after Discord ready
├── MintBot (queue + media-proxy poll → Discord; posts only when client is ready)
├── ScheduleBot (birthdays + optional trivia; starts after Discord ready)
├── OpenSeaEventsPollBot (sales backfill, 30s) — starts with the stream, not after Discord
├── MintBot (queue + media-proxy poll → Discord if connected, Twitter if connected)
├── ScheduleBot (birthdays + optional trivia; starts once Discord is ready)
└── TwitterBot (optional, TWITTER_ENABLED)
```

Expand Down Expand Up @@ -137,7 +137,7 @@ Token/mint data can include chain IDs (Ethereum, Arbitrum, Base). **OpenSea stre
10. **CODEOWNERS**: `@ArtBlocks/Eng-Approvers-Product`. Do not assign personal Discord handles from the old README.
11. **OpenSea stream reconnect must `disconnect()` the previous Phoenix client** before constructing a new one. Do not reset `reconnectAttempts` until a stream event confirms the socket is live. Keep wildcard `*` subscriptions (OpenSea topics are collection slugs, not contracts; ArtBot filters by contract address).
12. **Do not add urql `cacheExchange`** — this process is long-lived; the document cache never expires. App-level caches (project dicts, wallet TTL) are the right layer.
13. **OpenSea stream, sales poll, and ScheduleBot start only after Discord login succeeds.** Express binds PORT immediately (Render). Mint webhooks may queue, but MintBot does not post until `client.isReady()`. Do not start feed handlers in parallel with `login()`.
13. **OpenSea stream and sales poll start even if Discord login fails.** Express binds PORT immediately (Render). A down Discord or Twitter destination must not exit the process or stop the other one. Posts go to whichever destination is connected. Log sustained failures with `alert:destination_down` and recovery with `alert:destination_recovered` (`destination` is `discord` or `twitter`) so Datadog can page on those fields. ScheduleBot still starts only after Discord is ready. Do not `process.exit` on login failure.

## Common tasks

Expand Down
39 changes: 28 additions & 11 deletions src/Classes/APIBots/OpenSeaSaleBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export class OpenSeaSaleBot {
try {
const nftInfo = parseNftId(event.payload.item.nft_id)
if (!nftInfo) {
logger.warn({ nftId: event.payload.item.nft_id }, 'Could not parse NFT ID')
logger.warn(
{ nftId: event.payload.item.nft_id },
'Could not parse NFT ID'
)
return
}

Expand Down Expand Up @@ -151,7 +154,10 @@ export class OpenSeaSaleBot {
const now = Date.now()
const timeDiff = now - timestamp
if (timeDiff > 1000 * 60 * 60 * 4) {
logger.info({ timestamp }, 'Skipping OpenSea sale from more than 4 hours ago')
logger.info(
{ timestamp },
'Skipping OpenSea sale from more than 4 hours ago'
)
return
}

Expand Down Expand Up @@ -197,7 +203,11 @@ export class OpenSeaSaleBot {

let sellerText = await ensOrAddress(seller)
let buyerText = await ensOrAddress(buyer)
const platformUrl = buildArtBlocksTokenURL(sale.chainId, contractAddress, tokenId)
const platformUrl = buildArtBlocksTokenURL(
sale.chainId,
contractAddress,
tokenId
)

// Add OpenSea usernames if available (same logic as ReservoirSaleBot)
if (!sellerText.includes('.eth')) {
Expand Down Expand Up @@ -263,15 +273,19 @@ export class OpenSeaSaleBot {

if (artBlocksData.collection_name) {
logger.info({ name: artBlocksData.name }, 'OpenSea SALE')
sendEmbedToSaleChannels(
this.bot,
embed,
artBlocksData,
await getCollectionType(contractAddress)
)
try {
sendEmbedToSaleChannels(
this.bot,
embed,
artBlocksData,
await getCollectionType(contractAddress)
)
} catch (error) {
logger.error({ err: error }, 'Error posting OpenSea sale to Discord')
}
}

// Post to Twitter if TwitterBot is available and sale meets criteria
// Twitter is independent of whether the Discord post succeeded.
if (
this.twitterBot &&
this.shouldTweetNormalizedSale(sale, artBlocksData)
Expand Down Expand Up @@ -318,7 +332,10 @@ export class OpenSeaSaleBot {
}

if (sale.price < 0.1 && sale.currency.includes('ETH')) {
logger.info({ price: sale.price, currency: sale.currency }, 'Skipping twitter sale for low-value OpenSea sale')
logger.info(
{ price: sale.price, currency: sale.currency },
'Skipping twitter sale for low-value OpenSea sale'
)
return false
}

Expand Down
32 changes: 24 additions & 8 deletions src/Classes/MintBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ export class MintBot {
// Go through all mints in the queue and make sure the media image exists.
// Uses event data only (no token API call). Polls media URL until available, then posts.
async checkAndPostMints() {
if (!this.bot.isReady()) {
return
}
if (Object.keys(this.mintsToPost).length === 0) {
return
}
const discordReady = this.bot.isReady()

try {
await Promise.all(
Expand Down Expand Up @@ -164,8 +162,29 @@ export class MintBot {
mint.contractAddress,
mint.tokenId
)
await mint.postToDiscord()
await this.postToTwitter(mint)
if (discordReady) {
try {
await mint.postToDiscord()
} catch (e) {
logger.error(
{ err: e, id, destination: 'discord' },
'Discord mint post failed'
)
}
} else {
logger.info(
{ id, destination: 'discord' },
'Skipping Discord mint post; client is not connected'
)
}
Comment thread
mattetre marked this conversation as resolved.
Resolved
try {
await this.postToTwitter(mint)
} catch (e) {
logger.error(
{ err: e, id, destination: 'twitter' },
'Twitter mint post failed'
)
}
} catch (e) {
logger.info({ err: e, id }, 'Error fetching image for mint')
// Keep in queue to retry later
Expand Down Expand Up @@ -225,9 +244,6 @@ export class MintBot {
// tries to report any new mints to the discord!
startRoutine() {
this.intervalId = setInterval(async () => {
if (!this.bot.isReady()) {
return
}
if (Object.keys(this.mintsToPost).length > 0) {
logger.info(
{ count: Object.keys(this.mintsToPost).length },
Expand Down
Loading
Loading