Compare commits

...

36 Commits

Author SHA1 Message Date
luna 85c2bc3e18 Merge branch 'master' into 'feat/max_concurrency'
# Conflicts:
#   manage/cmd/users.py
2022-08-13 21:49:22 +00:00
Luna 4270b934f9 add v10 to default version prefix set 2022-08-13 17:04:21 -03:00
Luna a9c3537b88 fix static file send 2022-08-13 17:04:13 -03:00
Luna 1111fffd3a update lockfile 2022-08-13 17:00:43 -03:00
Luna 768611cc4e bump dependencies
use json provider interface for quart
2022-08-13 16:55:13 -03:00
Luna 3c815cf872 gateway: cast unknown status to offline 2022-08-13 15:51:44 -03:00
luna 5e50ca4356 Merge branch 'new-status-types' into 'master'
enums: add new entries to StatusType

See merge request litecord/litecord!89
2022-08-13 18:51:09 +00:00
NotNite 93c0df5b43
enums: add new entries to StatusType 2022-08-04 13:43:07 -04:00
luna 5f97103e1c Merge branch 'master' into 'master'
Fixed typo in README

See merge request litecord/litecord!88
2022-03-14 22:15:40 +00:00
Basil e9f762366e Fixed typo in README 2022-03-14 21:50:33 +00:00
Luna e85e38ddb7 add TODO note for voice key optimization 2022-02-19 17:47:55 -03:00
Luna 3d127b405f ignore possibly invalid VSUs but still warn on them 2022-02-19 17:45:09 -03:00
luna c1a6d9a53a Merge branch 'master' into 'master'
Fix LVSP health reporting and implement identify after hello

See merge request litecord/litecord!87
2022-02-19 16:56:35 +00:00
Evie Viau 21e9b782a4
Get LVSP secret fron config.py 2022-02-18 08:06:28 -05:00
Evie Viau 70a0379615
HEARTBEAT_ACK, READY, and basic IDENTIFY 2022-02-18 08:02:00 -05:00
luna 7d8488adc7 Merge branch 'janeptrv-master-patch-39499' into 'master'
Update lvsp.md

See merge request litecord/litecord!86
2022-02-17 22:04:08 +00:00
Jane Petrovna c579ade99c Update lvsp.md 2022-02-17 20:44:17 +00:00
luna 386354fd65 Merge branch 'refactor/wsproto-tests' into 'master'
tests: add websockets->wsproto translation layer

Closes #139

See merge request litecord/litecord!85
2022-01-29 23:38:21 +00:00
luna 3b87a17477 tests: add websockets->wsproto translation layer 2022-01-29 23:38:21 +00:00
Luna 6ac705f838 update dependencies 2022-01-27 21:56:16 -03:00
luna 6a617cf376 Merge branch 'addbot-manage' into 'master'
Add 'addbot' manage.py command

See merge request litecord/litecord!84
2022-01-27 14:40:26 +00:00
Bluenix 2fe50c4ac3 Add 'addbot' manage.py command 2022-01-27 14:40:26 +00:00
Luna ddd2469066 gateway: send zlib flush in the same websocket message
see #139
2022-01-26 21:54:32 -03:00
Luna c85f0806c7 test_websocket: add test for zlib stream 2022-01-25 23:47:33 -03:00
Luna f792769656 gateway: don't set FIN bit on zlib-stream chunks
close #139
2022-01-25 23:46:53 -03:00
Luna d77a84be97 handle bot gateway connections
close #134
2021-11-01 22:15:48 -03:00
Luna b0096f119a add hacky patch for python 3.10 2021-11-01 21:48:14 -03:00
NotNite b6b07073bc
Add user_settings_version to identify 2021-11-01 19:42:29 -04:00
Luna 3cfbbeecc7 add message reaction tests 2021-10-21 21:47:27 -03:00
Luna 55d8e3fe50 bump quart to git commit 2021-10-21 21:46:29 -03:00
Luna 8bdfdfa4ec enable raw tls on websocket 2021-10-09 12:59:48 -03:00
NotNite 2ba7a09796
gateway.schemas: add v identify field for eris 2021-09-24 21:54:17 -04:00
NotNite 2f33bb32a4
gateway.schemas: add missing guild_subscriptions 2021-09-24 21:53:55 -04:00
NotNite 2df5a93a9b
schemas: make allowed_mentions fields optional 2021-09-24 21:53:13 -04:00
luna 1b53cb404e Merge branch 'update-license-headers' into 'master'
Update license headers

See merge request litecord/litecord!83
2021-09-24 17:41:26 +00:00
Cynthia Foxwell f162f0ab60 Update license headers 2021-09-24 11:33:06 -06:00
132 changed files with 845 additions and 790 deletions

