Initial commit

This commit is contained in:
HoloTech
2025-09-01 20:26:45 +10:00
commit 1f60610947
19 changed files with 1293 additions and 0 deletions

82
src/botdata.py Normal file
View File

@@ -0,0 +1,82 @@
from data import Registry, RowModel, Table
from data.columns import String, Timestamp, Integer, Bool
class UserAuth(RowModel):
"""
Schema
======
CREATE TABLE user_auth(
userid TEXT PRIMARY KEY,
token TEXT NOT NULL,
refresh_token TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
"""
_tablename_ = 'user_auth'
_cache_ = {}
userid = String(primary=True)
token = String()
refresh_token = String()
created_at = Timestamp()
_timestamp = Timestamp()
class BotChannel(RowModel):
"""
Schema
======
CREATE TABLE bot_channels(
userid TEXT PRIMARY KEY REFERENCES user_auth(userid) ON DELETE CASCADE,
autojoin BOOLEAN DEFAULT true,
listen_redeems BOOLEAN,
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
"""
_tablename_ = 'bot_channels'
_cache_ = {}
userid = String(primary=True)
autojoin = Bool()
listen_redeems = Bool()
joined_at = Timestamp()
_timestamp = Timestamp()
class VersionHistory(RowModel):
"""
CREATE TABLE version_history(
component TEXT NOT NULL,
from_version INTEGER NOT NULL,
to_version INTEGER NOT NULL,
author TEXT NOT NULL,
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
);
"""
_tablename_ = 'version_history'
_cache_ = {}
component = String()
from_version = Integer()
to_version = Integer()
author = String()
_timestamp = Timestamp()
class BotData(Registry):
version_history = VersionHistory.table
user_auth = UserAuth.table
bot_channels = BotChannel.table
"""
CREATE TABLE user_auth_scopes(
userid TEXT NOT NULL REFERENCES user_auth(userid) ON DELETE CASCADE,
scope TEXT NOT NULL
);
"""
user_auth_scopes = Table('user_auth_scopes')