Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
musnows committed Jan 16, 2023
2 parents b08309d + ba3234a commit 937206e
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 175 deletions.
43 changes: 16 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>

## 功能
当前机器人基本完善,目前支持回复Valorant游戏错误码、查询Valorant每日商店/夜市/vp/r点,和一些简单功能。
当前机器人基本完善,目前支持回复Valorant游戏错误码、查询Valorant每日商店/夜市/vp/r点,和一些简单功能。邮箱验证用户登录也已添加。

下面是目前支持的功能列表:

Expand All @@ -29,7 +29,6 @@
| `/Ahri` | 回复使用帮助(因`/help`和其他机器人冲突,故用阿狸的英文名`Ahri`替代) |
| `/vhelp` | Valorant相关查询功能的帮助命令 |

关于商店查询的**初步功能**已经添加,但是其`稳定性/是否封号`未知,建议**谨慎**使用!


| 游戏相关 | 功能 |
Expand All @@ -42,7 +41,7 @@
| `/logout` | 退出riot账户登录 |
| `/shop` | 获取每日商店的4个皮肤 |
| `/night` | 获取夜市的6个皮肤 |
| `/uinfo``/point` | 获取玩家卡面和称号,剩余vp和r点 |
| `/uinfo``/point` | 获取玩家卡面和称号,剩余vp和r点 |
| `/notify-a 皮肤名` | 搜索皮肤名,并提供选项将指定皮肤加入商店提醒 |
| `/notify-l` | 查看当前已经设置了提醒的皮肤 |
| `/notify-d 皮肤uuid` | 使用uuid删除不需要提醒的皮肤 |
Expand All @@ -56,17 +55,11 @@
|`/rts 序号 打分 吐槽`|选中皮肤序号,给该皮肤打个分(0~100) 再吐槽一下!|
|`/kkn`|查看昨日评分最高/最低的用户|

更多vip用户的特殊功能
每日商店刷枪提醒功能 `/notify-a` 需要用户**保持登录状态**,bot会在每天的`08:00AM`遍历列表,查看您的商店是否刷出了您想要的皮肤;如果是vip用户,则会直接发送当日商店的图片。

