Compare commits

..

No commits in common. "main" and "780bf3a742280651f6050580fa8a14005813acdc" have entirely different histories.

12 changed files with 92 additions and 107 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
config.toml
.vs
.vscode
__pycache__
.idea

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

View 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>

View 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
View 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
View 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
View 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>

View File

@ -1,4 +1,5 @@
private_key = "" # 与 icalingua 客户端使用的 private_key 一致
host = "" # docker 版 icalingua 服务的地址
self_id = 0 # 机器人的 qq 号
private_key = "d76a25fea1d5c3c8ccfdb31179798f31f87a2afc7e8feda3f67d515790ee9ee5" # 与 icalingua 客户端使用的 private_key 一致
host = "http://192.168.1.6:6789" # docker 版 icalingua 服务的地址
self_id = 2163534756 # 机器人的 qq 号

View File

@ -18,7 +18,7 @@ from module import hitokoto
# 功能包结束引用
def get_config() -> Tuple[str, str, int]:
with open('config.toml', 'r', encoding='utf-8') as f:
with open('config-temp.toml', 'r', encoding='utf-8') as f:
config = qtoml.load(f)
return config['host'], config['private_key'], config['self_id']
@ -191,7 +191,6 @@ async def add_message(data: Dict[str, Any]):
sender_id = data['message']['senderId']
content = data['message']['content']
room_id = data['roomId']
reply = ReplyMessage(id=data['message']['_id'])
if not is_self:
if data.get('message').get('content') == '/bot':
@ -209,7 +208,7 @@ async def add_message(data: Dict[str, Any]):
# 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} 个玩家在线",room_id=data['roomId'])
await sio.emit('sendMessage', message.to_json())
@ -217,28 +216,22 @@ async def add_message(data: Dict[str, Any]):
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}",room_id=data['roomId'])
await sio.emit('sendMessage', message.to_json())
elif content.startswith("!!hitokoto"):
elif content.startswith("!!hitokoto "):
ctypet = content[len("!!hitokoto "):]
if content == "!!hitokoto":
result_code, result_data, result_type= hitokoto.hitokoto(None)
else:
result_code, result_data, result_type= hitokoto.hitokoto(ctypet)
result_code, result_data = hitokoto.hitokoto(ctypet)
if result_code == 3:
message = Message(content=f"参数不对哦!你可以输入!!hitokoto help查看帮助",reply_to=reply,room_id=data['roomId'])
elif result_code == 2:
message = Message(content=f"发生了不可描述的错误X_X但可以肯定的是模块炸了",reply_to=reply,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'])
message = Message(content=f"参数不对哦!",room_id=data['roomId'])
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(f"Hitokoto: {result_data['hitokoto']}")
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())
@ -277,18 +270,10 @@ async def add_message(data: Dict[str, Any]):
await asyncio.sleep(random.random() * 2)
await sio.emit('sendMessage', message.to_json())
elif data['message']['content'] == '!!jrrp':
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}')
reply = ReplyMessage(id=data['message']['_id'])
message = Message(content=f'{sender_name} 今日人品值为 {result}',
reply_to=reply,
room_id=room_id)

View File

@ -1,12 +1,8 @@
import requests
import random
def hitokoto(ctypet):
result_type = None
try:
if ctypet == '动画' or ctypet == 'a':
ctype = 'a'
elif ctypet == '漫画' or ctypet == 'b':
@ -17,7 +13,7 @@ def hitokoto(ctypet):
ctype = 'd'
elif ctypet == '原创' or ctypet == 'e':
ctype = 'e'
elif ctypet == '来自网络' or ctypet == 'f':
elif ctypet == '网络' or ctypet == 'f':
ctype = 'f'
elif ctypet == '其他' or ctypet == 'g':
ctype = 'g'
@ -31,48 +27,17 @@ def hitokoto(ctypet):
ctype = 'k'
elif ctypet == '抖机灵' or ctypet == 'l':
ctype = 'l'
elif ctypet == None:
ctype = random.choice('abcdefghijkl')
elif ctypet == 'help':
return 1, None, result_type
else:
return 3, None, result_type
ctype = random.choice('abcdefghijkl')
return 3, None
params_value = {'c': ctype}
hitokoto = requests.get('https://v1.hitokoto.cn', params=params_value)
htype=hitokoto.json()['type']
if htype=='a':
result_type = '动画'
elif htype=='b':
result_type = '动漫'
elif htype=='c':
result_type = '游戏'
elif htype=='d':
result_type = '文学'
elif htype=='e':
result_type = '原创'
elif htype=='f':
result_type = '来自网络'
elif htype=='g':
result_type = '其他'
elif htype=='h':
result_type = '影视'
elif htype=='i':
result_type = '诗词'
elif htype=='j':
result_type = '网易云'
elif htype=='k':
result_type = '哲学'
elif htype=='l':
result_type = '抖机灵'
else:
result_type = '无法获取'
return 0, hitokoto.json()
return 0, hitokoto.json(), result_type
except IOError:
return 2, None, result_type
# except Exception as e:
# return 2, None

0
module/hitokoto/test.py Normal file
View File

View File

@ -4,4 +4,3 @@ qtoml
pynacl
python-socketio[asyncio_client]
mcstatus
requests