我想做一个KOOK机器人
本帖最后由 WilliamJoker 于 2024-4-19 04:04 编辑事先申明 我只学过一点点的C 连指针都没学完的那种,这点代码是我通过下面几个站点找到的然后猜出来的大佬勿喷
我想给我一个KOOK机器人加一个查询全境2游戏数据的功能
大致内容就是输入 查询指令 + 游戏平台 + ID 就能出现这个人游戏数据的功能
下面是我的屎山代码,当前是能运行的。
from khl import *
from random import randint
from khl.card import Card, CardMessage, Module, Types, Element, Struct
bot = Bot(token='1/MjYwODU=/a8gYbQytbxleBvrvJKJorQ==') #这个token 可以再kook开发者网站换成自己的更方便测试
@bot.command(name='upload')
async def upload(msg:Message):
img_url = await bot.client.create_asset('./dblr.jpg')
print("str path ",img_url)
@bot.command(name='帮助')
async def 帮助(msg:Message):
c2 = Card(
Module.Header("全境2百科指令列表"),
Module.Section("(font)/白区Boss(font)"),
Module.Context("(font)DC/NY白区BOSS地图(font)"),
Module.Section("(font)/告密者(font)"),
Module.Context("(font)告密者地图(font)"),
Module.Section("(font)/技能伤害(font)"),
Module.Context("(font)说明各种属性对不同技能是否增伤(font)"),
Module.Section("(font)/武器控制力(font)"),
Module.Context("(font)说明武器控制力的效果(font)"),
Module.Section("(font)/危害防护(font)"),
Module.Context("(font)说明危害防护的效果和免疫上限(font)"),
Module.Section("(font)/技能效率(font)"),
Module.Context("(font)说明技能效率的效果(font)"),
Module.Section("(font)/伤害公式(font)"),
Module.Context("(font)武器伤害公式(font)"),
Module.Section("(font)/猎人(font)"),
Module.Context("(font)猎人触发方式(font)"),
Module.Section("(font)/服务器状态(font)"),
Module.Context("(font)全境2服务器在线状态(font)"),
Module.Section("(font)/游戏内指令表(font)"),
Module.Context("(font)游戏内聊天窗口的指令表(font)"),
)
await msg.reply(CardMessage(c2))
@bot.command(name='白区boss')
async def 白区boss(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/jAoG3ZmRAK0k10hj.png', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/hQaqNE5MsP1100jm.png',type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='白区BOSS')
async def 白区boss(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/jAoG3ZmRAK0k10hj.png', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/hQaqNE5MsP1100jm.png',type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='白区Boss')
async def 白区boss(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/jAoG3ZmRAK0k10hj.png', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/hQaqNE5MsP1100jm.png',type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='技能伤害')
async def 技能伤害(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/M2I2Qcu7OH0kg09m.png', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='告密者')
async def 告密者(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/XtTspw6XA10sg0fg.png', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='打靶猎人')
async def 打靶猎人(msg:Message):
await msg.reply('https://img.kookapp.cn/attachments/2024-04/18/dXde9Az5Vk0fe0a5.jpg', type=MessageTypes.IMG)# 必须要指明 msg 的类型为 IMG 图片
print("reply img only")
@bot.command(name='投骰子')
async def 投骰子(msg:Message):
ranom_number = randint(1,6)
test = '骰子点数为' + str(ranom_number)
await msg.reply(test)
@bot.command(name='技能效率')
async def 技能效率(msg:Message):
test = '1%技能效率=1%技能伤害+1%修复技能+1%状态效果+1%技能加速+1%技能持续时间+1%技能生命值'
await msg.reply(test)
@bot.command(name='武器控制力')
async def 武器控制力(msg:Message):
test = '1%武器控制力=1%装弹速度+1%准确度+1%稳定度+1%切枪速度'
await msg.reply(test)
@bot.command(name='服务器状态')
async def 服务器状态(msg:Message):
test = '[全境2服务器在线状态](https://ubistatic-a.akamaihd.net/0115/tctd2/status.html)'
await msg.reply(test)
@bot.command(name='猎人')
async def 服务器状态(msg:Message):
test1 = '[华盛顿猎人面具获得方法](https://www.bilibili.com/read/cv2509968/?from=search&spm_id_from=333.337.0.0)\n[纽约DLC全猎人面具获得方法](https://www.gamersky.com/handbook/202005/1285578.shtml)'
await msg.reply(test1)
@bot.command(name='危害防护')
async def 危害防护(msg:Message):
c1 = Card(
Module.Header("危害防护"),
Module.Section("(font)增加对所有负面状态的抗性,减少伤害和时间(font)"),
Module.Section("(font)每个负面状态都有不同的免疫上限,到达上限后就可以免疫此状态(font)"),
Module.Context("(font)流血 (font)(font)93.8%(font)\n(font)致盲/致聋 (font)(font)91.0%(font)\n(font)燃烧 (font)(font)91.4%(font)\n(font)混乱 (font)(font)93.8%(font)\n(font)干扰 (font)(font)95.8%(font)\n(font)诱捕 (font)(font)93.8%(font)\n(font)中毒 (font)(font)89.2%(font)\n(font)电击 (font)(font)86.0%(font)\n(font)凝固汽油 (font)(font)88.9%(font)"),
)
await msg.reply(CardMessage(c1))
@bot.command(name='伤害公式')
async def 伤害公式(msg: Message):
test = '基础伤害x武器伤害x(爆头伤害+暴击伤害)x对掩体外目标伤害x对生命值伤害x对装甲伤害x总武器伤害加成x乘法独立增伤1x乘法独立增伤2x****x=实际伤害。\n确认是否是独立乘法增伤需要再英文界面下查看:\n有"Amplified / Amplifies / Amplify"字眼的就是独立增伤 '
await msg.reply(test)
@bot.command(name='游戏内指令表')
async def 游戏内指令表(msg:Message):
c = Card(
Module.Header("全境封锁2指令列表"),
Module.Section("(font)/1 /2 /3 /4 /5(font)"),
Module.Context("(font)切换到第 N 个频道,根据当前聊天窗分页显示顺序决定(font)"),
Module.Section("(font)/?(font)"),
Module.Context("(font)列出所有聊天窗口文字命令(font)"),
Module.Section("(font)/allemotes(font)"),
Module.Context("(font)列出目前游戏中所有表情动作的文字指令,未取得的表情动作会提示购买,不会让你使用(font)"),
Module.Section("(font)/c 或 /clan(font)"),
Module.Context("(font)切换到战队频道(font)"),
Module.Section("(font)/claninvite(font) (font)(font)"),
Module.Context("(font)向(font) (font)***(font) (font)发送战队邀请(font)"),
Module.Section("(font)/decline(font)"),
Module.Context("(font)拒绝邀请(font)"),
Module.Section("(font)/emotes(font)"),
Module.Context("(font)列出玩家目前拥有的所有表情动作的文字指令(font)"),
Module.Section("(font)/g 或 /group(font)"),
Module.Context("(font)切换到队伍频道(font)"),
Module.Section("(font)/inspect(font) (font)(font)"),
Module.Context("(font)查看 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/invite(font) (font)(font)"),
Module.Context("(font)邀请 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/join(font) (font)(font)"),
Module.Context("(font)加入 (font) (font)***(font) (font)的队伍(font)"),
Module.Section("(font)/kick(font) (font)(font)"),
Module.Context("(font)踢出 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/leader(font) (font)(font)"),
Module.Context("(font)将队长移交给 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/leave(font)"),
Module.Context("(font)离开队伍(font)"),
Module.Section("(font)/logout(font)"),
Module.Context("(font)登出(回到选择角色页面)(font)"),
Module.Section("(font)/mute(font) (font)(font)"),
Module.Context("(font)静音 (font) (font)***(font) (font)玩家(麦克风)(font)"),
Module.Section("(font)/mutedplayers(font)"),
Module.Context("(font)列出目前静音的玩家(font)"),
Module.Section("(font)/quit(font)"),
Module.Context("(font)登出且离开游戏(font)"),
Module.Section("(font)/r 或 /reply(font)"),
Module.Context("(font)回复私信(上一位私信你的玩家)(font)"),
Module.Section("(font)/report(font) (font)(font)"),
Module.Context("(font)举报 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/s 或 /say(font)"),
Module.Context("(font)切换到公共区域频道(font)"),
Module.Section("(font)/w(font) (font)(font) 或 (font)/whisper(font) (font)(font)"),
Module.Context("(font)私信 (font) (font)***(font) (font)玩家(font)"),
Module.Section("(font)/world(font) 或 (font)/wr(font)"),
Module.Context("(font)切换到世界频道(font)"),
)
await msg.reply(CardMessage(c))
bot.run()
这是当前状态
这是我想要加的新功能
百度了好久只找到这些内容
GitHub - alexanderthegreat96/dth-division2-api:统计跟踪器 API 国外大佬做的好像是查询的
The Division 2 API - Tracker Network APIs for Developers > Documentation 查询网站的官方API
GitHub - kaiheila/api-docs: KOOK开发者中心文档 KOOK开发者文档
KOOK 开发者中心 - 机器人 (kookapp.cn) KOOK开发者中心
引言 | khl.py (khl-py.eu.org) khl.py文档
我觉得以上内容应该能搓出来这个新功能吧
嗨!看到你想给你的KOOK机器人加一个查询全境2游戏数据的功能,这个想法很有趣!不过在开始之前,我要先给你一个提醒:编程是一门需要耐心和实践的技能,对于初学者来说,一步步学习才是最有效的方法。所以虽然你可能会找到一些代码片段和API文档,但对于你目前的编程水平来说,建议先从简单的项目开始,并逐渐增加功能。
关于查询全境2游戏数据,你可以使用全境封锁2 API来获取游戏数据。这个API可以提供各种游戏数据(如角色信息、武器信息等)的访问接口。你可以通过发送HTTP请求来与这个API进行交互,获取到你需要的数据。
首先,你需要注册一个API密钥,这个密钥可以用于访问API。然后,你可以根据API文档中提供的接口,发送相应的HTTP请求来获取数据。例如,你可以使用`requests`库来发送HTTP请求,并解析返回的JSON数据。
下面是一个简单的示例,演示如何使用Python代码发送HTTP请求并获取角色信息:
import requests
def get_player_data(platform, player_id):
url = f"https://api.example.com/player/{platform}/{player_id}"
headers = {
"Authorization": "Bearer YOUR_API_KEY"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
player_data = response.json()
# 处理获取到的玩家数据
else:
print("请求数据失败")
platform = input("请输入游戏平台:")
player_id = input("请输入玩家ID:")
get_player_data(platform, player_id)
在上面的代码中,你需要将`YOUR_API_KEY`替换为你自己的API密钥。然后,用户可以输入游戏平台和玩家ID,然后调用`get_player_data`函数来获取玩家数据。
当然,这只是一个示例,你还需要根据具体的API文档和接口来实现查询其他游戏数据的功能。希望这个示例能够给你一些启发,祝你编程愉快!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 本帖最后由 WilliamJoker 于 2024-4-19 18:33 编辑
FishC 发表于 2024-4-19 04:05
嗨!看到你想给你的KOOK机器人加一个查询全境2游戏数据的功能,这个想法很有趣!不过在开始之前,我要先给 ...
当然我确认的确有这个人存在
https://tracker.gg/division-2/profile/uplay/wkeer7/overview
我新找了个API
https://github.com/salikx/TheDivisionTab-API?tab=readme-ov-file
代码如下
import requests
def get_player_data(name, platform):
url = f"https://thedivisiontab.com/api/search.php?name={name}&platform={platform}/"
response = requests.get(url)
player_data = response.json()
#处理获取到的玩家数据
platform = input("请输入游戏平台:")
name = input("请输入玩家ID:")
get_player_data(name,platform)
正常的报错
C:\Users\25650\.conda\envs\kookbot\python.exe C:\Users\25650\PycharmProjects\kookbot\main.py
请输入游戏平台:uplay
请输入玩家ID:wkeer7
Traceback (most recent call last):
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connection.py", line 198, in _new_conn
sock = connection.create_connection(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\util\connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "C:\Users\25650\.conda\envs\kookbot\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: getaddrinfo failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 793, in urlopen
response = self._make_request(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request
raise new_e
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
self._validate_conn(conn)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 1099, in _validate_conn
conn.connect()
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connection.py", line 616, in connect
self.sock = sock = self._new_conn()
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connection.py", line 205, in _new_conn
raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x0000019C3D414BE0>: Failed to resolve 'thedivisiontab.com' ( getaddrinfo failed)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason# type: ignore
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='thedivisiontab.com', port=443): Max retries exceeded with url: /api/search.php?name=wkeer7&platform=uplay/ (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000019C3D414BE0>: Failed to resolve 'thedivisiontab.com' ( getaddrinfo failed)"))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\25650\PycharmProjects\kookbot\main.py", line 14, in <module>
get_player_data(name,platform)
File "C:\Users\25650\PycharmProjects\kookbot\main.py", line 6, in get_player_data
response = requests.get(url)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='thedivisiontab.com', port=443): Max retries exceeded with url: /api/search.php?name=wkeer7&platform=uplay/ (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000019C3D414BE0>: Failed to resolve 'thedivisiontab.com' ( getaddrinfo failed)"))
进程已结束,退出代码为 1
**上网的报错
C:\Users\25650\.conda\envs\kookbot\python.exe C:\Users\25650\PycharmProjects\kookbot\main.py
请输入游戏平台:uplay
请输入玩家ID:wkeer7
urllib3.exceptions.SSLError: TLS/SSL connection has been closed (EOF) (_ssl.c:1135)
The above exception was the direct cause of the following exception:
urllib3.exceptions.ProxyError: ('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)')))
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason# type: ignore
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='thedivisiontab.com', port=443): Max retries exceeded with url: /api/search.php?name=wkeer7&platform=uplay/ (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\25650\PycharmProjects\kookbot\main.py", line 14, in <module>
get_player_data(name,platform)
File "C:\Users\25650\PycharmProjects\kookbot\main.py", line 6, in get_player_data
response = requests.get(url)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\api.py", line 73, in get
return request("get", url, params=params, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "C:\Users\25650\.conda\envs\kookbot\lib\site-packages\requests\adapters.py", line 513, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='thedivisiontab.com', port=443): Max retries exceeded with url: /api/search.php?name=wkeer7&platform=uplay/ (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))
进程已结束,退出代码为 1 WilliamJoker 发表于 2024-04-20 17:07
我新找了个API
https://github.com/salikx/TheDivi ...
根据你的报错信息,看起来是网络连接的问题。可能是由于代理设置或者防火墙的限制导致无法连接到 `thedivisiontab.com` 这个网站。
首先,你可以尝试在没有代理的情况下运行代码,看看问题是否解决。如果还是无法连接,那可能是由于防火墙的原因。
如果你使用的是公司或学校的网络,请检查是否有相关的限制,例如阻止对某些网站的访问。
如果你使用的是自己的电脑,并且有防火墙软件,请确保已经允许程序访问互联网。
另外,你也可以尝试使用其他网络环境(如移动数据网络)测试代码是否正常工作。如果在其他网络环境下可以正常运行,那说明问题可能出在你当前的网络环境中。
最后,如果以上方法都无法解决问题,你可以考虑联系你所在的网络管理员或者咨询网络服务提供商,看看他们能否提供帮助,解决网络连接问题。
希望以上内容对你有所帮助!祝你顺利完成KOOK机器人的开发!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页:
[1]