Skip to content

General cleanup of the library #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 123 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
b9f892b
Stuff
MCausc78 Jul 6, 2024
5dda0bd
Cache, Cache, and Cache!
MCausc78 Jul 6, 2024
c2a418d
Document State.settings add Client.settings
MCausc78 Jul 6, 2024
9806d67
More bloated docs
MCausc78 Jul 6, 2024
dc44fd9
Be consistent in routes.py
MCausc78 Jul 6, 2024
08f9df6
Correct DiscoveryTheme.variables doc
MCausc78 Jul 6, 2024
660e5e8
Add discovery test
MCausc78 Jul 6, 2024
984412c
Format discovery test
MCausc78 Jul 6, 2024
b9837f9
Use relative imports where possible
MCausc78 Jul 10, 2024
5dab858
Use relative imports in events.py and http.py
MCausc78 Jul 10, 2024
8661aae
Support `ServerMemberRemoveEvent`.reason
MCausc78 Jul 10, 2024
4974acd
General cleanup
MCausc78 Jul 11, 2024
ce87d58
Add TODO.md generator
MCausc78 Jul 11, 2024
3f4a8c6
Cleanup TODO generator
MCausc78 Jul 11, 2024
5fa7ae0
Try new TODO.md format
MCausc78 Jul 11, 2024
650fcc6
Another attempt at fixing bad TODO.md
MCausc78 Jul 11, 2024
bf5a1a1
Regenerate TODO.md
MCausc78 Jul 11, 2024
8a7afe1
And yet one failing attempt
MCausc78 Jul 11, 2024
d4eda52
Fix circular imports
MCausc78 Jul 11, 2024
be34c62
Refactor pyvolt a bit.
MCausc78 Jul 12, 2024
680ddeb
Fix user settings fetching. (Conflicts)
MCausc78 Jul 12, 2024
ba225f5
Change all :class:Error -> Error
MCausc78 Jul 13, 2024
5b0dca7
Remove core.ULID type
MCausc78 Jul 13, 2024
afdba3a
Remove ulid-py dependency 🎉
MCausc78 Jul 13, 2024
d97bdb1
Boost performance
MCausc78 Jul 13, 2024
f4b8052
Bring back performance (part 1)
MCausc78 Jul 13, 2024
821e206
Bring back performance (part 2)
MCausc78 Jul 13, 2024
d25aecc
Bring back performance (final part)
MCausc78 Jul 13, 2024
fc207e6
Add BaseEvent.cancel / BaseEvent.uncancel methods
MCausc78 Jul 13, 2024
8d5eac2
Keep TODO.md up to date
MCausc78 Jul 13, 2024
6db7c10
Use tables
MCausc78 Jul 13, 2024
2c6bf82
Add channels parsing benchmark
MCausc78 Jul 13, 2024
f744329
Fix circular imports usage (emojis moment)
MCausc78 Jul 14, 2024
6a3388f
Add DM/GDM channels parsing benchmark
MCausc78 Jul 14, 2024
d1198d3
Update typings and parsing
MCausc78 Jul 14, 2024
1934dc4
Update TODO list
MCausc78 Jul 14, 2024
53f0235
WIP: Convert Message -> MessageCreateEvent (short way)
MCausc78 Jul 15, 2024
04fdf54
Remove unused Server import in discovery.py and be consistent with he…
MCausc78 Jul 17, 2024
4f4acf1
Fix bugs in PR TODO.
MCausc78 Jul 17, 2024
194048d
Add get_emoji and get_member on Server
MCausc78 Jul 17, 2024
a40c2cf
Add Revolt#0000 sentinel
MCausc78 Jul 18, 2024
742ad6b
Refactor http.py docs.
MCausc78 Jul 19, 2024
02149ab
Refactor even more http.py docs.
MCausc78 Jul 20, 2024
3d4d8cb
Improve http.py docs, and check for system user in Message.get_author()
MCausc78 Jul 20, 2024
c6f5c2f
Partially finish up refactoring HTTPClient docs
MCausc78 Jul 20, 2024
51ab562
Rename `timed_out_until` parameter to `timeout`
MCausc78 Jul 20, 2024
65a4e7e
Add a few `fetch_` shortcut methods to Client.
MCausc78 Jul 20, 2024
035af17
Use `import typing` instead of `import typing as t`
MCausc78 Jul 20, 2024
22b76ce
Update TODO
MCausc78 Jul 20, 2024
66bd628
Add support for Android user settings
MCausc78 Jul 20, 2024
7dfcab8
Allow building Android user settings payload
MCausc78 Jul 20, 2024
b6260a9
WIP: Revite User Settings
MCausc78 Jul 20, 2024
bfee888
Add Revite user settings support.
MCausc78 Jul 20, 2024
4bdb0ac
Fix HTTPClient.edit_session not passing body
MCausc78 Jul 20, 2024
61aa520
WIP: Add `ReviteUserSettings.payload_for`
MCausc78 Jul 20, 2024
f4a2c5f
Fully support Revite User Settings
MCausc78 Jul 21, 2024
a6ea00c
Make system user always online
MCausc78 Jul 21, 2024
100d141
Rename `notification_servers` to `server_notifications`
MCausc78 Jul 21, 2024
9cfa4c7
Improve partial user settings updating
MCausc78 Jul 21, 2024
b3925cb
Fix UserSettingsUpdate removing android user settings
MCausc78 Jul 21, 2024
5ffed0d
Use ruff formatter
MCausc78 Jul 21, 2024
4e93a37
Add Ruff linting
MCausc78 Jul 22, 2024
b063180
Add pinned messages support
MCausc78 Jul 22, 2024
b90760c
Add RevoltConfig typings
MCausc78 Jul 22, 2024
1dffab2
Fully support pins
MCausc78 Jul 22, 2024
8e5e498
Fix throwing weird errors
MCausc78 Jul 22, 2024
4b8f918
Update message.py documentation
MCausc78 Jul 22, 2024
4ddd067
Properly resolve users in system events
MCausc78 Jul 22, 2024
d139979
Properly dispatch events
MCausc78 Jul 23, 2024
e83f0c2
Add more control over Revite user settings payloads
MCausc78 Jul 23, 2024
37ae9b4
Add `Theme.apply` method
MCausc78 Jul 23, 2024
3170651
Clear cached server emojis/members on ServerDelete
MCausc78 Jul 24, 2024
cc62051
Store authenticated user in cache upon joining server
MCausc78 Jul 24, 2024
cd16ccc
Set version to 0.7.0
MCausc78 Jul 24, 2024
8bab295
Temporary removal of docs/api
MCausc78 Jul 24, 2024
aedf0ac
Documentation for Client
MCausc78 Jul 24, 2024
4146d93
Document Shard
MCausc78 Jul 24, 2024
b151ed6
Document HTTPClient.request
MCausc78 Jul 24, 2024
423b745
Fix parsing error
MCausc78 Jul 24, 2024
17cc793
Regenerate TODO.md
MCausc78 Jul 24, 2024
58d06c2
Use `is` instead of `==` in `Shard.__init__`
MCausc78 Jul 24, 2024
b7cb6dd
Add copyright header
MCausc78 Jul 25, 2024
4c790de
Removal of `from . import core` imports
MCausc78 Jul 25, 2024
f6fc181
Add temporary event subscriptions
MCausc78 Jul 25, 2024
f2fadb4
Typo in EventSubscription**s**
MCausc78 Jul 25, 2024
289a9b0
Add 'pms_by_user' cache
MCausc78 Jul 26, 2024
fb92b13
Add 'Client.dm_channels'
MCausc78 Jul 26, 2024
cbd6d9f
Add examples
MCausc78 Jul 26, 2024
b203493
WIP: Cache contexts
MCausc78 Jul 26, 2024
994b194
Regenerate TODO.md
MCausc78 Jul 26, 2024
8fdb982
Add 'ProvideContextIn' variants
MCausc78 Jul 26, 2024
b640b5c
Add `User.default_avatar_url`
MCausc78 Jul 26, 2024
d4db56d
Add private channels cache
MCausc78 Jul 27, 2024
4e3abc4
Add `state.provide_cache_context_in`
MCausc78 Jul 27, 2024
9ce9400
Fix NameError in store_channel
MCausc78 Jul 27, 2024
a6c5f81
Fix circular imports in `Server.channels`
MCausc78 Jul 27, 2024
5458293
Rename `j` to `payload`
MCausc78 Jul 28, 2024
4dc1e1b
Don't compare all model fields anymore
MCausc78 Jul 28, 2024
9cda635
Add ``CDNClient.url_for`` and ``BaseEmoji.__str__``
MCausc78 Jul 28, 2024
97db4ab
Refactor http.py docs & handling.
MCausc78 Jul 28, 2024
f59b03b
Add CONTRIBUTING.md
MCausc78 Jul 29, 2024
5c63e35
Simplify resolve_emoji impl
MCausc78 Jul 29, 2024
e5113cf
Regenerate TODO
MCausc78 Jul 29, 2024
d6cb367
Add git hook
MCausc78 Jul 29, 2024
5743547
Format hook
MCausc78 Jul 29, 2024
371b70f
Delete hook as it bit of complex? (Or maybe skill issue)
MCausc78 Jul 29, 2024
bcd0712
Use :meth:`.bar` instead of :meth:`Foo.bar`
MCausc78 Jul 29, 2024
f8c7f8c
Clean up cache in ServerMemberRemoveEvent
MCausc78 Jul 29, 2024
5e4b4fb
Fix initiator_id
MCausc78 Jul 29, 2024
9994c41
Documentation for DMChannel
MCausc78 Jul 29, 2024
ad39fb4
Use .pop instead of del
MCausc78 Jul 29, 2024
5ef3a3d
Forgot in events.py and server.py
MCausc78 Jul 30, 2024
157ea5b
Allow use either `pyvolt.Client(token='token')` or `bot.run('token')`
MCausc78 Jul 30, 2024
95c3efb
Include pyvolt/pyvolt.raw/pyvolt.routes
MCausc78 Jul 31, 2024
052532c
Fix pip installation
MCausc78 Aug 1, 2024
ad9e347
Move all enums to enums
MCausc78 Aug 1, 2024
1272dec
Speed up flags
MCausc78 Aug 2, 2024
390b5dc
Fix typing error
MCausc78 Aug 2, 2024
1416367
Use ``FooFlags.__new__`` directly
MCausc78 Aug 2, 2024
bb709dc
Add support for ``AppleMusic`` embed specials
MCausc78 Aug 2, 2024
643d718
Add utility for getting user account token
MCausc78 Aug 2, 2024
af61ab7
Remove unused imports in examples/mfa.py
MCausc78 Aug 2, 2024
1e53731
Regenerate TODO.md
MCausc78 Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ cython_debug/
#.idea/

/local
/local*.py
/local*.py
/local*.json

# ruff
.ruff_cache/
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Contributing to pyvolt

First off, thanks for taking the time to contribute. It makes the library muuuuch better.

The following is a set of guidelines for contributing to the repository. These are guidelines, not hard rules.

## Submitting a Pull Request

Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is consistent to that found in the project. This project follows PEP-8 guidelines (mostly) with a column limit of 125.

### Git Commit Guidelines

- Use present tense (e.g. "Add feature" not "Added feature")
- Limit all lines to 72 characters or less.
- Reference issues or pull requests outside of the first line.
- Please use the shorthand `#123` and not the full URL.
- Commits regarding the commands extension must be prefixed with `[commands]`

If you do not meet any of these guidelines, don't fret. Chances are they will be fixed upon rebasing but please do try to meet them to remove some of the workload.

### Code Style

Use following order in models:
```py
@define(slots=True)
class Foo(Base):
# ... attrs properties
# ... getters (``get_x``)
# ... dunder methods (eq, hash, str), in alphabet order
# ... internal methods (`_update`, `_react`)
# ... properties
# ... async methods, in alphabet order
# ... methods
```
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

50 changes: 50 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pyvolt
======

A simple, flexible API wrapper for Revolt.

.. warning::
This is alpha software. Please report bugs on GitHub issues if you will find any.

