Compare commits

...

9 Commits
main ... main

Author SHA1 Message Date
bot
669a76f8a9 New build. 2024-12-14 03:42:04 +00:00
eaec9335dc Update url.
All checks were successful
devranta build / Build (push) Successful in 1m25s
2024-12-14 04:40:30 +01:00
bot
0811eb1db8 New build. 2024-12-14 03:19:28 +00:00
6a14dbe91a Account creation.
All checks were successful
devranta build / Build (push) Successful in 1m27s
2024-12-14 04:17:55 +01:00
bot
5d464ad271 New build. 2024-12-04 22:14:50 +00:00
2a3269edfa Update README.md
All checks were successful
devranta build / Build (push) Successful in 1m19s
2024-12-04 22:13:31 +00:00
bot
485144303f New build. 2024-12-03 22:13:56 +00:00
d1f8768b15 Merge pull request 'Add vote for rants and comments' (#1) from dr/devranta:vote into main
All checks were successful
devranta build / Build (push) Successful in 1m10s
Reviewed-on: retoor/devranta#1
2024-12-03 22:12:48 +00:00
dr
f947d5f088 Add vote for rants and comments 2024-12-03 22:27:40 +01:00
5 changed files with 45 additions and 8 deletions

View File

@ -30,8 +30,4 @@ async def list_rants():
``` ```
See [tests](src/devranta/tests.py) for [examples](src/devranta/tests.py) on how to use. See [tests](src/devranta/tests.py) for [examples](src/devranta/tests.py) on how to use.
## Todo
- voting comment
- edit message

Binary file not shown.

Binary file not shown.

View File

@ -43,8 +43,4 @@ async def list_rants():
``` ```
See [tests](src/devranta/tests.py) for [examples](src/devranta/tests.py) on how to use. See [tests](src/devranta/tests.py) for [examples](src/devranta/tests.py) on how to use.
## Todo
- voting comment
- edit message

View File

@ -1,5 +1,11 @@
from typing import Literal, Optional
import aiohttp import aiohttp
from enum import Enum
class VoteReason(Enum):
NOT_FOR_ME = 0
REPOST = 1
OFFENSIVE_SPAM = 2
class Api: class Api:
@ -65,6 +71,23 @@ class Api:
await self.session.close() await self.session.close()
self.session = None self.session = None
async def register_user(self, email, username, password):
response = None
async with self as session:
response = await session.post(
url=self.patch_url(f"users"),
data=self.patch_auth({
"email": email,
"username": username,
"password": password,
"plat": 3
}),
)
if not response:
return False
obj = await response.json()
return obj.get('success', False)
async def get_comments_from_user(self, username): async def get_comments_from_user(self, username):
user_id = await self.get_user_id(username) user_id = await self.get_user_id(username)
profile = await self.get_profile(user_id) profile = await self.get_profile(user_id)
@ -168,6 +191,28 @@ class Api:
obj = await response.json() obj = await response.json()
return obj.get("success", False) return obj.get("success", False)
async def vote_rant(self, rant_id: int, vote: Literal[-1, 0, 1], reason: Optional[VoteReason] = None):
if not await self.ensure_login():
return None
async with self as session:
response = await session.post(
url=self.patch_url(f"devrant/rants/{rant_id}/vote"),
data=self.patch_auth({"vote": vote, "reason": reason.value if reason else None}),
)
obj = await response.json()
return obj.get("success", False)
async def vote_comment(self, comment_id: int, vote: Literal[-1, 0, 1], reason: Optional[VoteReason] = None):
if not await self.ensure_login():
return None
async with self as session:
response = await session.post(
url=self.patch_url(f"comments/{comment_id}/vote"),
data=self.patch_auth({"vote": vote, "reason": reason.value if reason else None}),
)
obj = await response.json()
return obj.get("success", False)
@property @property
async def notifs(self): async def notifs(self):
response = None response = None