Skip to content

Commit

Permalink
Merge pull request #109 from AmiyaBot/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vivien8261 authored Nov 29, 2024
2 parents fdebdc6 + 310cb1a commit f3e7282
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 76 deletions.
195 changes: 121 additions & 74 deletions amiyabot/adapters/onebot/v11/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,116 +36,163 @@ async def request(self, url: str, method: str, *args, **kwargs):
**kwargs,
)

async def send_private_msg(self, *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,
},
)

async def send_group_msg(self, *args, **kwargs):
...
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,
},
)

async def send_msg(self, *args, **kwargs):
...
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,
},
)

async def delete_msg(self, *args, **kwargs):
...
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, *args, **kwargs):
...
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, *args, **kwargs):
...
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, *args, **kwargs):
...
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}
)

async def set_group_ban(self, *args, **kwargs):
...
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, *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, *args, **kwargs):
...
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, *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})

async def set_group_name(self, *args, **kwargs):
...
async def set_group_name(self, group_id: int, group_name: str):
return await self.post('/set_group_name', data={'group_id': group_id, 'group_name': group_name})

async def set_group_leave(self, *args, **kwargs):
...
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, *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,
},
)

async def set_group_add_request(self, *args, **kwargs):
...
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,
},
)

async def get_login_info(self, *args, **kwargs):
...
async def get_login_info(self):
return await self.post('/get_login_info')

async def get_stranger_info(self, *args, **kwargs):
...
async def get_stranger_info(self, user_id: int, no_cache: bool = False):
return await self.post('/get_stranger_info', data={'user_id': user_id, 'no_cache': no_cache})

async def get_friend_list(self, *args, **kwargs):
...
async def get_friend_list(self):
return await self.post('/get_friend_list')

async def get_group_info(self, *args, **kwargs):
...
async def get_group_info(self, group_id: int, no_cache: bool = False):
return await self.post('/get_group_info', data={'group_id': group_id, 'no_cache': no_cache})

async def get_group_list(self, *args, **kwargs):
...
async def get_group_list(self):
return await self.post('/get_group_list')

async def get_group_member_info(self, *args, **kwargs):
...
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,
},
)

async def get_group_member_list(self, *args, **kwargs):
...
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, *args, **kwargs):
...
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, *args, **kwargs):
...
async def get_cookies(self, domain: str):
return await self.post('/get_cookies', data={'domain': domain})

async def get_csrf_token(self, *args, **kwargs):
...
async def get_csrf_token(self):
return await self.post('/get_csrf_token')

async def get_credentials(self, *args, **kwargs):
...
async def get_credentials(self, domain: str):
return await self.post('/get_credentials', data={'domain': domain})

async def get_record(self, *args, **kwargs):
...
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, *args, **kwargs):
...
async def get_image(self, file: str):
return await self.post('/get_image', data={'file': file})

async def can_send_image(self, *args, **kwargs):
...
async def can_send_image(self):
return await self.post('/can_send_image')

async def can_send_record(self, *args, **kwargs):
...
async def can_send_record(self):
return await self.post('/can_send_record')

async def get_status(self, *args, **kwargs):
...
async def get_status(self):
return await self.post('/get_status')

async def get_version_info(self, *args, **kwargs):
...
async def get_version_info(self):
return await self.post('/get_version_info')

async def set_restart(self, *args, **kwargs):
...
async def set_restart(self, delay: int = 0):
return await self.post('/set_restart', data={'delay': delay})

async def clean_cache(self, *args, **kwargs):
...
async def clean_cache(self):
return await self.post('/clean_cache')
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 f3e7282

Please sign in to comment.