1+ import { Client , type TextBasedChannel } from "discord.js" ;
12import {
23 type EventTimestampSource ,
34 fetchCollectionSlug ,
45 fetchEvents ,
56 resolveLastEventTimestamp ,
67} from "./opensea" ;
7- import { messageEvents } from "./platforms/discord" ;
8+ import { channelsWithEvents , messageEvents } from "./platforms/discord" ;
89import { tweetEvents } from "./platforms/twitter" ;
910import type { OpenSeaAssetEvent } from "./types" ;
1011import { MS_PER_SECOND } from "./utils/constants" ;
@@ -19,7 +20,78 @@ import {
1920 minOfferETH ,
2021} from "./utils/utils" ;
2122
22- const logPlatformConfig = (
23+ const fetchDiscordChannelNames = async ( ) : Promise < Map < string , string > > => {
24+ const channelNames = new Map < string , string > ( ) ;
25+
26+ if ( ! ( process . env . DISCORD_TOKEN && process . env . DISCORD_EVENTS ) ) {
27+ return channelNames ;
28+ }
29+
30+ const client = new Client ( { intents : [ ] } ) ;
31+
32+ try {
33+ await new Promise < void > ( ( resolve ) => {
34+ client . on ( "ready" , ( ) => resolve ( ) ) ;
35+ client . login ( process . env . DISCORD_TOKEN ) ;
36+ } ) ;
37+
38+ const channelEvents = channelsWithEvents ( ) ;
39+ for ( const [ channelId ] of channelEvents ) {
40+ try {
41+ const channel = await client . channels . fetch ( channelId ) ;
42+ const name = ( channel as TextBasedChannel & { name ?: string } ) . name ;
43+ if ( name ) {
44+ channelNames . set ( channelId , name ) ;
45+ }
46+ } catch {
47+ // Channel might not be accessible
48+ }
49+ }
50+ } catch {
51+ // Discord connection failed
52+ } finally {
53+ client . destroy ( ) ;
54+ }
55+
56+ return channelNames ;
57+ } ;
58+
59+ const logTwitterConfig = ( ) => {
60+ const twitterEvents = process . env . TWITTER_EVENTS ?. replace ( / , / g, ", " ) ?? "" ;
61+ logger . info ( `│ ├─ Events: ${ twitterEvents } ` ) ;
62+ if ( process . env . TWITTER_PREPEND_TWEET ) {
63+ logger . info ( `│ ├─ Prepend: "${ process . env . TWITTER_PREPEND_TWEET } "` ) ;
64+ }
65+ if ( process . env . TWITTER_APPEND_TWEET ) {
66+ logger . info ( `│ ├─ Append: "${ process . env . TWITTER_APPEND_TWEET } "` ) ;
67+ }
68+ const config = getDefaultEventGroupConfig ( "TWITTER" ) ;
69+ const hasPrependOrAppend =
70+ process . env . TWITTER_PREPEND_TWEET || process . env . TWITTER_APPEND_TWEET ;
71+ logger . info ( `│ ${ hasPrependOrAppend ? "├─" : "└─" } Grouping` ) ;
72+ logger . info ( `│ ├─ Min Group Size: ${ config . minGroupSize } items` ) ;
73+ logger . info ( `│ └─ Settle Time: ${ config . settleMs / MS_PER_SECOND } s` ) ;
74+ } ;
75+
76+ const logDiscordConfig = async ( ) => {
77+ const channelNames = await fetchDiscordChannelNames ( ) ;
78+ const channelEvents = channelsWithEvents ( ) ;
79+ const config = getDefaultEventGroupConfig ( "DISCORD" ) ;
80+
81+ for ( const [ channelId , events ] of channelEvents ) {
82+ const channelName = channelNames . get ( channelId ) ;
83+ const channelDisplay = channelName
84+ ? `#${ channelName } (${ channelId } )`
85+ : channelId ;
86+ logger . info ( `│ ├─ ${ channelDisplay } = ${ events . join ( ", " ) } ` ) ;
87+ }
88+
89+ logger . info ( "│ └─ Grouping" ) ;
90+ logger . info ( `│ ├─ Min Group Size: ${ config . minGroupSize } items` ) ;
91+ logger . info ( `│ └─ Settle Time: ${ config . settleMs / MS_PER_SECOND } s` ) ;
92+ } ;
93+
94+ const logPlatformConfig = async (
2395 twitterEnabled : boolean ,
2496 discordEnabled : boolean
2597) => {
@@ -29,32 +101,14 @@ const logPlatformConfig = (
29101 `│ 🐦 Twitter: ${ twitterEnabled ? "✅ ENABLED" : "⭕ DISABLED" } `
30102 ) ;
31103 if ( twitterEnabled ) {
32- const twitterEvents = process . env . TWITTER_EVENTS ?. replace ( / , / g, ", " ) ?? "" ;
33- logger . info ( `│ ├─ Events: ${ twitterEvents } ` ) ;
34- if ( process . env . TWITTER_PREPEND_TWEET ) {
35- logger . info ( `│ ├─ Prepend: "${ process . env . TWITTER_PREPEND_TWEET } "` ) ;
36- }
37- if ( process . env . TWITTER_APPEND_TWEET ) {
38- logger . info ( `│ ├─ Append: "${ process . env . TWITTER_APPEND_TWEET } "` ) ;
39- }
40- const config = getDefaultEventGroupConfig ( "TWITTER" ) ;
41- const hasPrependOrAppend =
42- process . env . TWITTER_PREPEND_TWEET || process . env . TWITTER_APPEND_TWEET ;
43- logger . info ( `│ ${ hasPrependOrAppend ? "├─" : "└─" } Grouping` ) ;
44- logger . info ( `│ ├─ Min Group Size: ${ config . minGroupSize } items` ) ;
45- logger . info ( `│ └─ Settle Time: ${ config . settleMs / MS_PER_SECOND } s` ) ;
104+ logTwitterConfig ( ) ;
46105 }
47106 logger . info ( "│" ) ;
48107 logger . info (
49108 `│ 💬 Discord: ${ discordEnabled ? "✅ ENABLED" : "⭕ DISABLED" } `
50109 ) ;
51110 if ( discordEnabled ) {
52- const discordEvents = process . env . DISCORD_EVENTS ?. replace ( / , / g, ", " ) ?? "" ;
53- logger . info ( `│ ├─ Events: ${ discordEvents } ` ) ;
54- const config = getDefaultEventGroupConfig ( "DISCORD" ) ;
55- logger . info ( "│ └─ Grouping" ) ;
56- logger . info ( `│ ├─ Min Group Size: ${ config . minGroupSize } items` ) ;
57- logger . info ( `│ └─ Settle Time: ${ config . settleMs / MS_PER_SECOND } s` ) ;
111+ await logDiscordConfig ( ) ;
58112 }
59113 logger . info ( "│" ) ;
60114} ;
@@ -134,7 +188,7 @@ const logStartupConfiguration = async () => {
134188 const twitterEnabled = Boolean ( process . env . TWITTER_EVENTS ) ;
135189 const discordEnabled = Boolean ( process . env . DISCORD_EVENTS ) ;
136190
137- logPlatformConfig ( twitterEnabled , discordEnabled ) ;
191+ await logPlatformConfig ( twitterEnabled , discordEnabled ) ;
138192
139193 logger . info ( "└─" ) ;
140194 logger . info ( "" ) ;
0 commit comments