Skip to content

Commit

Permalink
合并dev分支
Browse files Browse the repository at this point in the history
  • Loading branch information
ImAmelie committed Jun 27, 2022
2 parents ef84e48 + 9319407 commit 7b1c4d2
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 50 deletions.
1 change: 1 addition & 0 deletions EVEBot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
nonebot.load_plugin('src.plugins.km')
nonebot.load_plugin('src.plugins.kb')
nonebot.load_plugin('src.plugins.checkServer')
nonebot.load_plugin('src.plugins.map') # 依赖 bind
nonebot.load_plugin('src.plugins.test')

# Please DO NOT modify this file unless you know what you are doing!
Expand Down
4 changes: 2 additions & 2 deletions EVEBot/src/plugins/bind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if not bind.bind :
bind.bind = {}

bind_function = on_regex(r'^[\.。](bind|绑定)\s*\S+')
bind_function = on_regex(r'^[\.。](bind|绑定) \s*\S+')
@bind_function.handle()
async def _(bot: Bot, event: Event):
global bind
Expand All @@ -49,7 +49,7 @@ async def _(bot: Bot, event: Event):

await bind_function.finish(message=Message('绑定成功'))

unbind_function = on_regex(r'^[\.。](unbind|解绑)\s*\S+')
unbind_function = on_regex(r'^[\.。](unbind|解绑) \s*\S+')
@unbind_function.handle()
async def _(bot: Bot, event: Event):
global bind
Expand Down
2 changes: 0 additions & 2 deletions EVEBot/src/plugins/checkServer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ async def check_server_every_1_time():
re = await client.get(url=f'https://esi.evetech.net/latest/status/?datasource=tranquility', headers=headers)
except:
return
if re.status_code != 200 :
return
re_json = re.json()
if 'start_time' in re_json :
if flag :
Expand Down
8 changes: 4 additions & 4 deletions EVEBot/src/plugins/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
content = {}
file.close()

load = on_regex(r'^[\.。](load|加载)\s*')
load = on_regex(r'^[\.。](load|加载)\s*$')
@load.handle()
async def _(bot: Bot, event: Event):
global content
Expand Down Expand Up @@ -61,7 +61,7 @@ async def _(bot: Bot, event: Event):
else:
await load.finish(message=Message(msg))

cmd = on_regex(r'^[\.。](cmd|a|gl|攻略)\s*\S+')
cmd = on_regex(r'^[\.。](cmd|a|gl|攻略) \s*\S+')
@cmd.handle()
async def _(bot: Bot, event: Event):
global content
Expand All @@ -87,7 +87,7 @@ async def _(bot: Bot, event: Event):
return
await cmd.finish(message=Message('标题不正确,请检查标题!'))

list_cmd = on_regex(r'^[\.。](list)\s*')
list_cmd = on_regex(r'^[\.。](list)\s*$')
@list_cmd.handle()
async def _(bot: Bot, event: Event):
global content
Expand All @@ -97,7 +97,7 @@ async def _(bot: Bot, event: Event):
if await util.isPass() or await util.isBan(event.user_id) :
return

msg = '关键字列表\n'
msg = '命令列表\n'

for k, _ in content.items() :
msg = msg + k + ' '
Expand Down
1 change: 1 addition & 0 deletions EVEBot/src/plugins/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def _(bot: Bot, event: Event):
'.tr / .tran / .翻译 <字符串> # 翻译\n'
'.kb / .zkb <name> # 查询人物基础信息\n'
'.tool / .工具 / .常用 # 常用工具网址\n'
'.map / .地图 # 翻译地图名称\n'
'管理员命令:\n'
'.bind / .绑定 <别名>,<物品名> \n'
'.unbind / .解绑 <别名>\n'
Expand Down
2 changes: 1 addition & 1 deletion EVEBot/src/plugins/jita/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

bind = pluginR('bind')

