Skip to content

Commit

Permalink
update: 修复代码;下载请求时附加根证书;
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien8261 committed Nov 29, 2024
1 parent 24bba69 commit 310cb1a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 20 deletions.
83 changes: 65 additions & 18 deletions amiyabot/adapters/onebot/v11/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,68 @@ async def request(self, url: str, method: str, *args, **kwargs):
)

async def send_private_msg(self, user_id: int, message: str, auto_escape: bool = False):
return await self.post('/send_private_msg', data={'user_id': user_id, 'message': message, 'auto_escape': auto_escape})
return await self.post(
'/send_private_msg',
data={
'user_id': user_id,
'message': message,
'auto_escape': auto_escape,
},
)

async def send_group_msg(self, group_id: int, message: str, auto_escape: bool = False):
return await self.post('/send_group_msg', data={'group_id': group_id, 'message': message, 'auto_escape': auto_escape})
return await self.post(
'/send_group_msg',
data={
'group_id': group_id,
'message': message,
'auto_escape': auto_escape,
},
)

async def send_msg(self, message_type: str, user_id: int, group_id: int, message: str, auto_escape: bool = False):
return await self.post('/send_msg', data={'message_type': message_type, 'user_id': user_id, 'group_id': group_id, 'message': message, 'auto_escape': auto_escape})
return await self.post(
'/send_msg',
data={
'message_type': message_type,
'user_id': user_id,
'group_id': group_id,
'message': message,
'auto_escape': auto_escape,
},
)

async def delete_msg(self, message_id: str):
return await self.post('/delete_msg', data={'message_id': message_id})

async def get_msg(self, message_id: str):
return await self.post('/get_msg', data={'message_id': message_id})

async def get_forward_msg(self, id: str):
return await self.post('/get_forward_msg', data={'id': id})
async def get_forward_msg(self, msg_id: str):
return await self.post('/get_forward_msg', data={'id': msg_id})

async def send_like(self, user_id: int, times: int):
return await self.post('/send_like', data={'user_id': user_id, 'times': times})

async def set_group_kick(self, group_id: int, user_id: int, reject_add_request: bool = False):
return await self.post('/set_group_kick', data={'group_id': group_id, 'user_id': user_id, 'reject_add_request': reject_add_request})
return await self.post(
'/set_group_kick', data={'group_id': group_id, 'user_id': user_id, 'reject_add_request': reject_add_request}
)

async def set_group_ban(self, group_id: int, user_id: int, duration: int):
return await self.post('/set_group_ban', data={'group_id': group_id, 'user_id': user_id, 'duration': duration})

#async def set_group_anonymous_ban(self, *args, **kwargs):
#...
# async def set_group_anonymous_ban(self, *args, **kwargs):
# ...

async def set_group_whole_ban(self, group_id: int, enable: bool = True):
return await self.post('/set_group_whole_ban', data={'group_id': group_id, 'enable': enable})

async def set_group_admin(self, group_id: int, user_id: int, enable: bool = True):
return await self.post('/set_group_admin', data={'group_id': group_id, 'user_id': user_id, 'enable': enable})

#async def set_group_anonymous(self, *args, **kwargs):
#...
# async def set_group_anonymous(self, *args, **kwargs):
# ...

async def set_group_card(self, group_id: int, user_id: int, card: str = ""):
return await self.post('/set_group_card', data={'group_id': group_id, 'user_id': user_id, 'card': card})
Expand All @@ -84,14 +109,29 @@ async def set_group_name(self, group_id: int, group_name: str):
async def set_group_leave(self, group_id: int, is_dismiss: bool = False):
return await self.post('/set_group_leave', data={'group_id': group_id, 'is_dismiss': is_dismiss})

#async def set_group_special_title(self, *args, **kwargs):
#...
# async def set_group_special_title(self, *args, **kwargs):
# ...

async def set_friend_add_request(self, flag: str, approve: bool = True, remark: str = ""):
return await self.post('/set_friend_add_request', data={'flag': flag, 'approve': approve, 'remark': remark})
return await self.post(
'/set_friend_add_request',
data={
'flag': flag,
'approve': approve,
'remark': remark,
},
)

async def set_group_add_request(self, flag: str, sub_type: str, approve: bool = True, reason: str = ""):
return await self.post('/set_group_add_request', data={'flag': flag, 'sub_type': sub_type, 'approve': approve, 'reason': reason})
return await self.post(
'/set_group_add_request',
data={
'flag': flag,
'sub_type': sub_type,
'approve': approve,
'reason': reason,
},
)

async def get_login_info(self):
return await self.post('/get_login_info')
Expand All @@ -109,13 +149,20 @@ async def get_group_list(self):
return await self.post('/get_group_list')

async def get_group_member_info(self, group_id: int, user_id: int, no_cache: bool = False):
return await self.post('/get_group_member_info', data={'group_id': group_id, 'user_id': user_id, 'no_cache': no_cache})
return await self.post(
'/get_group_member_info',
data={
'group_id': group_id,
'user_id': user_id,
'no_cache': no_cache,
},
)

async def get_group_member_list(self, group_id: int):
return await self.post('/get_group_member_list', data={'group_id': group_id})

async def get_group_honor_info(self, group_id: int, type: str):
return await self.post('/get_group_honor_info', data={'group_id': group_id, 'type': type})
async def get_group_honor_info(self, group_id: int, info_type: str):
return await self.post('/get_group_honor_info', data={'group_id': group_id, 'type': info_type})

async def get_cookies(self, domain: str):
return await self.post('/get_cookies', data={'domain': domain})
Expand All @@ -129,7 +176,7 @@ async def get_credentials(self, domain: str):
async def get_record(self, file: str, out_format: str):
return await self.post('/get_record', data={'file': file, 'out_format': out_format})

async def get_image(self, flie: str):
async def get_image(self, file: str):
return await self.post('/get_image', data={'file': file})

async def can_send_image(self):
Expand Down
7 changes: 5 additions & 2 deletions amiyabot/network/download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ssl
import certifi
import aiohttp
import requests

Expand All @@ -9,6 +11,7 @@
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) '
'AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
}
ssl_context = ssl.create_default_context(cafile=certifi.where())


def download_sync(
Expand Down Expand Up @@ -46,9 +49,9 @@ def download_sync(
log.error(e, desc='download error:')


async def download_async(url, headers: Optional[Dict[str, str]] = None, stringify: bool = False, **kwargs):
async def download_async(url: str, headers: Optional[Dict[str, str]] = None, stringify: bool = False, **kwargs):
async with log.catch('download error:', ignore=[requests.exceptions.SSLError]):
async with aiohttp.ClientSession(trust_env=True) as session:
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=ssl_context), trust_env=True) as session:
async with session.get(url, headers={**default_headers, **(headers or {})}, **kwargs) as res:
if res.status == 200:
if stringify:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
aiohttp~=3.7.4.post0
apscheduler~=3.10.4
certifi~=2023.7.22
concurrent-log-handler~=0.9.20
dhash~=1.3
fastapi-utils~=0.2.1
Expand All @@ -17,4 +18,5 @@ setuptools~=60.2.0
starlette~=0.19.1
uvicorn~=0.18.2
websockets~=10.1
wheel~=0.41.2
zhon~=1.1.5

0 comments on commit 310cb1a

Please sign in to comment.