Commit Graph

1054 Commits

Author SHA1 Message Date
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 aa76cc2c7d litecord.dispatcher: change dispatch_* methods into pubsub backends
- litecord: add pubsub module
 - schemas: change type to snowflake in MESSAGE_CREATE's nonce
2018-10-09 18:56:34 -03:00
Luna Mendes 5afc15c4f6 storage: fix bug on last_message_id
- storage: better member.roles
 - presence: cast guild_id to str
2018-10-04 04:13:46 -03:00
Luna Mendes 0ebbc4cd37 schema.sql: add UNIQUE to dm_channels
This should fix the `schema.sql` errors on 61e36f244b.

```sql
DROP TABLE dm_channels;
```

Then rerun `schema.sql`.
2018-10-03 22:11:07 -03:00
Luna Mendes 61e36f244b blueprints.users, channels: basic dm operations
SQL for instances:

```sql
ALTER TABLE messages
ADD CONSTRAINT messages_channels_fkey
FOREIGN KEY (channel_id)
REFERENCES channels (id)
ON DELETE CASCADE;

ALTER TABLE channel_pins ADD CONSTRAINT pins_channels_fkey
FOREIGN KEY (channel_id)
REFERENCES channels (id)
ON DELETE CASCADE;

ALTER TABLE channel_pins ADD CONSTRAINT pins_messages_fkey
FOREIGN KEY (message_id)
REFERENCES messages (id)
ON DELETE CASCADE;
```

After that, rerun `schema.sql`.

blueprints.channels:
 - check dms on channel_check
 - add DELETE /api/v6/channels/<int:channel_id>

blueprints.users:
 - add event dispatching for leaving guilds
 - add GET /api/v6/users/@me/channels, for DM fetching
 - add POST /api/v6/users/@me/channels, for DM creation
 - add POST /api/v6/users/<int:user_id>/channels for DM / Group DM
    creation

 - schemas: add CREATE, CREATE_GROUP_DM
 - storage: add last_message_id fetching for channels
 - storage: add support for DMs in get_channel
 - storage: add Storage.get_dm, Storage.get_dms, Storage.get_all_dms
 - schema.sql: add dm_channel_state table
 - schema.sql: add constriants for messages.channel_id and channel_pins
2018-10-03 21:49:35 -03:00
Luna Mendes 88bc4ceca8 blueprints.relationships: fix dispatches 2018-10-02 19:16:00 -03:00
Luna Mendes 45559608f3 litecord.storage: fix _chan_overwrites since table changes 2018-10-02 18:37:53 -03:00
Luna Mendes fcddd46d47 schema.sql: add draft for dm_channels
also add name to group_dm_channels, and a group_dm_members table.

SQL for moving to latest schema:

```sql
DROP TABLE dm_channels;
DROP TABLE group_dm_channels;
DROP TABLE channel_overwrites;
DROP TABLE guild_features;
```

Then rerun `schema.sql`.

 - schema.sql: revamp channel_overwrites table
 - schema.sql: add features table
 - schema.sql: make guild_features use the features table
2018-10-02 17:56:20 -03:00
Luna Mendes d7cc5568bc schema.sql: fix possible bug with some message tables
Drop the unused tables:
```sql
DROP TABLE message_attachments;
DROP TABLE message_reactions;
DROP TABLE channel_pins;
```

Rerun `schema.sql` to recreate them with the proper constraints.
2018-10-02 16:51:01 -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 bff5700d06 blueprints.users: add user setting patch impl
- schemas: add explicit type
 - schemas: add USER_SETTINGS
 - run: make Access-Control-Allow-Methods the same as Allow header when
    possible
2018-09-29 23:43:02 -03:00
Luna Mendes 624eb6eb0e blueprints.users: use Storage.get_user_settings
paving the way for user settings support.

 - storage: add Storage.get_user_settings
 - storage: add methods to fetch with json/jsonb codecs enabled
2018-09-29 23:10:42 -03:00
Luna Mendes 4841565f14 schema.sql: add user_settings table
rerunning the schema.sql file should get you up and running.

 - add POST /api/v6/users/@me/consent for consent changes (that get
    ignored)
2018-09-29 22:17:10 -03:00
Luna Mendes 993a2f3b08 blueprints.channels: add dummy search route 2018-09-28 20:08:07 -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 d9506f450d schema.sql: change from varchar to text on some fields
unicode!

sql for instances to upgrade:

