From 33219cb3f18d1e6022575dda35b3c45f8201d15c Mon Sep 17 00:00:00 2001 From: Emily J Date: Sun, 18 Oct 2020 11:47:11 +1100 Subject: [PATCH] reset functions --- bot/util/database.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bot/util/database.js b/bot/util/database.js index cd75afb..f3aaaa3 100644 --- a/bot/util/database.js +++ b/bot/util/database.js @@ -90,16 +90,38 @@ class Database { return; } - async resetGuild (id) { + async resetGuild (id, column) { + const regexp = /(?<=\')(.*?)(?=\')/; //eslint-disable-line no-useless-escape + const res = await this.client.db.pool.query( + 'SELECT column_default FROM information_schema.columns WHERE table_name=\'guilds\' AND column_name = $1;', [column]); + const def = res.rows[0].column_default.match(regexp)[0]; + await this.updateGuild(id, column, def); + + return; } - async resetMember (guild_id, member_id) { + async resetMember (guild_id, user_id, column) { + const key = guild_id + ':' + user_id; + const regexp = /(?<=\')(.*?)(?=\')/; //eslint-disable-line no-useless-escape + const res = await this.client.db.pool.query( + 'SELECT column_default FROM information_schema.columns WHERE table_name=\'members\' AND column_name = $1;', [column]); + const def = res.rows[0].column_default.match(regexp)[0]; + await this.updateGuild(key, column, def); + + return; } - async resetUser (id) { + async resetUser (id, column) { + const regexp = /(?<=\')(.*?)(?=\')/; //eslint-disable-line no-useless-escape + const res = await this.client.db.pool.query( + 'SELECT column_default FROM information_schema.columns WHERE table_name=\'users\' AND column_name = $1;', [column]); + const def = res.rows[0].column_default.match(regexp)[0]; + await this.updateGuild(id, column, def); + + return; } async deleteGuild (id) {