View File

@ -1,4 +1,4 @@
image: python:3.9-alpine image: python:3.10-alpine
variables: variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" 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. the "copyright" line and a pointer to where the full notice is found.
Litecord 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 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 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 If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode: 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 program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details. under certain conditions; type `show c' for details.

View File

@ -53,7 +53,7 @@ are not implemented, for example:
- Threads - Threads
- Channel Categories - 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 just v6 to make clients work, new payload structure support is
scattered throughout the codebase) scattered throughout the codebase)

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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. # e.g 'gateway.example.com' for reverse proxies.
WEBSOCKET_URL = "localhost:5001" 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? #: Where to host the websocket?
# (a local address the server will bind to) # (a local address the server will bind to)
WS_HOST = "0.0.0.0" WS_HOST = "0.0.0.0"
@ -61,6 +66,9 @@ class Config:
#: Postgres credentials #: Postgres credentials
POSTGRES = {} POSTGRES = {}
#: Shared secret for LVSP
LVSP_SECRET = ""
class Development(Config): class Development(Config):
DEBUG = True DEBUG = True

View File

@ -10,6 +10,8 @@ LVSP runs over a *long-lived* websocket with TLS. The encoding is JSON.
"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 | | opcode | name | sent by |
| --: | :-- | :-- | | --: | :-- | :-- |
| 0 | HELLO | server | | 0 | HELLO | server |
@ -119,15 +121,17 @@ are laid on.
### InfoType Enum ### 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 | | value | name | description |
| --: | :-- | :-- | | --: | :-- | :-- |
| 0 | CHANNEL\_REQ | channel assignment request | | 0 | CHANNEL\_REQ | channel assignment request |
| 1 | CHANNEL\_ASSIGN | channel assignment reply | | 1 | CHANNEL\_ASSIGN | channel assignment reply |
| 2 | CHANNEL\_DESTROY | channel destroy | | 2 | CHANNEL\_DESTROY | channel destroy |
| 3 | VST\_CREATE | voice state create request | | 3 | VOICE\_STATE\_CREATE | voice state create request |
| 4 | VST\_DONE | voice state created | | 4 | VOICE\_STATE\_DONE | voice state created |
| 5 | VST\_UPDATE | voice state update | | 5 | VOICE\_STATE\_DESTROY | voice state destroy |
| 6 | VST\_LEAVE | voice state leave | | 6 | VOICE\_STATE\_UPDATE | voice state update |
### CHANNEL\_REQ ### CHANNEL\_REQ
@ -158,7 +162,7 @@ a channel being deleted, or all members in it leaving.
Same data as CHANNEL\_ASSIGN, but without `token`. Same data as CHANNEL\_ASSIGN, but without `token`.
### VST\_CREATE ### VOICE\_STATE\_CREATE
Sent by the client to create a voice state. 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 | | channel\_id | snowflake | channel id |
| guild\_id | Optional[snowflake] | guild id. not provided if dm / group dm | | 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 | | field | type | description |
| --: | :-- | :-- | | --: | :-- | :-- |
| session\_id | string | session id for the voice state | | 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 Sent by the client when a user is leaving a channel OR moving between channels
in a guild. More on state transitions later on. in a guild. More on state transitions later on.
### VOICE\_STATE\_UPDATE
Sent to update an existing voice state. Potentially unused.
| field | type | description | | field | type | description |
| --: | :-- | :-- | | --: | :-- | :-- |
| session\_id | string | session id for the voice state | | 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. user join is here.
- Client will send a CHANNEL\_REQ. - 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 - The Server MUST process CHANNEL\_REQ first, so the Server can keep
a lock on channel operations while it is initialized. a lock on channel operations while it is initialized.
- Reply with CHANNEL\_ASSIGN once initialization is done. - Reply with CHANNEL\_ASSIGN once initialization is done.
- Process VST\_CREATE - Process VOICE\_STATE\_CREATE
### Updating a voice channel ### Updating a voice channel
@ -214,15 +222,15 @@ user join is here.
### User joining an (initialized) voice channel ### User joining an (initialized) voice channel
- Client sends VST\_CREATE - Client sends VOICE\_STATE\_CREATE
- Server sends VST\_DONE - Server sends VOICE\_STATE\_DONE
### User leaves a channel ### 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 ### User moves a channel
- Client sends VST\_DESTROY with the old fields - Client sends VOICE\_STATE\_DESTROY with the old fields
- Client sends VST\_CREATE with the new fields - Client sends VOICE\_STATE\_CREATE with the new fields
- Server sends VST\_DONE - Server sends VOICE\_STATE\_DONE

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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.enums import MessageType, ChannelType, GUILD_CHANS
from litecord.schemas import validate, MESSAGE_CREATE 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.permissions import get_permissions
from litecord.embed.sanitizer import fill_embed from litecord.embed.sanitizer import fill_embed

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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 from pathlib import Path
bp = Blueprint("static", __name__) bp = Blueprint("static", __name__)
@ -30,7 +30,10 @@ async def static_pages(path):
return "no", 404 return "no", 404
static_path = Path.cwd() / Path("static") / path 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("/") @bp.route("/")

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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.sanitizer import fill_embed, fetch_mediaproxy_img
from litecord.embed.messages import process_url_embed, is_media_url from litecord.embed.messages import process_url_embed, is_media_url
from litecord.embed.schemas import EmbedURL 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.enums import MessageType
from litecord.images import STATIC_IMAGE_MIMES from litecord.images import STATIC_IMAGE_MIMES

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by
@ -189,6 +189,8 @@ class StatusType(EasyEnum):
IDLE = "idle" IDLE = "idle"
INVISIBLE = "invisible" INVISIBLE = "invisible"
OFFLINE = "offline" OFFLINE = "offline"
STREAMING = "streaming"
UNKNOWN = "unknown"
class ExplicitFilter(EasyEnum): class ExplicitFilter(EasyEnum):

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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 json
import earl import earl
from litecord.utils import LitecordJSONEncoder from litecord.json import LitecordJSONEncoder
def encode_json(payload) -> str: def encode_json(payload) -> str:

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by
@ -120,8 +120,12 @@ IDENTIFY_SCHEMA = {
"type": "number", "type": "number",
"required": False, "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 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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"]: for recipient in private_channel["recipients"]:
users_to_send[recipient["id"]] = recipient 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"] relationship_user = relationship["user"]
users_to_send[relationship_user["id"]] = 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 # relationship object structure changed in v9
if ws_properties.version == 9: if ws_properties.version == 9:
ready["relationships"] = [] ready["relationships"] = []
for relationship in user_ready["relationships"]: for relationship in user_relationships:
ready["relationships"].append( ready["relationships"].append(
{ {
"user_id": relationship["user"]["id"], "user_id": relationship["user"]["id"],
@ -138,7 +139,9 @@ async def _compute_supplemental(app, base_ready, user_ready, users_to_send: dict
"guilds": [], "guilds": [],
} }
for relationship in user_ready["relationships"]: user_relationships = user_ready.get("relationships", [])
for relationship in user_relationships:
if relationship["type"] != RelationshipType.FRIEND.value: if relationship["type"] != RelationshipType.FRIEND.value:
continue continue
@ -265,16 +268,13 @@ class GatewayWebsocket:
"""Split data in chunk_size-big chunks and send them """Split data in chunk_size-big chunks and send them
over the websocket.""" over the websocket."""
log.debug( 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 # we send the entire iterator as per websockets documentation
for chunk in yield_chunks(data, chunk_size): # to pretent setting FIN when we don't want to
total_chunks += 1 # see https://gitlab.com/litecord/litecord/-/issues/139
log.debug("zlib-stream: chunk {}", total_chunks) await self.ws.send(yield_chunks(data, chunk_size))
await self.ws.send(chunk)
log.debug("zlib-stream: sent {} chunks", total_chunks)
async def _zlib_stream_send(self, encoded): async def _zlib_stream_send(self, encoded):
"""Sending a single payload across multiple compressed """Sending a single payload across multiple compressed
@ -283,39 +283,19 @@ class GatewayWebsocket:
# compress and flush (for the rest of compressed data + ZLIB_SUFFIX) # compress and flush (for the rest of compressed data + ZLIB_SUFFIX)
data1 = self.ws_properties.zctx.compress(encoded) data1 = self.ws_properties.zctx.compress(encoded)
data2 = self.ws_properties.zctx.flush(zlib.Z_FULL_FLUSH) data2 = self.ws_properties.zctx.flush(zlib.Z_FULL_FLUSH)
data = data1 + data2
log.debug( log.debug(
"zlib-stream: length {} -> compressed ({} + {})", "zlib-stream: length {} -> compressed ({})",
len(encoded), len(encoded),
len(data1), len(data),
len(data2),
) )
if not data1: # since we always chunk the entire compressed message, we shouldn't
# if data1 is nothing, that might cause problems # worry about sending big frames to the clients
# 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? # TODO: the chunks are 1024 bytes, 1KB, is this good enough?
await self._chunked_send(data1, 1024) await self._chunked_send(data, 1024)
await self._chunked_send(data2, 1024)
async def _zstd_stream_send(self, encoded): async def _zstd_stream_send(self, encoded):
compressor = self.ws_properties.zsctx.stream_writer( compressor = self.ws_properties.zsctx.stream_writer(
@ -730,7 +710,7 @@ class GatewayWebsocket:
presence.game = game presence.game = game
if presence.status == "invisible": if presence.status in ("invisible", "unknown"):
presence.status = "offline" presence.status = "offline"
self.state.presence = presence self.state.presence = presence
@ -915,6 +895,9 @@ class GatewayWebsocket:
# they CAN NOT enter two channels in a single guild. # they CAN NOT enter two channels in a single guild.
# this state id format takes care of that. # 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_key = (self.state.user_id, state_id2)
voice_state = await self.app.voice.get_state(voice_key) voice_state = await self.app.voice.get_state(voice_key)
@ -932,6 +915,10 @@ class GatewayWebsocket:
if same_guild and not same_channel: if same_guild and not same_channel:
return await self.app.voice.move_state(voice_state, channel_id) 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]): async def _handle_5(self, payload: Dict[str, Any]):
"""Handle OP 5 Voice Server Ping. """Handle OP 5 Voice Server Ping.

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

69
litecord/json.py Normal file
View File

@ -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",
)

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by
@ -450,8 +450,8 @@ MESSAGE_CREATE = {
"required": False, "required": False,
"nullable": True, "nullable": True,
"schema": { "schema": {
"parse": {"type": "list", "required": True}, "parse": {"type": "list", "required": False},
"replied_user": {"type": "boolean", "required": True}, "replied_user": {"type": "boolean", "required": False},
}, },
}, },
} }

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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.blueprints.user.billing import PLAN_ID_TO_TYPE
from litecord.types import timestamp_ from litecord.types import timestamp_
from litecord.utils import pg_set_json from litecord.json import pg_set_json
log = Logger(__name__) log = Logger(__name__)

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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 asyncio
import json
import secrets import secrets
import datetime import datetime
import re import re
from typing import Any, Iterable, Optional, Sequence, List, Dict, Union from typing import Any, Iterable, Optional, Sequence, List, Dict, Union
from logbook import Logger from logbook import Logger
from quart.json import JSONEncoder
from quart import current_app as app from quart import current_app as app
from litecord.common.messages import message_view from litecord.common.messages import message_view
@ -156,35 +154,6 @@ def mmh3(inp_str: str, seed: int = 0):
return _u(h1) >> 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): def yield_chunks(input_list: Sequence[Any], chunk_size: int):
"""Yield successive n-sized chunks from l. """Yield successive n-sized chunks from l.

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by
@ -24,6 +24,9 @@ from typing import Dict
import websockets import websockets
from logbook import Logger from logbook import Logger
import hmac
import hashlib
from litecord.voice.lvsp_opcodes import OPCodes as OP, InfoTable, InfoReverse from litecord.voice.lvsp_opcodes import OPCodes as OP, InfoTable, InfoReverse
log = Logger(__name__) log = Logger(__name__)
@ -59,7 +62,7 @@ class LVSPConnection:
"""Receive a payload.""" """Receive a payload."""
assert self.conn is not None assert self.conn is not None
msg = await self.conn.recv() msg = await self.conn.recv()
msg = json.dumps(msg) msg = json.loads(msg)
return msg return msg
async def send_op(self, opcode: int, data: dict): async def send_op(self, opcode: int, data: dict):
@ -100,10 +103,15 @@ class LVSPConnection:
"""Handle HELLO message.""" """Handle HELLO message."""
data = msg["d"] data = msg["d"]
# nonce = data['nonce']
self._hb_interval = data["heartbeat_interval"] 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): async def _update_health(self, new_health: float):
"""Update the health value of a given voice server.""" """Update the health value of a given voice server."""
@ -112,7 +120,7 @@ class LVSPConnection:
await self.app.db.execute( await self.app.db.execute(
""" """
UPDATE voice_servers UPDATE voice_servers
SET health = $1 SET last_health = $1
WHERE hostname = $2 WHERE hostname = $2
""", """,
new_health, new_health,
@ -124,13 +132,17 @@ class LVSPConnection:
We only start heartbeating after READY. We only start heartbeating after READY.
""" """
await self._update_health(msg["health"]) data = msg["d"]
await self._update_health(data["health"])
self._start_hb() self._start_hb()
async def _handle_5(self, msg): async def _handle_5(self, msg):
"""Handle HEARTBEAT_ACK.""" """Handle HEARTBEAT_ACK."""
self._stop_hb() self._stop_hb()
await self._update_health(msg["health"]) data = msg["d"]
await self._update_health(data["health"])
self._start_hb() self._start_hb()
async def _handle_6(self, msg): async def _handle_6(self, msg):

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 it under the terms of the GNU General Public License as published by

View File

@ -1,7 +1,7 @@
""" """
Litecord 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 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 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