Skip to content

Commit

Permalink
base stuff ready
Browse files Browse the repository at this point in the history
  • Loading branch information
grantoesterling committed Nov 30, 2023
1 parent 0d075b8 commit e89da27
Show file tree
Hide file tree
Showing 3 changed files with 101 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
59 changes: 58 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,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
}
}
38 changes: 36 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,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++
}
}
)
}
}

0 comments on commit e89da27

Please sign in to comment.