Skip to content

Commit

Permalink
Merge pull request #59 from Starry-OvO/develop
Browse files Browse the repository at this point in the history
Update 2.9.6
  • Loading branch information
Starry-OvO committed Nov 20, 2022
2 parents 9df8d01 + 87dc3c8 commit 7dbbc4a
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 66 deletions.
5 changes: 3 additions & 2 deletions aiotieba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .client import Client, ReqUInfo
from .database import MySQLDB, SQLiteDB
from .reviewer import BaseReviewer, Ops, Punish, Reviewer
from .typedefs import (
from .typedef import (
Appeal,
Appeals,
At,
Expand Down Expand Up @@ -59,10 +59,11 @@
UserInfo,
UserPost,
UserPosts,
VirtualImage,
VoteInfo,
)

__version__ = "2.9.6b1"
__version__ = "2.9.6"

if os.name == 'posix':
import signal
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions aiotieba/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from google.protobuf.json_format import ParseDict

from ._config import CONFIG
from ._exceptions import ContentTypeError, TiebaServerError
from ._helpers import JSON_DECODE_FUNC
from ._exception import ContentTypeError, TiebaServerError
from ._helper import JSON_DECODE_FUNC
from ._logger import LOG
from .protobuf import (
CommitPersonalMsgReqIdl_pb2,
Expand Down Expand Up @@ -61,7 +61,7 @@
UserPostReqIdl_pb2,
UserPostResIdl_pb2,
)
from .typedefs import (
from .typedef import (
Appeals,
Ats,
BlacklistUsers,
Expand Down
2 changes: 1 addition & 1 deletion aiotieba/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ._config import CONFIG
from ._logger import LOG
from .typedefs import UserInfo
from .typedef import UserInfo


class MySQLDB(object):
Expand Down
8 changes: 8 additions & 0 deletions aiotieba/protobuf/Post.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ message Post {
Agree agree = 37;
SimpleForum from_forum = 38;
int64 tid = 46;
message CustomFigure {
string background_value = 3;
}
CustomFigure custom_figure = 60;
message CustomState {
string content = 2;
}
CustomState custom_state = 61;
}
20 changes: 12 additions & 8 deletions aiotieba/protobuf/Post_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aiotieba/protobuf/ThreadInfo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ message ThreadInfo {
int32 is_deleted = 181;
int32 is_frs_mask = 198;
message CustomFigure {
string background_type = 2;
string background_value = 3;
}
CustomFigure custom_figure = 211;
message CustomState {
Expand Down
10 changes: 5 additions & 5 deletions aiotieba/protobuf/ThreadInfo_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aiotieba/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from collections.abc import Callable, Iterator
from typing import List, Literal, Optional, Tuple, Union

from ._helpers import alog_time
from ._helper import alog_time
from ._logger import LOG
from .client import Client, ReqUInfo, _ForumInfoCache
from .database import MySQLDB, SQLiteDB
from .typedefs import Comment, Comments, Post, Posts, Thread, Threads, UserInfo
from .typedef import Comment, Comments, Post, Posts, Thread, Threads, UserInfo


class BaseReviewer(object):
Expand Down
117 changes: 79 additions & 38 deletions aiotieba/typedefs.py → aiotieba/typedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'BasicForum',
'Page',
'VoteInfo',
'VirtualImage',
'ShareThread',
'Thread',
'Threads',
Expand Down Expand Up @@ -78,6 +79,55 @@
_TypeMessage = TypeVar('_TypeMessage', bound=Message)


class VirtualImage(object):
"""
虚拟形象信息
Attributes:
enabled (bool): 是否启用虚拟形象
state (str): 虚拟形象状态签名
"""

__slots__ = [
'_enabled',
'_state',
]

def __init__(self, enabled: bool = False, state: str = '') -> None:
self._enabled = enabled
self._state = state

def __str__(self) -> str:
return self._state

def __repr__(self) -> str:
return str(
{
'enabled': self.enabled,
'state': self.state,
}
)

def __bool__(self) -> bool:
return self._enabled

@property
def enabled(self) -> bool:
"""
是否启用虚拟形象
"""

return self._enabled

@property
def state(self) -> str:
"""
虚拟形象状态签名
"""

return self._state


class UserInfo(object):
"""
用户信息
Expand All @@ -100,13 +150,12 @@ class UserInfo(object):
fan_num (int): 粉丝数
follow_num (int): 关注数
sign (str): 个性签名
virtual_state (str): 虚拟形象状态签名
ip (str): ip归属地
vimage (VirtualImage): 虚拟形象信息
is_bawu (bool): 是否吧务
is_vip (bool): 是否超级会员
is_god (bool): 是否大神
has_virtual (bool): 是否设置虚拟形象
priv_like (int): 公开关注吧列表的设置状态
priv_reply (int): 帖子评论权限的设置状态
Expand All @@ -127,12 +176,11 @@ class UserInfo(object):
'_fan_num',
'_follow_num',
'_sign',
'_virtual_state',
'_vimage',
'_ip',
'_is_bawu',
'_is_vip',
'_is_god',
'_has_virtual',
'_priv_like',
'_priv_reply',
]
Expand All @@ -153,13 +201,14 @@ def __init__(self, _id: Union[str, int, None] = None, _raw_data: Optional[_TypeM
self._fan_num = _raw_data.fans_num
self._follow_num = _raw_data.concern_num
self._sign = _raw_data.intro
self._virtual_state = _raw_data.virtual_image_info.personal_state.text
self._ip = _raw_data.ip_address
self._vimage = VirtualImage(
bool(_raw_data.virtual_image_info.isset_virtual_image), _raw_data.virtual_image_info.personal_state.text
)

self._is_bawu = bool(_raw_data.is_bawu)
self._is_vip = True if _raw_data.new_tshow_icon else bool(_raw_data.vipInfo.v_status)
self._is_god = bool(_raw_data.new_god_data.status)
self._has_virtual = bool(_raw_data.virtual_image_info.isset_virtual_image)
self.priv_like = _raw_data.priv_sets.like
self.priv_reply = _raw_data.priv_sets.reply

Expand All @@ -177,13 +226,12 @@ def __init__(self, _id: Union[str, int, None] = None, _raw_data: Optional[_TypeM
self._fan_num = 0
self._follow_num = 0
self._sign = ''
self._virtual_state = ''
self._vimage = VirtualImage()
self._ip = ''

self._is_bawu = False
self._is_vip = False
self._is_god = False
self._has_virtual = False
self._priv_like = 1
self._priv_reply = 1

Expand Down Expand Up @@ -432,18 +480,6 @@ def sign(self) -> str:
def sign(self, new_sign: str) -> None:
self._sign = new_sign

@property
def virtual_state(self) -> str:
"""
虚拟形象状态签名
"""

return self._virtual_state

@virtual_state.setter
def virtual_state(self, new_virtual_state: str) -> None:
self._virtual_state = new_virtual_state

@property
def ip(self) -> str:
"""
Expand All @@ -456,6 +492,18 @@ def ip(self) -> str:
def ip(self, new_ip: str) -> None:
self._ip = new_ip

@property
def vimage(self) -> VirtualImage:
"""
虚拟形象信息
"""

return self._vimage

@vimage.setter
def vimage(self, new_vimage: VirtualImage) -> None:
self._vimage = new_vimage

@property
def is_bawu(self) -> bool:
"""
Expand Down Expand Up @@ -492,18 +540,6 @@ def is_god(self) -> bool:
def is_god(self, new_is_god: bool) -> None:
self._is_god = new_is_god

@property
def has_virtual(self) -> bool:
"""
是否设置虚拟形象
"""

return self._has_virtual

@has_virtual.setter
def has_virtual(self, new_has_virtual: bool) -> None:
self._has_virtual = new_has_virtual

@property
def priv_like(self) -> int:
"""
Expand Down Expand Up @@ -2088,10 +2124,10 @@ def objs(self) -> List[Thread]:

for thread, _proto in zip(threads, self._objs):
thread._fname = self.forum.fname
user = users[thread.author_id]
user.has_virtual = bool(_proto.custom_figure.background_type)
user.virtual_state = _proto.custom_state.content
thread._user = user
thread._user = users[thread.author_id]
thread._user.vimage = VirtualImage(
bool(_proto.custom_figure.background_value), _proto.custom_state.content
)

self._objs = threads

Expand Down Expand Up @@ -2394,16 +2430,19 @@ def objs(self) -> List[Post]:
if not isinstance(self._objs, list):
if self._objs is not None:

self._objs = [Post(_proto) for _proto in self._objs]
posts = [Post(_proto) for _proto in self._objs]
users = {user.user_id: user for _proto in self._users if (user := UserInfo(_raw_data=_proto)).user_id}
self._users = None

for post in self._objs:
for post, _proto in zip(posts, self._objs):

post._fid = self.forum.fid
post._fname = self.forum.fname
post._tid = self.thread.tid
post._user = users.get(post.author_id, None)
post._user.vimage = VirtualImage(
bool(_proto.custom_figure.background_value), _proto.custom_state.content
)
post._is_thread_author = self.thread.author_id == post.author_id

for comment in post.comments:
Expand All @@ -2412,6 +2451,8 @@ def objs(self) -> List[Post]:
comment._tid = post.tid
comment._user = users.get(comment.author_id, None)

self._objs = posts

else:
self._objs = []

Expand Down
4 changes: 2 additions & 2 deletions docs/ref/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def `get_fname`(*fid: int*) -> *str*
</div>


async def `get_user_info`(*_id: str | int*, /, *require: [ReqUInfo](#requinfo) = [ReqUInfo](#requinfo).ALL*) -> *[UserInfo](typedefs.md#userinfo)*
async def `get_user_info`(*_id: str | int*, /, *require: [ReqUInfo](#requinfo) = [ReqUInfo](#requinfo).ALL*) -> *[UserInfo](typedef.md#userinfo)*

<div class="docstring" markdown="1">
获取用户信息
Expand All @@ -81,7 +81,7 @@ async def `get_user_info`(*_id: str | int*, /, *require: [ReqUInfo](#requinfo) =
**返回**: 用户信息
</div>

async def `get_threads`(*fname_or_fid: str | int*, /, *pn: int = 1*, \*, *rn: int = 30*, *sort: int = 5*, *is_good: bool = False*) -> *[Threads](typedefs.md#threads)*
async def `get_threads`(*fname_or_fid: str | int*, /, *pn: int = 1*, \*, *rn: int = 30*, *sort: int = 5*, *is_good: bool = False*) -> *[Threads](typedef.md#threads)*

<div class="docstring" markdown="1">
获取首页帖子
Expand Down
File renamed without changes.
Loading

0 comments on commit 7dbbc4a

Please sign in to comment.