alter table users alter column username type text;
alter table guilds alter column name type text;
alter table members alter column nickname type text;
alter table roles alter column name type text;
alter table bans alter column reason type text;
2018-09-28 00:54:24 -03:00
Luna Mendes 37c61466a4 blueprints.channels: fix TYPING_START 2018-09-28 00:08:39 -03:00
Luna Mendes f5db1038eb blueprints.invites: fix typo on get_channel_invites 2018-09-27 23:29:55 -03:00
Luna Mendes e7d97ecdef run: have a fallback when Origin header is missing 2018-09-27 23:25:23 -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 dc62de37b2 basic invites
- add invites blueprint
 - add POST /api/v6/channels/<channel_id>/invites
 - add GET /api/v6/invites/<invite_code>
 - schema: add INVITE
 - storage: add get_member_ids, get_invite, get_invite_extra,
 get_invite_metadata
2018-09-26 20:29:22 -03:00
Luna Mendes ea9bb52e4f Merge branch 'patch-1' into 'master'
fix script error that would happen randomly

See merge request luna/litecord!1
2018-09-26 21:49:49 +00:00
Bootsy 8a25c9767e fix script error that would happen randomly 2018-09-26 21:48:51 +00: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 14d3149f50 storage: add presence fetching on get_guild_extra 2018-09-22 22:00:25 -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
Luna Mendes bfa0e61a0c gateway.websocket: give random heartbeat_interval 2018-09-12 21:27:19 -03:00
Luna Mendes 25cd85d704 gateway.websocket: rudimentary resuming 2018-09-12 20:53:29 -03:00
Luna Mendes 213eb328b2 gateway.websocket: add implementation for _handle_3
- gateway.websocket: add dummy implementation for _handle_5
2018-09-12 20:35:50 -03:00
Luna Mendes dd4ae44080 gateway.websocket: rudimentary lazy guilds
implementation details are on the docstrings for _handle_14.

 - presence: merge member dict instead of copying some fields from it
2018-09-10 22:32:58 -03:00
Luna Mendes 952b66a28c blueprints.{channels, guilds}: use *Type as enums instead of classes 2018-09-10 20:29:04 -03:00
Luna Mendes ee8cfedf69 schema: change raise_err default to True 2018-09-10 20:25:03 -03:00
Luna Mendes cd5dbc4886 Rough presence management
Lots of changes to get it working.

One day changes will be able to be small enough to be split across
commits.

 - enums: use enum.Enum, make EasyEnum subclass
 - enums: add ActivityType, ActivityFlags, StatusType
 - gateway.state: use 128 random bits instead of 256
 - gateway.state: add MAX_STORE_SIZE in PayloadStore and check it when
    adding a new payload
 - gateway.websocket: add GatewayWebsocket.update_status
 - presence: add PresenceManager.dispatch_guild_pres and
    PresenceManager.dispatch_pres
 - schema: add snowflake, activity_type, status_external types
 - schema: add GW_ACTIVITY, GW_STATUS_UPDATE
 - storage: fix _channels_extra and fixes for ChannelType as enum instead of
    class
2018-09-10 01:09:09 -03:00
Luna Mendes d39783e666 Add barebones implementation for GUILD_SYNC
- state_manager: add StateManager.guild_states
 - add PresenceManager in the presence module
 - fix get_user_guilds not returning ints
 - gateway: add dummy handler for op 4
 - gateway: add hazmat implementation for op 14
 - run: keep websockets logger on INFO
 - run: add more headers on app_after_request
2018-09-01 23:53:36 -03:00
slice ee6ad56604
Revert "refactor out _dummy function"
This reverts commit 24a19c8736.
2018-09-01 19:23:13 -07:00
slice 24a19c8736
refactor out _dummy function 2018-09-01 19:06:49 -07:00
slice 13f6842232
remove unnecessary ** in dict 2018-09-01 19:02:42 -07:00
slice f463d6c934
rewrite readme 2018-09-01 18:54:28 -07:00
Luna Mendes 4a658aec95 README: change from pipenv shell to pipenv run
Do we really need the shell as an extra step?
2018-08-21 05:17:24 -03:00
Luna Mendes 85d4f9e593 run: Add some headers for Access-Control-Allow-Headers 2018-08-21 05:13:38 -03:00
Luna Mendes b323368ffc config: s/WEBSERVER_URL/WEBSOCKET_URL
Also add explanation on how to use WEBSOCKET_URL
2018-07-21 17:19:57 -03:00
Luna Mendes 5e4230bc31 Revert "use ws settings for gateway endpoint"
This reverts commit cb70842280.

WEBSERVER_URL was made for the case where litecord is behind
a reverse proxy (nginx / cloudflare, etc). If the instance
isn't behind a reverse proxy, you can set WEBSERVER_URL to your
own local address.
2018-07-21 17:08:41 -03:00
slice 753dc03fc7
remove required_action
this is needed as it breaks the client
2018-07-21 11:53:00 -07:00
slice 4ff0314ab6
disable game tab by default 2018-07-21 11:52:42 -07:00