Compare commits

..

No commits in common. "85c2bc3e182f4172b2c5787363b797948b38ca72" and "e3f894330dafdbe7ab1d1e958cf0d0f3da1d1a40" have entirely different histories.

132 changed files with 789 additions and 844 deletions

View File

@ -1,4 +1,4 @@
image: python:3.10-alpine
image: python:3.9-alpine
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

View File

@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -651,7 +651,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
litecord Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
litecord Copyright (C) 2018 Luna Mendes
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

View File

@ -53,7 +53,7 @@ are not implemented, for example:
- Threads
- Channel Categories
- API v9 (Right now, Litecord, in general, assumes v9 is
- API v9 (Right now, Litecord, in generla, assumes v9 is
just v6 to make clients work, new payload structure support is
scattered throughout the codebase)

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -16,3 +16,4 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -48,11 +48,6 @@ class Config:
# e.g 'gateway.example.com' for reverse proxies.
WEBSOCKET_URL = "localhost:5001"
# Set these to file paths if you want to enable raw TLS support on
# the websocket (without NGINX)
WEBSOCKET_TLS_CERT_PATH = None
WEBSOCKET_TLS_KEY_PATH = None
#: Where to host the websocket?
# (a local address the server will bind to)
WS_HOST = "0.0.0.0"
@ -65,9 +60,6 @@ class Config:
#: Postgres credentials
POSTGRES = {}
#: Shared secret for LVSP
LVSP_SECRET = ""
class Development(Config):

View File

@ -8,9 +8,7 @@ LVSP runs over a *long-lived* websocket with TLS. The encoding is JSON.
## OP code table
"client" is litecord. "server" is the voice server.
note: only the opcode is sent in a message, so the names are determined by the implementation of LVSP.
"client" is litecord. "server" is the voice server.
| opcode | name | sent by |
| --: | :-- | :-- |
@ -121,17 +119,15 @@ are laid on.
### InfoType Enum
note: this enum is only ever identified by its opcode, so the `name` field can differ from the values in this enum without error.
| value | name | description |
| --: | :-- | :-- |
| 0 | CHANNEL\_REQ | channel assignment request |
| 1 | CHANNEL\_ASSIGN | channel assignment reply |
| 2 | CHANNEL\_DESTROY | channel destroy |
| 3 | VOICE\_STATE\_CREATE | voice state create request |
| 4 | VOICE\_STATE\_DONE | voice state created |
| 5 | VOICE\_STATE\_DESTROY | voice state destroy |
| 6 | VOICE\_STATE\_UPDATE | voice state update |
| 3 | VST\_CREATE | voice state create request |
| 4 | VST\_DONE | voice state created |
| 5 | VST\_UPDATE | voice state update |
| 6 | VST\_LEAVE | voice state leave |
### CHANNEL\_REQ
@ -162,7 +158,7 @@ a channel being deleted, or all members in it leaving.
Same data as CHANNEL\_ASSIGN, but without `token`.
### VOICE\_STATE\_CREATE
### VST\_CREATE
Sent by the client to create a voice state.
@ -172,25 +168,21 @@ Sent by the client to create a voice state.
| channel\_id | snowflake | channel id |
| guild\_id | Optional[snowflake] | guild id. not provided if dm / group dm |
### VOICE\_STATE\_DONE
### VST\_DONE
Sent by the server to indicate the success of a VOICE\_STATE\_CREATE.
Sent by the server to indicate the success of a VST\_CREATE.
Has the same fields as VOICE\_STATE\_CREATE, but with extras:
Has the same fields as VST\_CREATE, but with extras:
| field | type | description |
| --: | :-- | :-- |
| session\_id | string | session id for the voice state |
### VOICE\_STATE\_DESTROY
### VST\_DESTROY
Sent by the client when a user is leaving a channel OR moving between channels
in a guild. More on state transitions later on.
### VOICE\_STATE\_UPDATE
Sent to update an existing voice state. Potentially unused.
| field | type | description |
| --: | :-- | :-- |
| session\_id | string | session id for the voice state |
@ -203,11 +195,11 @@ Since the channel is unitialized, both logic on initialization AND
user join is here.
- Client will send a CHANNEL\_REQ.
- Client MAY send a VOICE\_STATE\_CREATE right after as well.
- Client MAY send a VST\_CREATE right after as well.
- The Server MUST process CHANNEL\_REQ first, so the Server can keep
a lock on channel operations while it is initialized.
- Reply with CHANNEL\_ASSIGN once initialization is done.
- Process VOICE\_STATE\_CREATE
- Process VST\_CREATE
### Updating a voice channel
@ -222,15 +214,15 @@ user join is here.
### User joining an (initialized) voice channel
- Client sends VOICE\_STATE\_CREATE
- Server sends VOICE\_STATE\_DONE
- Client sends VST\_CREATE
- Server sends VST\_DONE
### User leaves a channel
- Client sends VOICE\_STATE\_DESTROY with the old fields
- Client sends VST\_DESTROY with the old fields
### User moves a channel
- Client sends VOICE\_STATE\_DESTROY with the old fields
- Client sends VOICE\_STATE\_CREATE with the new fields
- Server sends VOICE\_STATE\_DONE
- Client sends VST\_DESTROY with the old fields
- Client sends VST\_CREATE with the new fields
- Server sends VST\_DONE

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -29,8 +29,7 @@ from litecord.errors import MessageNotFound, Forbidden
from litecord.enums import MessageType, ChannelType, GUILD_CHANS
from litecord.schemas import validate, MESSAGE_CREATE
from litecord.utils import query_tuple_from_args, extract_limit
from litecord.json import pg_set_json
from litecord.utils import pg_set_json, query_tuple_from_args, extract_limit
from litecord.permissions import get_permissions
from litecord.embed.sanitizer import fill_embed

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from quart import Blueprint, current_app as app, render_template_string, send_file
from quart import Blueprint, current_app as app, render_template_string
from pathlib import Path
bp = Blueprint("static", __name__)
@ -30,10 +30,7 @@ async def static_pages(path):
return "no", 404
static_path = Path.cwd() / Path("static") / path
if static_path.exists():
return await send_file(static_path)
else:
return "not found", 404
return await app.send_static_file(str(static_path))
@bp.route("/")

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -52,7 +52,7 @@ from litecord.common.messages import (
from litecord.embed.sanitizer import fill_embed, fetch_mediaproxy_img
from litecord.embed.messages import process_url_embed, is_media_url
from litecord.embed.schemas import EmbedURL
from litecord.json import pg_set_json
from litecord.utils import pg_set_json
from litecord.enums import MessageType
from litecord.images import STATIC_IMAGE_MIMES

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -189,8 +189,6 @@ class StatusType(EasyEnum):
IDLE = "idle"
INVISIBLE = "invisible"
OFFLINE = "offline"
STREAMING = "streaming"
UNKNOWN = "unknown"
class ExplicitFilter(EasyEnum):

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import earl
from litecord.json import LitecordJSONEncoder
from litecord.utils import LitecordJSONEncoder
def encode_json(payload) -> str:

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -120,12 +120,8 @@ IDENTIFY_SCHEMA = {
"type": "number",
"required": False,
},
"user_settings_version": {"type": "number", "required": False},
},
},
"guild_subscriptions": {"type": "boolean", "required": False},
# this is just to make bot libraries happy
"v": {"type": "number", "required": False},
},
}
},

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -91,8 +91,7 @@ def _complete_users_list(user_id: str, base_ready, user_ready, ws_properties) ->
for recipient in private_channel["recipients"]:
users_to_send[recipient["id"]] = recipient
user_relationships = user_ready.get("relationships", [])
for relationship in user_relationships:
for relationship in user_ready["relationships"]:
relationship_user = relationship["user"]
users_to_send[relationship_user["id"]] = relationship_user
@ -102,7 +101,7 @@ def _complete_users_list(user_id: str, base_ready, user_ready, ws_properties) ->
# relationship object structure changed in v9
if ws_properties.version == 9:
ready["relationships"] = []
for relationship in user_relationships:
for relationship in user_ready["relationships"]:
ready["relationships"].append(
{
"user_id": relationship["user"]["id"],
@ -139,9 +138,7 @@ async def _compute_supplemental(app, base_ready, user_ready, users_to_send: dict
"guilds": [],
}
user_relationships = user_ready.get("relationships", [])
for relationship in user_relationships:
for relationship in user_ready["relationships"]:
if relationship["type"] != RelationshipType.FRIEND.value:
continue
@ -268,13 +265,16 @@ class GatewayWebsocket:
"""Split data in chunk_size-big chunks and send them
over the websocket."""
log.debug(
"zlib-stream: sending {} bytes into {}-byte chunks", len(data), chunk_size
"zlib-stream: chunking {} bytes into {}-byte chunks", len(data), chunk_size
)
# we send the entire iterator as per websockets documentation
# to pretent setting FIN when we don't want to
# see https://gitlab.com/litecord/litecord/-/issues/139
await self.ws.send(yield_chunks(data, chunk_size))
total_chunks = 0
for chunk in yield_chunks(data, chunk_size):
total_chunks += 1
log.debug("zlib-stream: chunk {}", total_chunks)
await self.ws.send(chunk)
log.debug("zlib-stream: sent {} chunks", total_chunks)
async def _zlib_stream_send(self, encoded):
"""Sending a single payload across multiple compressed
@ -283,19 +283,39 @@ class GatewayWebsocket:
# compress and flush (for the rest of compressed data + ZLIB_SUFFIX)
data1 = self.ws_properties.zctx.compress(encoded)
data2 = self.ws_properties.zctx.flush(zlib.Z_FULL_FLUSH)
data = data1 + data2
log.debug(
"zlib-stream: length {} -> compressed ({})",
"zlib-stream: length {} -> compressed ({} + {})",
len(encoded),
len(data),
len(data1),
len(data2),
)
# since we always chunk the entire compressed message, we shouldn't
# worry about sending big frames to the clients
if not data1:
# if data1 is nothing, that might cause problems
# to clients, since they'll receive an empty message
data1 = bytes([data2[0]])
data2 = data2[1:]
log.debug(
"zlib-stream: len(data1) == 0, remaking as ({} + {})",
len(data1),
len(data2),
)
# NOTE: the old approach was ws.send(data1 + data2).
# I changed this to a chunked send of data1 and data2
# because that can bring some problems to the network
# since we can be potentially sending a really big packet
# as a single message.
# clients should handle chunked sends (via detection
# of the ZLIB_SUFFIX suffix appended to data2), so
# this shouldn't being problems.
# TODO: the chunks are 1024 bytes, 1KB, is this good enough?
await self._chunked_send(data, 1024)
await self._chunked_send(data1, 1024)
await self._chunked_send(data2, 1024)
async def _zstd_stream_send(self, encoded):
compressor = self.ws_properties.zsctx.stream_writer(
@ -710,7 +730,7 @@ class GatewayWebsocket:
presence.game = game
if presence.status in ("invisible", "unknown"):
if presence.status == "invisible":
presence.status = "offline"
self.state.presence = presence
@ -895,9 +915,6 @@ class GatewayWebsocket:
# they CAN NOT enter two channels in a single guild.
# this state id format takes care of that.
#
# TODO voice_key should have a type as a 0th element to prevent
# code from having to call get_guild(id2).
voice_key = (self.state.user_id, state_id2)
voice_state = await self.app.voice.get_state(voice_key)
@ -915,10 +932,6 @@ class GatewayWebsocket:
if same_guild and not same_channel:
return await self.app.voice.move_state(voice_state, channel_id)
# TODO: this is an edge case. we're trying to move guilds in
# a single message, perhaps?
log.warning("vsu payload does not appear logical")
async def _handle_5(self, payload: Dict[str, Any]):
"""Handle OP 5 Voice Server Ping.

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,69 +0,0 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import json
from typing import Any
from decimal import Decimal
from uuid import UUID
from dataclasses import asdict, is_dataclass
import quart.json.provider
class LitecordJSONEncoder(json.JSONEncoder):
"""Custom JSON encoder for Litecord. Useful for json.dumps"""
def default(self, value: Any):
if isinstance(value, (Decimal, UUID)):
return str(value)
if is_dataclass(value):
return asdict(value)
if hasattr(value, "to_json"):
return value.to_json
return super().default(self, value)
class LitecordJSONProvider(quart.json.provider.DefaultJSONProvider):
"""Custom JSON provider for Quart."""
def __init__(self, *args, **kwargs):
self.encoder = LitecordJSONEncoder(**kwargs)
def default(self, value: Any):
self.encoder.default(value)
async def pg_set_json(con):
"""Set JSON and JSONB codecs for an asyncpg connection."""
await con.set_type_codec(
"json",
encoder=lambda v: json.dumps(v, cls=LitecordJSONEncoder),
decoder=json.loads,
schema="pg_catalog",
)
await con.set_type_codec(
"jsonb",
encoder=lambda v: json.dumps(v, cls=LitecordJSONEncoder),
decoder=json.loads,
schema="pg_catalog",
)

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -450,8 +450,8 @@ MESSAGE_CREATE = {
"required": False,
"nullable": True,
"schema": {
"parse": {"type": "list", "required": False},
"replied_user": {"type": "boolean", "required": False},
"parse": {"type": "list", "required": True},
"replied_user": {"type": "boolean", "required": True},
},
},
}

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@ from litecord.blueprints.channel.reactions import (
from litecord.blueprints.user.billing import PLAN_ID_TO_TYPE
from litecord.types import timestamp_
from litecord.json import pg_set_json
from litecord.utils import pg_set_json
log = Logger(__name__)

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -18,12 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import asyncio
import json
import secrets
import datetime
import re
from typing import Any, Iterable, Optional, Sequence, List, Dict, Union
from logbook import Logger
from quart.json import JSONEncoder
from quart import current_app as app
from litecord.common.messages import message_view
@ -154,6 +156,35 @@ def mmh3(inp_str: str, seed: int = 0):
return _u(h1) >> 0
class LitecordJSONEncoder(JSONEncoder):
"""Custom JSON encoder for Litecord."""
def default(self, value: Any):
"""By default, this will try to get the to_json attribute of a given
value being JSON encoded."""
try:
return value.to_json
except AttributeError:
return super().default(value)
async def pg_set_json(con):
"""Set JSON and JSONB codecs for an asyncpg connection."""
await con.set_type_codec(
"json",
encoder=lambda v: json.dumps(v, cls=LitecordJSONEncoder),
decoder=json.loads,
schema="pg_catalog",
)
await con.set_type_codec(
"jsonb",
encoder=lambda v: json.dumps(v, cls=LitecordJSONEncoder),
decoder=json.loads,
schema="pg_catalog",
)
def yield_chunks(input_list: Sequence[Any], chunk_size: int):
"""Yield successive n-sized chunks from l.

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -24,9 +24,6 @@ from typing import Dict
import websockets
from logbook import Logger
import hmac
import hashlib
from litecord.voice.lvsp_opcodes import OPCodes as OP, InfoTable, InfoReverse
log = Logger(__name__)
@ -62,7 +59,7 @@ class LVSPConnection:
"""Receive a payload."""
assert self.conn is not None
msg = await self.conn.recv()
msg = json.loads(msg)
msg = json.dumps(msg)
return msg
async def send_op(self, opcode: int, data: dict):
@ -103,15 +100,10 @@ class LVSPConnection:
"""Handle HELLO message."""
data = msg["d"]
# nonce = data['nonce']
self._hb_interval = data["heartbeat_interval"]
token = hmac.new(
self.app.config.get("LVSP_SECRET").encode(),
data["nonce"].encode(),
hashlib.sha256,
).hexdigest()
await self.send_op(OP.identify, {"token": token})
# TODO: send identify
async def _update_health(self, new_health: float):
"""Update the health value of a given voice server."""
@ -120,7 +112,7 @@ class LVSPConnection:
await self.app.db.execute(
"""
UPDATE voice_servers
SET last_health = $1
SET health = $1
WHERE hostname = $2
""",
new_health,
@ -132,17 +124,13 @@ class LVSPConnection:
We only start heartbeating after READY.
"""
data = msg["d"]
await self._update_health(data["health"])
await self._update_health(msg["health"])
self._start_hb()
async def _handle_5(self, msg):
"""Handle HEARTBEAT_ACK."""
self._stop_hb()
data = msg["d"]
await self._update_health(data["health"])
await self._update_health(msg["health"])
self._start_hb()
async def _handle_6(self, msg):

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
"""
Litecord
Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
Copyright (C) 2018-2019 Luna Mendes
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

Some files were not shown because too many files have changed in this diff Show More