first commit

This commit is contained in:
KimigaiiWuyi 2021-08-02 23:53:33 +08:00
parent 08c11a109a
commit 12056ad280
46 changed files with 403 additions and 1 deletions

View File

@ -1 +1,50 @@
# GenshinUID
# GenshinUID
一个HoshinoBot插件用于查询原神UID信息。
已完成:角色排序(星级>等级>好感),背景图自定义(通过传参形式)
未完成:深渊数据导出,角色详细信息列表(包括武器信息,和全角色)
示例: ![1](C:\Users\44483\Desktop\1.PNG)
- [安装](#安装)
- [指令](#指令)
- [相关仓库](#相关仓库)
- [使用许可](#使用许可)
## 安装
基于[Mrs4s](https://github.com/Mrs4s) / [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 和 [HoshinoBot](https://github.com/Ice-Cirno/HoshinoBot) 的插件请确保你知晓HoshinoBot的插件安装方法和go-cqhttp的使用方法。
1、在hoshino/modules目录下执行
```sh
$ git clone https://github.com/KimigaiiWuyi/GenshinUID.git
```
2、进入GenshinUID文件夹内安装依赖库
```sh
$ pip3 install -r requirements.txt
```
3、在GenshinUID的文件夹下打开getData.py修改其中三条cookies的值改成自己的
4、在hoshino/config的`__bot__.py`文件中添加GenshinUID
## 指令
1、触发词uid后面跟九位uid即可。
![Snipaste_2021-08-02_23-06-56](C:\Users\44483\Desktop\Snipaste_2021-08-02_23-06-56.png)
2、触发词后跟九位uid后跟一张任意大小的图片不能是GIF可以自定义背景
![Snipaste_2021-08-02_22-46-55](C:\Users\44483\Desktop\Snipaste_2021-08-02_22-46-55.png)
![Snipaste_2021-08-02_23-06-45](C:\Users\44483\Desktop\Snipaste_2021-08-02_23-06-45.png)
## 相关仓库
- [PaimonBot](https://github.com/XiaoMiku01/PaimonBot) - 插件原始代码来自于它

45
__init__.py Normal file
View File

@ -0,0 +1,45 @@
import re
#from nonebot import on_command
#from nonebot.adapters.cqhttp import Event, Bot, Message
from .getImg import draw_pic
from nonebot import *
import json
from random import randint
import requests,random,os,json,re
from hoshino import Service,R,priv,util
from hoshino.typing import MessageSegment,CQEvent, HoshinoBot
from hoshino.util import FreqLimiter,pic2b64
import hoshino
import asyncio
import time
import string
import random
import hashlib
import requests
import os
from PIL import Image,ImageFont,ImageDraw
from io import BytesIO
import base64
import urllib
sv = Service('genshinuid')
bot = get_bot()
FILE_PATH = os.path.dirname(__file__)
FILE2_PATH = os.path.join(FILE_PATH,'mys')
Texture_PATH = os.path.join(FILE2_PATH,'texture2d')
@sv.on_prefix('uid')
async def _(bot:HoshinoBot, ev: CQEvent):
image = re.search(r"\[CQ:image,file=(.*),url=(.*)\]", str(ev.message))
message = ev.message.extract_plain_text()
try:
uid = re.findall(r"\d+", message)[0] # str
im = await draw_pic(uid,ev.sender['nickname'],image)
await bot.send(ev, im, at_sender=True)
except:
await bot.send(ev,'输入错误!')

128
getData.py Normal file
View File

@ -0,0 +1,128 @@
# https://github.com/Womsxd/YuanShen_User_Info
#import hashlib
#import json
#import random
#import string
import sys
#import time
from httpx import AsyncClient
from nonebot import *
import json
from random import randint
import requests,random,os,json,re
from hoshino import Service,R,priv,util
from hoshino.typing import MessageSegment,CQEvent, HoshinoBot
from hoshino.util import FreqLimiter,pic2b64
import hoshino
import asyncio
import time
import string
import random
import hashlib
import requests
import os
from PIL import Image,ImageFont,ImageDraw
from io import BytesIO
import base64
mhyVersion = "2.7.0"
def cache_Cookie():
return random.choice(cookie_list)
def md5(text):
md5 = hashlib.md5()
md5.update(text.encode())
return md5.hexdigest()
def DSGet():
n = "fd3ykrh7o1j54g581upo1tvpam0dsgtf"
i = str(int(time.time()))
r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6))
c = md5("salt=" + n + "&t=" + i + "&r=" + r)
return (i + "," + r + "," + c)
async def GetInfo(Uid, ServerID="cn_gf01",Schedule_type="1"):
if Uid[0] == '5':
ServerID = "cn_qd01"
try:
async with AsyncClient() as client:
req = await client.get(
url="https://api-takumi.mihoyo.com/game_record/genshin/api/index?server=" + ServerID + "&role_id=" + Uid,
headers={
'Accept': 'application/json, text/plain, */*',
'DS': DSGet(),
'Origin': 'https://webstatic.mihoyo.com',
'x-rpc-app_version': mhyVersion,
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.2.0',
'x-rpc-client_type': '2',
'Referer': 'https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.8',
'X-Requested-With': 'com.mihoyo.hyperion',
"Cookie": ''})
data1 = json.loads(req.text)
async with AsyncClient() as client:
req = await client.get(
url="https://api-takumi.mihoyo.com/game_record/genshin/api/spiralAbyss?schedule_type=" + Schedule_type + "&server="+ ServerID +"&role_id=" + Uid,
headers={
'Accept': 'application/json, text/plain, */*',
'DS': DSGet(),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': '',#自己获取
'x-rpc-app_version': mhyVersion,
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.2.0',
'x-rpc-client_type': '2',
'Referer': 'https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.8',
'X-Requested-With': 'com.mihoyo.hyperion'
}
)
data2 = json.loads(req.text)
data = data1
#data3 = data1 + data2
#f=open("/root/hoshino/HoshinoBot/hoshino/modules/GenshinUID/mys/chars/666.txt",'w')
#f.write(str(data))
return data
except:
print("访问失败,请重试!")
sys.exit(1)
def GetCharacter(Uid,Character_ids, ServerID="cn_gf01"):
print("8")
if Uid[0] == '5':
ServerID = "cn_qd01"
try:
req = requests.post(
url = "https://api-takumi.mihoyo.com/game_record/genshin/api/character",
headers = {
'Accept': 'application/json, text/plain, */*',
'DS': DSGet(),
'Origin': 'https://webstatic.mihoyo.com',
'Cookie': '',#自己获取
'x-rpc-app_version': mhyVersion,
'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.2.0',
'x-rpc-client_type': '2',
'Referer': 'https://webstatic.mihoyo.com/app/community-game-records/index.html?v=6',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.8',
'X-Requested-With': 'com.mihoyo.hyperion'
},
json = {"character_ids": Character_ids ,"role_id": Uid ,"server": ServerID }
)
data2 = json.loads(req.text)
#f=open("/root/hoshino/HoshinoBot/hoshino/modules/Genshin/mys/chars/555.txt",'w')
#f.write(str(data2))
return data2
except:
print ("访问失败,请重试!")
#sys.exit (1)
return

176
getImg.py Normal file
View File

@ -0,0 +1,176 @@
import time
from base64 import b64encode
from io import BytesIO
import urllib
import math
from PIL import Image, ImageDraw, ImageFont, ImageFilter
from .getData import GetInfo,GetCharacter
import os
FILE_PATH = os.path.dirname(__file__)
FILE2_PATH = os.path.join(FILE_PATH,'mys')
CHAR_PATH = os.path.join(FILE2_PATH,'chars')
TEXT_PATH = os.path.join(FILE2_PATH,'texture2d')
def ys_font(size):
return ImageFont.truetype(os.path.join(FILE2_PATH,"yuanshen.ttf"), size=size)
async def draw_pic(uid,nickname,image = None):
is_edit = False
if image != None:
image_file= image.group(1)
image_data = image.group(2)
urllib.request.urlretrieve(f'{image_data}', os.path.join(TEXT_PATH,nickname + '.png'))
is_edit = True
raw_data = await GetInfo(uid)
if (raw_data["retcode"] != 0):
if (raw_data["retcode"] == 10001):
return ("Cookie错误/过期请重置Cookie")
return (
"Api报错返回内容为\r\n"
+ str(raw_data) + "\r\n出现这种情况可能的UID输入错误 or 不存在"
)
else:
pass
bg_path = os.path.join(TEXT_PATH,"bg.png")
bg2_path = os.path.join(TEXT_PATH,"bg_img.png")
fg_path = os.path.join(TEXT_PATH,"fg_img.png")
mask_path = os.path.join(TEXT_PATH,"mask_img.png")
if is_edit == True:
bg_path_edit = os.path.join(TEXT_PATH,f"{nickname}.png")
edit_bg = Image.open(bg_path_edit)
w, h = edit_bg.size
scale_f = w / h
scale = '%.4f' % scale_f
new_w = math.ceil(1200*float(scale))
new_h = math.ceil(800/float(scale))
if w > h:
bg_img2 = edit_bg.resize((new_w, 1200),Image.ANTIALIAS)
else:
bg_img2 = edit_bg.resize((800, new_h),Image.ANTIALIAS)
bg_img = bg_img2.crop((0, 0, 800, 1200))
else:
bg_img = Image.open(bg2_path)
raw_data = raw_data['data']
fg_img = Image.open(fg_path)
mask_img = Image.open(mask_path)
#img = Image.open(bg_path)
area = (37, 268, 764, 1154)
img_bb = bg_img.crop(area)
img_blur = img_bb.filter(ImageFilter.GaussianBlur(5))
bg_img.paste(img_blur, (37,268),mask_img)
bg_img.paste(fg_img,(0,0),fg_img)
text_draw = ImageDraw.Draw(bg_img)
text_draw.text((192.6,128.3), f"{nickname}", (217,217,217), ys_font(32))
text_draw.text((210.6, 165.3), 'UID ' + f"{uid}", (217,217,217), ys_font(14))
char_data = raw_data["avatars"]
index_char = ["神里绫华","","迪卢克","温迪","","可莉","钟离","达达利亚","七七","甘雨","阿贝多","莫娜","刻晴","胡桃","枫原万叶","优菈","丽莎","芭芭拉","凯亚","雷泽","安柏","香菱","北斗","行秋","凝光","菲谢尔","班尼特","诺艾尔","重云","迪奥娜","砂糖","辛焱","罗莎莉亚","烟绯","旅行者"]
five_star_char = ["神里绫华","","迪卢克","温迪","","可莉","钟离","达达利亚","七七","甘雨","阿贝多","莫娜","刻晴","胡桃","枫原万叶","优菈"]
four_star_char = ["丽莎","芭芭拉","凯亚","雷泽","安柏","香菱","北斗","行秋","凝光","菲谢尔","班尼特","诺艾尔","重云","迪奥娜","砂糖","辛焱","罗莎莉亚","烟绯","旅行者"]
for k in raw_data['avatars']:
if k['name'] in five_star_char:
k['star'] = 5
if k['name'] in four_star_char:
k['star'] = 4
if k['name'] == '旅行者':
k['star'] = 3
#char_data.sort(key=lambda x: index_char.index(x['name']))
char_data.sort(key=lambda x: (-x['star'],-x['level'],-x['fetter']))
text_draw.text((590, 94.8),str(raw_data['stats']['active_day_number']), (21, 21, 21), ys_font(26))
text_draw.text((590, 139.3),str(raw_data['stats']['achievement_number']), (21, 21, 21), ys_font(26))
text_draw.text((590, 183.9),raw_data['stats']['spiral_abyss'], (21, 21, 21), ys_font(26))
text_draw.text((635.4, 462.8), str(raw_data['stats']['anemoculus_number']), 'white', ys_font(26))
text_draw.text((635.4, 493.6), str(raw_data['stats']['geoculus_number']), 'white', ys_font(26))
text_draw.text((635.4, 524.8), str(raw_data['stats']['electroculus_number']), 'white', ys_font(26))
text_draw.text((224.6, 379.1),str(raw_data['stats']['common_chest_number']),'white', ys_font(28))
text_draw.text((436.5, 379.1),str(raw_data['stats']['exquisite_chest_number']),'white', ys_font(28))
text_draw.text((224.6, 416),str(raw_data['stats']['precious_chest_number']), 'white', ys_font(28))
text_draw.text((436.5, 416),str(raw_data['stats']['luxurious_chest_number']), 'white', ys_font(28))
text_draw.text((646.3, 379.1),str(raw_data['stats']['avatar_number']),'white', ys_font(26))
text_draw.text((646.3, 416),str(raw_data['stats']['way_point_number']),'white', ys_font(26))
text_draw.text((228.9, 502),str(raw_data['world_explorations'][3]['exploration_percentage']/10) + '%','white', ys_font(20))
text_draw.text((228.9, 538),'lv.' + str(raw_data['world_explorations'][3]['level']),'white', ys_font(20))
text_draw.text((451.1, 502),str(raw_data['world_explorations'][2]['exploration_percentage']/10) + '%','white', ys_font(20))
text_draw.text((451.1, 538),'lv.' + str(raw_data['world_explorations'][2]['level']),'white', ys_font(20))
text_draw.text((228.9, 606.4),str(raw_data['world_explorations'][1]['exploration_percentage']/10) + '%','white', ys_font(20))
text_draw.text((228.9, 641),'lv.' + str(raw_data['world_explorations'][1]['level']),'white', ys_font(20))
text_draw.text((451.1, 597),str(raw_data['world_explorations'][0]['exploration_percentage']/10) + '%','white', ys_font(20))
text_draw.text((451.1, 624),'lv.' + str(raw_data['world_explorations'][0]['level']),'white', ys_font(20))
text_draw.text((451.1, 652),'lv.' + str(raw_data['world_explorations'][0]['offerings'][0]['level']),'white', ys_font(20))
if len(raw_data['homes']):
text_draw.text((594.5, 565),'lv.' + str(raw_data['homes'][0]['level']),'white', ys_font(26))
text_draw.text((594.5, 598),str(raw_data['homes'][0]['visit_num']),'white', ys_font(26))
text_draw.text((594.5, 630),str(raw_data['homes'][0]['item_num']),'white', ys_font(26))
text_draw.text((594.5, 662),str(raw_data['homes'][0]['comfort_num']),'white', ys_font(26))
else:
text_draw.text((594.5, 616.6),'未开',(0, 0, 0), ys_font(26))
num = 0
for i in raw_data['avatars']:
if num < 15:
char = os.path.join(CHAR_PATH,str(char_data[num]['id']) + ".png")
char_img = Image.open(char)
char_draw = ImageDraw.Draw(char_img)
char_draw.text((38.6,108),f'Lv.{str(char_data[num]["level"])}',(21,21,21),ys_font(18))
char_draw.text((97,19),f'{str(char_data[num]["actived_constellation_num"])}','white',ys_font(18))
if str(char_data[num]["fetter"]) == "10":
char_draw.text((97,40),"F",(21,21,21),ys_font(17))
else:
char_draw.text((97,40),f'{str(char_data[num]["fetter"])}',(21,21,21),ys_font(18))
if num < 5:
char_crop = (74+133*num,750)
bg_img.paste(char_img,char_crop,char_img)
elif num >= 5 and num < 10:
char_crop = (74+133*(num-5),875)
bg_img.paste(char_img,(char_crop),char_img)
elif num >= 10 and num < 15:
char_crop = (74+133*(num-10),1000)
bg_img.paste(char_img,(char_crop),char_img)
else:
break
num = num+1
result_buffer = BytesIO()
bg_img.save(result_buffer, format='png')
imgmes = 'base64://' + b64encode(result_buffer.getvalue()).decode()
resultmes = f"[CQ:image,file={imgmes}]"
#return 'base64://' + b64encode(result_buffer.getvalue()).decode()
return resultmes
if __name__ == '__main__':
pass

BIN
mys/chars/10000002.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
mys/chars/10000003.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000005.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000006.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
mys/chars/10000007.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
mys/chars/10000014.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
mys/chars/10000015.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
mys/chars/10000016.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000020.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
mys/chars/10000021.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000022.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
mys/chars/10000023.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
mys/chars/10000024.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000025.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
mys/chars/10000026.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000027.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000029.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000030.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000031.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000032.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000033.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000034.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000035.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000036.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
mys/chars/10000037.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000038.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000039.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000041.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
mys/chars/10000042.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
mys/chars/10000043.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000044.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
mys/chars/10000045.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000046.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
mys/chars/10000047.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
mys/chars/10000048.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
mys/chars/10000051.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
mys/texture2d/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 KiB

BIN
mys/texture2d/bg_img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
mys/texture2d/fg_img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 KiB

BIN
mys/texture2d/mask_img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
mys/yuanshen.ttf Normal file

Binary file not shown.

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
nonebot==1.8.2
requests==2.25.1
httpx==0.18.1
Pillow==8.3.1