mirror of https://gitlab.com/litecord/litecord.git
Compare commits
36 Commits
e3f894330d
...
85c2bc3e18
| Author | SHA1 | Date |
|---|---|---|
|
|
85c2bc3e18 | |
|
|
4270b934f9 | |
|
|
a9c3537b88 | |
|
|
1111fffd3a | |
|
|
768611cc4e | |
|
|
3c815cf872 | |
|
|
5e50ca4356 | |
|
|
93c0df5b43 | |
|
|
5f97103e1c | |
|
|
e9f762366e | |
|
|
e85e38ddb7 | |
|
|
3d127b405f | |
|
|
c1a6d9a53a | |
|
|
21e9b782a4 | |
|
|
70a0379615 | |
|
|
7d8488adc7 | |
|
|
c579ade99c | |
|
|
386354fd65 | |
|
|
3b87a17477 | |
|
|
6ac705f838 | |
|
|
6a617cf376 | |
|
|
2fe50c4ac3 | |
|
|
ddd2469066 | |
|
|
c85f0806c7 | |
|
|
f792769656 | |
|
|
d77a84be97 | |
|
|
b0096f119a | |
|
|
b6b07073bc | |
|
|
3cfbbeecc7 | |
|
|
55d8e3fe50 | |
|
|
8bdfdfa4ec | |
|
|
2ba7a09796 | |
|
|
2f33bb32a4 | |
|
|
2df5a93a9b | |
|
|
1b53cb404e | |
|
|
f162f0ab60 |
|
|
@ -1,4 +1,4 @@
|
|||
image: python:3.9-alpine
|
||||
image: python:3.10-alpine
|
||||
|
||||
variables:
|
||||
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
|
||||
|
|
|
|||
4
LICENSE
4
LICENSE
|
|
@ -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 Luna Mendes
|
||||
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
|
||||
|
|
@ -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 Luna Mendes
|
||||
litecord Copyright (C) 2018-2021 Luna Mendes and Litecord Contributors
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ are not implemented, for example:
|
|||
|
||||
- Threads
|
||||
- Channel Categories
|
||||
- API v9 (Right now, Litecord, in generla, assumes v9 is
|
||||
- API v9 (Right now, Litecord, in general, assumes v9 is
|
||||
just v6 to make clients work, new payload structure support is
|
||||
scattered throughout the codebase)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018 Luna Mendes
|
||||
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
|
||||
|
|
@ -16,4 +16,3 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -48,6 +48,11 @@ 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"
|
||||
|
|
@ -60,6 +65,9 @@ class Config:
|
|||
|
||||
#: Postgres credentials
|
||||
POSTGRES = {}
|
||||
|
||||
#: Shared secret for LVSP
|
||||
LVSP_SECRET = ""
|
||||
|
||||
|
||||
class Development(Config):
|
||||
|
|
|
|||
44
docs/lvsp.md
44
docs/lvsp.md
|
|
@ -8,7 +8,9 @@ LVSP runs over a *long-lived* websocket with TLS. The encoding is JSON.
|
|||
|
||||
## OP code table
|
||||
|
||||
"client" is litecord. "server" is the voice server.
|
||||
"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.
|
||||
|
||||
| opcode | name | sent by |
|
||||
| --: | :-- | :-- |
|
||||
|
|
@ -119,15 +121,17 @@ 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 | VST\_CREATE | voice state create request |
|
||||
| 4 | VST\_DONE | voice state created |
|
||||
| 5 | VST\_UPDATE | voice state update |
|
||||
| 6 | VST\_LEAVE | voice state leave |
|
||||
| 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 |
|
||||
|
||||
### CHANNEL\_REQ
|
||||
|
||||
|
|
@ -158,7 +162,7 @@ a channel being deleted, or all members in it leaving.
|
|||
|
||||
Same data as CHANNEL\_ASSIGN, but without `token`.
|
||||
|
||||
### VST\_CREATE
|
||||
### VOICE\_STATE\_CREATE
|
||||
|
||||
Sent by the client to create a voice state.
|
||||
|
||||
|
|
@ -168,21 +172,25 @@ 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 |
|
||||
|
||||
### VST\_DONE
|
||||
### VOICE\_STATE\_DONE
|
||||
|
||||
Sent by the server to indicate the success of a VST\_CREATE.
|
||||
Sent by the server to indicate the success of a VOICE\_STATE\_CREATE.
|
||||
|
||||
Has the same fields as VST\_CREATE, but with extras:
|
||||
Has the same fields as VOICE\_STATE\_CREATE, but with extras:
|
||||
|
||||
| field | type | description |
|
||||
| --: | :-- | :-- |
|
||||
| session\_id | string | session id for the voice state |
|
||||
|
||||
### VST\_DESTROY
|
||||
### VOICE\_STATE\_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 |
|
||||
|
|
@ -195,11 +203,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 VST\_CREATE right after as well.
|
||||
- Client MAY send a VOICE\_STATE\_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 VST\_CREATE
|
||||
- Process VOICE\_STATE\_CREATE
|
||||
|
||||
### Updating a voice channel
|
||||
|
||||
|
|
@ -214,15 +222,15 @@ user join is here.
|
|||
|
||||
### User joining an (initialized) voice channel
|
||||
|
||||
- Client sends VST\_CREATE
|
||||
- Server sends VST\_DONE
|
||||
- Client sends VOICE\_STATE\_CREATE
|
||||
- Server sends VOICE\_STATE\_DONE
|
||||
|
||||
### User leaves a channel
|
||||
|
||||
- Client sends VST\_DESTROY with the old fields
|
||||
- Client sends VOICE\_STATE\_DESTROY with the old fields
|
||||
|
||||
### User moves a channel
|
||||
|
||||
- Client sends VST\_DESTROY with the old fields
|
||||
- Client sends VST\_CREATE with the new fields
|
||||
- Server sends VST\_DONE
|
||||
- Client sends VOICE\_STATE\_DESTROY with the old fields
|
||||
- Client sends VOICE\_STATE\_CREATE with the new fields
|
||||
- Server sends VOICE\_STATE\_DONE
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -29,7 +29,8 @@ 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 pg_set_json, query_tuple_from_args, extract_limit
|
||||
from litecord.utils import query_tuple_from_args, extract_limit
|
||||
from litecord.json import pg_set_json
|
||||
from litecord.permissions import get_permissions
|
||||
|
||||
from litecord.embed.sanitizer import fill_embed
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -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
|
||||
from quart import Blueprint, current_app as app, render_template_string, send_file
|
||||
from pathlib import Path
|
||||
|
||||
bp = Blueprint("static", __name__)
|
||||
|
|
@ -30,7 +30,10 @@ async def static_pages(path):
|
|||
return "no", 404
|
||||
|
||||
static_path = Path.cwd() / Path("static") / path
|
||||
return await app.send_static_file(str(static_path))
|
||||
if static_path.exists():
|
||||
return await send_file(static_path)
|
||||
else:
|
||||
return "not found", 404
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -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.utils import pg_set_json
|
||||
from litecord.json import pg_set_json
|
||||
from litecord.enums import MessageType
|
||||
from litecord.images import STATIC_IMAGE_MIMES
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -189,6 +189,8 @@ class StatusType(EasyEnum):
|
|||
IDLE = "idle"
|
||||
INVISIBLE = "invisible"
|
||||
OFFLINE = "offline"
|
||||
STREAMING = "streaming"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class ExplicitFilter(EasyEnum):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import json
|
||||
import earl
|
||||
|
||||
from litecord.utils import LitecordJSONEncoder
|
||||
from litecord.json import LitecordJSONEncoder
|
||||
|
||||
|
||||
def encode_json(payload) -> str:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -120,8 +120,12 @@ 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},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -91,7 +91,8 @@ 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
|
||||
|
||||
for relationship in user_ready["relationships"]:
|
||||
user_relationships = user_ready.get("relationships", [])
|
||||
for relationship in user_relationships:
|
||||
relationship_user = relationship["user"]
|
||||
users_to_send[relationship_user["id"]] = relationship_user
|
||||
|
||||
|
|
@ -101,7 +102,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_ready["relationships"]:
|
||||
for relationship in user_relationships:
|
||||
ready["relationships"].append(
|
||||
{
|
||||
"user_id": relationship["user"]["id"],
|
||||
|
|
@ -138,7 +139,9 @@ async def _compute_supplemental(app, base_ready, user_ready, users_to_send: dict
|
|||
"guilds": [],
|
||||
}
|
||||
|
||||
for relationship in user_ready["relationships"]:
|
||||
user_relationships = user_ready.get("relationships", [])
|
||||
|
||||
for relationship in user_relationships:
|
||||
if relationship["type"] != RelationshipType.FRIEND.value:
|
||||
continue
|
||||
|
||||
|
|
@ -265,16 +268,13 @@ class GatewayWebsocket:
|
|||
"""Split data in chunk_size-big chunks and send them
|
||||
over the websocket."""
|
||||
log.debug(
|
||||
"zlib-stream: chunking {} bytes into {}-byte chunks", len(data), chunk_size
|
||||
"zlib-stream: sending {} bytes into {}-byte chunks", len(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)
|
||||
# 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))
|
||||
|
||||
async def _zlib_stream_send(self, encoded):
|
||||
"""Sending a single payload across multiple compressed
|
||||
|
|
@ -283,39 +283,19 @@ 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(data1),
|
||||
len(data2),
|
||||
len(data),
|
||||
)
|
||||
|
||||
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.
|
||||
# since we always chunk the entire compressed message, we shouldn't
|
||||
# worry about sending big frames to the clients
|
||||
|
||||
# TODO: the chunks are 1024 bytes, 1KB, is this good enough?
|
||||
await self._chunked_send(data1, 1024)
|
||||
await self._chunked_send(data2, 1024)
|
||||
await self._chunked_send(data, 1024)
|
||||
|
||||
async def _zstd_stream_send(self, encoded):
|
||||
compressor = self.ws_properties.zsctx.stream_writer(
|
||||
|
|
@ -730,7 +710,7 @@ class GatewayWebsocket:
|
|||
|
||||
presence.game = game
|
||||
|
||||
if presence.status == "invisible":
|
||||
if presence.status in ("invisible", "unknown"):
|
||||
presence.status = "offline"
|
||||
|
||||
self.state.presence = presence
|
||||
|
|
@ -915,6 +895,9 @@ 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)
|
||||
|
||||
|
|
@ -932,6 +915,10 @@ 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.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
"""
|
||||
|
||||
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",
|
||||
)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -450,8 +450,8 @@ MESSAGE_CREATE = {
|
|||
"required": False,
|
||||
"nullable": True,
|
||||
"schema": {
|
||||
"parse": {"type": "list", "required": True},
|
||||
"replied_user": {"type": "boolean", "required": True},
|
||||
"parse": {"type": "list", "required": False},
|
||||
"replied_user": {"type": "boolean", "required": False},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -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.utils import pg_set_json
|
||||
from litecord.json import pg_set_json
|
||||
|
||||
log = Logger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -18,14 +18,12 @@ 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
|
||||
|
|
@ -156,35 +154,6 @@ 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.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
@ -24,6 +24,9 @@ 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__)
|
||||
|
|
@ -59,7 +62,7 @@ class LVSPConnection:
|
|||
"""Receive a payload."""
|
||||
assert self.conn is not None
|
||||
msg = await self.conn.recv()
|
||||
msg = json.dumps(msg)
|
||||
msg = json.loads(msg)
|
||||
return msg
|
||||
|
||||
async def send_op(self, opcode: int, data: dict):
|
||||
|
|
@ -100,10 +103,15 @@ class LVSPConnection:
|
|||
"""Handle HELLO message."""
|
||||
data = msg["d"]
|
||||
|
||||
# nonce = data['nonce']
|
||||
self._hb_interval = data["heartbeat_interval"]
|
||||
|
||||
# TODO: send identify
|
||||
token = hmac.new(
|
||||
self.app.config.get("LVSP_SECRET").encode(),
|
||||
data["nonce"].encode(),
|
||||
hashlib.sha256,
|
||||
).hexdigest()
|
||||
|
||||
await self.send_op(OP.identify, {"token": token})
|
||||
|
||||
async def _update_health(self, new_health: float):
|
||||
"""Update the health value of a given voice server."""
|
||||
|
|
@ -112,7 +120,7 @@ class LVSPConnection:
|
|||
await self.app.db.execute(
|
||||
"""
|
||||
UPDATE voice_servers
|
||||
SET health = $1
|
||||
SET last_health = $1
|
||||
WHERE hostname = $2
|
||||
""",
|
||||
new_health,
|
||||
|
|
@ -124,13 +132,17 @@ class LVSPConnection:
|
|||
|
||||
We only start heartbeating after READY.
|
||||
"""
|
||||
await self._update_health(msg["health"])
|
||||
data = msg["d"]
|
||||
|
||||
await self._update_health(data["health"])
|
||||
self._start_hb()
|
||||
|
||||
async def _handle_5(self, msg):
|
||||
"""Handle HEARTBEAT_ACK."""
|
||||
self._stop_hb()
|
||||
await self._update_health(msg["health"])
|
||||
data = msg["d"]
|
||||
|
||||
await self._update_health(data["health"])
|
||||
self._start_hb()
|
||||
|
||||
async def _handle_6(self, msg):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
Litecord
|
||||
Copyright (C) 2018-2019 Luna Mendes
|
||||
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
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue