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 7123a15
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) {

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 guild = await discordClient.guilds.fetch(GUILD)

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`
const channels = await guild.channels.fetch()

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`
const archiveThreshold = weekdaysBefore(moment(), 4)

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`
channels

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

View workflow job for this annotation

GitHub Actions / lint

Replace `↹` with `····`
.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 7123a15

Please sign in to comment.