jita = on_regex(r'^[\.。](jita|吉他|jt)\s*\S+')
jita = on_regex(r'^[\.。](jita|吉他|jt) \s*\S+')
@jita.handle()
async def _(bot: Bot, event: Event):
global bind
Expand Down
2 changes: 0 additions & 2 deletions EVEBot/src/plugins/jita/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ async def get_price(name: str, num: int = 1):
re = await client.get(url=f'https://esi.evetech.net/latest/markets/10000002/orders/?datasource=tranquility&order_type=all&type_id={itemID}', headers=headers)
except:
return '连接服务器失败,请稍后尝试!'
if re.status_code != 200 :
return '连接服务器失败,请稍后尝试!'
re_json = re.json()
buy = 0
sell = 0
Expand Down
16 changes: 4 additions & 12 deletions EVEBot/src/plugins/kb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ async def _(bot: Bot, event: Event):
except:
await kb.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
if name_re.status_code != 200 :
await kb.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
name_json = name_re.json()

if 'character' in name_json :
Expand All @@ -48,9 +45,6 @@ async def _(bot: Bot, event: Event):
except:
await kb.finish(message=Message('zkb网连接失败,请稍后进行查询!'))
return
if zkb_re.status_code != 200 :
await kb.finish(message=Message('zkb网连接失败,请稍后进行查询!'))
return
zkb_json = zkb_re.json()

if zkb_json['info'] is None :
Expand Down Expand Up @@ -82,17 +76,15 @@ async def _(bot: Bot, event: Event):
if corporation_str is None and 'corporationID' in zkb_json['info'] :
try:
corporation_re = await client.get(url=f"https://esi.evetech.net/latest/corporations/{zkb_json['info']['corporationID']}/?datasource=tranquility", headers=headers)
if corporation_re.status_code == 200 :
corporation_json = corporation_re.json()
corporation_str = corporation_json['name'] + ' [' + corporation_json['ticker'] + ']'
corporation_json = corporation_re.json()
corporation_str = corporation_json['name'] + ' [' + corporation_json['ticker'] + ']'
except:
pass
if alliance_str is None and 'allianceID' in zkb_json['info'] :
try:
alliance_re = await client.get(url=f"https://esi.evetech.net/latest/alliances/{zkb_json['info']['allianceID']}/?datasource=tranquility", headers=headers)
if alliance_re.status_code == 200 :
alliance_json = alliance_re.json()
alliance_str = alliance_json['name'] + ' <' + alliance_json['ticker'] + '>'
alliance_json = alliance_re.json()
alliance_str = alliance_json['name'] + ' <' + alliance_json['ticker'] + '>'
except:
pass
if corporation_str is not None :
Expand Down
55 changes: 36 additions & 19 deletions EVEBot/src/plugins/km/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from nonebot.adapters.cqhttp import Event, Bot, Message
import nonebot
from nonebot.plugin import require as pluginR
from nonebot.log import logger
import sys
import time
import json
import asyncio
import httpx
import websockets
import ssl
import math
from pathlib import Path

driver=get_driver()
Expand Down Expand Up @@ -71,6 +74,7 @@ async def km():
try:
re = await websocket.recv()
except:
logger.error(f'websocket.recv() 错误 文件:{__file__} 行号:{sys._getframe().f_lineno}')
break

new_time = time.time()
Expand All @@ -97,8 +101,7 @@ async def km():
try:
zkb_re = await client.get(url=f'https://zkillboard.com/api/killID/{killID}/')
except:
continue
if zkb_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
zkb_json = zkb_re.json()

Expand All @@ -112,8 +115,7 @@ async def km():
try:
esi_re = await client.get(url=f'https://esi.evetech.net/latest/killmails/{killID}/{killHash}/?datasource=tranquility')
except:
continue
if esi_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
esi_json = esi_re.json()

