Skip to content

Commit

Permalink
Add a command to blow everything up
Browse files Browse the repository at this point in the history
By this we mean archive all open threads that haven't been active in 4
weekdays.

Currently we just log what threads we would archive.
  • Loading branch information
Shadowfiend committed Nov 3, 2023
1 parent f296158 commit f006548
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions discord-scripts/blow-everything-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Client, TextChannel } from "discord.js"
import { Robot } from "hubot"
import moment from "moment"

const GUILD: string = process.env.GUILD ?? ""

function weekdaysBefore(theMoment: any, days: any) {
let newMoment = theMoment.clone()
while(days > 0) {
if (newMoment.isoWeekday() < 6) {
days -= 1
}
newMoment = newMoment.subtract(1, 'days')
}
return newMoment
}

export default async function webhookDiscord(
discordClient: Client,
robot: Robot,
) {
robot.hear(/blow everything up/, (msg) => {
const guild = await discordClient.guilds.fetch(GUILD)
const channels = await guild.channels.fetch()
const archiveThreshold = weekdaysBefore(moment(), 4)
channels
.filter((channel): channel is TextChannel => channel !== null && channel.isTextBased() && channel.viewable)
.forEach(async channel => {
const threads = await channel.threads.fetch()
threads.threads.forEach(async thread => {
const messages = await thread.messages.fetch({limit: 1})

const firstMessage = messages.first()
const lastActivity = Math.max(
firstMessage?.createdTimestamp ?? 0,
thread.archiveTimestamp ?? 0
)
if (moment(lastActivity).isAfter(archiveThreshold)) {
return
}

// await thread.setArchived(true)
msg.reply("We would archive", thread.name)
})
}
})

Check failure on line 46 in discord-scripts/blow-everything-up.ts

View workflow job for this annotation

GitHub Actions / lint

',' expected.
}

0 comments on commit f006548

Please sign in to comment.