From df032a8f7869e9bbba4ad7f7efbc2afa00fc0b39 Mon Sep 17 00:00:00 2001 From: JetRaidz Date: Sat, 19 Feb 2022 21:00:08 +1300 Subject: [PATCH 1/5] (data): Adding support for premium currency. --- bot/core/data.py | 15 ++++++++++++++- data/schema.sql | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bot/core/data.py b/bot/core/data.py index 58c1331b..53066580 100644 --- a/bot/core/data.py +++ b/bot/core/data.py @@ -14,7 +14,7 @@ meta = RowTable( user_config = RowTable( 'user_config', - ('userid', 'timezone', 'topgg_vote_reminder', 'avatar_hash'), + ('userid', 'timezone', 'topgg_vote_reminder', 'avatar_hash', 'gems'), 'userid', cache=TTLCache(5000, ttl=60*5) ) @@ -120,6 +120,19 @@ def get_member_rank(guildid, userid, untracked): return curs.fetchone() or (None, None) +@user_config.save_query +def set_gems(userid, amount): + with user_config.conn as conn: + cursor = conn.cursor() + cursor.execute( + "UPDATE user_config SET gems = %s WHERE userid = %s RETURNING *", + (amount, userid) + ) + data = cursor.fetchone() + if data: + return user_config._make_rows(data)[0] + + global_guild_blacklist = Table('global_guild_blacklist') global_user_blacklist = Table('global_user_blacklist') ignored_members = Table('ignored_members') diff --git a/data/schema.sql b/data/schema.sql index 5287648e..640a3c39 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -42,9 +42,10 @@ CREATE TABLE global_guild_blacklist( CREATE TABLE user_config( userid BIGINT PRIMARY KEY, timezone TEXT, - topgg_vote_reminder, + topgg_vote_reminder BOOLEAN, avatar_hash TEXT, - API_timestamp BIGINT + API_timestamp BIGINT, + gems INTEGER DEFAULT 0 ); -- }}} From 5ecb10be43aa8653b5d4a5bd41ca85bda8fa10f6 Mon Sep 17 00:00:00 2001 From: JetRaidz Date: Sun, 6 Mar 2022 00:18:49 +1300 Subject: [PATCH 2/5] Add premium group in help command. --- bot/modules/meta/help.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bot/modules/meta/help.py b/bot/modules/meta/help.py index 1329fc02..c9d02b0a 100644 --- a/bot/modules/meta/help.py +++ b/bot/modules/meta/help.py @@ -21,26 +21,27 @@ group_hints = { 'Personal Settings': "*Tell me about yourself!*", 'Guild Admin': "*Dangerous administration commands!*", 'Guild Configuration': "*Control how I behave in your server.*", - 'Meta': "*Information about me!*" + 'Meta': "*Information about me!*", + 'Premium': "*Support the team and keep the project alive by using LionGems!*" } standard_group_order = ( - ('Pomodoro', 'Productivity', 'Statistics', 'Economy', 'Personal Settings', 'Meta'), + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings', 'Meta'), ) mod_group_order = ( ('Moderation', 'Meta'), - ('Pomodoro', 'Productivity', 'Statistics', 'Economy', 'Personal Settings') + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings') ) admin_group_order = ( ('Guild Admin', 'Guild Configuration', 'Moderation', 'Meta'), - ('Pomodoro', 'Productivity', 'Statistics', 'Economy', 'Personal Settings') + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings', 'LionGems') ) bot_admin_group_order = ( ('Bot Admin', 'Guild Admin', 'Guild Configuration', 'Moderation', 'Meta'), - ('Pomodoro', 'Productivity', 'Statistics', 'Economy', 'Personal Settings') + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings', 'LionGems') ) # Help embed format From 61f22b3d4f51e2266badf6a799df391a21a08c11 Mon Sep 17 00:00:00 2001 From: JetRaidz Date: Sun, 6 Mar 2022 00:20:38 +1300 Subject: [PATCH 3/5] Remove old group names --- bot/modules/meta/help.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/modules/meta/help.py b/bot/modules/meta/help.py index c9d02b0a..ff797cc4 100644 --- a/bot/modules/meta/help.py +++ b/bot/modules/meta/help.py @@ -36,12 +36,12 @@ mod_group_order = ( admin_group_order = ( ('Guild Admin', 'Guild Configuration', 'Moderation', 'Meta'), - ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings', 'LionGems') + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings') ) bot_admin_group_order = ( ('Bot Admin', 'Guild Admin', 'Guild Configuration', 'Moderation', 'Meta'), - ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings', 'LionGems') + ('Pomodoro', 'Productivity', 'Premium', 'Statistics', 'Economy', 'Personal Settings') ) # Help embed format From 08eb9e8890f42eada461ec9e09dfa064bf7e3dca Mon Sep 17 00:00:00 2001 From: JetRaidz Date: Wed, 23 Mar 2022 21:02:01 +1300 Subject: [PATCH 4/5] (data): Add LionGem audit log database table. --- data/schema.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/data/schema.sql b/data/schema.sql index 640a3c39..330b078c 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -802,4 +802,18 @@ create TABLE topgg( CREATE INDEX topgg_userid_timestamp ON topgg (userid, boostedTimestamp); -- }}} +-- LionGem audit log {{{ +CREATE TABLE gem_transactions( + transactionid SERIAL PRIMARY KEY, + actorid BIGINT NOT NULL, + targetid BIGINT NOT NULL, + amount INTEGER NOT NULL, + total INTEGER NOT NULL, + reason TEXT NOT NULL, + note TEXT, + gift BOOLEAN DEFAULT FALSE, + _timestamp TIMESTAMPTZ DEFAULT now() +); +-- }}} + -- vim: set fdm=marker: From 6f9c8b7138a981de0569635a63a8c21067298c88 Mon Sep 17 00:00:00 2001 From: Conatum Date: Sat, 2 Apr 2022 11:40:42 +0300 Subject: [PATCH 5/5] gems: Generalise gem transaction table. Updates gem audit table for more generality. Fixes issue with `Row._refresh()`. Data migration v11 -> v12. Remove `set_gems` (not needed due to gem module refactor). --- bot/constants.py | 2 +- bot/core/data.py | 13 ------------- bot/data/interfaces.py | 2 +- data/migration/v11-v12/migration.sql | 27 +++++++++++++++++++++++++++ data/schema.sql | 19 ++++++++++++++----- 5 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 data/migration/v11-v12/migration.sql diff --git a/bot/constants.py b/bot/constants.py index 7038953b..ffe4b057 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,2 +1,2 @@ CONFIG_FILE = "config/bot.conf" -DATA_VERSION = 11 +DATA_VERSION = 12 diff --git a/bot/core/data.py b/bot/core/data.py index b2747a7e..a74c754c 100644 --- a/bot/core/data.py +++ b/bot/core/data.py @@ -123,19 +123,6 @@ def get_member_rank(guildid, userid, untracked): return curs.fetchone() or (None, None) -@user_config.save_query -def set_gems(userid, amount): - with user_config.conn as conn: - cursor = conn.cursor() - cursor.execute( - "UPDATE user_config SET gems = %s WHERE userid = %s RETURNING *", - (amount, userid) - ) - data = cursor.fetchone() - if data: - return user_config._make_rows(data)[0] - - global_guild_blacklist = Table('global_guild_blacklist') global_user_blacklist = Table('global_user_blacklist') ignored_members = Table('ignored_members') diff --git a/bot/data/interfaces.py b/bot/data/interfaces.py index 501acdc0..44cc4a3c 100644 --- a/bot/data/interfaces.py +++ b/bot/data/interfaces.py @@ -149,7 +149,7 @@ class Row: self._pending = None def _refresh(self): - row = self.table.select_one_where(self.table.dict_from_id(self.rowid)) + row = self.table.select_one_where(**self.table.dict_from_id(self.rowid)) if not row: raise ValueError("Refreshing a {} which no longer exists!".format(type(self).__name__)) self.data = row diff --git a/data/migration/v11-v12/migration.sql b/data/migration/v11-v12/migration.sql new file mode 100644 index 00000000..460f037b --- /dev/null +++ b/data/migration/v11-v12/migration.sql @@ -0,0 +1,27 @@ +-- Add gem support +ALTER TABLE user_config ADD COLUMN gems INTEGER DEFAULT 0; + +-- LionGem audit log {{{ +CREATE TYPE GemTransactionType AS ENUM ( + 'ADMIN', + 'GIFT', + 'PURCHASE', + 'AUTOMATIC' +); + +CREATE TABLE gem_transactions( + transactionid SERIAL PRIMARY KEY, + transaction_type GemTransactionType NOT NULL, + actorid BIGINT NOT NULL, + from_account BIGINT, + to_account BIGINT, + amount INTEGER NOT NULL, + description TEXT NOT NULL, + note TEXT, + reference TEXT, + _timestamp TIMESTAMPTZ DEFAULT now() +); +CREATE INDEX gem_transactions_from ON gem_transactions (from_account); +-- }}} + +INSERT INTO VersionHistory (version, author) VALUES (12, 'v11-v12 migration'); diff --git a/data/schema.sql b/data/schema.sql index dafd6291..cbaebd3e 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -4,7 +4,7 @@ CREATE TABLE VersionHistory( time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, author TEXT ); -INSERT INTO VersionHistory (version, author) VALUES (11, 'Initial Creation'); +INSERT INTO VersionHistory (version, author) VALUES (12, 'Initial Creation'); CREATE OR REPLACE FUNCTION update_timestamp_column() @@ -823,17 +823,26 @@ CREATE TABLE sponsor_guild_whitelist( -- }}} -- LionGem audit log {{{ +CREATE TYPE GemTransactionType AS ENUM ( + 'ADMIN', + 'GIFT', + 'PURCHASE', + 'AUTOMATIC' +); + CREATE TABLE gem_transactions( transactionid SERIAL PRIMARY KEY, + transaction_type GemTransactionType NOT NULL, actorid BIGINT NOT NULL, - targetid BIGINT NOT NULL, + from_account BIGINT, + to_account BIGINT, amount INTEGER NOT NULL, - total INTEGER NOT NULL, - reason TEXT NOT NULL, + description TEXT NOT NULL, note TEXT, - gift BOOLEAN DEFAULT FALSE, + reference TEXT, _timestamp TIMESTAMPTZ DEFAULT now() ); +CREATE INDEX gem_transactions_from ON gem_transactions (from_account); -- }}} -- vim: set fdm=marker: