Skip to content

Commit

Permalink
Merge pull request #231 from yepcord/remove-aiohttp-and-update-deps
Browse files Browse the repository at this point in the history
Remove aiohttp and update deps
  • Loading branch information
RuslanUC authored Sep 3, 2024
2 parents 9805f9f + fe3f000 commit c506025
Show file tree
Hide file tree
Showing 15 changed files with 966 additions and 1,070 deletions.
1,891 changes: 885 additions & 1,006 deletions poetry.lock

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,35 @@ yepcord = "yepcord.cli:main"

[tool.poetry.dependencies]
python = "^3.9"
quart = "0.19.5"
aiofiles = "23.2.1"
websockets = "12.0"
uvicorn = "0.29.0"
aiohttp = "3.9.5"
python-magic = "0.4.27"
pillow = "10.3.0"
quart = "0.19.6"
aiofiles = "^24.1.0"
websockets = "13.0.1"
uvicorn = "^0.30.6"
python-magic = "^0.4.27"
pillow = "^10.4.0"
protobuf = "4.25.3"
python-dateutil = "2.9.0.post0"
cryptography = "42.0.7"
emoji = "2.11.1"
six = "1.16.0"
bcrypt = "4.1.3"
quart-schema = "0.19.1"
pydantic = "2.7.1"
werkzeug = "3.0.3"
aioftp = "0.22.3"
orjson = "3.10.3"
mailers = {version = "3.0.5", extras = ["smtp"]}
redis = ">=4.6.0"
click = "8.1.7"
maxminddb = "2.6.1"
python-dateutil = "^2.9.0.post0"
cryptography = "^43.0.0"
emoji = "^2.12.1"
bcrypt = "^4.2.0"
quart-schema = "0.20.0"
pydantic = "^2.8.2"
werkzeug = "3.0.4"
aioftp = "^0.22.3"
orjson = "^3.10.7"
mailers = {version = "^3.0.5", extras = ["smtp"]}
redis = "^5.0.8"
click = "^8.1.7"
maxminddb = "^2.6.2"
wget = "3.2"
tortoise-orm = {extras = ["aiosqlite", "asyncmy", "accel"], version = "^0.20.0"}
uvloop = "0.19.0"
tortoise-orm = {extras = ["aiosqlite", "asyncmy", "accel"], version = "^0.21.6"}
uvloop = "^0.20.0"
async-timeout = "^4.0.3"
aerich = "^0.7.2"
yc-protobuf3-to-dict = "^0.3.0"
s3lite = "^0.1.4"
fast-depends = ">=2.4.2"
faststream = {extras = ["kafka", "nats", "rabbit", "redis"], version = "^0.5.4"}
s3lite = "^0.1.8"
fast-depends = "^2.4.11"
faststream = {extras = ["kafka", "nats", "rabbit", "redis"], version = "^0.5.20"}

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.0"
Expand Down
2 changes: 1 addition & 1 deletion yepcord/rest_api/routes/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def create_application(data: CreateApplication, user: User = DepUser):
app = await Application.create(id=app_id, owner=user, name=name)
bot_user = await User.create(id=app_id, email=f"bot_{app_id}", password="", is_bot=True)
await UserData.create(id=app_id, user=bot_user, birth=datetime.now(), username=username, discriminator=disc)
await UserSettings.create(id=app_id, user=user, locale=(await user.settings).locale)
await UserSettings.create(id=app_id, user=bot_user, locale=(await user.settings).locale)
await Bot.create(id=app_id, application=app, user=bot_user)
return await app.ds_json()

Expand Down
17 changes: 8 additions & 9 deletions yepcord/yepcord/classes/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from typing import Type

from aiohttp import ClientSession, FormData
from httpx import AsyncClient

from ..config import Config

Expand All @@ -32,14 +32,13 @@ class Captcha:
@classmethod
async def verify(cls, captcha_key: str) -> tuple[bool, list[str]]:
captcha = Config.CAPTCHA[cls.NAME]
async with ClientSession() as sess:
form = FormData()
form.add_field("secret", captcha["secret"])
form.add_field("response", captcha_key)
form.add_field("sitekey", captcha["sitekey"])

