Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
lumina37 committed Jul 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents f294916 + b689f11 commit 3ef30dd
Showing 21 changed files with 366 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Pages.yml
Original file line number Diff line number Diff line change
@@ -6,12 +6,14 @@ on:
paths:
- "mkdocs.yml"
- "docs/**"
- "aiotieba/__version__.py"
- ".github/workflows/Pages*"
pull_request:
branches: [develop]
paths:
- "mkdocs.yml"
- "docs/**"
- "aiotieba/__version__.py"
- ".github/workflows/Pages*"

jobs:
2 changes: 1 addition & 1 deletion aiotieba/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.5.0"
__version__ = "3.5.1"
40 changes: 40 additions & 0 deletions aiotieba/api/_protobuf/CommonReq.proto
Original file line number Diff line number Diff line change
@@ -4,5 +4,45 @@ syntax = "proto3";
message CommonReq {
int32 _client_type = 1;
string _client_version = 2;
string _client_id = 3;
string _phone_imei = 5;
string _from = 6;
string cuid = 7;
int64 _timestamp = 8;
string model = 9;
string BDUSS = 10;
string tbs = 11;
int32 net_type = 12;
string pversion = 24;
string _os_version = 25;
string brand = 26;
string lego_lib_version = 28;
string applist = 29;
string stoken = 30;
string z_id = 31;
string cuid_galaxy2 = 32;
string cuid_gid = 33;
string c3_aid = 35;
string sample_id = 36;
int32 scr_w = 37;
int32 scr_h = 38;
double scr_dip = 39;
int32 q_type = 40;
int32 is_teenager = 41;
string sdk_ver = 42;
string framework_ver = 43;
string naws_game_ver = 44;
int64 active_timestamp = 49;
int64 first_install_time = 50;
int64 last_update_time = 51;
string event_day = 53;
string android_id = 54;
int32 cmode = 55;
string start_scheme = 56;
int32 start_type = 57;
string idfv = 60;
string extra = 61;
string user_agent = 62;
int32 personalized_rec_switch = 63;
string device_score = 70;
}
6 changes: 3 additions & 3 deletions aiotieba/api/_protobuf/CommonReq_pb2.py
Original file line number Diff line number Diff line change
@@ -8,13 +8,13 @@


DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
b'\n\x0f\x43ommonReq.proto\"I\n\tCommonReq\x12\x14\n\x0c_client_type\x18\x01 \x01(\x05\x12\x17\n\x0f_client_version\x18\x02 \x01(\t\x12\r\n\x05\x42\x44USS\x18\n \x01(\tb\x06proto3'
b'\n\x0f\x43ommonReq.proto\"\xc6\x06\n\tCommonReq\x12\x14\n\x0c_client_type\x18\x01 \x01(\x05\x12\x17\n\x0f_client_version\x18\x02 \x01(\t\x12\x12\n\n_client_id\x18\x03 \x01(\t\x12\x13\n\x0b_phone_imei\x18\x05 \x01(\t\x12\r\n\x05_from\x18\x06 \x01(\t\x12\x0c\n\x04\x63uid\x18\x07 \x01(\t\x12\x12\n\n_timestamp\x18\x08 \x01(\x03\x12\r\n\x05model\x18\t \x01(\t\x12\r\n\x05\x42\x44USS\x18\n \x01(\t\x12\x0b\n\x03tbs\x18\x0b \x01(\t\x12\x10\n\x08net_type\x18\x0c \x01(\x05\x12\x10\n\x08pversion\x18\x18 \x01(\t\x12\x13\n\x0b_os_version\x18\x19 \x01(\t\x12\r\n\x05\x62rand\x18\x1a \x01(\t\x12\x18\n\x10lego_lib_version\x18\x1c \x01(\t\x12\x0f\n\x07\x61pplist\x18\x1d \x01(\t\x12\x0e\n\x06stoken\x18\x1e \x01(\t\x12\x0c\n\x04z_id\x18\x1f \x01(\t\x12\x14\n\x0c\x63uid_galaxy2\x18 \x01(\t\x12\x10\n\x08\x63uid_gid\x18! \x01(\t\x12\x0e\n\x06\x63\x33_aid\x18# \x01(\t\x12\x11\n\tsample_id\x18$ \x01(\t\x12\r\n\x05scr_w\x18% \x01(\x05\x12\r\n\x05scr_h\x18& \x01(\x05\x12\x0f\n\x07scr_dip\x18\' \x01(\x01\x12\x0e\n\x06q_type\x18( \x01(\x05\x12\x13\n\x0bis_teenager\x18) \x01(\x05\x12\x0f\n\x07sdk_ver\x18* \x01(\t\x12\x15\n\rframework_ver\x18+ \x01(\t\x12\x15\n\rnaws_game_ver\x18, \x01(\t\x12\x18\n\x10\x61\x63tive_timestamp\x18\x31 \x01(\x03\x12\x1a\n\x12\x66irst_install_time\x18\x32 \x01(\x03\x12\x18\n\x10last_update_time\x18\x33 \x01(\x03\x12\x11\n\tevent_day\x18\x35 \x01(\t\x12\x12\n\nandroid_id\x18\x36 \x01(\t\x12\r\n\x05\x63mode\x18\x37 \x01(\x05\x12\x14\n\x0cstart_scheme\x18\x38 \x01(\t\x12\x12\n\nstart_type\x18\x39 \x01(\x05\x12\x0c\n\x04idfv\x18< \x01(\t\x12\r\n\x05\x65xtra\x18= \x01(\t\x12\x12\n\nuser_agent\x18> \x01(\t\x12\x1f\n\x17personalized_rec_switch\x18? \x01(\x05\x12\x14\n\x0c\x64\x65vice_score\x18\x46 \x01(\tb\x06proto3'
)

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'CommonReq_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
DESCRIPTOR._options = None
_globals['_COMMONREQ']._serialized_start = 19
_globals['_COMMONREQ']._serialized_end = 92
_globals['_COMMONREQ']._serialized_start = 20
_globals['_COMMONREQ']._serialized_end = 858
2 changes: 1 addition & 1 deletion aiotieba/api/add_post/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from ._api import parse_body, request
from ._api import CMD, pack_proto, parse_body, request_http, request_ws
153 changes: 106 additions & 47 deletions aiotieba/api/add_post/_api.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,127 @@
import datetime
import sys
import time

