From e89da27090de4f622e14b1ebf9152eaa2d46ca5e Mon Sep 17 00:00:00 2001 From: grant Date: Thu, 30 Nov 2023 11:43:40 -0600 Subject: [PATCH 1/6] base stuff ready --- src/Classes/ArtIndexerBot.ts | 7 +++++ src/Classes/ProjectBot.ts | 59 +++++++++++++++++++++++++++++++++++- src/Classes/SchedulerBot.ts | 38 +++++++++++++++++++++-- 3 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/Classes/ArtIndexerBot.ts b/src/Classes/ArtIndexerBot.ts index 12371e8..59b94de 100644 --- a/src/Classes/ArtIndexerBot.ts +++ b/src/Classes/ArtIndexerBot.ts @@ -77,6 +77,7 @@ export class ArtIndexerBot { platforms: { [id: string]: ProjectBot[] } = {} flagship: { [id: string]: ProjectBot } = {} + tempFlagshipMapping: { [id: number]: ProjectBot } = {} constructor(projectFetch = getAllProjects) { this.projectFetch = projectFetch @@ -201,6 +202,12 @@ export class ArtIndexerBot { if (project.is_artblocks) { this.flagship[projectKey] = newBot + if ( + project.vertical.category_name !== 'collaborations' && + project.vertical.category_name !== 'explorations' + ) { + this.tempFlagshipMapping[newBot.projectNumber] = newBot + } this.platforms['artblocks'] = this.platforms['artblocks'] ?? [] this.platforms['artblocks'].push(newBot) } else { diff --git a/src/Classes/ProjectBot.ts b/src/Classes/ProjectBot.ts index 36758e2..0cc2daa 100644 --- a/src/Classes/ProjectBot.ts +++ b/src/Classes/ProjectBot.ts @@ -27,6 +27,7 @@ import { ProjectConfig } from '../ProjectConfig/projectConfig' import { ProjectHandlerHelper } from './ProjectHandlerHelper' import { UpcomingProjectDetailFragment } from '../../generated/graphql' import { getDayName, getMonthName, getDayOfMonth } from '../Utils/common' +import { randomColor } from '../Utils/smartBotResponse' const ONE_MILLION = 1e6 @@ -349,7 +350,8 @@ export class ProjectBot { What are your favorite outputs from ${this.projectName}? [Explore the full project here](${ - artBlocksData.external_url + PROJECTBOT_UTM + getProjectUrl(this.coreContract, this.projectNumber.toString()) + + PROJECTBOT_UTM }) ` ) @@ -473,4 +475,59 @@ export class ProjectBot { msg.channel.send({ embeds: [embedContent] }) } + + async sendSpecialMessage(channel: TextChannel) { + try { + const invocation = Math.floor(Math.random() * this.editionSize) + const artBlocksResponse = await axios.get( + getTokenApiUrl( + this.coreContract, + `${this.projectNumber * ONE_MILLION + invocation}` + ) + ) + const artBlocksData = await artBlocksResponse.data + let assetUrl = artBlocksData?.preview_asset_url + if ( + !artBlocksData || + !assetUrl || + !artBlocksData.collection_name || + !artBlocksData.artist + ) { + return + } + const title = `:tada: Celebrating ${artBlocksData.collection_name}! :tada:` + + assetUrl = await replaceVideoWithGIF(assetUrl) + + const embedContent = new EmbedBuilder() + .setColor(randomColor()) + .setTitle(title) + .setImage(assetUrl) + .setDescription( + `${this.projectName} is project #${ + this.projectNumber + } and was released on ${this.startTime?.toLocaleDateString()}! + + What are your favorite outputs from ${this.projectName}? + + [Explore the full project here](${ + getProjectUrl(this.coreContract, this.projectNumber.toString()) + + PROJECTBOT_UTM + }) + ` + ) + .setFooter({ + text: artBlocksData.name, + }) + + channel?.send({ embeds: [embedContent] }) + } catch (err) { + console.error( + 'Error sending birthday message for:', + this.projectName, + err + ) + } + return + } } diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index 08071cc..02b8864 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -1,6 +1,8 @@ -import { Channel, Collection } from 'discord.js' +import * as dotenv from 'dotenv' +dotenv.config() +import { Channel, Collection, TextChannel } from 'discord.js' import { ProjectConfig } from '../ProjectConfig/projectConfig' -import { artIndexerBot } from '..' +import { artIndexerBot, projectConfig } from '..' import { delay } from './APIBots/utils' import { Cron } from 'croner' @@ -45,5 +47,37 @@ export class ScheduleBot { // console.log('Trivia Time!') // artIndexerBot.askRandomTriviaQuestion() // }) + + let currProjectId = parseInt(process.env.SPAM_START_INDEX ?? '0') + Cron( + '* * * * *', + { timezone: 'America/New_York', name: 'Bday Spam' }, + () => { + if (currProjectId === -1) { + console.log('Spamming disabled') + return + } + console.log('Spam Time!') + const now = new Date() + const n = new Date(now.getTime() + 1000 * 60 * 60 * 25) + const startDate = new Date('2023-12-01T17:00:00.000Z') // 12pm ET 12/1/23 + if (n > startDate) { + // TODO: replace with now + const currProject = artIndexerBot.tempFlagshipMapping[currProjectId] + if (!currProject || currProject.editionSize === 0) { + return + } + console.log( + 'Spamming! ' + currProject.projectName + ' ' + currProjectId + ) + currProject.sendSpecialMessage( + this.channels.get( + projectConfig.chIdByName['block-talk'] + ) as TextChannel + ) + currProjectId++ + } + } + ) } } From 931528fb3d564da72777e4f4c811510995c3ac48 Mon Sep 17 00:00:00 2001 From: grant Date: Thu, 30 Nov 2023 12:19:47 -0600 Subject: [PATCH 2/6] finalizing copy --- src/Classes/ProjectBot.ts | 14 ++++++++------ src/Classes/SchedulerBot.ts | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Classes/ProjectBot.ts b/src/Classes/ProjectBot.ts index 0cc2daa..fbf03c2 100644 --- a/src/Classes/ProjectBot.ts +++ b/src/Classes/ProjectBot.ts @@ -495,7 +495,7 @@ export class ProjectBot { ) { return } - const title = `:tada: Celebrating ${artBlocksData.collection_name}! :tada:` + const title = `:tada: Block Friday - Celebrating 3 Years of Art Blocks! :tada:` assetUrl = await replaceVideoWithGIF(assetUrl) @@ -504,11 +504,13 @@ export class ProjectBot { .setTitle(title) .setImage(assetUrl) .setDescription( - `${this.projectName} is project #${ - this.projectNumber - } and was released on ${this.startTime?.toLocaleDateString()}! - - What are your favorite outputs from ${this.projectName}? + `Project #${this.projectNumber} - **${ + this.projectName + }** was released on ${this.startTime?.toLocaleString('en-US', { + day: 'numeric', + month: 'long', + year: 'numeric', + })}! [Explore the full project here](${ getProjectUrl(this.coreContract, this.projectNumber.toString()) + diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index 02b8864..613214d 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -65,6 +65,7 @@ export class ScheduleBot { // TODO: replace with now const currProject = artIndexerBot.tempFlagshipMapping[currProjectId] if (!currProject || currProject.editionSize === 0) { + currProjectId++ return } console.log( From bb699d6878b2c9f99bd00b6a5629b9820deb5090 Mon Sep 17 00:00:00 2001 From: grant Date: Thu, 30 Nov 2023 12:33:05 -0600 Subject: [PATCH 3/6] fix copy --- src/Classes/ProjectBot.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Classes/ProjectBot.ts b/src/Classes/ProjectBot.ts index fbf03c2..13c9d4a 100644 --- a/src/Classes/ProjectBot.ts +++ b/src/Classes/ProjectBot.ts @@ -504,8 +504,8 @@ export class ProjectBot { .setTitle(title) .setImage(assetUrl) .setDescription( - `Project #${this.projectNumber} - **${ - this.projectName + `Project #${this.projectNumber} - **${this.projectName} by ${ + this.artistName }** was released on ${this.startTime?.toLocaleString('en-US', { day: 'numeric', month: 'long', From 02fb2fbfddda7d6997d67a2fd5904d256867cddc Mon Sep 17 00:00:00 2001 From: grant Date: Thu, 30 Nov 2023 12:33:48 -0600 Subject: [PATCH 4/6] reverting --- src/Classes/SchedulerBot.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index 613214d..6bea79a 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -59,10 +59,8 @@ export class ScheduleBot { } console.log('Spam Time!') const now = new Date() - const n = new Date(now.getTime() + 1000 * 60 * 60 * 25) const startDate = new Date('2023-12-01T17:00:00.000Z') // 12pm ET 12/1/23 - if (n > startDate) { - // TODO: replace with now + if (now > startDate) { const currProject = artIndexerBot.tempFlagshipMapping[currProjectId] if (!currProject || currProject.editionSize === 0) { currProjectId++ From 9033570377d0009eeb2a28ff9f8af0c32578d2c9 Mon Sep 17 00:00:00 2001 From: grant Date: Fri, 1 Dec 2023 10:00:25 -0500 Subject: [PATCH 5/6] fix cron --- src/Classes/SchedulerBot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index 6bea79a..c4243a6 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -50,7 +50,7 @@ export class ScheduleBot { let currProjectId = parseInt(process.env.SPAM_START_INDEX ?? '0') Cron( - '* * * * *', + '*/3 * * * *', { timezone: 'America/New_York', name: 'Bday Spam' }, () => { if (currProjectId === -1) { From d2a97140a1311ebaa75bc98eb6c9df585f043682 Mon Sep 17 00:00:00 2001 From: grant Date: Mon, 4 Dec 2023 09:40:32 -0600 Subject: [PATCH 6/6] pulling out anniversary stuff --- src/Classes/ArtIndexerBot.ts | 7 ----- src/Classes/ProjectBot.ts | 58 ------------------------------------ src/Classes/SchedulerBot.ts | 35 ++-------------------- 3 files changed, 2 insertions(+), 98 deletions(-) diff --git a/src/Classes/ArtIndexerBot.ts b/src/Classes/ArtIndexerBot.ts index 59b94de..12371e8 100644 --- a/src/Classes/ArtIndexerBot.ts +++ b/src/Classes/ArtIndexerBot.ts @@ -77,7 +77,6 @@ export class ArtIndexerBot { platforms: { [id: string]: ProjectBot[] } = {} flagship: { [id: string]: ProjectBot } = {} - tempFlagshipMapping: { [id: number]: ProjectBot } = {} constructor(projectFetch = getAllProjects) { this.projectFetch = projectFetch @@ -202,12 +201,6 @@ export class ArtIndexerBot { if (project.is_artblocks) { this.flagship[projectKey] = newBot - if ( - project.vertical.category_name !== 'collaborations' && - project.vertical.category_name !== 'explorations' - ) { - this.tempFlagshipMapping[newBot.projectNumber] = newBot - } this.platforms['artblocks'] = this.platforms['artblocks'] ?? [] this.platforms['artblocks'].push(newBot) } else { diff --git a/src/Classes/ProjectBot.ts b/src/Classes/ProjectBot.ts index 13c9d4a..5317a5e 100644 --- a/src/Classes/ProjectBot.ts +++ b/src/Classes/ProjectBot.ts @@ -27,7 +27,6 @@ import { ProjectConfig } from '../ProjectConfig/projectConfig' import { ProjectHandlerHelper } from './ProjectHandlerHelper' import { UpcomingProjectDetailFragment } from '../../generated/graphql' import { getDayName, getMonthName, getDayOfMonth } from '../Utils/common' -import { randomColor } from '../Utils/smartBotResponse' const ONE_MILLION = 1e6 @@ -475,61 +474,4 @@ export class ProjectBot { msg.channel.send({ embeds: [embedContent] }) } - - async sendSpecialMessage(channel: TextChannel) { - try { - const invocation = Math.floor(Math.random() * this.editionSize) - const artBlocksResponse = await axios.get( - getTokenApiUrl( - this.coreContract, - `${this.projectNumber * ONE_MILLION + invocation}` - ) - ) - const artBlocksData = await artBlocksResponse.data - let assetUrl = artBlocksData?.preview_asset_url - if ( - !artBlocksData || - !assetUrl || - !artBlocksData.collection_name || - !artBlocksData.artist - ) { - return - } - const title = `:tada: Block Friday - Celebrating 3 Years of Art Blocks! :tada:` - - assetUrl = await replaceVideoWithGIF(assetUrl) - - const embedContent = new EmbedBuilder() - .setColor(randomColor()) - .setTitle(title) - .setImage(assetUrl) - .setDescription( - `Project #${this.projectNumber} - **${this.projectName} by ${ - this.artistName - }** was released on ${this.startTime?.toLocaleString('en-US', { - day: 'numeric', - month: 'long', - year: 'numeric', - })}! - - [Explore the full project here](${ - getProjectUrl(this.coreContract, this.projectNumber.toString()) + - PROJECTBOT_UTM - }) - ` - ) - .setFooter({ - text: artBlocksData.name, - }) - - channel?.send({ embeds: [embedContent] }) - } catch (err) { - console.error( - 'Error sending birthday message for:', - this.projectName, - err - ) - } - return - } } diff --git a/src/Classes/SchedulerBot.ts b/src/Classes/SchedulerBot.ts index c4243a6..7816ae0 100644 --- a/src/Classes/SchedulerBot.ts +++ b/src/Classes/SchedulerBot.ts @@ -1,8 +1,8 @@ import * as dotenv from 'dotenv' dotenv.config() -import { Channel, Collection, TextChannel } from 'discord.js' +import { Channel, Collection } from 'discord.js' import { ProjectConfig } from '../ProjectConfig/projectConfig' -import { artIndexerBot, projectConfig } from '..' +import { artIndexerBot } from '..' import { delay } from './APIBots/utils' import { Cron } from 'croner' @@ -47,36 +47,5 @@ export class ScheduleBot { // console.log('Trivia Time!') // artIndexerBot.askRandomTriviaQuestion() // }) - - let currProjectId = parseInt(process.env.SPAM_START_INDEX ?? '0') - Cron( - '*/3 * * * *', - { timezone: 'America/New_York', name: 'Bday Spam' }, - () => { - if (currProjectId === -1) { - console.log('Spamming disabled') - return - } - console.log('Spam Time!') - const now = new Date() - const startDate = new Date('2023-12-01T17:00:00.000Z') // 12pm ET 12/1/23 - if (now > startDate) { - const currProject = artIndexerBot.tempFlagshipMapping[currProjectId] - if (!currProject || currProject.editionSize === 0) { - currProjectId++ - return - } - console.log( - 'Spamming! ' + currProject.projectName + ' ' + currProjectId - ) - currProject.sendSpecialMessage( - this.channels.get( - projectConfig.chIdByName['block-talk'] - ) as TextChannel - ) - currProjectId++ - } - } - ) } }