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 5250921
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions discord-scripts/blow-everything-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Client, TextChannel } from "discord.js"
import { Robot } from "hubot"
import moment from "moment"

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

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

View workflow job for this annotation

GitHub Actions / lint

'GUILD' is assigned a value but never used

function weekdaysBefore(theMoment: any, days: any) {

Check warning on line 7 in discord-scripts/blow-everything-up.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 7 in discord-scripts/blow-everything-up.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
let newMoment = theMoment.clone()
while(days > 0) {

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

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
if (newMoment.isoWeekday() < 6) {
days -= 1

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

View workflow job for this annotation

GitHub Actions / lint

Assignment to function parameter 'days'
}
newMoment = newMoment.subtract(1, 'days')

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

View workflow job for this annotation

GitHub Actions / lint

Replace `'days'` with `"days"`

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

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote

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

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
}
return newMoment
}

export default async function webhookDiscord(
discordClient: Client,
robot: Robot,
) {
robot.hear(/blow everything up/, async (msg) => {

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `··`
const guilds = discordClient.guilds.cache

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`

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

View workflow job for this annotation

GitHub Actions / lint

'guilds' is assigned a value but never used
const guild = discordClient.guilds.cache.first()

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`
if (guild === undefined) {
msg.reply("Whoops, no guilds.")
return
} else {
msg.reply("Running it with", guild.name)
}
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)
})
})
})
}

0 comments on commit 5250921

Please sign in to comment.