Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Discord integration checks to frontend. #296

Merged
merged 10 commits into from
Jul 18, 2024
7 changes: 7 additions & 0 deletions api/migrations/54-add-discord-integration-enabled.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE ctfnote.settings
ADD COLUMN "discord_integration_enabled" boolean NOT NULL DEFAULT FALSE;

GRANT SELECT ("discord_integration_enabled") ON ctfnote.settings TO user_anonymous;
REVOKE UPDATE ("discord_integration_enabled") ON ctfnote.settings FROM user_admin;
GRANT UPDATE ("discord_integration_enabled") ON ctfnote.settings TO user_postgraphile;

17 changes: 17 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import discordHooks from "./plugins/discordHooks";
import { getDiscordClient } from "./discord";
import PgManyToManyPlugin from "@graphile-contrib/pg-many-to-many";
import ProfileSubscriptionPlugin from "./plugins/ProfileSubscriptionPlugin";
import { connectToDatabase } from "./discord/database/database";

function getDbUrl(role: "user" | "admin") {
const login = config.db[role].login;
Expand Down Expand Up @@ -154,6 +155,22 @@ async function main() {

getDiscordClient();

const pgClient = await connectToDatabase(); //? maybe we should not keep this dependency in the discord folder?

try {
const query =
"UPDATE ctfnote.settings SET discord_integration_enabled = $1";
const values = [config.discord.use.toLowerCase() !== "false"];
await pgClient.query(query, values);
} catch (error) {
console.error(
"Failed to set discord_integration_enabled flag in the database:",
error
);
} finally {
pgClient.release();
}

app.listen(config.web.port, () => {
//sendMessageToDiscord("CTFNote API started");
console.log(`Listening on :${config.web.port}`);
Expand Down
Loading
Loading