>* 「全新商店返回值」vip用户将获取到16-9的超帅商店返回值
>* 「保存登录信息」vip用户登陆后,阿狸会自动保存您的cookie。在阿狸维护重启的时候,您的登录信息不会丢失
>* 「早八商店提醒」阿狸将在早8点获取vip用户的每日商店并私聊发图给用户,同时会对这张图片进行缓存,当天使用/shop命令的时候,只需2s获取结果,三倍于普通用户的响应速度!
>
>目前商店查询背景图diy支持16-9(横屏)的图片,图片url获取:`PC端将图片上传到kook→点击图片→底部...处复制图片链接→使用/vip-shop命令设置背景` [教程图](https://img.kookapp.cn/assets/2022-12/nICYcewY8a0u00yt.png)
>
>请不要设置违规图片(擦边也不行)!若因为您上传违禁图片后导致阿狸被封,您将被剥夺vip并永久禁止兑换vip
cookie 登录信息将在2-3天后失效,所以皮肤提醒功能会出现用户没有登录而无法获取的情况。

每日商店刷枪提醒功能需要用户**保持登录状态**,bot会在每天的`08:01`遍历列表,查看您的商店是否刷出了您想要的皮肤
`/rate` 参与的打分,其会显示在 `/shop` 商店查询结果的尾部,同时统计当日商店最高分和最低分,可以在第二天用 `/kkn` 来查看。

| 其他命令 | 功能 |
| ----------------- | ------------------------------------------------------------ |
Expand Down Expand Up @@ -99,6 +92,8 @@
<img src="./screenshot/vip_daily_shop.png" height="300px" alt="vip_shop">
</details>

----

### valorant-shop-img-api

> Api源码见 [api.py](./code/api.py)
Expand All @@ -123,13 +118,9 @@ Api请求返回示例图:
pip install -r requirements.txt
~~~

> Q:为何`khl.py`只需要3.6.8以上版本,而本仓库需要3.8+?
>
> A:因为Valorant的第三方`Python Api`需要3.8+版本
建议根据[khl.py](https://github.com/TWT233/khl.py)`example`教程,学习KOOK机器人的基本搭建(很简单的,相信我)
建议根据 [khl.py/example](https://github.com/TWT233/khl.py/tree/main/example) 的教程,学习KOOK机器人的基本搭建(很简单的,相信我)

如果你想直接使用本机器人,可以转到本仓库[WIKI](https://github.com/Aewait/Valorant-kaiheila-bot/wiki)查看更多引导内容
如果你想直接使用本机器人,可以转到本仓库 [WIKI](https://github.com/Aewait/Valorant-kaiheila-bot/wiki) 查看更多引导内容

----

Expand All @@ -148,9 +139,7 @@ pip install -r requirements.txt
- [ ] 以类似抽卡的方式,用按钮、图片等等方式显示用户的夜市
- [ ] Api增加使用Riot Token调用的接口,方便本地管理登录信息,调用api画图

~~由于很多人在使用类似商店查询软件后被ban,我决定正式停止相关功能的开发~~

咳咳,虽然初步的商店查询功能已经上线,但是其是否`封号`依旧有争论!目前功能已经上线一个月有余,且询问过外网开发者,其表示没有听说过有人因为使用api被封号。
咳咳,虽然初步的商店查询功能已经上线,但是其是否`封号`依旧有争论!目前功能已经上线半年有余,未出现异常现象;且询问过外网开发者,其表示没有听说过有人因为使用api查询而被封号。

**如果您担心风险,请不要使用相关功能**!bot的`/vhelp`命令`/login`命令中有相关警告提示,使用即代表您同意了承担风险!

Expand All @@ -161,16 +150,16 @@ pip install -r requirements.txt
## 依赖

由于本人压根没有系统的学过Python,所以本仓库的很多代码都是根据他人教程修改后使用的
* 基本框架参考[khl.py](https://github.com/TWT233/khl.py)提供的`kook sdk`以及使用教程
* Valorant游戏`leaderboard`排行榜获取基于 [frissyn/valorant.py](https://github.com/frissyn/valorant.py/) 提供的`sdk`
* Valorant游戏主要查询代码基于 [ValorantClientAPI](https://github.com/HeyM1ke/ValorantClientAPI) 项目提供的`api文档`
* 基本框架参考[khl.py](https://github.com/TWT233/khl.py)提供的 `kook sdk` 以及使用教程
* Valorant游戏皮肤/捆绑包/玩家卡面等素材源自 [valorant-api.com](https://valorant-api.com/)
* Valorant游戏主要商店查询代码基于 [ValorantClientAPI](https://github.com/HeyM1ke/ValorantClientAPI) 项目提供的 `api文档`
* 通过账户密码获取 `riot_auth_token` 基于 [floxay/python-riot-auth](https://github.com/floxay/python-riot-auth) 项目


### 特别鸣谢🎁
* [@DeeChael](https://github.com/DeeChael) for helping me debug
* [@Edint386](https://github.com/Edint386) for adding `PIL_code` for `/shop`
* [@staciax](https://github.com/staciax) for [Valorant-DiscordBot/issues/74](https://github.com/staciax/Valorant-DiscordBot/issues/74)
* [@DeeChael](https://github.com/DeeChael) 帮我 debug
* [@Edint386](https://github.com/Edint386) 帮助添加了 `PIL` 代码来进行 `/shop` 的画图
* [@staciax](https://github.com/staciax) for [Valorant-DiscordBot/issues/74](https://github.com/staciax/Valorant-DiscordBot/issues/74) & [issues/97](https://github.com/staciax/Valorant-DiscordBot/issues/97)


### 支持本项目😘
Expand Down
53 changes: 17 additions & 36 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ KOOK(once called kaiheila) is a Chinese voice communication software.

>Because this bot are only used in Chinese platform,so I didn't write a more detail Readme in English.Sorry for that
I just develop basic `/login` and `/shop` to fetch daily shop, hoping it's save for using

* night market check as `/night` command was publish at `v0.2.4`

----

## Command

Expand Down Expand Up @@ -59,9 +54,9 @@ Recommended to use after the Valorant_Function is stable.
|`/rts NO. point comment`|select skin_no. to rate a point(0~100) and leave a comment to it|
|`/kkn`|checkout yesterday's heighest/lowest rate_point of daily shop |

notify function require user to stay `login`, bot wil fetch your daily shop at `08:01AM GMT+8` .If the skin is in daily shop, bot will send a private message to user.
notify function require user to stay `login`, bot wil fetch your daily shop at `08:00AM GMT+8` .If the skin is in daily shop, bot will send a private message to user.

If the user is a vip, the bot will also send the full picture of the store on that day through private message.
If the user is a vip, the bot will also send the full picture of the daily-shop on that day through private message.

>Because the bot is only using in Chinese platform, the skin `name` only support `zh-TW`
Expand Down Expand Up @@ -93,56 +88,42 @@ You can find image examples for the functions in [screenshot](./screenshot) flod

<img src="./screenshot/night.png" height="300px" alt="night">

<img src="./screenshot/val_api_img.png" height="300px" alt="api_shop_img">

</details>

For more guild and information, check out [wiki pages](https://github.com/Aewait/Valorant-kaiheila-bot/wiki)

----

## Breaking Changes at `V0.2.0`
First Breaking Changes for bot
## 1. publish vip!
### 1.1 add vip daily shop reply
vip user will get different daily shop reply from bot.
* normal user get `1000*1000` img
* vip user get `1280*720` img
## How to used?


this background can be modified by vip-user,using picture they liked!
make sure your Windows/Linux `Python` version `3.8+`

<img src="./screenshot/vip_daily_shop.png" height="290px" alt="vip_shop">
~~~
pip install -r requirements.txt
~~~

### 1.2 add special command for vip user
* `vip-u`: get vip from uuid
* `vip-c`: check remaining time for vip
* `vip-l`: list vip user
* `vip-shop`: vip user can modify their background of daily shop
It is highly recommand to checkout [khl.py/example](https://github.com/TWT233/khl.py/tree/main/example) first for basic kook bot init

### 1.3 more great fuctions!
* vip user will get automatic daily shop reply at `8AM BJS`
* bot will log vip user daily shop img, next time when vip user use `/shop` command, bot will upload it from local path instead of drawing the img,which will save `2-3s` of response time
* using `aiohttp cookie_jar` to save vip user cookie, don't need to login again when bot restart because of maintenance。
If you want to use this bot, go [WIKI](https://github.com/Aewait/Valorant-kaiheila-bot/wiki) for more infomation

## 2. other changes
* `add_date` will fetch `debug_channel` at start,don't need to fetch every time when exception
* change err reply to card message, bot will update msg instead of replying a new one when using `/shop` or `/uinfo`
* add `class icon` for easy manage icon-url

---

## About

Many codes in this repo are modified and used according to others' tutorials
* KOOK_api base on [khl.py](https://github.com/TWT233/khl.py)
* ValorantGameApi base on [frissyn/valorant.py](https://github.com/frissyn/valorant.py/)
* KOOK Bot base on [khl.py](https://github.com/TWT233/khl.py)
* Valorant Skin Api base on [valorant-api.com](https://valorant-api.com/)
* Main fetch_code base on [ValorantClientAPI](https://github.com/HeyM1ke/ValorantClientAPI)
* Fetch riot_auth_token base on [floxay/python-riot-auth](https://github.com/floxay/python-riot-auth)
* Fetch riot_auth_token base on [floxay/python-riot-auth](https://github.com/floxay/python-riot-auth) &


### Special Thanks🎁
* [@DeeChael](https://github.com/DeeChael) for helping me debug
* [@Edint386](https://github.com/Edint386) for adding PIL_code for `/shop`
* [@staciax](https://github.com/staciax) for [Valorant-DiscordBot/issues/74](https://github.com/staciax/Valorant-DiscordBot/issues/74)
* [@staciax](https://github.com/staciax) for [Valorant-DiscordBot/issues/74](https://github.com/staciax/Valorant-DiscordBot/issues/74) & [issues/97](https://github.com/staciax/Valorant-DiscordBot/issues/97)


If you like this project,please hit a star!✨
> sorry for my poor English
If you like this project,please hit a star!✨
12 changes: 9 additions & 3 deletions code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async def get_dailshop_img(request):
else:
return web.Response(body=json.dumps(ret,ensure_ascii=False), content_type='application/json')
except:
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{traceback.format_exc()}'},ensure_ascii=False), content_type='application/json')
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-img\n{err_cur}")
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{err_cur}'},ensure_ascii=False), content_type='application/json')

# 获取图片url
@routes.get('/shop-url')
Expand All @@ -36,7 +38,9 @@ async def get_dailshop_img(request):
ret = await base_img_request(request)
return web.Response(body=json.dumps(ret,ensure_ascii=False), content_type='application/json')
except:
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{traceback.format_exc()}'},ensure_ascii=False), content_type='application/json')
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /shop-url\n{err_cur}")
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{err_cur}'},ensure_ascii=False), content_type='application/json')

@routes.post('/tfa')
async def get_dailshop_img(request):
Expand All @@ -45,7 +49,9 @@ async def get_dailshop_img(request):
ret = await tfa_code_requeset(request)
return web.Response(body=json.dumps(ret,ensure_ascii=False), content_type='application/json')
except:
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{traceback.format_exc()}'},ensure_ascii=False), content_type='application/json')
err_cur = traceback.format_exc()
print(f"[{GetTime()}] [Api] ERR in /tfa\n{err_cur}")
return web.Response(body=json.dumps({'code':200,'message': 'unkown err','info':f'未知错误','except':f'{err_cur}'},ensure_ascii=False), content_type='application/json')


print(f"[API Start] starting at {GetTime()}")
Expand Down
8 changes: 4 additions & 4 deletions code/endpoints/ApiHandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import time
import threading
import aiofiles
import traceback
from endpoints.EzAuth import auth_exceptions,auth2fa,auth2faWait,Get2faWait_Key,User2faCode
from endpoints.ApiToken import token_ck,ApiTokenDict,save_token_files
from endpoints.Gtime import GetTime
Expand Down Expand Up @@ -78,7 +78,7 @@ async def base_img_request(request):
print(f"ERR! [{GetTime()}] login - riot_auth.riot_auth.auth_exceptions.RiotRatelimitError")
return {'code': 200, 'message': "riot_auth.auth_exceptions.RiotRatelimitError",'info':'riot登录api超速,请稍后重试'}
except Exception as result:
print(f"ERR! [{GetTime()}] login - {result}")
print(f"ERR! [{GetTime()}] login\n{traceback.format_exc()}")
return {'code': 200, 'message': f"{result}",'info':'riot登录错误,详见message'}

print(f'[{GetTime()}] [Api] k:{key} - user auth success')
Expand All @@ -90,7 +90,6 @@ async def base_img_request(request):
resp = await fetch_daily_shop(userdict) #获取每日商店
print(f'[{GetTime()}] [Api] fetch_daily_shop success')
list_shop = resp["SkinsPanelLayout"]["SingleItemOffers"] # 商店刷出来的4把枪
res_vprp = await fetch_vp_rp_dict(userdict) # 获取vp和r点

# 自定义背景
if 'img_src' in params:
Expand All @@ -105,9 +104,10 @@ async def base_img_request(request):
if 'img_ratio' in params and params['img_ratio']=='1':
ret = await get_shop_img_11(list_shop,bg_img_src=img_src)
else:
res_vprp = await fetch_vp_rp_dict(userdict) # 只有16-9的图片需获取vp和r点
ret = await get_shop_img_169(list_shop,vp=res_vprp['vp'],rp=res_vprp['rp'],bg_img_src=img_src)
# 打印计时
print("[IMGdraw]",format(time.perf_counter() - start, '.2f'))# 结果为浮点数,保留两位小数
print(f"[{GetTime()}] [IMGdraw]",format(time.perf_counter() - start, '.2f'))# 结果为浮点数,保留两位小数

start = time.perf_counter()
if ret['status']:
Expand Down
13 changes: 7 additions & 6 deletions code/endpoints/ApiToken.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
import json
import time
from endpoints.Gtime import GetTime

# 所有token
with open("./log/ApiToken.json", 'r', encoding='utf-8') as frpr:
Expand All @@ -14,9 +15,9 @@ def get_uuid():

def save_token_files(text=''):
global ApiTokenDict
with open("./log/UserToken.json", 'w', encoding='utf-8') as fw2:
with open("./log/ApiToken.json", 'w', encoding='utf-8') as fw2:
json.dump(ApiTokenDict, fw2, indent=2, sort_keys=True, ensure_ascii=False)
print(f"[token] files saved! {text}")
print(f"[{GetTime()}] [API token] files saved! [{text}]")

# 生成uuid
def create_token_uuid(num: int = 10, day: int = 30):
Expand Down Expand Up @@ -53,7 +54,7 @@ def create_token_uuid(num: int = 10, day: int = 30):
for uuid in NewUuid:
text += f"{uuid}" + "\n"

print(f"[token] create_token_uuid - num:{num} - day:{day}")
print(f"[{GetTime()}] [token] create_token_uuid - num:{num} - day:{day}")
return text

# 检查用户token是否失效或者不是token
Expand All @@ -71,13 +72,13 @@ async def token_ck(token:str):
del ApiTokenDict['data'][token]
# 更新uuid
save_token_files("token expire")
print(f"[token-ck] T:{token} out of date")
print(f"[{GetTime()}] [token-ck] T:{token} out of date")
return False
else:#没有过期,返回真
print(f"[token-ck] T:{token} is token")
print(f"[{GetTime()}] [token-ck] T:{token} is token")
return True
else:#token不在
print(f"[token-ck] T:{token} not token")
print(f"[{GetTime()}] [token-ck] T:{token} not token")
return False


Expand Down
Loading

0 comments on commit 937206e

Please sign in to comment.