Key Features
-------------

- Built on ``asyncio``.
- Probably handles ratelimiting.
- Fast. Really faster than Revolt.py and voltage.
- Low memory usage.
- Customizable architecture. Build object parser in Rust to achieve high speeds.
- Focuses on supporting both, bot and user accounts.

Quick Example
--------------

.. code:: py

from pyvolt import Client, ReadyEvent, MessageCreateEvent

class MyClient(Client):
@Client.listens_on(ReadyEvent)
async def on_ready(self, _):
print('Logged on as', self.me)

@Client.listens_on(MessageCreateEvent)
async def on_message(self, event):
message = event.message
# don't respond to ourselves
if message.author_id == self.me.id:
return

if message.content == 'ping':
await message.channel.send('pong')

# You can pass ``bot=False`` to run as user account
client = MyClient(token='token')
client.run()

Links
------

- `Documentation <https://pyvolt.readthedocs.io/en/latest/index.html>`_
- `Official Revolt Server <https://rvlt.gg/ZZQb4sxx>`_
- `Revolt API <https://rvlt.gg/API>`_
30 changes: 30 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# TODO

* TODO: events

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/cache.py#L149C7-L149C19

* TODO: Remove when backend will tell us to update all channels. (ServerUpdate event)

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/events.py#L234C11-L234C94

