Skip to content

Commit 9e4028a

Browse files
committed
更新:服务器查询图片化
1 parent 9d67a95 commit 9e4028a

28 files changed

+115
-9
lines changed

Group.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
@sche.schedule(timers.every_custom_seconds(60))
4949
async def Schedule_Task():
5050
UseTime = time.strftime('%H:%M', time.localtime(time.time()))
51-
if UseTime == "8:00":
51+
if UseTime == "08:00":
5252
for i in range(len(ScheduleGroup)):
5353
await app.sendGroupMessage(ScheduleGroup[i], MessageChain.create([Image.fromLocalFile("./Menhera/121.png"), Plain("早早早(*´▽`)ノノ")]))
5454
elif UseTime == "12:00":
@@ -69,7 +69,7 @@ async def Schedule_Task():
6969
async def battlefield(message: MessageChain, app: GraiaMiraiApplication, group: Group, member: Member):
7070
MessageStr = message.asDisplay()
7171
if group.id in WhiteGroup:
72-
if MessageStr.startswith("/服务器") or MessageStr.startswith("/武器") or MessageStr.startswith("/载具") or MessageStr.startswith("/最近"):
72+
if MessageStr.startswith("/武器") or MessageStr.startswith("/载具") or MessageStr.startswith("/最近"):
7373
if member.id in BlackId:
7474
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Plain("哼(╯▔皿▔)╯,不理你了!")]))
7575
else:
@@ -85,7 +85,15 @@ async def battlefield(message: MessageChain, app: GraiaMiraiApplication, group:
8585
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Image.fromNetworkAddress(avatar), Plain("\n" + MessageStr)]))
8686
else:
8787
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Plain("\n" + MessageGet)]))
88-
88+
elif MessageStr.startswith("/服务器"):
89+
if member.id in BlackId:
90+
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Plain("哼(╯▔皿▔)╯,不理你了!")]))
91+
else:
92+
MessageGet = await BFservers(member.id, MessageStr)
93+
if MessageGet.startswith("./"):
94+
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Image.fromLocalFile(MessageGet)]))
95+
else:
96+
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Plain("\n" + MessageGet)]))
8997
elif MessageStr.startswith("/帮助"):
9098
await app.sendGroupMessage(group, MessageChain.create([At(member.id), Plain("\n" + await BFservers(member.id, MessageStr))]))
9199
elif MessageStr.startswith("/绑定"):
@@ -203,8 +211,7 @@ async def AutoReply_Friend_listener(message: MessageChain, app: GraiaMiraiApplic
203211
async def Admin_Test(message: MessageChain, app: GraiaMiraiApplication, friend: Friend):
204212
if friend.id == Admin:
205213
if message.asDisplay().startswith("/test"):
206-
print(await app.groupList())
207-
# await app.sendFriendMessage(friend, MessageChain.create([Plain(MessageGet)]))
214+
await app.sendFriendMessage(friend, MessageChain.create([Plain("ok")]))
208215

209216

210217
app.launch_blocking()

XunProxy.py

+19
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ async def aioRequest(url):
5656
except:
5757
i += 1
5858
return None
59+
60+
61+
async def PicDownload(url):
62+
file_name = "./pic" + url[url.rfind('/'):]
63+
try:
64+
fp = open(file_name, 'rb')
65+
fp.close()
66+
return file_name
67+
except:
68+
async with aiohttp.ClientSession() as session:
69+
try:
70+
async with session.get(url, timeout=5, headers=headers, verify_ssl=False) as resp:
71+
pic = await resp.read()
72+
fp = open(file_name, 'wb')
73+
fp.write(pic)
74+
fp.close()
75+
return file_name
76+
except:
77+
return "./pic/play.png"

battlefield.py

+60-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import opencc
44
import csv
55
import re
6+
import time
67
import asyncio
8+
import random
9+
from PIL import Image, ImageDraw, ImageFont
710
from bs4 import BeautifulSoup
8-
from XunProxy import aioRequest
11+
from XunProxy import aioRequest, PicDownload
12+
from picture import AlphaPicOverlay
913

1014
cc = opencc.OpenCC('t2s')
1115

@@ -18,7 +22,7 @@ async def ServerList(name):
1822
if html is not None:
1923
data = json.loads(cc.convert(html))
2024
if len(data['servers']) == 0:
21-
return "未搜索到相关服务器或者EA服务器已经崩溃!"
25+
return "未能搜索到相关服务器。"
2226
else:
2327
returnStr = ""
2428
for i in range(len(data['servers'])):
@@ -31,6 +35,57 @@ async def ServerList(name):
3135
return "查询超时,请稍后再试!"
3236

3337

38+
async def PicServerList(name):
39+
if name == "":
40+
name = "[LSP]"
41+
url = "https://api.jobse.space/bf1/servers/?name=" + name + "&lang=zh-TW"
42+
bg = "./pic/server_bg" + str(random.randint(1, 4)) + ".png"
43+
SavePic = "./Temp/" + str(int(time.time())) + ".png"
44+
45+
html = await aioRequest(url)
46+
if html is not None:
47+
titleFont = ImageFont.truetype(u"./font/DFP_sougeitai_W5-d813b437.ttf", size=70)
48+
searchFont = ImageFont.truetype(u"./font/DFP_sougeitai_W5-d813b437.ttf", size=35)
49+
nameFont = ImageFont.truetype(u"./font/DFP_sougeitai_W5-d813b437.ttf", size=25)
50+
detailFont = ImageFont.truetype(u"./font/DFP_sougeitai_W5-d813b437.ttf", size=20)
51+
im = Image.open(bg)
52+
draw = ImageDraw.Draw(im)
53+
draw.text((300, 40), "伺服器列表", font=titleFont)
54+
draw.text((300, 120), "搜索内容:" + name.replace("%20", " "), font=searchFont)
55+
im.save(SavePic)
56+
data = json.loads(html)
57+
if len(data['servers']) == 0:
58+
im = Image.open(SavePic)
59+
draw = ImageDraw.Draw(im)
60+
draw.text((800, 500), "找不到伺服器", font=searchFont)
61+
draw.text((795, 545), "變更篩選條件並重試", font=nameFont)
62+
im.save(SavePic)
63+
else:
64+
for i in range(len(data['servers'])):
65+
title = str(data['servers'][i]['prefix'])
66+
queue = str(data['servers'][i]['serverInfo']) + "[" + str(data['servers'][i]['inQue']) + "]"
67+
pic = str(data['servers'][i]['url'])
68+
detail = str(data['servers'][i]['mode']) + " - " + str(data['servers'][i]['currentMap']) + " - 60HZ"
69+
70+
PicUrl = await PicDownload(pic)
71+
im = Image.open(SavePic)
72+
im1 = Image.open(PicUrl)
73+
im1.thumbnail((144, 84))
74+
im.paste(im1, (250, 200 + 100 * i))
75+
76+
draw = ImageDraw.Draw(im)
77+
draw.text((400, 210 + 100 * i), title, font=nameFont)
78+
draw.text((1400, 210 + 100 * i), queue, font=nameFont)
79+
draw.text((400, 250 + 100 * i), detail, font=detailFont)
80+
im.save(SavePic)
81+
AlphaPicOverlay(SavePic, "./pic/ping-best.png", SavePic, 1510, 210 + 100 * i)
82+
if i >= 7:
83+
break
84+
return SavePic
85+
else:
86+
return "查询超时,请稍后再试!"
87+
88+
3489
async def Stats(name):
3590
if name is None:
3691
return "未绑定昵称!请使用“/绑定+(空格)+[ID]”绑定昵称"
@@ -154,7 +209,8 @@ async def TempStats(name):
154209
general = stats[1].find_all(name="div", attrs={"class": "value"})
155210
content.append(''.join(re.findall('[0-9.,%]', general[5].string)))
156211
content.append(''.join(re.findall('[0-9.,%]', general[6].string)))
157-
returnStr = "昵称:" + name + "\n等级:" + content[0] + "\nKD:" + content[1] + "\n胜率:" + content[2] + "\n游戏时间:" + content[3] + "\nSPM:" + content[4] + "\n场均击杀:" + content[5] + "\nKPM:" + content[6] + "\n技巧值:" +content[7] + "\n精准度:" + content[8]
212+
returnStr = "昵称:" + name + "\n等级:" + content[0] + "\nKD:" + content[1] + "\n胜率:" + content[2] + "\n游戏时间:" + content[3] + "\nSPM:" + content[4] + "\n场均击杀:" + content[
213+
5] + "\nKPM:" + content[6] + "\n技巧值:" + content[7] + "\n精准度:" + content[8]
158214
except:
159215
return "查询昵称有误!"
160216
return returnStr
@@ -206,7 +262,7 @@ def FindBinding(id):
206262

207263
async def BFservers(id, command):
208264
if command.startswith("/服务器"):
209-
return await ServerList(command.replace("/服务器", "").replace(" ", ""))
265+
return await PicServerList(command.replace("/服务器 ", "").replace("/服务器", "").replace(" ", "%20"))
210266
elif command.startswith("/战绩"):
211267
if command.replace("/战绩", "") == "":
212268
return await Stats(FindBinding(id))

font/DFP_sougeitai_W5-d813b437.ttf

2.66 MB
Binary file not shown.
29.4 KB
Loading
29.4 KB
Loading
29 KB
Loading
27.3 KB
Loading
16.1 KB
Loading
20.9 KB
Loading
32.2 KB
Loading
25.3 KB
Loading
22.8 KB
Loading
13.7 KB
Loading
26.5 KB
Loading
23.2 KB
Loading
26.4 KB
Loading
31.4 KB
Loading
25.9 KB
Loading
27 KB
Loading
20.2 KB
Loading

pic/ping-best.png

160 Bytes
Loading

pic/server_bg1.png

726 KB
Loading

pic/server_bg2.png

750 KB
Loading

pic/server_bg3.png

726 KB
Loading

pic/server_bg4.png

964 KB
Loading

picture.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from PIL import Image, ImageDraw, ImageFont
2+
3+
4+
def AlphaPicOverlay(MotherImg, SonImg, SaveImg, x, y, Opacity=1):
5+
overlay = Image.open(SonImg)
6+
base = Image.open(MotherImg)
7+
bands = list(overlay.split())
8+
if len(bands) == 4:
9+
bands[3] = bands[3].point(lambda x: x * Opacity)
10+
overlay = Image.merge(overlay.mode, bands)
11+
base.paste(overlay, (x, y), overlay)
12+
base.save(SaveImg)

videolist.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BV13y4y1E7v9
2+
BV1RX4y1V7ap
3+
BV1Jr4y1A7kW
4+
BV1Vo4y1R7Vw
5+
BV13N411X7qa
6+
BV1zy4y1a7w9
7+
BV17K4y1U7rZ
8+
BV1vV411Y7LN
9+
BV15b4y1Q7Ez
10+
BV16X4y1V7C9
11+
BV1Yh411Q735
12+
BV1rv411Y7jF

0 commit comments

Comments
 (0)