import yarl

from ...__version__ import __version__
from ...const import APP_BASE_HOST, APP_SECURE_SCHEME, POST_VERSION
from ...core import HttpCore
from ...core import Account, HttpCore, WsCore
from ...exception import TiebaServerError, TiebaValueError
from ...helper import log_success, parse_json
from ...helper import log_success
from .protobuf import AddPostReqIdl_pb2, AddPostResIdl_pb2

CMD = 309731


def parse_body(body: bytes) -> None:
res_json = parse_json(body)
if code := int(res_json['error_code']):
raise TiebaServerError(code, res_json['error_msg'])
if int(res_json['info']['need_vcode']):
res_proto = AddPostResIdl_pb2.AddPostResIdl()
res_proto.ParseFromString(body)

if code := res_proto.error.errorno:
raise TiebaServerError(code, res_proto.error.errmsg)
if int(res_proto.data.info.need_vcode):
raise TiebaValueError("Need verify code")


async def request(http_core: HttpCore, fname: str, fid: int, tid: int, content: str) -> bool:
core = http_core.account
data = [
('BDUSS', core._BDUSS),
('_client_id', core._client_id),
('_client_type', '2'),
('_client_version', POST_VERSION),
('_phone_imei', '000000000000000'),
('anonymous', '1'),
('barrage_time', '0'),
('can_no_forum', '0'),
('content', content),
('cuid', core.cuid),
('cuid_galaxy2', core.cuid_galaxy2),
('cuid_gid', ''),
('fid', fid),
('from', '1021099l'),
('from_forum_id', 'null'),
('is_ad', '0'),
('is_barrage', '0'),
('is_feedback', '0'),
('kw', fname),
('model', 'M2012K11AC'),
('net_type', '1'),
('new_vcode', '1'),
('post_from', '3'),
('reply_uid', 'null'),
('stoken', core._STOKEN),
('subapp_type', 'mini'),
('tbs', core._tbs),
('tid', tid),
('timestamp', int(time.time() * 1000)),
('v_fid', ''),
('v_fname', ''),
('vcode_tag', '12'),
('z_id', core._z_id),
]