* TODO: What we should do in case of mentions? This solution sucks.

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/events.py#L321C15-L321C80

* TODO: Handle 10053?

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/http.py#L285C19-L285C38

* TODO: Remove when Revolt will fix this

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/http.py#L408C11-L408C49

* TODO: Remove when Revolt will fix this

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/http.py#L484C11-L484C49

* TODO: Handle 10053?

Source: https://github.com/MCausc78/pyvolt/blob/ready/pyvolt/shard.py#L353C19-L353C38

32 changes: 32 additions & 0 deletions bench/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asyncio

from .bench_channel import bench_dm_channels, bench_group_channels, bench_text_channels
from .bench_member import bench_members
from .bench_message import bench_messages
from .bench_server import bench_servers
from .bench_user import bench_users

async def main():
print('Benchmarking DMChannel parsing.')
await bench_dm_channels()

print('Benchmarking GroupChannel parsing.')
await bench_group_channels()

print('Benchmarking TextChannel parsing.')
await bench_text_channels()

print('Benchmarking Member parsing.')
await bench_members()

print('Benchmarking Message parsing.')
await bench_messages()

print('Benchmarking Server parsing.')
await bench_servers()

print('Benchmarking User parsing.')
await bench_users()


asyncio.run(main())
172 changes: 172 additions & 0 deletions bench/bench_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import asyncio

import json
import pyvolt

import revolt
import revolt.http
import revolt.state

import timeit
import typing
import voltage
import voltage.internals

async def bench_dm_channels():
with open('./tests/data/channels/dm.json', 'r') as fp:
payload = json.load(fp)

state = pyvolt.State()
parser = pyvolt.Parser(state)
state.setup(parser=parser)

def using_pyvolt():
return parser.parse_direct_message_channel(payload)

import aiohttp
session = aiohttp.ClientSession()

api_info: typing.Any = {
'features': {
'autumn': {
'url': 'https://autumn.revolt.chat/'
}
}
}
rpy_http = revolt.http.HttpClient(
session,
'',
'https://api.revolt.chat/',
api_info
)
rpy_state = revolt.state.State(rpy_http, api_info, 1000)

def using_revoltpy():
return revolt.DMChannel(data=payload, state=rpy_state)

vpy_http = voltage.internals.http.HTTPHandler(session, '')
vpy_cache = voltage.internals.cache.CacheHandler(vpy_http, asyncio.get_event_loop())

def using_voltage():
return voltage.DMChannel(data=payload, cache=vpy_cache)

time_pyvolt = timeit.timeit(using_pyvolt, number=100_000)
time_revoltpy = timeit.timeit(using_revoltpy, number=100_000)
time_voltage = timeit.timeit(using_voltage, number=100_000)

