first commit
This commit is contained in:
0
control/__init__.py
Normal file
0
control/__init__.py
Normal file
BIN
control/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
control/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
control/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/__init__.cpython-38.pyc
Normal file
BIN
control/__pycache__/__init__.cpython-38.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/group.cpython-311.pyc
Normal file
BIN
control/__pycache__/group.cpython-311.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/notice.cpython-311.pyc
Normal file
BIN
control/__pycache__/notice.cpython-311.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/private.cpython-311.pyc
Normal file
BIN
control/__pycache__/private.cpython-311.pyc
Normal file
Binary file not shown.
BIN
control/__pycache__/request.cpython-311.pyc
Normal file
BIN
control/__pycache__/request.cpython-311.pyc
Normal file
Binary file not shown.
150
control/group.py
Normal file
150
control/group.py
Normal file
@@ -0,0 +1,150 @@
|
||||
from model.AiCat import AiCat
|
||||
from model.McList import McList
|
||||
from model.McFind import McFind
|
||||
from model.McHh import McHh
|
||||
from model.McBind import McBind
|
||||
import toml
|
||||
import logging
|
||||
|
||||
class group:
|
||||
def __init__(self, msg):
|
||||
self.user_id = msg.user_id
|
||||
self.group_id = msg.group_id
|
||||
self.message_id = msg.message_id
|
||||
self.message_type = msg.message_type
|
||||
self.raw_message = msg.raw_message
|
||||
self.sender = msg.sender
|
||||
self.message = msg.message
|
||||
self.self_id = msg.self_id
|
||||
self.time = msg.time
|
||||
def main(self):
|
||||
is_at = self.is_at()
|
||||
if is_at is None:
|
||||
return None
|
||||
else:
|
||||
permission = self.check_permission()
|
||||
if permission is None:
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
elif permission:
|
||||
return self.menu(is_at)
|
||||
else:
|
||||
return "此bot未在该群启用"
|
||||
|
||||
def is_at(self):
|
||||
for seg in self.message:
|
||||
if seg['type'] == 'at' and seg['data'].get('qq') == str(self.self_id):
|
||||
texts = [s['data']['text'].strip() for s in self.message if s['type'] == 'text']
|
||||
full_text = ' '.join(texts).strip()
|
||||
return full_text
|
||||
|
||||
return None
|
||||
|
||||
def check_permission(self):
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
allowed_groups = config.get("allowed_groups", [])
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return None
|
||||
|
||||
# 检查当前群是否在允许列表中
|
||||
if allowed_groups == "all":
|
||||
return True
|
||||
elif self.group_id in allowed_groups:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def menu(self,command):
|
||||
if command.startswith("/help"):
|
||||
return " \n /help -- 获取帮助 \n /list [服务器名/all] [页数] -- 列出服务器在线人数 \n /find <玩家名>-- 查找指定玩家是否在线 \n /bind <授权码> -- 绑定UNC游戏账户 \n /hh <喊话内容> -- 全服喊话 \n /cat <聊天内容> -- 与猫娘对话 \n /chat <提问内容> -- 智能问答(开发中,暂不可用) \n /status -- 查看bot状态 \n <必要参数> [可选参数]"
|
||||
elif command.startswith("/list"):
|
||||
# 去除前导空格并分割命令
|
||||
parts = command.strip().split()
|
||||
if len(parts) == 1:
|
||||
# 只有 "/list" 命令
|
||||
server = 'all'
|
||||
page = '1'
|
||||
elif len(parts) == 2:
|
||||
# "/list server"
|
||||
server = parts[1]
|
||||
page = '1'
|
||||
elif len(parts) == 3:
|
||||
# "/list server page"
|
||||
server = parts[1]
|
||||
page = parts[2]
|
||||
else:
|
||||
return "参数错误 \n 格式:/list [服务器名/all] [页数]"
|
||||
try:
|
||||
page = int(page)
|
||||
if page < 1:
|
||||
return "请输入大于1的页数 \n 格式:/list [服务器名/all] [页数]"
|
||||
except ValueError:
|
||||
return "输入的页数需为整数 \n 格式 /list [服务器名/all] [页数]"
|
||||
except Exception as e:
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
page -= 1
|
||||
list_player = McList(server, page)
|
||||
answer = McList.main(list_player)
|
||||
return answer
|
||||
elif command.startswith("/find"):
|
||||
# 排除 " /find "" /find"未传参情况
|
||||
parts = command.split("/find ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
find = McFind(chat_content)
|
||||
answer = McFind.main(find)
|
||||
return answer
|
||||
else:
|
||||
return "请提供查找的玩家名 \n 格式:/find <玩家名>"
|
||||
else:
|
||||
return "请提供查找的玩家名 \n 格式:/find <玩家名>"
|
||||
elif command.startswith("/hh"):
|
||||
# 排除“ /hh "” /hh“未传参情况
|
||||
parts = command.split("/hh ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
hh = McHh(self.user_id,chat_content)
|
||||
answer = McHh.main(hh)
|
||||
return answer
|
||||
else:
|
||||
return "请提供喊话内容 \n 格式:/hh <喊话内容>"
|
||||
else:
|
||||
return "请提供喊话内容 \n 格式:/hh <喊话内容>"
|
||||
elif command.startswith("/chat"):
|
||||
return "智能问答功能正在开发中,尚不可用!\n开发进度:5%"
|
||||
elif command.startswith("/cat"):
|
||||
# # 排除 " /cat "" /cat"未传参情况
|
||||
# parts = self.content.split(" /cat ", 1)
|
||||
# if len(parts) > 1:
|
||||
# chat_content = parts[1].strip()
|
||||
# if chat_content:
|
||||
# cat = AiCat(chat_content,self.id)
|
||||
# answer = AiCat.main(cat)
|
||||
# return answer
|
||||
# else:
|
||||
# return "你似乎没有提供想和我聊的内容喵~ \n 格式:/cat <提问内容>"
|
||||
# else:
|
||||
# return "你似乎没有提供想和我聊的内容喵~ \n 格式:/cat <提问内容>"
|
||||
return "该内容已移动至猫娘qbot"
|
||||
elif command.startswith("/bind"):
|
||||
# 排除“ /bind "” /bind“未传参情况
|
||||
parts = command.split("/bind ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
bind = McBind(self.user_id, chat_content)
|
||||
answer = McBind.main(bind)
|
||||
return answer
|
||||
else:
|
||||
return "授权码不可为空 \n 格式:/bind <授权码> \n 在服务器内输入/bind指令获取授权码"
|
||||
else:
|
||||
return "授权码不可为空 \n 格式:/bind <授权码>"
|
||||
elif command.startswith("/status"):
|
||||
return "---MCUNC QBOT---\n Q bot 运行正常 \n 版本: 2.0 pre \n © 融玩文化 | 无尽创意MCUNC"
|
||||
# return "\n Q Bot运行正常 \n Version: 0.2.1 pre-release \n © 融玩文化 | 无尽创意mcunc"
|
||||
else:
|
||||
return "功能不存在 \n 输入/help 查看帮助"
|
||||
62
control/notice.py
Normal file
62
control/notice.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import toml
|
||||
import logging
|
||||
|
||||
class notice:
|
||||
def __init__(self,msg):
|
||||
if msg["notice_type"] == "group_increase" or msg["notice_type"] == "group_decrease":
|
||||
self.time = msg["time"]
|
||||
self.self_id = msg["self_id"]
|
||||
self.post_type = msg["post_type"]
|
||||
self.notice_type = msg["notice_type"]
|
||||
self.sub_type = msg["sub_type"]
|
||||
self.group_id = msg["group_id"]
|
||||
self.operator_id = msg["operator_id"]
|
||||
self.user_id = msg["user_id"]
|
||||
else:
|
||||
pass
|
||||
|
||||
def main(self):
|
||||
if self.notice_type == "group_increase":
|
||||
return self.group_increase()
|
||||
elif self.notice_type == "group_decrease":
|
||||
return self.group_decrease()
|
||||
else:
|
||||
return None
|
||||
|
||||
def group_increase(self):
|
||||
print(1)
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
group_welcome = config.get("group_welcome")
|
||||
print(group_welcome)
|
||||
group_welcome_message = config.get("group_welcome_message")
|
||||
print(group_welcome_message)
|
||||
if group_welcome:
|
||||
if "!at" in group_welcome_message:
|
||||
return group_welcome_message.replace("!at", f"[CQ:at,qq={self.user_id}]")
|
||||
else:
|
||||
return group_welcome_message
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
logging.error(f"读取配置文件错误:{e}")
|
||||
return None
|
||||
|
||||
def group_decrease(self):
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
group_leave = config.get("group_leave")
|
||||
group_leave_message = config.get("group_leave_message")
|
||||
print(group_leave_message)
|
||||
if group_leave:
|
||||
if "{userid}" in group_leave_message:
|
||||
return group_leave_message.replace("{userid}", str(self.user_id))
|
||||
else:
|
||||
return group_leave_message
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
logging.error(f"读取配置文件错误:{e}")
|
||||
return None
|
||||
141
control/private.py
Normal file
141
control/private.py
Normal file
@@ -0,0 +1,141 @@
|
||||
from model.AiCat import AiCat
|
||||
from model.McList import McList
|
||||
from model.McFind import McFind
|
||||
from model.McHh import McHh
|
||||
from model.McBind import McBind
|
||||
import toml
|
||||
import logging
|
||||
|
||||
class private:
|
||||
def __init__(self, msg):
|
||||
self.user_id = msg.user_id
|
||||
self.message_id = msg.message_id
|
||||
self.message_type = msg.message_type
|
||||
self.raw_message = msg.raw_message
|
||||
self.sender = msg.sender
|
||||
self.message = msg.message
|
||||
self.self_id = msg.self_id
|
||||
self.time = msg.time
|
||||
def main(self):
|
||||
texts = [seg['data']['text'].strip() for seg in self.message if seg['type'] == 'text']
|
||||
full_text = ' '.join(texts).strip()
|
||||
permission = self.check_permission()
|
||||
if permission is None:
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
elif permission:
|
||||
return self.menu(full_text)
|
||||
else:
|
||||
return "此bot未在该群启用"
|
||||
|
||||
|
||||
|
||||
def check_permission(self):
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
allowed_users = config.get("allowed_users", [])
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return None
|
||||
|
||||
# 检查当前群是否在允许列表中
|
||||
if allowed_users == "all":
|
||||
return True
|
||||
elif self.user_id in allowed_users:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def menu(self,command):
|
||||
print( command)
|
||||
if command.startswith("/help"):
|
||||
return " \n /help -- 获取帮助 \n /list [服务器名/all] [页数] -- 列出服务器在线人数 \n /find <玩家名>-- 查找指定玩家是否在线 \n /bind <授权码> -- 绑定UNC游戏账户 \n /hh <喊话内容> -- 全服喊话 \n /cat <聊天内容> -- 与猫娘对话 \n /chat <提问内容> -- 智能问答(开发中,暂不可用) \n /status -- 查看bot状态 \n <必要参数> [可选参数]"
|
||||
elif command.startswith("/list"):
|
||||
# 去除前导空格并分割命令
|
||||
parts = command.strip().split()
|
||||
if len(parts) == 1:
|
||||
# 只有 "/list" 命令
|
||||
server = 'all'
|
||||
page = '1'
|
||||
elif len(parts) == 2:
|
||||
# "/list server"
|
||||
server = parts[1]
|
||||
page = '1'
|
||||
elif len(parts) == 3:
|
||||
# "/list server page"
|
||||
server = parts[1]
|
||||
page = parts[2]
|
||||
else:
|
||||
return "参数错误 \n 格式:/list [服务器名/all] [页数]"
|
||||
try:
|
||||
page = int(page)
|
||||
if page < 1:
|
||||
return "请输入大于1的页数 \n 格式:/list [服务器名/all] [页数]"
|
||||
except ValueError:
|
||||
return "输入的页数需为整数 \n 格式 /list [服务器名/all] [页数]"
|
||||
except Exception as e:
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
page -= 1
|
||||
list_player = McList(server, page)
|
||||
answer = McList.main(list_player)
|
||||
return answer
|
||||
elif command.startswith("/find"):
|
||||
# 排除 " /find "" /find"未传参情况
|
||||
parts = command.split("/find ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
find = McFind(chat_content)
|
||||
answer = McFind.main(find)
|
||||
return answer
|
||||
else:
|
||||
return "请提供查找的玩家名 \n 格式:/find <玩家名>"
|
||||
else:
|
||||
return "请提供查找的玩家名 \n 格式:/find <玩家名>"
|
||||
elif command.startswith("/hh"):
|
||||
# 排除“ /hh "” /hh“未传参情况
|
||||
parts = command.split("/hh ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
hh = McHh(self.user_id,chat_content)
|
||||
answer = McHh.main(hh)
|
||||
return answer
|
||||
else:
|
||||
return "请提供喊话内容 \n 格式:/hh <喊话内容>"
|
||||
else:
|
||||
return "请提供喊话内容 \n 格式:/hh <喊话内容>"
|
||||
elif command.startswith("/chat"):
|
||||
return "智能问答功能正在开发中,尚不可用!\n开发进度:5%"
|
||||
elif command.startswith("/cat"):
|
||||
# # 排除 " /cat "" /cat"未传参情况
|
||||
# parts = self.content.split(" /cat ", 1)
|
||||
# if len(parts) > 1:
|
||||
# chat_content = parts[1].strip()
|
||||
# if chat_content:
|
||||
# cat = AiCat(chat_content,self.id)
|
||||
# answer = AiCat.main(cat)
|
||||
# return answer
|
||||
# else:
|
||||
# return "你似乎没有提供想和我聊的内容喵~ \n 格式:/cat <提问内容>"
|
||||
# else:
|
||||
# return "你似乎没有提供想和我聊的内容喵~ \n 格式:/cat <提问内容>"
|
||||
return "该内容已移动至猫娘qbot"
|
||||
elif command.startswith("/bind"):
|
||||
# 排除“ /bind "” /bind“未传参情况
|
||||
parts = command.split("/bind ", 1)
|
||||
if len(parts) > 1:
|
||||
chat_content = parts[1].strip()
|
||||
if chat_content:
|
||||
bind = McBind(self.user_id, chat_content)
|
||||
answer = McBind.main(bind)
|
||||
return answer
|
||||
else:
|
||||
return "授权码不可为空 \n 格式:/bind <授权码> \n 在服务器内输入/bind指令获取授权码"
|
||||
else:
|
||||
return "授权码不可为空 \n 格式:/bind <授权码>"
|
||||
elif command.startswith("/status"):
|
||||
return "---MCUNC QBOT---\n Q bot 运行正常 \n 版本: 2.0 pre \n © 融玩文化 | 无尽创意MCUNC"
|
||||
# return "\n Q Bot运行正常 \n Version: 0.2.1 pre-release \n © 融玩文化 | 无尽创意mcunc"
|
||||
else:
|
||||
return "功能不存在 \n 输入/help 查看帮助"
|
||||
42
control/request.py
Normal file
42
control/request.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
import toml
|
||||
|
||||
class request:
|
||||
def __init__(self,msg):
|
||||
self.time = msg.time
|
||||
self.self_id = msg.self_id
|
||||
self.request_type = msg.request_type
|
||||
self.sub_type = msg.sub_type
|
||||
self.group_id = msg.group_id
|
||||
self.user_id = msg.user_id
|
||||
self.comment = msg.comment
|
||||
self.flag = msg.flag
|
||||
|
||||
def main(self):
|
||||
if self.request_type == "friend":
|
||||
friend_auto = self.get_info()
|
||||
if friend_auto:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def get_info(self):
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
friend_auto = config.get("friend_auto")
|
||||
return friend_auto
|
||||
except Exception as e:
|
||||
logging.error(f"读取配置文件错误:{e}")
|
||||
return False
|
||||
|
||||
def get_allow_group(self):
|
||||
try:
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
allow_group = config.get("allowed_groups")
|
||||
return allow_group
|
||||
except Exception as e:
|
||||
logging.error(f"读取配置文件错误:{e}")
|
||||
return []
|
||||
Reference in New Issue
Block a user