mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
added user-fetching functionality on build
This commit is contained in:
committed by
Jean-Philippe Sirois
parent
1d93f4e160
commit
1b6525f4b4
@@ -0,0 +1,42 @@
|
||||
// This script will be ran periodically through CI
|
||||
// don't touch it
|
||||
const Discord = require("discord.js")
|
||||
const fs = require("fs")
|
||||
const { Readable, Writable } = require("stream")
|
||||
|
||||
const client = new Discord.Client()
|
||||
|
||||
const { BOT_TOKEN } = process.env
|
||||
const TPH = "244230771232079873"
|
||||
const DESTINATION = "./users.json"
|
||||
|
||||
if (!BOT_TOKEN) {
|
||||
throw Error("Missing BOT_TOKEN environment variable")
|
||||
}
|
||||
|
||||
const writeS = (content, dest) => {
|
||||
const source = new Readable()
|
||||
source.push(JSON.stringify(content))
|
||||
source.push(null)
|
||||
source.pipe(dest)
|
||||
}
|
||||
|
||||
client.once("ready", async () => {
|
||||
console.log("Bot ready, fetching user list...")
|
||||
const tph = client.guilds.get(TPH)
|
||||
if (!tph) {
|
||||
throw Error("Bot is not in TPH, cannot fetch users")
|
||||
}
|
||||
const guild = await tph.fetchMembers()
|
||||
const memberInfo = guild.members.map(member => ({
|
||||
identifier: `${member.user.username}#${member.user.discriminator}`,
|
||||
avatar: member.user.displayAvatarURL,
|
||||
}))
|
||||
const wrs = fs.createWriteStream(DESTINATION)
|
||||
console.log(`Fetched ${memberInfo.length} users, writing to ${DESTINATION}`)
|
||||
writeS(memberInfo, wrs)
|
||||
process.exit(0)
|
||||
})
|
||||
|
||||
console.log("Attempting to log in...")
|
||||
client.login(process.env.BOT_TOKEN)
|
||||
Reference in New Issue
Block a user