diff --git a/.gitignore b/.gitignore index e634f1d..65d5e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ config.toml .vs .vscode -.idea \ No newline at end of file +__pycache__ \ No newline at end of file diff --git a/config-temp.toml b/config-temp.toml index e239552..5ff2239 100644 --- a/config-temp.toml +++ b/config-temp.toml @@ -1,4 +1,4 @@ private_key = "" # 与 icalingua 客户端使用的 private_key 一致 -host = " " # docker 版 icalingua 服务的地址 +host = "" # docker 版 icalingua 服务的地址 self_id = 0 # 机器人的 qq 号 diff --git a/connect.py b/connect.py index 1dfb715..ecbc076 100644 --- a/connect.py +++ b/connect.py @@ -15,10 +15,8 @@ from mcstatus import JavaServer # 功能包引用处 from module import hitokoto - # 功能包结束引用 -# 读取配置 def get_config() -> Tuple[str, str, int]: with open('config.toml', 'r', encoding='utf-8') as f: config = qtoml.load(f) @@ -87,7 +85,7 @@ async def require_auth(salt: str, versions: Dict[str, str]): # 准备数据 sign = SigningKey(bytes.fromhex(KEY)) signature = sign.sign(bytes.fromhex(salt)) - + # 发送数据 print(f"{len(signature.signature)=} {type(signature.signature)=}") await sio.emit('auth', signature.signature) @@ -184,10 +182,8 @@ def safe_eval(code: str) -> str: return result -# 获取到新的消息 @sio.on('addMessage') async def add_message(data: Dict[str, Any]): - print(f"{Fore.MAGENTA}add_message: {data}{Style.RESET_ALL}") is_self = data['message']['senderId'] == SELF_ID @@ -198,37 +194,33 @@ async def add_message(data: Dict[str, Any]): reply = ReplyMessage(id=data['message']['_id']) if not is_self: - # /bot if data.get('message').get('content') == '/bot': message = Message(content='icalingua bot test', room_id=data['roomId']) await sio.emit('sendMessage', message.to_json()) - - # !!status + elif content == '!!status': server = JavaServer.lookup("192.168.1.6:25565") - status = server.status() + status=server.status() # query = server.query() - + # if status.players.online != 0: # message = Message(content=f"此服务器有 {status.players.online} 个玩家在线\n当前在线玩家有 {.join(query.players.names)}",room_id=data['roomId']) # else: # message = Message(content=f"此服务器空无一人",room_id=data['roomId']) - - message = Message(content=f"此服务器有 {status.players.online} 个玩家在线", reply_to=reply, room_id=data['roomId']) + + message = Message(content=f"此服务器有 {status.players.online} 个玩家在线",reply_to=reply,room_id=data['roomId']) await sio.emit('sendMessage', message.to_json()) - - # !!players + elif content == '!!players': server = JavaServer.lookup("192.168.1.6:25565") query = server.query() players = query.players.names - message = Message(content=f"此服务器当前在线玩家有 {players}", reply_to=reply, room_id=data['roomId']) - + message = Message(content=f"此服务器当前在线玩家有 {players}",reply_to=reply,room_id=data['roomId']) + await sio.emit('sendMessage', message.to_json()) - # !!hitokoto elif content.startswith("!!hitokoto"): ctypet = content[len("!!hitokoto "):] @@ -250,7 +242,6 @@ async def add_message(data: Dict[str, Any]): await sio.emit('sendMessage', message.to_json()) - # 未知 elif data.get('message').get('content').startswith('=='): evals: str = data.get('message').get('content')[2:] @@ -285,18 +276,24 @@ async def add_message(data: Dict[str, Any]): await asyncio.sleep(random.random() * 2) await sio.emit('sendMessage', message.to_json()) - - # !!jrrp elif data['message']['content'] == '!!jrrp': - randomer = random.Random(f'{sender_id}-{data["message"]["date"]}-jrrp-v2') - result = randomer.randint(0, 50) + randomer.randint(0, 50) - print(f'{sender_name} 今日人品值为 {result}') - message = Message(content=f'{sender_name} 今日人品值为 {result}', - reply_to=reply, - room_id=room_id) - await asyncio.sleep(0.5) - await sio.emit('sendMessage', message.to_json()) - + examSet = False + if examSet == True: + print('examSet参数被设定,替换人品值') + message = Message(content=f'{sender_name} 今日人品值为 100\n为了让你安心备考,加油考试,今天你的人品值是100!', + reply_to=reply, + room_id=room_id) + await asyncio.sleep(0.5) + await sio.emit('sendMessage', message.to_json()) + else: + randomer = random.Random(f'{sender_id}-{data["message"]["date"]}-jrrp-v2') + result = randomer.randint(0, 50) + randomer.randint(0, 50) + print(f'{sender_name} 今日人品值为 {result}') + message = Message(content=f'{sender_name} 今日人品值为 {result}', + reply_to=reply, + room_id=room_id) + await asyncio.sleep(0.5) + await sio.emit('sendMessage', message.to_json()) # 如果只包括一个或多个 6 # elif data['message']['content'].replace(' ', '') in ('6', '666', '六', '3+3', '5+1', '4+2', '2+4', '1+5'): # reply = ReplyMessage(id=data['message']['_id']) diff --git a/module/hitokoto/__init__.py b/module/hitokoto/__init__.py index 445be9d..a37f290 100644 --- a/module/hitokoto/__init__.py +++ b/module/hitokoto/__init__.py @@ -1,7 +1,6 @@ import requests import random - def hitokoto(ctypet): result_type = None diff --git a/module/hitokoto/__pycache__/__init__.cpython-311.pyc b/module/hitokoto/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 2ae9f3e..0000000 Binary files a/module/hitokoto/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/module/hitokoto/__pycache__/__init__.cpython-39.pyc b/module/hitokoto/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 68862f7..0000000 Binary files a/module/hitokoto/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/module/minecraft_server/__init__.py b/module/minecraft_server/__init__.py index 91576ee..e69de29 100644 --- a/module/minecraft_server/__init__.py +++ b/module/minecraft_server/__init__.py @@ -1,17 +0,0 @@ -import time -import random -import asyncio -import traceback - -from typing import Dict, List, Tuple, Any, Optional, Union, Literal - -import qtoml -import socketio -from colorama import Fore, Style -from nacl.signing import SigningKey -from lib_not_dr.types import Options -from mcstatus import JavaServer - -server = JavaServer.lookup("192.168.1.6:25565") - -def mcstatus():