request = http_core.pack_form_request(
yarl.URL.build(scheme=APP_SECURE_SCHEME, host=APP_BASE_HOST, path="/c/c/post/add"), data
def pack_proto(account: Account, fname: str, fid: int, tid: int, show_name: str, content: str) -> bytes:
req_proto = AddPostReqIdl_pb2.AddPostReqIdl()
req_proto.data.common.BDUSS = account._BDUSS
req_proto.data.common._client_type = 2
req_proto.data.common._client_version = POST_VERSION
req_proto.data.common._client_id = account.client_id
req_proto.data.common._phone_imei = '000000000000000'
req_proto.data.common._from = '1008621x'
req_proto.data.common.cuid = account.cuid_galaxy2
current_ts = time.time()
current_tsms = int(current_ts * 1000)
current_dt = datetime.datetime.fromtimestamp(current_ts)
req_proto.data.common._timestamp = current_tsms
req_proto.data.common.model = 'SM-G988N'
req_proto.data.common.tbs = account._tbs
req_proto.data.common.net_type = 1
req_proto.data.common.pversion = '1.0.3'
req_proto.data.common._os_version = '9'
req_proto.data.common.brand = 'samsung'
req_proto.data.common.lego_lib_version = '3.0.0'
req_proto.data.common.applist = ''
req_proto.data.common.stoken = account._STOKEN
req_proto.data.common.z_id = account._z_id
req_proto.data.common.cuid_galaxy2 = account._cuid_galaxy2
req_proto.data.common.cuid_gid = ''
req_proto.data.common.c3_aid = account.c3_aid
req_proto.data.common.sample_id = account._sample_id
req_proto.data.common.scr_w = 720
req_proto.data.common.scr_w = 1280
req_proto.data.common.scr_dip = 1.5
req_proto.data.common.q_type = 0
req_proto.data.common.is_teenager = 0
req_proto.data.common.sdk_ver = '2.34.0'
req_proto.data.common.framework_ver = '3340042'
req_proto.data.common.naws_game_ver = '1038000'
req_proto.data.common.active_timestamp = current_tsms - 86400 * 30
req_proto.data.common.first_install_time = current_tsms - 86400 * 30
req_proto.data.common.last_update_time = current_tsms - 86400 * 30
req_proto.data.common.event_day = f'{current_dt.year}{current_dt.month}{current_dt.day}'
req_proto.data.common.android_id = account.android_id
req_proto.data.common.cmode = 1
req_proto.data.common.start_scheme = ''
req_proto.data.common.start_type = 1
req_proto.data.common.idfv = '0'
req_proto.data.common.extra = ''
req_proto.data.common.user_agent = f'aiotieba/{__version__}'
req_proto.data.common.personalized_rec_switch = 1
req_proto.data.common.device_score = '0.4'

req_proto.data.anonymous = '1'
req_proto.data.can_no_forum = '0'
req_proto.data.is_feedback = '0'
req_proto.data.takephoto_num = '0'
req_proto.data.entrance_type = '0'
req_proto.data.vcode_tag = '12'
req_proto.data.new_vcode = '1'
req_proto.data.content = content
req_proto.data.fid = str(fid)
req_proto.data.v_fid = ''
req_proto.data.v_fname = ''
req_proto.data.kw = fname
req_proto.data.is_barrage = '0'
req_proto.data.from_fourm_id = str(fid)
req_proto.data.tid = str(tid)
req_proto.data.is_ad = '0'
req_proto.data.post_from = '3'
req_proto.data.name_show = show_name
req_proto.data.is_pictxt = '0'
req_proto.data.show_custom_figure = 0
req_proto.data.is_show_bless = 0

return req_proto.SerializeToString()


async def request_http(http_core: HttpCore, fname: str, fid: int, tid: int, show_name: str, content: str) -> bool:
data = pack_proto(http_core.account, fname, fid, tid, show_name, content)

request = http_core.pack_proto_request(
yarl.URL.build(scheme=APP_SECURE_SCHEME, host=APP_BASE_HOST, path="/c/c/post/add", query_string=f"cmd={CMD}"),
data,
)

__log__ = f"fname={fname} tid={tid}"

body = await http_core.net_core.send_request(request, read_bufsize=2 * 1024)
body = await http_core.net_core.send_request(request, read_bufsize=1024)
parse_body(body)

log_success(sys._getframe(1), __log__)
return True


async def request_ws(ws_core: WsCore, fname: str, fid: int, tid: int, show_name: str, content: str) -> bool:
data = pack_proto(ws_core.account, fname, fid, tid, show_name, content)

__log__ = f"fname={fname} tid={tid}"

response = await ws_core.send(data, CMD)
parse_body(await response.read())

log_success(sys._getframe(1), __log__)
return True
33 changes: 33 additions & 0 deletions aiotieba/api/add_post/protobuf/AddPostReqIdl.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// tbclient.AddPost.AddPostReqIdl
syntax = "proto3";

import "CommonReq.proto";

message AddPostReqIdl {
message DataReq {
CommonReq common = 1;
string anonymous = 6;
string can_no_forum = 7;
string is_feedback = 8;
string takephoto_num = 9;
string entrance_type = 10;
string vcode_tag = 16;
string new_vcode = 18;
string content = 19;
string fid = 26;
string v_fid = 28;
string v_fname = 29;
string kw = 30;
string is_barrage = 31;
string barrage_time = 32;
string from_fourm_id = 44;
string tid = 45;
string is_ad = 51;
string post_from = 55;
string name_show = 58;
string is_pictxt = 60;
int32 show_custom_figure = 64;
int32 is_show_bless = 67;
}
DataReq data = 1;
}
24 changes: 24 additions & 0 deletions aiotieba/api/add_post/protobuf/AddPostReqIdl_pb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder

_sym_db = _symbol_database.Default()


from ..._protobuf import CommonReq_pb2 as CommonReq__pb2

DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
b'\n\x13\x41\x64\x64PostReqIdl.proto\x1a\x0f\x43ommonReq.proto\"\x82\x04\n\rAddPostReqIdl\x12$\n\x04\x64\x61ta\x18\x01 \x01(\x0b\x32\x16.AddPostReqIdl.DataReq\x1a\xca\x03\n\x07\x44\x61taReq\x12\x1a\n\x06\x63ommon\x18\x01 \x01(\x0b\x32\n.CommonReq\x12\x11\n\tanonymous\x18\x06 \x01(\t\x12\x14\n\x0c\x63\x61n_no_forum\x18\x07 \x01(\t\x12\x13\n\x0bis_feedback\x18\x08 \x01(\t\x12\x15\n\rtakephoto_num\x18\t \x01(\t\x12\x15\n\rentrance_type\x18\n \x01(\t\x12\x11\n\tvcode_tag\x18\x10 \x01(\t\x12\x11\n\tnew_vcode\x18\x12 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x13 \x01(\t\x12\x0b\n\x03\x66id\x18\x1a \x01(\t\x12\r\n\x05v_fid\x18\x1c \x01(\t\x12\x0f\n\x07v_fname\x18\x1d \x01(\t\x12\n\n\x02kw\x18\x1e \x01(\t\x12\x12\n\nis_barrage\x18\x1f \x01(\t\x12\x14\n\x0c\x62\x61rrage_time\x18 \x01(\t\x12\x15\n\rfrom_fourm_id\x18, \x01(\t\x12\x0b\n\x03tid\x18- \x01(\t\x12\r\n\x05is_ad\x18\x33 \x01(\t\x12\x11\n\tpost_from\x18\x37 \x01(\t\x12\x11\n\tname_show\x18: \x01(\t\x12\x11\n\tis_pictxt\x18< \x01(\t\x12\x1a\n\x12show_custom_figure\x18@ \x01(\x05\x12\x15\n\ris_show_bless\x18\x43 \x01(\x05\x62\x06proto3'
)

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'AddPostReqIdl_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
DESCRIPTOR._options = None
_globals['_ADDPOSTREQIDL']._serialized_start = 41
_globals['_ADDPOSTREQIDL']._serialized_end = 555
_globals['_ADDPOSTREQIDL_DATAREQ']._serialized_start = 97
_globals['_ADDPOSTREQIDL_DATAREQ']._serialized_end = 555
19 changes: 19 additions & 0 deletions aiotieba/api/add_post/protobuf/AddPostResIdl.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// tbclient.AddPost.AddPostResIdl
syntax = "proto3";

