first commit

This commit is contained in:
2025-07-05 17:26:12 +08:00
commit cef359da64
39 changed files with 820 additions and 0 deletions

55
model/AiCat.py Normal file
View File

@@ -0,0 +1,55 @@
import requests
import json
import logging
class AiCat:
def __init__(self,message,qid):
self.message = message
self.qid = qid
self.query = f"<qid>{self.qid}</qid>{self.message}"
print(self.query) # test
def main(self):
# API URL
url = "https://ai.mcunc.cn/v1/chat-messages" # 替换为实际的 API 地址
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer app-pqib8uic8oBP95XmXuBi5ANq" # 替换为你的 API 密钥
}
# 请求体
payload = {
"query": self.query, # 用户输入/提问内容
"inputs": {}, # App 定义的变量值(默认为空)
"response_mode": "blocking", # 流式模式或阻塞模式
"user": "QBotAPI", # 用户标识,需保证唯一性
"conversation_id": "09cc6545-b0e0-4611-aad1-cf9bf51600e1", # (选填)会话 ID继续对话时需要传入
"files": [], # 文件列表(选填),适用于文件结合文本理解
"auto_generate_name": True # (选填)自动生成标题,默认为 True
}
# 发送 POST 请求
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查响应状态码
if response.status_code == 200:
logging.info("请求成功!返回结果:")
response_data = response.json()
logging.info(json.dumps(response_data, indent=4, ensure_ascii=False)) # 格式化输出 JSON
# 提取 answer 值
answer = response_data.get("answer", "answer 字段不存在")
print(response_data.get("conversation_id")) # test
return answer
else:
logging.info(f"请求失败!状态码: {response.status_code}")
logging.info(f"错误信息: {response.text}") # 打印错误信息
return "诶呀! 服务器好像出现了一点点错误呐~稍等一会再重试哦喵~"
except Exception as e:
logging.info(f"请求过程中出现异常: {e}")
return "诶呀! 服务器好像出现了一点点错误呐~稍等一会再重试哦喵~"

51
model/McBind.py Normal file
View File

