63 changed files with 2161 additions and 2034 deletions
-
0.gitignore
-
0LICENSE
-
3Pipfile
-
193Pipfile.lock
-
0README.md
-
2api_v1/__init__.py
-
15api_v1/admin/__init__.py
-
7api_v1/categories/__init__.py
-
21api_v1/client.py
-
79api_v1/comment/__init__.py
-
79api_v1/community/__init__.py
-
23api_v1/community/reports.py
-
15api_v1/community/settings.py
-
99api_v1/helpers.py
-
7api_v1/modlog/__init__.py
-
111api_v1/post/__init__.py
-
39api_v1/private_message/__init__.py
-
3api_v1/routes.py
-
7api_v1/search/__init__.py
-
31api_v1/site/__init__.py
-
15api_v1/site/config.py
-
7api_v1/site/mods.py
-
19api_v1/sitemod/__init__.py
-
19api_v1/types/__init__.py
-
5api_v1/types/category.py
-
58api_v1/types/comment.py
-
81api_v1/types/comment_view.py
-
100api_v1/types/community.py
-
32api_v1/types/community_settings.py
-
77api_v1/types/community_view.py
-
38api_v1/types/lib.py
-
107api_v1/types/moderator_views.py
-
81api_v1/types/post.py
-
13api_v1/types/post_hexbear.py
-
53api_v1/types/post_view.py
-
24api_v1/types/private_message_view.py
-
63api_v1/types/report.py
-
34api_v1/types/report_views.py
-
119api_v1/types/site.py
-
23api_v1/types/site_view.py
-
0api_v1/types/user.py
-
39api_v1/types/user_mention_view.py
-
26api_v1/types/user_view.py
-
449api_v1/user/__init__.py
-
1hexbear/__init__.py
-
4hexbear/v1/__init__.py
-
19hexbear/v1/admin.py
-
20hexbear/v1/categories.py
-
123hexbear/v1/comment.py
-
218hexbear/v1/community.py
-
154hexbear/v1/lib.py
-
34hexbear/v1/modlog.py
-
187hexbear/v1/post.py
-
75hexbear/v1/private_message.py
-
119hexbear/v1/reports.py
-
27hexbear/v1/search.py
-
121hexbear/v1/site.py
-
19hexbear/v1/sitemod.py
-
351hexbear/v1/user.py
-
463hexbear/v1/views.py
-
22main.py
-
2scripts/rust_to_python.py
-
20tests/test_noauth.py
@ -1,2 +0,0 @@ |
|||
from .routes import * |
|||
from .types import * |
@ -1,15 +0,0 @@ |
|||
class AddAdminRequest(NamedTuple): |
|||
user_id: int |
|||
added: bool |
|||
auth: str |
|||
|
|||
class AddAdminResponse(NamedTuple): |
|||
admins: List[UserView] |
|||
|
|||
def add(payload: AddAdminRequest): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/admin/add', |
|||
payload=payload, |
|||
response_type=AddAdminResponse |
|||
) |
@ -1,7 +0,0 @@ |
|||
def get_list(payload: site.ListCategories): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/categories', |
|||
payload=payload, |
|||
response_type=site.ListCategoriesResponse |
|||
) |
@ -1,21 +0,0 @@ |
|||
from functools import partial |
|||
from .types import Login, LoginResponse |
|||
from .routes import login |
|||
|
|||
class Client: |
|||
def __init__(self, *, username: str, password: str): |
|||
request = Login(username_or_email=username, password=password) |
|||
token = login(payload=request) |
|||
while token.requires_2fa == True: |
|||
auth_code = input("2FA Code (Check email): ") |
|||
request = Login(username_or_email=username, password=password, code_2fa=auth_code) |
|||
token = login(payload=request) |
|||
if token.requies_2fa == True: |
|||
print("Incorrect 2FA code") |
|||
if token.jwt is None: |
|||
raise ValueError("Invalid JWT token received from server") |
|||
self.auth = token.jwt |
|||
|
|||
def authorize(self, func): |
|||
return partial(func, auth=self.auth) |
|||
|
@ -1,79 +0,0 @@ |
|||
def create_comment(payload: comment.CreateComment): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def edit_comment(payload: comment.EditComment): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/comment', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def create_comment_report(payload: report.CreateCommentReport): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/report', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def delete_comment(payload: comment.DeleteComment): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/delete', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def remove_comment(payload: comment.RemoveComment): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/remove', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def mark_comment_as_read(payload: comment.MarkCommentAsRead): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/mark_as_read', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def create_comment_like(payload: comment.CreateCommentLike): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/like', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def save_comment(payload: comment.SaveComment): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/comment/save', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def resolve_comment_report(payload: report.ResolveCommentReport): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/comment/resolve_report', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def get_comments(payload: comment.GetComments): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/comment/list', |
|||
payload=payload, |
|||
response_type=comment.GetCommentsResponse |
|||
) |
@ -1,79 +0,0 @@ |
|||
def create(payload: community.CreateCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def get(payload: community.GetCommunity): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community', |
|||
payload=payload, |
|||
response_type=community.GetCommunityResponse |
|||
) |
|||
|
|||
def edit(payload: community.EditCommunity): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/community', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def get_list(payload: community.ListCommunities): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community/list', |
|||
payload=payload, |
|||
response_type=community.ListCommunitiesResponse |
|||
) |
|||
|
|||
def follow(payload: community.FollowCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/follow', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def delete(payload: community.DeleteCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/delete', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def remove(payload: community.RemoveCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/remove', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def transfer(payload: community.TransferCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/transfer', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def ban_user(payload: community.BanFromCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/ban_user', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def add_mod(payload: community.AddModToCommunity): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/community/mod', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,23 +0,0 @@ |
|||
def comments(payload: report.ListCommentReports): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community/comment_reports', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def posts(payload: report.ListPostReports): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community/post_reports', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def get_count(payload: report.GetReportCount): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community/reports', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,15 +0,0 @@ |
|||
def get(payload: community_settings.GetCommunitySettings): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/community/settings', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def edit(payload: community_settings.EditCommunitySettings): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/community/settings', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,99 +0,0 @@ |
|||
from typing import NamedTuple, Literal, TypeVar, Optional, Union |
|||
import requests |
|||
from typing_inspect import is_optional_type, is_generic_type, get_origin, get_args |
|||
from datetime import datetime |
|||
import json |
|||
|
|||
Method = Literal['get', 'post', 'put'] |
|||
R = TypeVar('R') |
|||
|
|||
class APIError(NamedTuple): |
|||
message: str |
|||
|
|||
class ErrorResponse(NamedTuple): |
|||
error: APIError |
|||
|
|||
def request( |
|||
method: Method, |
|||
*, |
|||
endpoint: str, |
|||
payload: NamedTuple, |
|||
response_type: R, |
|||
base_url='https://www.chapo.chat' |
|||
) -> Union[R, ErrorResponse]: |
|||
"""Make API call and parse response""" |
|||
payload = { |
|||
key: ( |
|||
str(value).lower() # Why the fuck does requests not automtically make booleans lowercase? |
|||
if type(value) == bool |
|||
else value |
|||
) |
|||
for key, value in payload._asdict().items() |
|||
} |
|||
url = f'{base_url}{endpoint}' |
|||
if method == 'get': |
|||
response = requests.get(url, params=payload) |
|||
elif method == 'put': |
|||
response = requests.put(url, data=payload) |
|||
elif method == 'post': |
|||
resposne = requests.post(url, data=payload) |
|||
else: |
|||
ValueError(f'Method must be "get", "put", or "post", not "{method}"') |
|||
response.raise_for_status() |
|||
parsed = response.json() |
|||
return parse_to_namedtuple(parsed, parsed_type=response_type) |
|||
|
|||
def parse_to_namedtuple(obj: dict, parsed_type: type): |
|||
if 'error' in obj: |
|||
parsed_type = ErrorResponse |
|||
if parsed_type is None or parsed_type == dict: |
|||
return obj |
|||
if not is_typed_named_tuple(parsed_type): |
|||
raise TypeError(f'parsed_type must be NamedTuple, not {parsed_type}') |
|||
field_types = vars(parsed_type)['__annotations__'] # parsed_type._field_types doesn't exist when running tests for some reason |
|||
defaults = parsed_type._field_defaults |
|||
parsed_obj = {} |
|||
for field, type_ in field_types.items(): |
|||
try: |
|||
value = obj[field] |
|||
except KeyError: |
|||
if field in defaults: |
|||
value = defaults[field] |
|||
else: |
|||
raise ValueError(f'Missing required field encountered while parsing: {field}') |
|||
else: |
|||
parsed_obj[field] = ensure_type(type_, value) |
|||
return parsed_type(**parsed_obj) |
|||
|
|||
def is_typed_named_tuple(t): |
|||
return all( |
|||
hasattr(t, attr) |
|||
for attr in ('_fields', '_field_defaults', '__annotations__') # '_field_types') |
|||
) |
|||
|
|||
def ensure_type(type_, value): |
|||
if type(value) == type_: |
|||
return value |
|||
|
|||
if type_ == datetime: |
|||
return datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f") |
|||
|
|||
if is_optional_type(type_): |
|||
if value is None: |
|||
return None |
|||
else: |
|||
optional_type = get_args(type_)[0] |
|||
return ensure_type(optional_type, value) |
|||
|
|||
if is_generic_type(type_): |
|||
origin = get_origin(type_) |
|||
if origin == list: |
|||
list_type = get_args(type_)[0] |
|||
return [ensure_type(list_type, item) for item in value] |
|||
else: |
|||
raise TypeError(f"Unknown generic type: {type_}") |
|||
|
|||
if is_typed_named_tuple(type_): |
|||
return parse_to_namedtuple(value, parsed_type=type_) |
|||
|
|||
raise TypeError(f'Type mismatch: {type_} and {type(value)}') |
@ -1,7 +0,0 @@ |
|||
def get(payload: site.GetModlog): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/modlog', |
|||
payload=payload, |
|||
response_type=site.GetModlogResponse |
|||
) |
@ -1,111 +0,0 @@ |
|||
def create(payload: post.CreatePost): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def get(payload: post.GetPost): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/post', |
|||
payload=payload, |
|||
response_type=post.GetPostResponse |
|||
) |
|||
|
|||
def edit(payload: post.EditPost): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/post', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def create_report(payload: report.CreatePostReport): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/report', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def delete(payload: post.DeletePost): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/delete', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def remove(payload: post.RemovePost): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/remove', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def lock(payload: post.LockPost): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/lock', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def sticky(payload: post.StickyPost): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/sticky', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def feed(payload: post.GetPosts): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/post/list', |
|||
payload=payload, |
|||
response_type=post.GetPostsResponse |
|||
) |
|||
|
|||
def create_like(payload: post.CreatePostLike): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/like', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def save(payload: post.SavePost): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/post/save', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def resolve_report(payload: report.ResolvePostReport): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/post/resolve_report', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def list_featured(payload: post_hexbear.GetFeaturedPosts): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/post/featured', |
|||
payload=payload, |
|||
response_type=post_hexbear.GetFeaturedPostsResponse |
|||
) |
|||
|
|||
def feature(payload: post_hexbear.FeaturePost): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/post/featured', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,39 +0,0 @@ |
|||
def create_private_message(payload: user.CreatePrivateMessage): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/private_message', |
|||
payload=payload, |
|||
response_type=user.PrivateMessageResponse |
|||
) |
|||
|
|||
def edit_private_message(payload: user.EditPrivateMessage): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/private_message', |
|||
payload=payload, |
|||
response_type=user.PrivateMessageResponse |
|||
) |
|||
|
|||
def get_private_messages(payload: user.GetPrivateMessages): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/private_message/list', |
|||
payload=payload, |
|||
response_type=user.PrivateMessagesResponse |
|||
) |
|||
|
|||
def delete_private_message(payload: user.DeletePrivateMessage): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/private_message/delete', |
|||
payload=payload, |
|||
response_type=user.PrivateMessageResponse |
|||
) |
|||
|
|||
def mark_private_message_as_read(payload: user.MarkPrivateMessageAsRead): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/private_message/mark_as_read', |
|||
payload=payload, |
|||
response_type=user.PrivateMessageResponse |
|||
) |
@ -1,3 +0,0 @@ |
|||
from .types import site, community, report, community_settings, post_hexbear, post, comment, user |
|||
from .helpers import request, ErrorResponse |
|||
from typing import Union |
@ -1,7 +0,0 @@ |
|||
def search(payload: site.Search): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/search', |
|||
payload=payload, |
|||
response_type=site.SearchResponse |
|||
) |
@ -1,31 +0,0 @@ |
|||
def get(payload: site.GetSite): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/site', |
|||
payload=payload, |
|||
response_type=site.GetSiteResponse |
|||
) |
|||
|
|||
def create(payload: site.CreateSite): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/site', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def edit(payload: site.EditSite): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/site', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def transfer(payload: site.TransferSite): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/site/transfer', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,15 +0,0 @@ |
|||
def get(payload: site.GetSiteConfig): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/site/config', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
|||
|
|||
def save(payload: site.SaveSiteConfig): |
|||
return request( |
|||
'put', |
|||
endpoint='/api/v1/site/config', |
|||
payload=payload, |
|||
response_type=dict |
|||
) |
@ -1,7 +0,0 @@ |
|||
def get(payload: site.GetSiteModerators): |
|||
return request( |
|||
'get', |
|||
endpoint='/api/v1/site/mods', |
|||
payload=payload, |
|||
response_type=site.GetSiteModeratorsResponse |
|||
) |
@ -1,19 +0,0 @@ |
|||
from typing import NamedTuple, List |
|||
from ..views import UserView |
|||
|
|||
|
|||
class AddSitemodRequest(NamedTuple): |
|||
user_id: int |
|||
added: bool |
|||
auth: str |
|||
|
|||
class AddSitemodResponse(NamedTuple): |
|||
sitemods: List[UserView] |
|||
|
|||
def add(payload: AddSitemodRequest): |
|||
return request( |
|||
'post', |
|||
endpoint='/api/v1/sitemod/add', |
|||
payload=payload, |
|||
response_type=AddSitemodResponse |
|||
) |
@ -1,19 +0,0 @@ |
|||
from .category import * |
|||
from .comment import * |
|||
from .comment_view import * |
|||
from .community import * |
|||
from .community_view import * |
|||
from .community_settings import * |
|||
from .lib import * |
|||
from .moderator_views import * |
|||
from .post import * |
|||
from .post_hexbear import * |
|||
from .post_view import * |
|||
from .private_message_view import * |
|||
from .report import * |
|||
from .report_views import * |
|||
from .site import * |
|||
from .site_view import * |
|||
from .user import * |
|||
from .user_mention_view import * |
|||
from .user_view import * |
@ -1,5 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
|
|||
class Category(NamedTuple): |
|||
id: int |
|||
name: str |
@ -1,58 +0,0 @@ |
|||
from .comment_view import CommentView |
|||
from .lib import ListingType, SortType |
|||
from typing import NamedTuple, Optional, List |
|||
|
|||
class CreateComment(NamedTuple): |
|||
content: str |
|||
parent_id: Optional[int] |
|||
post_id: int |
|||
form_id: Optional[str] |
|||
auth: str |
|||
|
|||
class EditComment(NamedTuple): |
|||
content: str |
|||
edit_id: int |
|||
form_id: Optional[str] |
|||
auth: str |
|||
|
|||
class DeleteComment(NamedTuple): |
|||
edit_id: int |
|||
deleted: bool |
|||
auth: str |
|||
|
|||
class RemoveComment(NamedTuple): |
|||
edit_id: int |
|||
removed: bool |
|||
reason: Optional[str] |
|||
auth: str |
|||
|
|||
class MarkCommentAsRead(NamedTuple): |
|||
edit_id: int |
|||
read: bool |
|||
auth: str |
|||
|
|||
class SaveComment(NamedTuple): |
|||
comment_id: int |
|||
save: bool |
|||
auth: str |
|||
|
|||
class CommentResponse(NamedTuple): |
|||
comment: CommentView |
|||
recipient_ids: List[int] |
|||
form_id: Optional[str] |
|||
|
|||
class CreateCommentLike(NamedTuple): |
|||
comment_id: int |
|||
score: int |
|||
auth: str |
|||
|
|||
class GetComments(NamedTuple): |
|||
type_: ListingType = 'All' |
|||
sort: SortType = 'New' |
|||
page: Optional[int] = None |
|||
limit: Optional[int] = None |
|||
community_id: Optional[int] = None |
|||
auth: Optional[str] = None |
|||
|
|||
class GetCommentsResponse(NamedTuple): |
|||
comments: List[CommentView] |
@ -1,81 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from datetime import datetime |
|||
|
|||
class CommentView(NamedTuple): |
|||
id: int |
|||
creator_id: int |
|||
post_id: int |
|||
post_name: str |
|||
parent_id: Optional[int] |
|||
content: str |
|||
removed: bool |
|||
read: bool |
|||
published: datetime |
|||
updated: Optional[datetime] |
|||
deleted: bool |
|||
ap_id: str |
|||
local: bool |
|||
community_id: int |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
|||
banned: bool |
|||
banned_from_community: bool |
|||
creator_actor_id: str |
|||
creator_local: bool |
|||
creator_name: str |
|||
creator_preferred_username: Optional[str] |
|||
creator_published: datetime |
|||
creator_avatar: Optional[str] |
|||
creator_tags: Optional[dict] |
|||
creator_community_tags: Optional[dict] |
|||
score: int |
|||
upvotes: int |
|||
downvotes: int |
|||
hot_rank: int |
|||
hot_rank_active: int |
|||
user_id: Optional[int] |
|||
my_vote: Optional[int] |
|||
subscribed: Optional[bool] |
|||
saved: Optional[bool] |
|||
|
|||
class ReplyView(NamedTuple): |
|||
id: int |
|||
creator_id: int |
|||
post_id: int |
|||
post_name: str |
|||
parent_id: Optional[int] |
|||
content: str |
|||
removed: bool |
|||
read: bool |
|||
published: datetime |
|||
updated: Optional[datetime] |
|||
deleted: bool |
|||
ap_id: str |
|||
local: bool |
|||
community_id: int |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
|||
banned: bool |
|||
banned_from_community: bool |
|||
creator_actor_id: str |
|||
creator_local: bool |
|||
creator_name: str |
|||
creator_preferred_username: Optional[str] |
|||
creator_avatar: Optional[str] |
|||
creator_tags: Optional[dict] |
|||
creator_community_tags: Optional[dict] |
|||
creator_published: datetime |
|||
score: int |
|||
upvotes: int |
|||
downvotes: int |
|||
hot_rank: int |
|||
hot_rank_active: int |
|||
user_id: Optional[int] |
|||
my_vote: Optional[int] |
|||
subscribed: Optional[bool] |
|||
saved: Optional[bool] |
|||
recipient_id: int |
@ -1,100 +0,0 @@ |
|||
from .community_view import CommunityFollowerView, CommunityModeratorView, CommunityView |
|||
from .user_view import UserView |
|||
from .lib import SortType |
|||
|
|||
from typing import NamedTuple, Optional, List |
|||
|
|||
class GetCommunity(NamedTuple): |
|||
id: Optional[int] = None |
|||
name: Optional[str] = None |
|||
auth: Optional[str] = None |
|||
|
|||
class GetCommunityResponse(NamedTuple): |
|||
community: CommunityView |
|||
moderators: List[CommunityModeratorView] |
|||
online: int |
|||
admins: List[UserView] # hexbear |
|||
sitemods: List[UserView] # hexbear |
|||
|
|||
class CreateCommunity(NamedTuple): |
|||
name: str |
|||
title: str |
|||
description: Optional[str] |
|||
icon: Optional[str] |
|||
banner: Optional[str] |
|||
category_id: int |
|||
nsfw: bool |
|||
auth: str |
|||
|
|||
class CommunityResponse(NamedTuple): |
|||
community: CommunityView |
|||
|
|||
class ListCommunities(NamedTuple): |
|||
sort: SortType |
|||
page: Optional[int] = None |
|||
limit: Optional[int] = None |
|||
auth: Optional[str] = None |
|||
|
|||
class ListCommunitiesResponse(NamedTuple): |
|||
communities: List[CommunityView] |
|||
|
|||
class BanFromCommunity(NamedTuple): |
|||
community_id: int |
|||
user_id: int |
|||
ban: bool |
|||
remove_data: Optional[bool] |
|||
reason: Optional[str] |
|||
expires: Optional[int] |
|||
auth: str |
|||
|
|||
class BanFromCommunityResponse(NamedTuple): |
|||
user: UserView |
|||
banned: bool |
|||
|
|||
class AddModToCommunity(NamedTuple): |
|||
community_id: int |
|||
user_id: int |
|||
added: bool |
|||
auth: str |
|||
|
|||
class AddModToCommunityResponse(NamedTuple): |
|||
moderators: List[CommunityModeratorView] |
|||
|
|||
class EditCommunity(NamedTuple): |
|||
edit_id: int |
|||
title: str |
|||
description: Optional[str] |
|||
icon: Optional[str] |
|||
banner: Optional[str] |
|||
category_id: int |
|||
nsfw: bool |
|||
auth: str |
|||
|
|||
class DeleteCommunity(NamedTuple): |
|||
edit_id: int |
|||
deleted: bool |
|||
auth: str |
|||
|
|||
class RemoveCommunity(NamedTuple): |
|||
edit_id: int |
|||
removed: bool |
|||
reason: Optional[str] |
|||
expires: Optional[int] |
|||
auth: str |
|||
|
|||
class FollowCommunity(NamedTuple): |
|||
community_id: int |
|||
follow: bool |
|||
auth: str |
|||
|
|||
class GetFollowedCommunities(NamedTuple): |
|||
auth: str |
|||
|
|||
class GetFollowedCommunitiesResponse(NamedTuple): |
|||
communities: List[CommunityFollowerView] |
|||
|
|||
class TransferCommunity(NamedTuple): |
|||
community_id: int |
|||
user_id: int |
|||
auth: str |
|||
|
@ -1,32 +0,0 @@ |
|||
from datetime import datetime |
|||
from typing import NamedTuple, Optional, List |
|||
|
|||
class GetCommunitySettings(NamedTuple): |
|||
community_id: int |
|||
auth: Optional[str] = None |
|||
|
|||
class GetCommunitySettingsResponse(NamedTuple): |
|||
read_only: bool |
|||
private: bool |
|||
post_links: bool |
|||
comment_images: int |
|||
published: datetime |
|||
allow_as_default: bool |
|||
|
|||
class EditCommunitySettings(NamedTuple): |
|||
community_id: int |
|||
read_only: bool |
|||
private: bool |
|||
post_links: bool |
|||
comment_images: int |
|||
allow_as_default: bool |
|||
auth: str |
|||
|
|||
class EditCommunitySettingsResponse(NamedTuple): |
|||
read_only: bool |
|||
private: bool |
|||
post_links: bool |
|||
comment_images: int |
|||
published: datetime |
|||
allow_as_default: bool |
|||
|
@ -1,77 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from datetime import datetime |
|||
|
|||
class CommunityView(NamedTuple): |
|||
id: int |
|||
name: str |
|||
title: str |
|||
icon: Optional[str] |
|||
banner: Optional[str] |
|||
description: Optional[str] |
|||
category_id: int |
|||
creator_id: int |
|||
removed: bool |
|||
published: datetime |
|||
updated: Optional[datetime] |
|||
deleted: bool |
|||
nsfw: bool |
|||
actor_id: str |
|||
local: bool |
|||
last_refreshed_at: datetime |
|||
creator_actor_id: str |
|||
creator_local: bool |
|||
creator_name: str |
|||
creator_preferred_username: Optional[str] |
|||
creator_avatar: Optional[str] |
|||
category_name: str |
|||
number_of_subscribers: int |
|||
number_of_posts: int |
|||
number_of_comments: int |
|||
hot_rank: int |
|||
user_id: Optional[int] |
|||
subscribed: Optional[bool] |
|||
|
|||
class CommunityModeratorView(NamedTuple): |
|||
id: int |
|||
community_id: int |
|||
user_id: int |
|||
published: datetime |
|||
user_actor_id: str |
|||
user_local: bool |
|||
user_name: str |
|||
user_preferred_username: Optional[str] |
|||
avatar: Optional[str] |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
|||
|
|||
class CommunityFollowerView(NamedTuple): |
|||
id: int |
|||
community_id: int |
|||
user_id: int |
|||
published: datetime |
|||
user_actor_id: str |
|||
user_local: bool |
|||
user_name: str |
|||
user_preferred_username: Optional[str] |
|||
avatar: Optional[str] |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
|||
|
|||
class CommunityUserBanView(NamedTuple): |
|||
id: int |
|||
community_id: int |
|||
user_id: int |
|||
published: datetime |
|||
user_actor_id: str |
|||
user_local: bool |
|||
user_name: str |
|||
user_preferred_username: Optional[str] |
|||
avatar: Optional[str] |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
@ -1,38 +0,0 @@ |
|||
from typing import NamedTuple, Literal |
|||
|
|||
class APIError(NamedTuple): |
|||
message: str |
|||
|
|||
SortType = Literal[ |
|||
'Active', |
|||
'Hot', |
|||
'New', |
|||
'TopDay', |
|||
'TopWeek', |
|||
'TopMonth', |
|||
'TopYear', |
|||
'TopAll' |
|||
] |
|||
|
|||
ListingType = Literal[ |
|||
'All', |
|||
'Local', |
|||
'Subscribed', |
|||
'Community' |
|||
] |
|||
|
|||
SearchType = Literal[ |
|||
'All', |
|||
'Comments', |
|||
'Posts', |
|||
'Communities', |
|||
'Users', |
|||
'Url' |
|||
] |
|||
|
|||
ListingType = Literal[ |
|||
'All', |
|||
'Local', |
|||
'Subscribed', |
|||
'Community', |
|||
] |
@ -1,107 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from datetime import datetime |
|||
|
|||
class ModRemovePostView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
post_id: int |
|||
reason: Optional[str] |
|||
removed: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
post_name: str |
|||
community_id: int |
|||
community_name: str |
|||
|
|||
class ModLockPostView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
post_id: int |
|||
locked: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
post_name: str |
|||
community_id: int |
|||
community_name: str |
|||
|
|||
class ModStickyPostView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
post_id: int |
|||
stickied: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
post_name: str |
|||
community_id: int |
|||
community_name: str |
|||
|
|||
class ModRemoveCommentView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
comment_id: int |
|||
reason: Optional[str] |
|||
removed: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
comment_user_id: int |
|||
comment_user_name: str |
|||
comment_content: str |
|||
post_id: int |
|||
post_name: str |
|||
community_id: int |
|||
community_name: str |
|||
|
|||
class ModRemoveCommunityView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
community_id: int |
|||
reason: Optional[str] |
|||
removed: Optional[bool] |
|||
expires: Optional[datetime] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
community_name: str |
|||
|
|||
class ModBanFromCommunityView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
other_user_id: int |
|||
community_id: int |
|||
reason: Optional[str] |
|||
banned: Optional[bool] |
|||
expires: Optional[datetime] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
other_user_name: str |
|||
community_name: str |
|||
|
|||
class ModBanView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
other_user_id: int |
|||
reason: Optional[str] |
|||
banned: Optional[bool] |
|||
expires: Optional[datetime] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
other_user_name: str |
|||
|
|||
class ModAddCommunityView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
other_user_id: int |
|||
community_id: int |
|||
removed: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
other_user_name: str |
|||
community_name: str |
|||
|
|||
class ModAddView(NamedTuple): |
|||
id: int |
|||
mod_user_id: int |
|||
other_user_id: int |
|||
removed: Optional[bool] |
|||
when_: datetime |
|||
mod_user_name: str |
|||
other_user_name: str |
@ -1,81 +0,0 @@ |
|||
from .comment_view import CommentView |
|||
from .community_view import CommunityModeratorView, CommunityView |
|||
from .post_view import PostView |
|||
from .user_view import UserView |
|||
|
|||
from typing import NamedTuple, Optional, List |
|||
|
|||
class CreatePost(NamedTuple): |
|||
name: str |
|||
url: Optional[str] |
|||
body: Optional[str] |
|||
nsfw: bool |
|||
community_id: int |
|||
auth: str |
|||
|
|||
class PostResponse(NamedTuple): |
|||
post: PostView |
|||
|
|||
class GetPost(NamedTuple): |
|||
id: int |
|||
auth: Optional[str] = None |
|||
|
|||
class GetPostResponse(NamedTuple): |
|||
post: PostView |
|||
comments: List[CommentView] |
|||
community: CommunityView |
|||
moderators: List[CommunityModeratorView] |
|||
online: int |
|||
admins: List[UserView] # Hexbear |
|||
sitemods: List[UserView] # Hexbear |
|||
|
|||
class GetPosts(NamedTuple): |
|||
type_: str |
|||
sort: str |
|||
page: Optional[int] |
|||
limit: Optional[int] |
|||
community_id: Optional[int] |
|||
community_name: Optional[str] |
|||
auth: Optional[str] |
|||
|
|||
class GetPostsResponse(NamedTuple): |
|||
posts: List[PostView] |
|||
|
|||
class CreatePostLike(NamedTuple): |
|||
post_id: int |
|||
score: int |
|||
auth: str |
|||
|
|||
class EditPost(NamedTuple): |
|||
edit_id: int |
|||
name: str |
|||
url: Optional[str] |
|||
body: Optional[str] |
|||
nsfw: bool |
|||
auth: str |
|||
|
|||
class DeletePost(NamedTuple): |
|||
edit_id: int |
|||
deleted: bool |
|||
auth: str |
|||
|
|||
class RemovePost(NamedTuple): |
|||
edit_id: int |
|||
removed: bool |
|||
reason: Optional[str] |
|||
auth: str |
|||
|
|||
class LockPost(NamedTuple): |
|||
edit_id: int |
|||
locked: bool |
|||
auth: str |
|||
|
|||
class StickyPost(NamedTuple): |
|||
edit_id: int |
|||
stickied: bool |
|||
auth: str |
|||
|
|||
class SavePost(NamedTuple): |
|||
post_id: int |
|||
save: bool |
|||
auth: str |
@ -1,13 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from .post import PostView |
|||
|
|||
class GetFeaturedPosts(NamedTuple): |
|||
auth: Optional[str] = None |
|||
|
|||
class GetFeaturedPostsResponse(NamedTuple): |
|||
posts: List[PostView] |
|||
|
|||
class FeaturePost(NamedTuple): |
|||
id: int |
|||
featured: bool |
|||
auth: str |
@ -1,53 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from datetime import datetime |
|||
|
|||
class PostView(NamedTuple): |
|||
id: int |
|||
name: str |
|||
url: Optional[str] |
|||
body: Optional[str] |
|||
creator_id: int |
|||
community_id: int |
|||
removed: bool |
|||
locked: bool |
|||
published: datetime |
|||
updated: Optional[datetime] |
|||
deleted: bool |
|||
nsfw: bool |
|||
stickied: bool |
|||
featured: bool |
|||
embed_title: Optional[str] |
|||
embed_description: Optional[str] |
|||
embed_html: Optional[str] |
|||
thumbnail_url: Optional[str] |
|||
ap_id: str |
|||
local: bool |
|||
creator_actor_id: str |
|||
creator_local: bool |
|||
creator_name: str |
|||
creator_preferred_username: Optional[str] |
|||
creator_published: datetime |
|||
creator_avatar: Optional[str] |
|||
creator_tags: Optional[dict] |
|||
creator_community_tags: Optional[dict] |
|||
banned: bool |
|||
banned_from_community: bool |
|||
community_actor_id: str |
|||
community_local: bool |
|||
community_name: str |
|||
community_icon: Optional[str] |
|||
community_removed: bool |
|||
community_deleted: bool |
|||
community_nsfw: bool |
|||
number_of_comments: int |
|||
score: int |
|||
upvotes: int |
|||
downvotes: int |
|||
hot_rank: int |
|||
hot_rank_active: int |
|||
newest_activity_time: datetime |
|||
user_id: Optional[int] |
|||
my_vote: Optional[int] |
|||
subscribed: Optional[bool] |
|||
read: Optional[bool] |
|||
saved: Optional[bool] |
@ -1,24 +0,0 @@ |
|||
from typing import NamedTuple, Optional, List |
|||
from datetime import datetime |
|||
|
|||
class PrivateMessageView(NamedTuple): |
|||
id: int |
|||
creator_id: int |
|||
recipient_id: int |
|||
content: str |
|||
deleted: bool |
|||
read: bool |
|||
published: datetime |
|||
updated: Optional[datetime] |
|||
ap_id: str |
|||
local: bool |
|||
creator_name: str |
|||
creator_preferred_username: Optional[str] |
|||
creator_avatar: Optional[str] |
|||
creator_actor_id: str |
|||
creator_local: bool |
|||
recipient_name: str |
|||
recipient_preferred_username: Optional[str] |
|||
recipient_avatar: Optional[str] |
|||
recipient_actor_id: str |
|||
recipient_local: bool |
@ -1,63 +0,0 @@ |
|||
from .report_views import CommentReportView, PostReportView |
|||
from typing import NamedTuple, Optional, List |
|||
from uuid import UUID |
|||
|
|||
class CreateCommentReport(NamedTuple): |
|||
comment: int |
|||
reason: Optional[str] |
|||
auth: str |
|||
|
|||
class CommentReportResponse(NamedTuple): |
|||
success: bool |
|||
|
|||
class CreatePostReport(NamedTuple): |
|||
post: int |
|||
reason: Optional[str] |
|||
auth: str |
|||
|
|||
class PostReportResponse(NamedTuple): |
|||
success: bool |
|||
|
|||
class ListCommentReports(NamedTuple): |
|||
page: Optional[int] |
|||
limit: Optional[int] |
|||
community: int |
|||
auth: str |
|||
|
|||
class ListCommentReportResponse(NamedTuple): |
|||
reports: List[CommentReportView] |
|||
|
|||
class ListPostReports(NamedTuple): |
|||