Commit Graph

85 Commits

Author SHA1 Message Date
Luna Mendes 2ac2ac262a gateway.websocket: fix permission object fetch 2018-11-21 21:13:17 -03:00
Luna Mendes 8a3e55b511 gateway.websocket: fix storage kwarg on get_permissions 2018-11-21 21:12:13 -03:00
Luna Mendes c7f6c5c6b4 gateway.websocket: add READ_MESSAGES check on OP 14 handler
this should make sure to not leak information through shard queries.
2018-11-21 21:09:19 -03:00
Luna Mendes e627d61fd0 gateway.websocket: add debug logging for dispatch()
helps track down double-sends to session ids
2018-11-19 15:43:29 -03:00
Luna Mendes 994c3eb640 pubzub.lazy_guild: remove any of the user's states on remove_member 2018-11-19 03:50:15 -03:00
Luna Mendes 9db9c75602 gateway.websocket: fix extracting guild ids when handling op 8 2018-11-18 01:24:32 -03:00
Luna Mendes 66ea960f71 gateway.websocket: anoter Storage -> UserStorage 2018-11-18 01:05:53 -03:00
Luna Mendes 0aa679677f user_storage: add UserStorage.get_user_guilds
So that we're consistent.

 - gateway.websocket, presence: change to UserStorage for
    get_user_guilds