@@ -0,0 +1,51 @@
import requests
import json
import logging
import toml
class McBind:
def __init__(self,qid,code):
self.qid = qid
self.code = code
def main(self):
with open('./config.toml', 'r', encoding='utf-8') as f:
config = toml.load(f)
# 获取所需字段
velocity_ip = config.get("velocity_ip")
velocity_port = config.get("velocity_port")
velocity_token = config.get("velocity_token")
# API URL
url = f"http://{velocity_ip}:{velocity_port}/vc/blind" # 替换为实际的 API 地址
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": velocity_token # 替换为你的 API 密钥
}
# 请求体
payload = {
"qqID": self.qid,
"code": self.code
}
# 发送 POST 请求
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查响应状态码
if response.status_code == 200:
return "您已成功绑定MCUNC游戏账户"
elif response.status_code == 403:
logging.info("授权码不存在或过期")
return "授权码不存在或过期"
else:
logging.error("请求失败!状态码: {response.status_code}")
logging.error(f"错误信息: {response.text}") # 打印错误信息
return "服务器繁忙,请稍后再逝"
except Exception as e:
logging.error(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"

55
model/McFind.py Normal file
View File

@@ -0,0 +1,55 @@
import requests
import json
import logging
import toml
class McFind:
def __init__(self,name):
self.name = name
def main(self):
with open('./config.toml', 'r', encoding='utf-8') as f:
config = toml.load(f)
# 获取所需字段
velocity_ip = config.get("velocity_ip")
velocity_port = config.get("velocity_port")
velocity_token = config.get("velocity_token")
# API URL
url = f"http://{velocity_ip}:{velocity_port}/vc/find_player" # 替换为实际的 API 地址
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": velocity_token # 替换为你的 API 密钥
}
# 请求体
payload = {
"name": self.name,
}
# 发送 POST 请求
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查响应状态码
if response.status_code == 200:
logging.info("请求成功!返回结果:")
response_data = response.json()
logging.info(json.dumps(response_data, indent=4, ensure_ascii=False)) # 格式化输出 JSON
# 提取 answer 值
online = response_data.get("online", "online 字段不存在")
server = response_data.get("server", "server 字段不存在")
if online:
return f"{self.name}在线,所在服务器:{server}"
else:
return f"{self.name}不在线"
else:
logging.error(f"请求失败!状态码: {response.status_code}")
logging.error(f"错误信息: {response.text}") # 打印错误信息
return "服务器繁忙,请稍后再逝"
except Exception as e:
logging.error(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"

68
model/McHh.py Normal file
View File

@@ -0,0 +1,68 @@
import requests
import json
import logging
import toml
class McHh:
def __init__(self,qid,message):
self.qid = qid
self.message = message
def main(self):
with open('./config.toml', 'r', encoding='utf-8') as f:
config = toml.load(f)
# 获取所需字段
velocity_ip = config.get("velocity_ip")
velocity_port = config.get("velocity_port")
velocity_token = config.get("velocity_token")
# API URL
url = f"http://{velocity_ip}:{velocity_port}/vc/hh" # 替换为实际的 API 地址
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": velocity_token # 替换为你的 API 密钥
}
# 请求体
payload = {
"qID": self.qid,
"message": self.message
}
# 发送 POST 请求
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
time = response.text
try:
time = int(time)
seconds = time / 1000
formatted_time = round(seconds, 1)
except Exception as e :
logging.error(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"
# 检查响应状态码
if response.status_code == 200:
return "喊话成功"
elif response.status_code == 403:
return "您未绑定MCUNC游戏账户请先绑定后重试"
elif response.status_code == 429:
return f"喊话过快,剩余时间:{formatted_time}s"
elif response.status_code == 409:
return "喊话失败:您没有足够的话筒!"
else:
logging.error(f"请求失败!状态码: {response.status_code}")
logging.error(f"错误信息: {response.text}") # 打印错误信息
return "服务器繁忙,请稍后再逝"
except Exception as e:
logging.error(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"

87
model/McList.py Normal file
View File

@@ -0,0 +1,87 @@
import requests
import json
import logging
import toml
class McList:
def __init__(self,server,page):
self.server = server
self.page = page
def main(self):
with open('./config.toml', 'r', encoding='utf-8') as f:
config = toml.load(f)
# 获取所需字段
velocity_ip = config.get("velocity_ip")
velocity_port = config.get("velocity_port")
velocity_token = config.get("velocity_token")
# API URL
url = f"http://{velocity_ip}:{velocity_port}/vc/query"
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": velocity_token # 替换为你的 API 密钥
}
# 请求体
payload = {
"server": self.server,
"page": self.page
}
# 发送 POST 请求
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
# 检查响应状态码
if response.status_code == 200:
logging.info("请求成功!返回结果:")
response_data = response.json()
logging.info(json.dumps(response_data, indent=4, ensure_ascii=False)) # 格式化输出 JSON
# 提取 player_number 值
player_number = response_data.get("player_number", "player_number 字段不存在")
totalpage = response_data.get("totalPage", "totalPage 字段不存在")
players = response_data.get("players", "players 字段不存在")
try:
page = int(self.page)
formatted_page = page + 1
except Exception as e:
logging.error(f"请求过程中出现异常: {e}")
return "服务繁忙,请稍后再逝"
try:
formatted_totalpage = int(totalpage)
if formatted_totalpage == 0:
formatted_totalpage = 1
elif formatted_totalpage == -1:
return f"服务器:{self.server} 不存在"
else:
formatted_totalpage = totalpage
success = True
except Exception as e:
logging.info(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"
if players is None :
logging.info("玩家列表为空")
formatted_players = ""
else:
try:
formatted_players = "\n".join(f"{i+1}{player}" for i, player in enumerate(players))
except Exception as e:
logging.info(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"
answer = f"当前服务器共有{player_number}个玩家,\n{formatted_players} \n [{formatted_page}页/{formatted_totalpage}页]"
return answer
else:
logging.info(f"请求失败!状态码: {response.status_code}")
logging.info(f"错误信息: {response.text}")
logging.info(response.json)
return "服务器繁忙,请稍后再逝"
except Exception as e:
logging.info(f"请求过程中出现异常: {e}")
return "服务器繁忙,请稍后再逝"

0
model/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.