import "Error.proto";

message AddPostResIdl {
Error error = 1;
message DataRes {
string video_id = 4;
string msg = 5;
string pre_msg = 6;
string color_msg = 7;
message PostAntiInfo {
string need_vcode = 3;
}
PostAntiInfo info = 14;
}
DataRes data = 2;
}
26 changes: 26 additions & 0 deletions aiotieba/api/add_post/protobuf/AddPostResIdl_pb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder

_sym_db = _symbol_database.Default()


from ..._protobuf import Error_pb2 as Error__pb2

DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
b'\n\x13\x41\x64\x64PostResIdl.proto\x1a\x0b\x45rror.proto\"\xf2\x01\n\rAddPostResIdl\x12\x15\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x06.Error\x12$\n\x04\x64\x61ta\x18\x02 \x01(\x0b\x32\x16.AddPostResIdl.DataRes\x1a\xa3\x01\n\x07\x44\x61taRes\x12\x10\n\x08video_id\x18\x04 \x01(\t\x12\x0b\n\x03msg\x18\x05 \x01(\t\x12\x0f\n\x07pre_msg\x18\x06 \x01(\t\x12\x11\n\tcolor_msg\x18\x07 \x01(\t\x12\x31\n\x04info\x18\x0e \x01(\x0b\x32#.AddPostResIdl.DataRes.PostAntiInfo\x1a\"\n\x0cPostAntiInfo\x12\x12\n\nneed_vcode\x18\x03 \x01(\tb\x06proto3'
)

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'AddPostResIdl_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
DESCRIPTOR._options = None
_globals['_ADDPOSTRESIDL']._serialized_start = 37
_globals['_ADDPOSTRESIDL']._serialized_end = 279
_globals['_ADDPOSTRESIDL_DATARES']._serialized_start = 116
_globals['_ADDPOSTRESIDL_DATARES']._serialized_end = 279
_globals['_ADDPOSTRESIDL_DATARES_POSTANTIINFO']._serialized_start = 245
_globals['_ADDPOSTRESIDL_DATARES_POSTANTIINFO']._serialized_end = 279
Loading

0 comments on commit 3ef30dd

Please sign in to comment.