Skip to content

Commit

Permalink
Merge pull request #8 from Valorant-Shop-CN/develop
Browse files Browse the repository at this point in the history
chome(1.1.0): release v1.1.0
  • Loading branch information
musnows committed Mar 3, 2023
2 parents f30571a + 26b74c4 commit 986df07
Show file tree
Hide file tree
Showing 20 changed files with 1,279 additions and 925 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@



<h1 align="center">Kook-Valorant--bot</h1>
<h1 align="center">Kook-Valorant-Bot</h1>


<h4 align="center">这是一个KOOK的「Valorant」小机器人</h4>
Expand Down
98 changes: 79 additions & 19 deletions code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import traceback
from aiohttp import web
from utils.Gtime import GetTime
from utils.api.ApiHandler import tfa_code_requeset, afd_request, login_img_request, img_draw_request
from utils.api import ApiHandler

# 初始化节点
routes = web.RouteTableDef()


# 基础返回
@routes.get('/')
def hello_world(request): # put application's code here
async def hello_world(request): # put application's code here
print(f"[{GetTime()}] [request] /")
return web.Response(body=json.dumps(
{
'code': 0,
'message': 'Hello! Use path /shop-url or /shop-img to get valorant daily shop',
'message': 'Hello! Use path /shop or /shop-img to get valorant daily shop',
'info':
'在path后添加/shop-img或者/shop-url来获取每日商店,前者会直接跳转,后者返回一个带图片url的json。示例: /shop-url?account=Riot账户&passwd=Riot密码&img_src=可选参数,自定义背景图',
'在path后添加/shop-img或者/shop来获取每日商店,前者会直接跳转,后者返回一个带图片url的json。示例: /shop?account=Riot账户&passwd=Riot密码&img_src=可选参数,自定义背景图',
'docs': 'https://github.com/Aewait/Kook-Valorant-Bot/blob/main/docs/valorant-shop-img-api.md'
},
indent=2,
Expand All @@ -29,15 +29,15 @@ def hello_world(request): # put application's code here

# 提供4个皮肤uuid,返回图片
@routes.get('/shop-draw')
async def get_dailshop_img(request):
async def get_shop_draw(request):
print(f"[{GetTime()}] [request] /shop-draw")
try:
ret = await img_draw_request(request)
ret = await ApiHandler.img_draw_request(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-url\n{err_cur}")
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -54,10 +54,10 @@ async def get_dailshop_img(request):

# 直接跳转图片(浏览器访问,get方法不安全)
@routes.get('/shop-img')
async def get_dailshop_img(request):
async def get_shop_img(request):
print(f"[{GetTime()}] [request] /shop-img")
try:
ret = await login_img_request(request)
ret = await ApiHandler.login_request(request,"GET")
if ret['code'] == 0:
return web.Response(headers={'Location': ret['message']}, status=303) # 303是直接跳转到图片
else:
Expand All @@ -80,17 +80,17 @@ async def get_dailshop_img(request):
content_type='application/json')


# 获取图片url
@routes.post('/shop')
async def get_dailshop_img(request):
print(f"[{GetTime()}] [request] /shop")
# 登录接口
@routes.post('/login')
async def post_login(request):
print(f"[{GetTime()}] [request] /login")
try:
ret = await login_img_request(request,"POST")
ret = await ApiHandler.login_request(request,"POST")
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-url\n{err_cur}")
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
return web.Response(body=json.dumps(
{
'code': 200,
Expand All @@ -104,12 +104,12 @@ async def get_dailshop_img(request):
status=200,
content_type='application/json')


# 邮箱验证登录
@routes.post('/tfa')
async def post_tfa_code(request):
print(f"[{GetTime()}] [request] /tfa")
try:
ret = await tfa_code_requeset(request)
ret = await ApiHandler.tfa_code_requeset(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
Expand All @@ -127,17 +127,77 @@ async def post_tfa_code(request):
ensure_ascii=False),
status=200,
content_type='application/json')

@routes.post('/shop')
async def post_shop(request):
print(f"[{GetTime()}] [request] /shop")
try:
body = await request.content.read()
params = json.loads(body.decode('UTF8'))
# 判断必须要的参数是否齐全
if 'account' not in params or 'token' not in params: # 不全,报错
print(f"ERR! [{GetTime()}] params needed: token/account/passwd")
ret = {
'code': 400,
'message': 'params needed: token/account/passwd',
'info': '缺少参数!示例: /shop-img?token=api凭证&account=Riot账户&passwd=Riot密码&img_src=自定义背景图(可选)',
'docs': 'https://github.com/Aewait/Kook-Valorant-Bot/blob/main/docs/valorant-shop-img-api.md'
}
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
# 画图请求,不需要检测token速率
ret = await ApiHandler.shop_get_request(params,params['account'])
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop\n{err_cur}")
return web.Response(body=json.dumps(
{
'code': 200,
'message': 'unkown err',
'info': f'未知错误',
'except': f'{err_cur}'
},
indent=2,
sort_keys=True,
ensure_ascii=False),
status=200,
content_type='application/json')

# 用于控制db中ShopCmp的更新
@routes.post('/shop-cmp')
async def post_shop_cmp(request):
print(f"[{GetTime()}] [request] /shop-cmp")
try:
ret = await ApiHandler.shop_cmp_request(request)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json',status=200)
except:
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-cmp\n{err_cur}")
return web.Response(body=json.dumps(
{
'code': 200,
'message': 'unkown err',
'info': f'未知错误',
'except': f'{err_cur}'
},
indent=2,
sort_keys=True,
ensure_ascii=False),
status=200,
content_type='application/json')

from main import bot


# 爱发电的wh
from main import bot
@routes.post('/afd')
async def aifadian_webhook(request):
print(f"[{GetTime()}] [request] /afd")
try:
ret = await afd_request(request, bot)
ret = await ApiHandler.afd_request(request, bot)
return web.Response(body=json.dumps(ret, indent=2, sort_keys=True, ensure_ascii=False),
content_type='application/json')
except:
Expand Down
8 changes: 6 additions & 2 deletions code/config/config.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
},
"leancloud":{
"appid":"leancloud数据库的appid(可联系作者,共用皮肤评价数据库)",
"master_key":"leancloud数据库的masterkey"
"appkey":"leancloud数据库的appkey",
"master_key":"leancloud数据库的masterkey",
"user_name":"数据库内置用户id",
"user_pwd":"数据库内置用户密码"
},
"no":1000
"no":1000,
"platform":"kook"
}
Loading

0 comments on commit 986df07

Please sign in to comment.