Add guild_member_stats table and update permissions for Discord members
- Created a new table `guild_member_stats` to track message counts and voice activity for users in each guild. - Updated the database schema and models to include the new table. - Added a new permission entry for `discord_members` in the `webapp_page_permission` table. - Enhanced the webapp to include links and settings for managing Discord member statistics.
This commit is contained in:
@@ -227,6 +227,30 @@ def _doAddColumnMigrations(cursor: Cursor):
|
||||
except Exception as e:
|
||||
logging.warning(f"Table webapp_page_permission: {e}")
|
||||
|
||||
if not _tableExists('guild_member_stats', cursor):
|
||||
try:
|
||||
cursor.execute("""
|
||||
CREATE TABLE guild_member_stats (
|
||||
guild_id VARCHAR(64) NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL,
|
||||
message_count INTEGER NOT NULL DEFAULT 0,
|
||||
voice_seconds INTEGER NOT NULL DEFAULT 0,
|
||||
updated_at DATETIME,
|
||||
PRIMARY KEY (guild_id, user_id)
|
||||
)
|
||||
""")
|
||||
logging.info("Table guild_member_stats créée")
|
||||
except Exception as e:
|
||||
logging.warning(f"Table guild_member_stats: {e}")
|
||||
|
||||
if _tableExists("webapp_page_permission", cursor):
|
||||
try:
|
||||
cursor.execute(
|
||||
"INSERT OR IGNORE INTO webapp_page_permission (page_key, min_level, write_level) VALUES ('discord_members', 1, 1)"
|
||||
)
|
||||
except Exception as e:
|
||||
logging.warning(f"Permission page discord_members: {e}")
|
||||
|
||||
|
||||
def _doSeedAuth(cursor: Cursor):
|
||||
"""Seed rôles par défaut et permissions des pages si vides."""
|
||||
@@ -270,6 +294,7 @@ def _doSeedAuth(cursor: Cursor):
|
||||
("freeloot", 1, 2),
|
||||
("patreon", 1, 2),
|
||||
("moderation", 1, 2),
|
||||
("discord_members", 1, 1),
|
||||
("users", 5, 5),
|
||||
("settings", 5, 5),
|
||||
]
|
||||
|
||||
@@ -260,3 +260,12 @@ class ModShoutboxMessage(db.Model):
|
||||
message = db.Column(db.String(500), nullable=False)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||
|
||||
|
||||
class GuildMemberStats(db.Model):
|
||||
__tablename__ = 'guild_member_stats'
|
||||
guild_id = db.Column(db.String(64), primary_key=True)
|
||||
user_id = db.Column(db.String(64), primary_key=True)
|
||||
message_count = db.Column(db.Integer, nullable=False, default=0)
|
||||
voice_seconds = db.Column(db.Integer, nullable=False, default=0)
|
||||
updated_at = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
|
||||
@@ -99,6 +99,15 @@ CREATE TABLE IF NOT EXISTS `member_invites` (
|
||||
`join_date` DATETIME NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `guild_member_stats` (
|
||||
`guild_id` VARCHAR(64) NOT NULL,
|
||||
`user_id` VARCHAR(64) NOT NULL,
|
||||
`message_count` INTEGER NOT NULL DEFAULT 0,
|
||||
`voice_seconds` INTEGER NOT NULL DEFAULT 0,
|
||||
`updated_at` DATETIME,
|
||||
PRIMARY KEY (`guild_id`, `user_id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `twitch_link_filter` (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`enabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
|
||||
Reference in New Issue
Block a user