resp = await sess.post(cls.VERIFY_ENDPOINT, data=form)
resp = await resp.json()
async with AsyncClient() as client:
resp = await client.post(cls.VERIFY_ENDPOINT, data={
"secret": captcha["secret"],
"response": captcha_key,
"sitekey": captcha["sitekey"],
})
resp = resp.json()

return resp["success"], resp.get("error_codes", [])

Expand Down
42 changes: 21 additions & 21 deletions yepcord/yepcord/classes/gifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from time import time
from typing import List

from aiohttp import ClientSession
from httpx import AsyncClient

from .singleton import Singleton

Expand Down Expand Up @@ -85,10 +85,10 @@ async def _update_categories(self) -> None:
self._categories = []
return
categories = []
async with ClientSession() as sess:
async with sess.get(f"https://tenor.googleapis.com/v2/categories?key={self._key}") as resp:
for category in (await resp.json())["tags"]:
categories.append(GifCategory(category["name"][1:], category["image"]))
async with AsyncClient() as client:
resp = await client.get(f"https://tenor.googleapis.com/v2/categories?key={self._key}")
for category in resp.json()["tags"]:
categories.append(GifCategory(category["name"][1:], category["image"]))
self._categories = categories
self._last_update = time()

Expand All @@ -109,19 +109,19 @@ async def search(self, q: str=None, **kwargs) -> GifSearchResult:
gifs = []
if "key" in kwargs: del kwargs["key"]
_params = {"key": self._key, "q": q, **kwargs}
async with ClientSession() as sess:
async with sess.get(f"https://tenor.googleapis.com/v2/search", params=_params) as resp:
for gif in (await resp.json())["results"]:
gifs.append(Gif(
id=gif["id"],
title=gif["title"],
preview=gif["media_formats"]["gifpreview"]["url"],
gif_src=gif["media_formats"]["gif"]["url"],
height=gif["media_formats"]["mp4"]["dims"][0],
width=gif["media_formats"]["mp4"]["dims"][1],
src=gif["media_formats"]["mp4"]["url"],
url=gif["itemurl"]
))
async with AsyncClient() as client:
resp = await client.get(f"https://tenor.googleapis.com/v2/search", params=_params)
for gif in resp.json()["results"]:
gifs.append(Gif(
id=gif["id"],
title=gif["title"],
preview=gif["media_formats"]["gifpreview"]["url"],
gif_src=gif["media_formats"]["gif"]["url"],
height=gif["media_formats"]["mp4"]["dims"][0],
width=gif["media_formats"]["mp4"]["dims"][1],
src=gif["media_formats"]["mp4"]["url"],
url=gif["itemurl"]
))

search = GifSearchResult(q, gifs, int(time()))

Expand All @@ -148,9 +148,9 @@ async def suggest(self, q: str=None, limit: int = 5, **kwargs) -> List[str]:

if "key" in kwargs: del kwargs["key"]
_params = {"key": self._key, "q": q, **kwargs}
async with ClientSession() as sess:
async with sess.get(f"https://tenor.googleapis.com/v2/search_suggestions", params=_params) as resp:
suggestions = (await resp.json())["results"]
async with AsyncClient() as client:
resp = await client.get(f"https://tenor.googleapis.com/v2/search_suggestions", params=_params)
suggestions = resp.json()["results"]

self._last_suggestions.append(GifSuggestion(q, suggestions, int(time())))

Expand Down
4 changes: 2 additions & 2 deletions yepcord/yepcord/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def gen_token_secret() -> str:

class Bot(Model):
id: int = SnowflakeField(pk=True)
application: models.Application = fields.ForeignKeyField("models.Application", null=False, unique=True)
user: User = fields.ForeignKeyField("models.User", null=True, default=None, related_name="bot_user")
application: models.Application = fields.OneToOneField("models.Application")
user: User = fields.OneToOneField("models.User", null=True, default=None, related_name="bot_user")
bot_public: bool = fields.BooleanField(default=True)
bot_require_code_grant: bool = fields.BooleanField(default=True)
token_secret: str = fields.CharField(max_length=128, default=gen_token_secret)
Expand Down
2 changes: 1 addition & 1 deletion yepcord/yepcord/models/frecency_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class FrecencySettings(Model):
id: int = SnowflakeField(pk=True)
user: models.User = fields.ForeignKeyField("models.User")
user: models.User = fields.OneToOneField("models.User")
settings: str = fields.TextField()

