mirror of https://gitlab.com/litecord/litecord.git
Add user notes
- blueprints.users: fix get_other
- blueprints.users: add dummy get_user_settings,
patch_current_settings, get_consent, get_harvest and get_library
- enums: add ExplicitFilter
- storage: add Storage.fetch_notes
- schema.sql: add incomplete user_settings table
This commit is contained in:
parent
26931425c4
commit
3858e20080
|
|
@ -23,6 +23,7 @@ $ createdb litecord
|
||||||
$ psql -f schema.sql litecord
|
$ psql -f schema.sql litecord
|
||||||
|
|
||||||
# Configure litecord:
|
# Configure litecord:
|
||||||
|
# edit config.py as you wish
|
||||||
$ cp config.example.py config.py
|
$ cp config.example.py config.py
|
||||||
|
|
||||||
# Install all packages:
|
# Install all packages:
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ async def get_me():
|
||||||
return jsonify(user)
|
return jsonify(user)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<int:user_id>', methods=['GET'])
|
@bp.route('/<int:target_id>', methods=['GET'])
|
||||||
async def get_other():
|
async def get_other(target_id):
|
||||||
"""Get any user, given the user ID."""
|
"""Get any user, given the user ID."""
|
||||||
user_id = await token_check()
|
user_id = await token_check()
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ async def get_other():
|
||||||
if not bot:
|
if not bot:
|
||||||
raise Forbidden('Only bots can use this endpoint')
|
raise Forbidden('Only bots can use this endpoint')
|
||||||
|
|
||||||
other = await app.storage.get_user(user_id)
|
other = await app.storage.get_user(target_id)
|
||||||
return jsonify(other)
|
return jsonify(other)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -109,3 +109,92 @@ async def get_dms():
|
||||||
# @bp.route('/@me/channels', methods=['POST'])
|
# @bp.route('/@me/channels', methods=['POST'])
|
||||||
async def start_dm():
|
async def start_dm():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/notes/<int:target_id>', methods=['PUT'])
|
||||||
|
async def put_note(target_id: int):
|
||||||
|
"""Put a note to a user."""
|
||||||
|
user_id = await token_check()
|
||||||
|
|
||||||
|
j = await request.get_json()
|
||||||
|
note = str(j['note'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
await app.db.execute("""
|
||||||
|
INSERT INTO notes (user_id, target_id, note)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
""", user_id, target_id, note)
|
||||||
|
except UniqueViolationError:
|
||||||
|
await app.db.execute("""
|
||||||
|
UPDATE notes
|
||||||
|
SET note = $3
|
||||||
|
WHERE user_id = $1 AND target_id = $2
|
||||||
|
""", user_id, target_id, note)
|
||||||
|
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/settings', methods=['GET'])
|
||||||
|
async def get_user_settings():
|
||||||
|
# TODO: for now, just return hardcoded defaults,
|
||||||
|
# once we get the user_settings table working
|
||||||
|
# we can move to that.
|
||||||
|
await token_check()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'afk_timeout': 300,
|
||||||
|
'animate_emoji': True,
|
||||||
|
'convert_emoticons': False,
|
||||||
|
'default_guilds_restricted': True,
|
||||||
|
'detect_platform_accounts': False,
|
||||||
|
'developer_mode': True,
|
||||||
|
'disable_games_tab': True,
|
||||||
|
'enable_tts_command': False,
|
||||||
|
'explicit_content_filter': 2,
|
||||||
|
'friend_source_flags': {
|
||||||
|
'mutual_friends': True
|
||||||
|
},
|
||||||
|
'gif_auto_play': True,
|
||||||
|
'guild_positions': [],
|
||||||
|
'inline_attachment_media': True,
|
||||||
|
'inline_embed_media': True,
|
||||||
|
'locale': 'en-US',
|
||||||
|
'message_display_compact': False,
|
||||||
|
'render_embeds': True,
|
||||||
|
'render_reactions': True,
|
||||||
|
'restricted_guilds': [],
|
||||||
|
'show_current_game': True,
|
||||||
|
'status': 'online',
|
||||||
|
'theme': 'dark',
|
||||||
|
'timezone_offset': 420,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/settings', methods=['PATCH'])
|
||||||
|
async def patch_current_settings():
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/consent', methods=['GET'])
|
||||||
|
async def get_consent():
|
||||||
|
"""Always disable data collection."""
|
||||||
|
return jsonify({
|
||||||
|
'usage_statistics': {
|
||||||
|
'consented': False,
|
||||||
|
},
|
||||||
|
'personalization': {
|
||||||
|
'consented': False,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/harvest', methods=['GET'])
|
||||||
|
async def get_harvest():
|
||||||
|
"""Dummy route"""
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/@me/library', methods=['GET'])
|
||||||
|
async def get_library():
|
||||||
|
"""Probably related to Discord Store?"""
|
||||||
|
return jsonify([])
|
||||||
|
|
|
||||||
|
|
@ -71,3 +71,9 @@ class StatusType(EasyEnum):
|
||||||
IDLE = 'idle'
|
IDLE = 'idle'
|
||||||
INVISIBLE = 'invisible'
|
INVISIBLE = 'invisible'
|
||||||
OFFLINE = 'offline'
|
OFFLINE = 'offline'
|
||||||
|
|
||||||
|
|
||||||
|
class ExplicitFilter(EasyEnum):
|
||||||
|
EDGE = 0
|
||||||
|
FRIENDS = 1
|
||||||
|
SAFE = 2
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,7 @@ class GatewayWebsocket:
|
||||||
# TODO
|
# TODO
|
||||||
'user_guild_settings': [],
|
'user_guild_settings': [],
|
||||||
|
|
||||||
# TODO
|
'notes': await self.storage.fetch_notes(self.state.user_id),
|
||||||
'notes': {},
|
|
||||||
'friend_suggestion_count': 0,
|
'friend_suggestion_count': 0,
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
|
||||||
|
|
@ -380,3 +380,14 @@ class Storage:
|
||||||
res['pinned'] = False
|
res['pinned'] = False
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
async def fetch_notes(self, user_id: int) -> dict:
|
||||||
|
"""Fetch a users' notes"""
|
||||||
|
note_rows = await self.db.fetch("""
|
||||||
|
SELECT target_id, note
|
||||||
|
FROM notes
|
||||||
|
WHERE user_id = $1
|
||||||
|
""", user_id)
|
||||||
|
|
||||||
|
return {str(row['target_id']): row['note']
|
||||||
|
for row in note_rows}
|
||||||
|
|
|
||||||
42
schema.sql
42
schema.sql
|
|
@ -78,6 +78,48 @@ CREATE TABLE IF NOT EXISTS users (
|
||||||
PRIMARY KEY (id, username, discriminator)
|
PRIMARY KEY (id, username, discriminator)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_settings (
|
||||||
|
id bigint REFERENCES users (id),
|
||||||
|
afk_timeout int DEFAULT 300,
|
||||||
|
animate_emoji bool DEFAULT true,
|
||||||
|
convert_emoticons bool DEFAULT false,
|
||||||
|
default_guilds_restricted bool DEFAULT false,
|
||||||
|
detect_platform_accounts bool DEFAULT false,
|
||||||
|
|
||||||
|
-- smirk emoji
|
||||||
|
developer_mode bool DEFAULT true,
|
||||||
|
|
||||||
|
disable_games_tab bool DEFAULT true,
|
||||||
|
enable_tts_command bool DEFAULT false,
|
||||||
|
explicit_content_filter int DEFAULT 2,
|
||||||
|
|
||||||
|
friend_source_everyone bool DEFAULT true,
|
||||||
|
friend_source_mutuals bool DEFAULT true,
|
||||||
|
friend_source_guilds bool DEFAULT true,
|
||||||
|
|
||||||
|
gif_auto_play bool DEFAULT true,
|
||||||
|
|
||||||
|
-- TODO: guild_positions
|
||||||
|
-- TODO: restricted_guilds
|
||||||
|
|
||||||
|
inline_attachment_media bool DEFAULT true,
|
||||||
|
inline_embed_media bool DEFAULT true,
|
||||||
|
locale text DEFAULT 'en-US',
|
||||||
|
message_display_compact bool DEFAULT false,
|
||||||
|
render_embeds bool DEFAULT true,
|
||||||
|
render_reactions bool DEFAULT true,
|
||||||
|
show_current_game bool DEFAULT true,
|
||||||
|
|
||||||
|
status text DEFAULT 'online' NOT NULL,
|
||||||
|
theme text DEFAULT 'dark' NOT NULL,
|
||||||
|
|
||||||
|
timezone_offset int DEFAULT 0,
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS notes (
|
CREATE TABLE IF NOT EXISTS notes (
|
||||||
user_id bigint REFERENCES users (id),
|
user_id bigint REFERENCES users (id),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue