You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.5 KiB
30 lines
1.5 KiB
import {APIWebhook} from "discord-api-types";
|
|
import {readFile} from "fs/promises";
|
|
import {Pool} from "pg";
|
|
import dotenv from "dotenv";
|
|
|
|
async function loadHooksIntoDatabase(client: Pool, gameHook: APIWebhook & { channelName: string }, adminHook: APIWebhook & { channelName: string }): Promise<void> {
|
|
await client.query({
|
|
text: `
|
|
INSERT INTO DiscordChannel (discordId, name, broadcastGame, sendLogs, acceptGameCommands,
|
|
acceptAdminCommands, priority, guildId, webhookId, webhookToken)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10),
|
|
($11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
|
|
ON CONFLICT DO NOTHING`,
|
|
values: [gameHook.channel_id, gameHook.channelName, true, false, true, false, 0, gameHook.guild_id, gameHook.id, gameHook.token,
|
|
adminHook.channel_id, adminHook.channelName, false, true, false, true, 0, adminHook.guild_id, adminHook.id, adminHook.token]
|
|
})
|
|
}
|
|
|
|
async function main() {
|
|
const {DATABASE_URL: connectionString} = dotenv.config().parsed ?? {}
|
|
const client = new Pool({
|
|
connectionString
|
|
})
|
|
|
|
const gameHook: APIWebhook & { channelName: string } = JSON.parse(await readFile("runtime/webhooks/game.json", {encoding: "utf-8"}))
|
|
const adminHook: APIWebhook & { channelName: string } = JSON.parse(await readFile("runtime/webhooks/admin.json", {encoding: "utf-8"}))
|
|
await loadHooksIntoDatabase(client, gameHook, adminHook)
|
|
}
|
|
|
|
main() |