def to_proto(self) -> FrecencyUserSettings:
Expand Down
5 changes: 5 additions & 0 deletions yepcord/yepcord/models/guild_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class GuildMember(Model):

guildevents: fields.ReverseRelation[models.GuildEvent]

class Meta:
unique_together = (
("user", "guild"),
)

@property
def joined_at(self) -> datetime:
return Snowflake.toDatetime(self.id)
Expand Down
2 changes: 1 addition & 1 deletion yepcord/yepcord/models/guild_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class GuildTemplate(Model):
id: int = SnowflakeField(pk=True)
name: str = fields.CharField(max_length=64)
guild: models.Guild = fields.ForeignKeyField("models.Guild")
guild: models.Guild = fields.OneToOneField("models.Guild")
description: Optional[str] = fields.CharField(max_length=128, null=True, default=None)
usage_count: int = fields.BigIntField(default=0)
creator: Optional[models.User] = fields.ForeignKeyField("models.User", on_delete=fields.SET_NULL, null=True)
Expand Down
5 changes: 5 additions & 0 deletions yepcord/yepcord/models/readstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class ReadState(Model):
last_read_id: int = fields.BigIntField()
count: int = fields.IntField()

class Meta:
unique_together = (
("channel", "user"),
)

async def ds_json(self) -> dict:
last_pin = await getCore().getLastPinnedMessage(self.channel)
last_pin_ts = last_pin.pinned_timestamp.strftime("%Y-%m-%dT%H:%M:%S+00:00") if last_pin is not None else None
Expand Down
5 changes: 5 additions & 0 deletions yepcord/yepcord/models/thread_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class ThreadMember(Model):
channel: models.Channel = fields.ForeignKeyField("models.Channel")
guild: models.Guild = fields.ForeignKeyField("models.Guild")

class Meta:
unique_together = (
("user", "channel"),
)

@property
def joined_at(self) -> datetime:
return Snowflake.toDatetime(self.id)
Expand Down
2 changes: 1 addition & 1 deletion yepcord/yepcord/models/thread_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class ThreadMetadata(Model):
id: int = SnowflakeField(pk=True)
channel: models.Channel = fields.ForeignKeyField("models.Channel")
channel: models.Channel = fields.OneToOneField("models.Channel")
archived: bool = fields.BooleanField(default=False)
locked: bool = fields.BooleanField(default=False)
archive_timestamp: datetime = fields.DatetimeField()
Expand Down
5 changes: 5 additions & 0 deletions yepcord/yepcord/models/user_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class UserNote(Model):
target: models.User = fields.ForeignKeyField("models.User", related_name="target")
text: str = fields.CharField(null=True, default=None, max_length=256)

class Meta:
unique_together = (
("user", "target"),
)

def ds_json(self) -> dict:
return {
"user_id": self.user.id,
Expand Down
2 changes: 1 addition & 1 deletion yepcord/yepcord/models/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class UserSettings(Model):
id: int = SnowflakeField(pk=True)
user: models.User = fields.ForeignKeyField("models.User")
user: models.User = fields.OneToOneField("models.User")
inline_attachment_media: bool = fields.BooleanField(default=True)
show_current_game: bool = fields.BooleanField(default=True)
view_nsfw_guilds: bool = fields.BooleanField(default=False)
Expand Down
2 changes: 1 addition & 1 deletion yepcord/yepcord/models/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Meta:
unique_together = (("username", "discriminator"),)

id: int = SnowflakeField(pk=True)
user: models.User = fields.ForeignKeyField("models.User")
user: models.User = fields.OneToOneField("models.User")
birth: date = fields.DateField()
username: str = fields.CharField(max_length=128)
discriminator: int = fields.IntField(validators=[MinValueValidator(0), MaxValueValidator(9999)])
Expand Down

0 comments on commit c506025

Please sign in to comment.