diff options
| author | Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net> | 2026-04-22 22:49:01 +0200 |
|---|---|---|
| committer | Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net> | 2026-04-22 22:49:01 +0200 |
| commit | 3572b97661a3f7c6c29e958b63c20d9f2ef936ac (patch) | |
| tree | b3ee056039cf792edd467e5172feee25a07dd56c /libs | |
initialise repository
Signed-off-by: Amygdala Peanut-Almond <amygdala@almond.desloratadyna.net>
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/datajob.js | 27 | ||||
| -rw-r--r-- | libs/webhook.js | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/libs/datajob.js b/libs/datajob.js new file mode 100644 index 0000000..3453bcd --- /dev/null +++ b/libs/datajob.js @@ -0,0 +1,27 @@ +function queryAw(connection, id, key, value) { + connection.query("INSERT INTO amygdala_profile(timestamp, userID, key, value) VALUES ($1, $2, $3, $4);", [Date.now(), id, key, value]); +} + +module.exports = { + async saveUserData(connection, userId) { + let userData = client.users.cache.get(userId); + if (userData === undefined) { + userData = await client.users.fetch(userId); + } + + await connection.query("BEGIN;"); + + try { + if (userData.globalName !== null) await queryAw(connection, userId, "discord_globalName", userData.globalName); + if (userData.avatar !== null) await queryAw(connection, userId, "discord_avatar", userData.avatar); + await queryAw(connection, userId, "discord_username", userData.username); + await queryAw(connection, userId, "discord_discriminator", userData.discriminator); + } catch (e) { + await connection.query("ROLLBACK;"); + throw e; + } + + await connection.query("COMMIT;"); + } +} + diff --git a/libs/webhook.js b/libs/webhook.js new file mode 100644 index 0000000..5c89f12 --- /dev/null +++ b/libs/webhook.js @@ -0,0 +1,11 @@ +const Discord = require("discord.js"); + +module.exports = { + async getWebhook(guildId) { + const result = await database.query("SELECT * FROM amygdala_webhook WHERE guildId = $1;", [guildId]); + if (result.rows.length !== 1) return null; + + return new Discord.WebhookClient({ url: result.rows[0].webhookurl }); + } +} + |
