Skip to content

Commit

Permalink
Merge pull request #625 from ArtBlocks/artbot-birthday
Browse files Browse the repository at this point in the history
Anniversary posts
  • Loading branch information
grantoesterling authored Dec 1, 2023
2 parents 0d075b8 + 9033570 commit ffe0501
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Classes/ArtIndexerBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
61 changes: 60 additions & 1 deletion src/Classes/ProjectBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
})
`
)
Expand Down Expand Up @@ -473,4 +475,61 @@ 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
}
}
37 changes: 35 additions & 2 deletions src/Classes/SchedulerBot.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -45,5 +47,36 @@ 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++
}
}
)
}
}

0 comments on commit ffe0501

Please sign in to comment.