Expand All @@ -132,8 +134,7 @@ async def km():
try:
ship_re = await client.get(url=f'https://esi.evetech.net/latest/universe/types/{ship_type_id}/?datasource=tranquility&language=zh', headers=headers)
except:
continue
if ship_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
ship_json = ship_re.json()
ship_name = ship_json['name']
Expand All @@ -147,26 +148,23 @@ async def km():
try:
dead_re = await client.get(url=f'https://esi.evetech.net/latest/characters/{dead_id}/?datasource=tranquility', headers=headers)
except:
continue
if dead_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
dead_json = dead_re.json()
dead_name = dead_json['name']
if 'corporation_id' in dead_json :
try:
dead_corporation_re = await client.get(url=f'https://esi.evetech.net/latest/corporations/{dead_json["corporation_id"]}/?datasource=tranquility', headers=headers)
except:
continue
if dead_corporation_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
dead_corporation_json = dead_corporation_re.json()
dead_corporation_ticker = '[' + dead_corporation_json['ticker'] + ']'
if 'alliance_id' in dead_json :
try:
dead_alliance_re = await client.get(url=f'https://esi.evetech.net/latest/alliances/{dead_json["alliance_id"]}/?datasource=tranquility', headers=headers)
except:
continue
if dead_alliance_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
dead_alliance_json = dead_alliance_re.json()
dead_alliance_ticker = '<' + dead_alliance_json['ticker'] + '>'
Expand All @@ -188,17 +186,15 @@ async def km():
try:
killer_re = await client.get(url=f'https://esi.evetech.net/latest/characters/{killer_id}/?datasource=tranquility', headers=headers)
except:
continue
if killer_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
killer_json = killer_re.json()
killer_name = killer_json['name']
if 'corporation_id' in killer_json :
try:
killer_corporation_re = await client.get(url=f'https://esi.evetech.net/latest/corporations/{killer_json["corporation_id"]}/?datasource=tranquility', headers=headers)
except:
continue
if killer_corporation_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
killer_corporation_json = killer_corporation_re.json()
killer_corporation_ticker = '[' + killer_corporation_json['ticker'] + ']'
Expand All @@ -208,8 +204,7 @@ async def km():
try:
killer_alliance_re = await client.get(url=f'https://esi.evetech.net/latest/alliances/{killer_json["alliance_id"]}/?datasource=tranquility', headers=headers)
except:
continue
if killer_alliance_re.status_code != 200 :
logger.error(f'文件:{__file__} 行号:{sys._getframe().f_lineno} killID:{killID}')
continue
killer_alliance_json = killer_alliance_re.json()
killer_alliance_ticker = '<' + killer_alliance_json['ticker'] + '>'
Expand All @@ -232,12 +227,34 @@ async def km():
region_re = await client.get(url=f'https://esi.evetech.net/latest/universe/regions/{region_id}/?datasource=tranquility&language=zh', headers=headers)
region_json = region_re.json()
region_name = region_json['name']
msg = msg + f'位置: {system_name} / {constellation_name} / {region_name}\n'
msg = msg + f'星系: {system_name} / {constellation_name} / {region_name}\n'
try:
moon_id = zkb_json[0]['zkb']['locationID']
moon_re = await client.get(url=f'https://esi.evetech.net/latest/universe/moons/{moon_id}/?datasource=tranquility', headers=headers)
moon_json = moon_re.json()
moon_name = moon_json['name']
dx = math.fabs(esi_json['victim']['position']['x'] - moon_json['position']['x'])
dy = math.fabs(esi_json['victim']['position']['y'] - moon_json['position']['y'])
dz = math.fabs(esi_json['victim']['position']['z'] - moon_json['position']['z'])
distance = math.sqrt(dx**2 + dy**2 + dz**2)
if distance >= 149597870700 * 0.1 :
distance = distance / 149597870700
unit = 'AU'
elif distance >= 1000 :
distance = distance / 1000
unit = 'km'
else:
unit = 'm'
msg = msg + f'位置: {moon_name} | 距离: {distance:,.2f} {unit}\n'
except:
pass
except:
pass

