Compare commits
49 Commits
Author | SHA1 | Date | |
---|---|---|---|
6de8b46cc8 | |||
51011ec401 | |||
6a3a31ab18 | |||
48867b8cf9 | |||
70a01ec9f5 | |||
49be7abc97 | |||
92e86ae7cc | |||
1ea0744062 | |||
7c0016c4be | |||
88260597b9 | |||
e035c8e93c | |||
ec3962306e | |||
a7c4686f66 | |||
3e68e1b509 | |||
332657936f | |||
196d3d8549 | |||
c138f0ac7e | |||
43dc6deaea | |||
014116c105 | |||
fc0b10815f | |||
cebf394e23 | |||
1a5001312b | |||
4526284902 | |||
47e4912c97 | |||
4d38da674e | |||
07d297173d | |||
dcdf91f445 | |||
a38a925e72 | |||
018a5cd9ea | |||
daf53ba226 | |||
27db3d5ef0 | |||
d1b27d3825 | |||
ec399233cc | |||
29c43e64e6 | |||
8dfbf1d7ab | |||
6200a18b82 | |||
df616d8b53 | |||
c1966e6f55 | |||
88c46f754f | |||
a2f5b30e75 | |||
d5f289887f | |||
78b24f0689 | |||
bc42df2472 | |||
43a79b3f1c | |||
8584c6c6fd | |||
b6d58cf9fc | |||
e55c85a5ad | |||
0a8350e934 | |||
a562ae4cef |
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -2,4 +2,8 @@
|
||||||
config.toml
|
config.toml
|
||||||
.vs
|
.vs
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
<<<<<<< HEAD
|
||||||
|
.idea
|
||||||
|
=======
|
||||||
|
__pycache__
|
||||||
|
>>>>>>> 51011ec401ee07fe7446b24fad680a629e12ff56
|
||||||
|
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
8
.idea/icalingua-python-bot.iml
Normal file
8
.idea/icalingua-python-bot.iml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.9 (2)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (2)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/icalingua-python-bot.iml" filepath="$PROJECT_DIR$/.idea/icalingua-python-bot.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
|
||||||
host = " " # docker 版 icalingua 服务的地址
|
host = "" # docker 版 icalingua 服务的地址
|
||||||
self_id = 0 # 机器人的 qq 号
|
self_id = 0 # 机器人的 qq 号
|
||||||
|
|
44
connect.py
44
connect.py
|
@ -15,10 +15,8 @@ from mcstatus import JavaServer
|
||||||
# 功能包引用处
|
# 功能包引用处
|
||||||
from module import hitokoto
|
from module import hitokoto
|
||||||
|
|
||||||
|
|
||||||
# 功能包结束引用
|
# 功能包结束引用
|
||||||
|
|
||||||
# 读取配置
|
|
||||||
def get_config() -> Tuple[str, str, int]:
|
def get_config() -> Tuple[str, str, int]:
|
||||||
with open('config.toml', 'r', encoding='utf-8') as f:
|
with open('config.toml', 'r', encoding='utf-8') as f:
|
||||||
config = qtoml.load(f)
|
config = qtoml.load(f)
|
||||||
|
@ -87,7 +85,7 @@ async def require_auth(salt: str, versions: Dict[str, str]):
|
||||||
# 准备数据
|
# 准备数据
|
||||||
sign = SigningKey(bytes.fromhex(KEY))
|
sign = SigningKey(bytes.fromhex(KEY))
|
||||||
signature = sign.sign(bytes.fromhex(salt))
|
signature = sign.sign(bytes.fromhex(salt))
|
||||||
|
|
||||||
# 发送数据
|
# 发送数据
|
||||||
print(f"{len(signature.signature)=} {type(signature.signature)=}")
|
print(f"{len(signature.signature)=} {type(signature.signature)=}")
|
||||||
await sio.emit('auth', signature.signature)
|
await sio.emit('auth', signature.signature)
|
||||||
|
@ -184,10 +182,8 @@ def safe_eval(code: str) -> str:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
# 获取到新的消息
|
|
||||||
@sio.on('addMessage')
|
@sio.on('addMessage')
|
||||||
async def add_message(data: Dict[str, Any]):
|
async def add_message(data: Dict[str, Any]):
|
||||||
|
|
||||||
print(f"{Fore.MAGENTA}add_message: {data}{Style.RESET_ALL}")
|
print(f"{Fore.MAGENTA}add_message: {data}{Style.RESET_ALL}")
|
||||||
|
|
||||||
is_self = data['message']['senderId'] == SELF_ID
|
is_self = data['message']['senderId'] == SELF_ID
|
||||||
|
@ -195,62 +191,54 @@ async def add_message(data: Dict[str, Any]):
|
||||||
sender_id = data['message']['senderId']
|
sender_id = data['message']['senderId']
|
||||||
content = data['message']['content']
|
content = data['message']['content']
|
||||||
room_id = data['roomId']
|
room_id = data['roomId']
|
||||||
reply = ReplyMessage(id=data['message']['_id'])
|
|
||||||
|
|
||||||
if not is_self:
|
if not is_self:
|
||||||
# /bot
|
|
||||||
if data.get('message').get('content') == '/bot':
|
if data.get('message').get('content') == '/bot':
|
||||||
message = Message(content='icalingua bot test',
|
message = Message(content='icalingua bot test',
|
||||||
room_id=data['roomId'])
|
room_id=data['roomId'])
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# !!status
|
|
||||||
elif content == '!!status':
|
elif content == '!!status':
|
||||||
server = JavaServer.lookup("192.168.1.6:25565")
|
server = JavaServer.lookup("192.168.1.6:25565")
|
||||||
status=server.status()
|
status=server.status()
|
||||||
# query = server.query()
|
# query = server.query()
|
||||||
|
|
||||||
# if status.players.online != 0:
|
# if status.players.online != 0:
|
||||||
# message = Message(content=f"此服务器有 {status.players.online} 个玩家在线\n当前在线玩家有 {.join(query.players.names)}",room_id=data['roomId'])
|
# message = Message(content=f"此服务器有 {status.players.online} 个玩家在线\n当前在线玩家有 {.join(query.players.names)}",room_id=data['roomId'])
|
||||||
# else:
|
# else:
|
||||||
# message = Message(content=f"此服务器空无一人",room_id=data['roomId'])
|
# 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} 个玩家在线",room_id=data['roomId'])
|
||||||
|
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# !!players
|
|
||||||
elif content == '!!players':
|
elif content == '!!players':
|
||||||
server = JavaServer.lookup("192.168.1.6:25565")
|
server = JavaServer.lookup("192.168.1.6:25565")
|
||||||
query = server.query()
|
query = server.query()
|
||||||
players = query.players.names
|
players = query.players.names
|
||||||
message = Message(content=f"此服务器当前在线玩家有 {players}",reply_to=reply,room_id=data['roomId'])
|
message = Message(content=f"此服务器当前在线玩家有 {players}",room_id=data['roomId'])
|
||||||
|
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# !!hitokoto
|
|
||||||
elif content.startswith("!!hitokoto"):
|
elif content.startswith("!!hitokoto"):
|
||||||
|
|
||||||
ctypet = content[len("!!hitokoto "):]
|
ctypet = content[len("!!hitokoto "):]
|
||||||
if content == "!!hitokoto":
|
if content == "!!hitokoto":
|
||||||
result_code, result_data, result_type= hitokoto.hitokoto(None)
|
result_code, result_data = hitokoto.hitokoto("没有")
|
||||||
else:
|
else:
|
||||||
result_code, result_data, result_type= hitokoto.hitokoto(ctypet)
|
result_code, result_data = hitokoto.hitokoto(ctypet)
|
||||||
|
|
||||||
if result_code == 3:
|
if result_code == 3:
|
||||||
message = Message(content=f"参数不对哦!你可以输入!!hitokoto help查看帮助",reply_to=reply,room_id=data['roomId'])
|
message = Message(content=f"参数不对哦!",room_id=data['roomId'])
|
||||||
elif result_code == 2:
|
elif result_code == 2:
|
||||||
message = Message(content=f"发生了不可描述的错误X_X,但可以肯定的是模块炸了(",reply_to=reply,room_id=data['roomId'])
|
message = Message(content=f"发生了不可描述的错误X_X", room_id=data['roomId'])
|
||||||
elif result_code == 1:
|
|
||||||
message = Message(content=f"(参数)句子类型如下\na 动画\nb 漫画\nc 游戏\nd 文学\ne 原创\nf 来自网络\ng 其他\nh 影视\ni 诗词\nj 网易云\nk 哲学\nl 抖机灵",reply_to=reply,room_id=data['roomId'])
|
|
||||||
elif result_code == 0:
|
elif result_code == 0:
|
||||||
message = Message(content=f"“{result_data['hitokoto']}”\n来源:{result_data['from']}\n类型:{result_type}",reply_to=reply,room_id=data['roomId'])
|
message = Message(content=f"Hitokoto: {result_data['hitokoto']}", room_id=data['roomId'])
|
||||||
else:
|
else:
|
||||||
message = Message(content=f"你看到这条消息就代表有bug出炉,但肯定不是模块炸了(",reply_to=reply,room_id=data['roomId'])
|
message = Message(content=f"但你看到这条消息就代表有bug出炉", room_id=data['roomId'])
|
||||||
|
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# 未知
|
|
||||||
elif data.get('message').get('content').startswith('=='):
|
elif data.get('message').get('content').startswith('=='):
|
||||||
|
|
||||||
evals: str = data.get('message').get('content')[2:]
|
evals: str = data.get('message').get('content')[2:]
|
||||||
|
@ -285,18 +273,16 @@ async def add_message(data: Dict[str, Any]):
|
||||||
|
|
||||||
await asyncio.sleep(random.random() * 2)
|
await asyncio.sleep(random.random() * 2)
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# !!jrrp
|
|
||||||
elif data['message']['content'] == '!!jrrp':
|
elif data['message']['content'] == '!!jrrp':
|
||||||
randomer = random.Random(f'{sender_id}-{data["message"]["date"]}-jrrp-v2')
|
randomer = random.Random(f'{sender_id}-{data["message"]["date"]}-jrrp-v2')
|
||||||
result = randomer.randint(0, 50) + randomer.randint(0, 50)
|
result = randomer.randint(0, 50) + randomer.randint(0, 50)
|
||||||
print(f'{sender_name} 今日人品值为 {result}')
|
print(f'{sender_name} 今日人品值为 {result}')
|
||||||
|
reply = ReplyMessage(id=data['message']['_id'])
|
||||||
message = Message(content=f'{sender_name} 今日人品值为 {result}',
|
message = Message(content=f'{sender_name} 今日人品值为 {result}',
|
||||||
reply_to=reply,
|
reply_to=reply,
|
||||||
room_id=room_id)
|
room_id=room_id)
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
await sio.emit('sendMessage', message.to_json())
|
await sio.emit('sendMessage', message.to_json())
|
||||||
|
|
||||||
# 如果只包括一个或多个 6
|
# 如果只包括一个或多个 6
|
||||||
# elif data['message']['content'].replace(' ', '') in ('6', '666', '六', '3+3', '5+1', '4+2', '2+4', '1+5'):
|
# elif data['message']['content'].replace(' ', '') in ('6', '666', '六', '3+3', '5+1', '4+2', '2+4', '1+5'):
|
||||||
# reply = ReplyMessage(id=data['message']['_id'])
|
# reply = ReplyMessage(id=data['message']['_id'])
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import requests
|
import requests
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
def hitokoto(ctypet):
|
def hitokoto(ctypet):
|
||||||
|
|
||||||
result_type = None
|
result_type = None
|
||||||
|
@ -17,6 +18,7 @@ def hitokoto(ctypet):
|
||||||
ctype = 'd'
|
ctype = 'd'
|
||||||
elif ctypet == '原创' or ctypet == 'e':
|
elif ctypet == '原创' or ctypet == 'e':
|
||||||
ctype = 'e'
|
ctype = 'e'
|
||||||
|
elif ctypet == '网络' or ctypet == 'f':
|
||||||
elif ctypet == '来自网络' or ctypet == 'f':
|
elif ctypet == '来自网络' or ctypet == 'f':
|
||||||
ctype = 'f'
|
ctype = 'f'
|
||||||
elif ctypet == '其他' or ctypet == 'g':
|
elif ctypet == '其他' or ctypet == 'g':
|
||||||
|
@ -31,6 +33,15 @@ def hitokoto(ctypet):
|
||||||
ctype = 'k'
|
ctype = 'k'
|
||||||
elif ctypet == '抖机灵' or ctypet == 'l':
|
elif ctypet == '抖机灵' or ctypet == 'l':
|
||||||
ctype = 'l'
|
ctype = 'l'
|
||||||
|
|
||||||
|
elif ctypet == '没有':
|
||||||
|
ctype = random.choice('abcdefghijkl')
|
||||||
|
params_value = {'c': ctype}
|
||||||
|
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||||
|
|
||||||
|
return 0, hitokoto.json()
|
||||||
|
else:
|
||||||
|
return 3, None
|
||||||
elif ctypet == None:
|
elif ctypet == None:
|
||||||
ctype = random.choice('abcdefghijkl')
|
ctype = random.choice('abcdefghijkl')
|
||||||
elif ctypet == 'help':
|
elif ctypet == 'help':
|
||||||
|
@ -41,6 +52,11 @@ def hitokoto(ctypet):
|
||||||
params_value = {'c': ctype}
|
params_value = {'c': ctype}
|
||||||
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
|
||||||
|
|
||||||
|
return 0, hitokoto.json()
|
||||||
|
|
||||||
|
except IOError:
|
||||||
|
return 2, None
|
||||||
|
|
||||||
htype=hitokoto.json()['type']
|
htype=hitokoto.json()['type']
|
||||||
if htype=='a':
|
if htype=='a':
|
||||||
result_type = '动画'
|
result_type = '动画'
|
||||||
|
|
0
module/hitokoto/test.py
Normal file
0
module/hitokoto/test.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
def mcstatus():
|
|
@ -3,5 +3,9 @@ colorama
|
||||||
qtoml
|
qtoml
|
||||||
pynacl
|
pynacl
|
||||||
python-socketio[asyncio_client]
|
python-socketio[asyncio_client]
|
||||||
|
<<<<<<< HEAD
|
||||||
mcstatus
|
mcstatus
|
||||||
requests
|
=======
|
||||||
|
mcstatus
|
||||||
|
requests
|
||||||
|
>>>>>>> 51011ec401ee07fe7446b24fad680a629e12ff56
|
||||||
|
|
Loading…
Reference in New Issue
Block a user