print(f"[DMChannel] Time using pyvolt ----: {time_pyvolt:.6f} seconds")
print(f"[DMChannel] Time using revolt.py -: {time_revoltpy:.6f} seconds")
print(f"[DMChannel] Time using voltage ---: {time_voltage:.6f} seconds")

await session.close()

async def bench_group_channels():
with open('./tests/data/channels/group.json', 'r') as fp:
payload = json.load(fp)

state = pyvolt.State()
parser = pyvolt.Parser(state)
state.setup(parser=parser)

def using_pyvolt():
return parser.parse_group_channel(payload, (True, payload['recipients']))

import aiohttp
session = aiohttp.ClientSession()

api_info: typing.Any = {
'features': {
'autumn': {
'url': 'https://autumn.revolt.chat/'
}
}
}
rpy_http = revolt.http.HttpClient(
session,
'',
'https://api.revolt.chat/',
api_info
)
rpy_state = revolt.state.State(rpy_http, api_info, 1000)

def using_revoltpy():
return revolt.GroupDMChannel(data=payload, state=rpy_state)

vpy_http = voltage.internals.http.HTTPHandler(session, '')
vpy_cache = voltage.internals.cache.CacheHandler(vpy_http, asyncio.get_event_loop())

with open('./tests/data/users/me.json', 'r') as fp:
me = json.load(fp)
vpy_cache.add_user(me)

with open('./tests/data/users/mecha.json', 'r') as fp:
mecha = json.load(fp)
vpy_cache.add_user(mecha)


def using_voltage():
return voltage.GroupDMChannel(data=payload, cache=vpy_cache)

time_pyvolt = timeit.timeit(using_pyvolt, number=100_000)
time_revoltpy = timeit.timeit(using_revoltpy, number=100_000)
time_voltage = timeit.timeit(using_voltage, number=100_000)

print(f"[GroupChannel] Time using pyvolt ----: {time_pyvolt:.6f} seconds")
print(f"[GroupChannel] Time using revolt.py -: {time_revoltpy:.6f} seconds")
print(f"[GroupChannel] Time using voltage ---: {time_voltage:.6f} seconds")

await session.close()

async def bench_text_channels():
with open('./tests/data/channels/rules_channel.json', 'r') as fp:
payload = json.load(fp)

with open('./tests/data/servers/server.json', 'r') as fp:
server_payload = json.load(fp)

state = pyvolt.State()
parser = pyvolt.Parser(state)
state.setup(parser=parser)

def using_pyvolt():
return parser.parse_text_channel(payload)

import aiohttp
session = aiohttp.ClientSession()

api_info: typing.Any = {
'features': {
'autumn': {
'url': 'https://autumn.revolt.chat/'
}
}
}
rpy_http = revolt.http.HttpClient(
session,
'',
'https://api.revolt.chat/',
api_info
)
rpy_state = revolt.state.State(rpy_http, api_info, 1000)

def using_revoltpy():
return revolt.TextChannel(data=payload, state=rpy_state)

vpy_http = voltage.internals.http.HTTPHandler(session, '')
vpy_cache = voltage.internals.cache.CacheHandler(vpy_http, asyncio.get_event_loop())
server_id = payload['server']
vpy_server = voltage.Server(data=server_payload, cache=vpy_cache)
vpy_cache.servers[vpy_server.id] = vpy_server

def using_voltage():
return voltage.TextChannel(data=payload, cache=vpy_cache, server_id=server_id)

time_pyvolt = timeit.timeit(using_pyvolt, number=100_000)
time_revoltpy = timeit.timeit(using_revoltpy, number=100_000)
time_voltage = timeit.timeit(using_voltage, number=100_000)

print(f"[TextChannel] Time using pyvolt ----: {time_pyvolt:.6f} seconds")
print(f"[TextChannel] Time using revolt.py -: {time_revoltpy:.6f} seconds")
print(f"[TextChannel] Time using voltage ---: {time_voltage:.6f} seconds")

await session.close()
Loading