if zkb_json[0]['zkb']['solo'] == True :
msg = msg + 'SOLO\n'
else:
msg = msg + f'签名人数: {len(esi_json["attackers"])}\n'

msg = msg + '\n'

Expand Down
88 changes: 88 additions & 0 deletions EVEBot/src/plugins/map/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from nonebot import on_regex
from nonebot.adapters.cqhttp import Event, Bot, Message
from nonebot.plugin import require as pluginR
import httpx
import urllib.parse

tool = pluginR('tool')

util = pluginR('util')

bind = pluginR('bind')

headers = {"accept": "application/json", "Cache-Control": "no-cache"}

client = httpx.AsyncClient()

search_map = on_regex(r'^[\.。](map|地图) \s*\S+')
@search_map.handle()
async def _(bot: Bot, event: Event):
global bind

if not (event.message_type == 'group' and event.group_id in tool.group_ids) :
return

if await util.isPass() or await util.isBan(event.user_id) :
return

name = str(event.get_message()).split(' ', 1)[1].strip()

if name in bind.bind :
name = bind.bind[name]

if len(name) <= 2 :
name = f' {name} '

url_name = urllib.parse.quote(name)

input_lang = 'zh'
output_lang = 'en'

for i in range(2) :
try:
esi_re = await client.get(url=f'https://esi.evetech.net/latest/search/?categories=constellation,region,solar_system&datasource=tranquility&language={input_lang}&search={url_name}&strict=true', headers=headers)
except:
await search_map.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
esi_json = esi_re.json()
if ('region' not in esi_json) and ('constellation' not in esi_json) and ('solar_system' not in esi_json) :
input_lang = 'en'
output_lang = 'zh'
else:
break


if 'region' in esi_json :
region_id = esi_json['region'][0]
try:
region_re = await client.get(url=f'https://esi.evetech.net/latest/universe/regions/{region_id}/?datasource=tranquility&language={output_lang}', headers=headers)
except:
await search_map.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
region_json = region_re.json()
region_name = region_json['name']
msg = f'星域: {name} / {region_name}'
elif 'constellation' in esi_json :
constellation_id = esi_json['constellation'][0]
try:
constellation_re = await client.get(url=f'https://esi.evetech.net/latest/universe/constellations/{constellation_id}/?datasource=tranquility&language={output_lang}', headers=headers)
except:
await search_map.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
constellation_json = constellation_re.json()
constellation_name = constellation_json['name']
msg = f'星座: {name} / {constellation_name}'
elif 'solar_system' in esi_json :
system_id = esi_json['solar_system'][0]
try:
system_re = await client.get(url=f'https://esi.evetech.net/latest/universe/systems/{system_id}/?datasource=tranquility&language={output_lang}', headers=headers)
except:
await search_map.finish(message=Message('当前网络连接错误,请稍后进行查询!'))
return
system_json = system_re.json()
system_name = system_json['name']
msg = f'星系: {name} / {system_name}'
else:
msg = '没有该名称对应的星域/星座/星系,请检查输入是否正确!'

await search_map.finish(message=Message(msg))
2 changes: 1 addition & 1 deletion EVEBot/src/plugins/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

util = pluginR('util')

search = on_regex(r'^[\.。](search|搜索)\s*\S+')
search = on_regex(r'^[\.。](search|搜索) \s*\S+')
@search.handle()
async def _(bot: Bot, event: Event):
if not (event.message_type == 'group' and event.group_id in group_ids) :
Expand Down
2 changes: 1 addition & 1 deletion EVEBot/src/plugins/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if 'ban' not in settings.data :
settings.data['ban'] = []

limit = on_regex(r'^[\.。](limit|限制)\s+\S+')
limit = on_regex(r'^[\.。](limit|限制) \s+\S+')
@limit.handle()
async def _(bot: Bot, event: Event):
global util
Expand Down
Loading

0 comments on commit 7b1c4d2

Please sign in to comment.