Commit Graph

61 Commits

Author SHA1 Message Date
Luna Mendes 8492b6eb33 channel.messages: handle role mentions and at-everyone mentions 2018-11-18 02:25: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 b6f2d5fdd8 storage: s/guild_emojis/guild_emoji table 2018-11-17 18:03:02 -03:00
Luna Mendes 64af426035 guild: add emoji blueprint
- storage: add get_emoji, get_guild_emojis
2018-11-17 17:06:27 -03:00
Luna Mendes 978ad9075e gateway.websocket: fix more Storage -> UserStorage references 2018-11-17 03:10:45 -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 2f972fc735 storage: use get_member_data_one 2018-11-15 18:36:11 -03:00
Luna Mendes eed4912440 litecord.storage: give pinned value 2018-11-15 00:07:48 -03:00
Luna Mendes 31042e4129 litecord.storage: only query secure fields when actually secure=True 2018-11-14 23:44:35 -03:00
Luna Mendes 46759a4e7c pylint pass
fixing unused imports across all code
2018-11-13 01:40:31 -03:00
Luna Mendes 7c274f0f70 channels: add PUT /api/v6/:chan_id/permissions/:overwrite_id
This finishes the basics on channel overwrites.

SQL for instances:
```sql
DROP TABLE channel_overwrites;
```
Then run `schema.sql`.

 - channels: finish implementations for update_{text,voice}_channel
 - storage: fix _overwrite_convert
 - schema.sql: use unique constraint instead of primary key in
    channel_overwrites
2018-11-05 04:12:16 -03:00
Luna Mendes da8b049174 channel.messages: add permission checks
this commit only adds permission checking to most parts of the
message endpoints.

 - channel.messages: fix extract_limit's default param
 - channel.messages: check send_messages, mention_everyone, send_tts_messages
 - channel.messages: check manage_messages
 - blueprints.checks: add guild_perm_check, channel_perm_check
 - errors: add error_code property, change some inheritance
 - permissions: fix base_permissions
 - storage: fix get_reactions
 - storage: remove print-debug
 - run: use error_code property when given
2018-11-04 19:55:21 -03:00
Luna Mendes 87dd70b4d9 permissions: add basic permission api
- litecord.auth: insert request.user_id
 - storage: add get_member_role_ids
2018-11-04 17:54:48 -03:00
Luna Mendes 0f7ffaf717 storage: add Storage.get_reactions
This finishes basic reaction code (both inserting and putting a reaction).

SQL for instances:
```sql
DROP TABLE message_reactions;
```

Then rerun `schema.sql`

 - channel.reactions: fix partial_emoji
 - schema.sql: add message_reactions.react_ts and unique constraint
    instead of primary key
2018-11-02 22:07:32 -03:00
Luna Mendes 1db27a811f litecord.storage: proper fix for missing guild everyone role 2018-11-02 19:20:39 -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 ce5b75921a members: add role change impl
- lazy_guild: add to online/offline groups when role isnt hoisted
 - schemas: fix MEMBER_UPDATE.nick
2018-10-27 21:50:15 -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 ef5d4f30e1 blueprints: create dms blueprint
It should be safe for instances to run the `schema.sql` file and update.

 - blueprints.users: s/GUILD_SETTINGS_UPDATE/USER_GUILD_SETTINGS_UPDATE
 - storage: fix get_guild_settings returning a dict instead of a list
 - schema.sql: fix types and syntax
2018-10-19 16:21:33 -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 cabc31360a blueprints.relationships: fix blocking when rel already exists
- storage: fix block fetch
2018-10-15 15:54:40 -03:00
Luna Mendes 1ab8dc0052 storage: only set mobile and phone when secure=True 2018-10-12 21:36:29 -03:00
Luna Mendes 051cdd8ff2 blueprints.users: finish user patch impl
- blueprints.auth: check availability of username on register
 - enums: add UserFlags
 - schemas: add DATA_REGEX, USER_UPDATE
 - storage: add dummy mobile and phone values on get_user
2018-10-12 21:34:45 -03:00
Luna Mendes da4ce66a0c storage: multiple enhancements
storage:
 - don't use SELECT * when get_guild'ing
 - use field::text instead of the str() call madness
 - simplify get_member_data_one
 - fix parent_id being an int on get_channel_data
 - add Storage.get_role
 - better mention resolving on get_message
 - remove Storage.get_all_dms
2018-10-12 19:06:13 -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 efefb0cc2f blueprints.channels: use ChannelDispatcher for MESSAGE_* events
- storage: add Storage.guild_from_channel
2018-10-11 22:12:51 -03:00
Luna Mendes 37d8114ae2 pubsub: add ChannelDispatcher
- pubsub: call ChannelDispatcher from GuildDispatcher when subbing a
    user
2018-10-11 18:56:40 -03:00
Luna Mendes 76f3a9f868 storage: use premium_since instead of premium 2018-10-10 19:16:35 -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 737129bd20 blueprints.channels: fix channel deletion
- blueprints.guilds: fix channel creation
 - blueprints.relationships: add POST /api/v6/users/@me/relationships
 - storage: add Storage.search_user, for ^
 - storage: fix bug with last_message_id returning "None" (as a str)
2018-10-10 17:09:39 -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 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 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 45559608f3 litecord.storage: fix _chan_overwrites since table changes 2018-10-02 18:37:53 -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 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 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 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 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 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 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