2018-11-17 18:41:54 -03:00
Luna Mendes 978ad9075e gateway.websocket: fix more Storage -> UserStorage references 2018-11-17 03:10:45 -03:00
Luna Mendes 00c976c552 gateway.gateway: add default args when connecting
- gateway.gateway: pass app instance instead of a 7-tuple
2018-11-17 02:20:48 -03:00
Luna Mendes 11d4b54f87 split Storage into UserStorage
this should help with the amount of methods being tossed in the Storage
class.
2018-11-17 02:14:10 -03:00
Luna Mendes bf661fa237 gateway.websocket: use non-whitespace separators on encode_json
decreases overall bytes needed to send a payload
2018-11-16 17:18:20 -03:00
Luna Mendes bf8eca95b1 gateway.websocket: add GatewayWebsocket.send_op 2018-11-16 17:14:46 -03:00
Luna Mendes 61d553efb8 gateway.websocket: account for sharding in _guild_ids
Closes #1
2018-11-14 23:24:38 -03:00
Luna Mendes 46759a4e7c pylint pass
fixing unused imports across all code
2018-11-13 01:40:31 -03:00
Luna Mendes fad8484a74 pubsub.lazy_guild: use SYNC instead of DELETE->INSERT->DELETE
This makes our implementation go off-spec (depends on what you'd even
call a spec, considering lazy guilds are not documented and probably
won't be), but well... *it works*

There are also a lot of print-debugs on this commit, will clean them up.

 - pubsub.lazy_guild: filter empty groups out of items list
 - pubsub.lazy_guild: check operator's op on Operation.to_dict
 - pubsub.lazy_guild: add resync() method to deal with re-SYNCs easily
 - pubsub.lazy_guild: fix get_item_index and get_group_item_index
 - pubsub.lazy_guild: drop the ops in complex presence updates in favour
    of using resync()
 - pubsub.lazy_guild: resync on group resorting
 - pubsub.lazy_guild: use resync() on role delete
2018-11-12 02:02:56 -03:00
Luna Mendes 864f6a5d9f guild.members: add basic handling of nicks in lazy guilds
- pubsub.lazy_guilds: add a list lock to prevent inconsistencies
 - pubsub.lazy_guilds: add a lot of debug info related to list sorting
2018-11-09 19:02:26 -03:00
Luna Mendes bd9c4cb26c pubsub.lazy_guild: add implementation for pres_update
- utils: fix index_by_func
2018-11-07 18:52:50 -03:00
Luna Mendes c710ad5aaf gateway.websocket: add _ws.session ratelimit 2018-11-04 16:36:11 -03:00
Luna Mendes 33f893c0ff all: add ratelimit implementation
haven't tested yet, but it should work in theory.

 - gateway.websocket: add the 3 main ws ratelimits
 - litecord: add ratelimits package
 - ratelimits.main: add implementation
 - run: add app_set_ratelimit_headers
2018-11-04 02:06:40 -03:00
Luna Mendes 69fbd9c117 gateway.state_manager: send OP 7 Reconnect to clients
- gateway.websocket: check StateManager flags on new connections
 - gateway.websocket: cancel all tasks on GatewayWebsocket.wsp.tasks
 - run: call StateManager.gen_close_tasks() and StateManager.close() on
    app shutdown
2018-11-03 21:58:51 -03:00
Luna Mendes 378809bdd6 all: misc fixes
- gateway.websocket: fix etf dict decode
 - auth: better token parsing
 - auth: fix new_discrim calc
 - channel.messages: call _dm_pre_dispatch on get_messages
 - channels: fix get_pins
 - guilds: make sure guild owner has guild everyone role
 - invites: replace sub_guild to sub
2018-11-02 19:14:41 -03:00
Luna Mendes 4d4b075de9 auth: move last_session update from gateway to auth
this should help in cases where the client has long-lived sessions (more
than a day)
2018-10-27 23:48:28 -03:00
Luna Mendes 80c29265f3 schema.sql: add users.last_session
- gateway.websocket: update users.last_session

SQL for instances:
```sql
ALTER TABLE users ADD COLUMN last_session timestamp without time zone default (now() at time zone 'utc');
```
2018-10-27 23:40:35 -03:00
Luna Mendes f8e44d62bd gateway.websocket: handle missing 'channels' on op 14 2018-10-26 04:30:56 -03:00
Luna Mendes 2605836790 dispatcher: add dispatch_filter
- presence: (basic) handle member lists when presence update.
    Note that the respective GUILD_UPDATE_MEMBER_LIST doesn't happen
    yet. we'll need roles beforehand.
2018-10-24 19:09:05 -03:00
Luna Mendes cd4181c327 litecord.pubsub: add more functionality to GuildMemberList
GuildMemberList, as of this commit, can generate a correct list
and handle (some of) the data given in OP 14. The implementation
is still rudimentary and there's a lot of work to finish.

 - dispatcher: add LazyGuildDispatcher
 - gateway.state_manager: add states_raw to fetch
    a single state without uid
 - gateway.websocket: remove rudimentary implementation
    (moved it to GuildMemberList in litecord.pubsub.lazy_guild)
2018-10-24 16:36:24 -03:00
Luna Mendes 79f91cd774 blueprints.users: fix user guild settings
- blueprints.users: make sure a row exists on guild_settings when
    patching
 - schemas: fix all 'bool' types to 'boolean'
 - schemas: fix GUILD_SETTINGS_CHAN_OVERRIDE
 - storage: add Storage.get_guild_settings_one
 - storage: fix Storage.get_guild_settings
2018-10-19 17:36:54 -03:00
Luna Mendes a926ed47ae storage: add Storage.get_guild_settings
- gateway.websocket: use Storage.get_guild_settings
 - schema.sql: chande defaults on message_notifications to 0
2018-10-19 04:45:56 -03:00
Luna Mendes 1d3520876d gateway: more comments and docstrings 2018-10-13 17:30:02 -03:00
Luna Mendes 3f54f35dce gateway.websocket: only use pure zlib when payload is big
big here being more than 1024 characters.
2018-10-12 23:41:41 -03:00
Luna Mendes d28c0f1bc6 litecord.pubsub: add FriendDispatcher
- gateway.websocket: subscribe to friends on startup
 - presence: dispatch to friends on dispatch_pres
 - storage: add Storage.get_friend_ids
2018-10-12 16:17:29 -03:00
Luna Mendes 46fac95979 gateway.websocket: add presences field to ready payload
- presences: add PresenceManager.friend_presences
 - blueprints.auth: fix resend route
 - pubsub: add DispatcherWithState to decrease amount of
    repeated code between GuildDispatcher and ChannelDispatcher
 - storage: fix relationship id field
2018-10-12 02:10:31 -03:00
Luna Mendes 20332805b8 blueprints.channels: support dms on message create
- storage: add Storage.get_dm_peer
 - gateway.websocket: subscribe to dms as well as guilds
2018-10-11 23:01:56 -03:00
Luna Mendes ebf16754af gateway.opcodes: add CALL_SYNC
- gateway.websocket: add dummy handler for CALL_SYNC
2018-10-10 18:21:18 -03:00
Luna Mendes 71d1adac53 blueprints.users: dispatch USER_NOTE_UPDATE
- gateway.websocket: show packet when bad op
2018-10-10 18:09:39 -03:00
Luna Mendes e210c20d0f various fixes to dms
- blueprints.checks: fix party fetching
 - blueprints.users: fix try_dm_state
 - blueprints.users: fix create_dm
 - blueprints.users: fix create_group_dm being used for 1-on-1 dm
 - gateway.websocket: add support for pure zlib
 - schemas: fix CREATE_GROUP_DM
 - storage: fix _filter_recipients, get_channel and get_dms
2018-10-10 17:53:31 -03:00
Luna Mendes adc6a58179 blueprints.channels: add channel and guild ack routes
SQL for instances: Rerun `schema.sql` for the new table.

 - gateway.websocket: add get_read_state to read_state's ready
 - gateway.websocket: add get_dms on private_channels' ready
 - storage: fix get_dms()
 - storage: add Storage.get_channel_ids()
 - storage: add Storage.get_read_state()
 - schema.sql: add user_read_state table
2018-10-09 22:52:12 -03:00
Luna Mendes b0d1c9765c dispatcher: add some dispatch_* methods for backwards compatibility
- dispatcher: add EventDispatcher.remove()
 - blueprints.guilds: use remove() and unsub()
 - gateway.websocket: fix sub_many() call
2018-10-09 20:13:39 -03:00
Luna Mendes c7923da124 relationship support!
friendships and blocks are possible, however presence code isn't ready
to handle presences of people who are friends.

SQL for instances, this is going to fix bad timestamps on the messages:

```sql
ALTER TABLE ONLY members ALTER COLUMN joined_at SET DEFAULT (now() at time zone 'utc');
 ALTER TABLE ONLY messages ALTER COLUMN created_at SET DEFAULT (now() at time zone 'utc');
ALTER TABLE ONLY invites ALTER COLUMN created_at SET DEFAULT (now() at time zone 'utc');
```

After that, rerun the schema.sql file to have the new relationships
table.

 - blueprints: add relationships blueprint
 - enums: add RelationshipType
 - storage: add get_relationships
 - storage: fix bug on lazy guild changes and messages
 - schemas: return validator.document instead of reqjson
 - gateway.websocket: use Storage.get_relationships
2018-10-02 03:43:57 -03:00
Luna Mendes b091bd5c49 Add hazmat impl for OP 8 Request Guild Members
- storage: add Storage.guild_exists, Storage.query_members
2018-10-01 18:07:29 -03:00
Luna Mendes 51f7ea5ad0 gateway.websocket: use Storage.get_user_settings 2018-09-29 23:54:01 -03:00
Luna Mendes 02f2ee6943 Add some lazy loading handling
Mostly adding guild_id to some events. It isn't complete support for
them, but its some of the way there.

 - storage: give guild_id on get_message

 - gateway.websocket: decrease logging for some stuff
    - a debug log for the whole packet is still there for development
       reasons, maybe i'll put it on a config option.

 - gateway.websocket: dispatch an offline presence when the user has no
    connections tied to them anymore
2018-09-28 19:34:50 -03:00
Luna Mendes b06c07c097 gateway.websocket: add handler for heartbeats
this should keep connections more stable since we reply and update
WebsocketState.last_seq
2018-09-28 17:50:18 -03:00
Luna Mendes 92f6e3cf75 add invite usage
users can now join guilds!

invites:
 - add GET /api/v6/invites/<invite_code>
 - add DELETE /api/v6/invites/<invite_code>
 - add GET /api/v6/guilds/<guild_id>/invites
 - add GET /api/v6/channels/<channel_id>/invites
 - add POST /api/v6/invite/<invite_code>

storage:
 - add verification_level to invites
 - add empty invite.guild.features

gateway.state_manager:
 - add StateManager.user_states
 - give a dummy offline state on guild_states
    - this makes it possible for people to see offline members even when
       those members never logged in (since the would have no state being
       reffered to them)

 - gateway.websocket: use get_member_ids on lazy guild handler
 - auth: add GET /api/v6/auth/consent-required
 - dispatcher: add dispatch_user_guild and dispatch_user
 - run: use Origin header on Access-Control-Allow-Origin
2018-09-27 23:10:30 -03:00
Luna Mendes f346a991c5 gateway.state_manager: handle member_states being empty 2018-09-26 20:32:43 -03:00
Luna Mendes 34eda81e4f remove some print debug 2018-09-26 18:10:43 -03:00
Luna Mendes d242ef230a gateway.websocket: various fixes to presence
- handle BadRequest instead of passing raise_err=False
 - handle status.activities
 - ready: call update_status BEFORE subscribing and dispatching_ready

presence:
 - better presence object on guild_presences

schema:
 - handle activities, change required to false in game
2018-09-26 18:08:12 -03:00
Luna Mendes 3858e20080 Add user notes
- blueprints.users: fix get_other
 - blueprints.users: add dummy get_user_settings,
     patch_current_settings, get_consent, get_harvest and get_library
 - enums: add ExplicitFilter
 - storage: add Storage.fetch_notes
 - schema.sql: add incomplete user_settings table
2018-09-22 20:18:48 -03:00
Luna Mendes 26931425c4 gateway.websocket: fix resuming woes 2018-09-22 19:01:42 -03:00