Skip to content

Commit

Permalink
自动生成更多文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi committed Aug 18, 2022
1 parent cb7b418 commit 3511734
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 176 deletions.
2 changes: 2 additions & 0 deletions core/folder_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
os.mkdir("./images")
if not os.path.exists("./data"):
os.mkdir("./data")
if not os.path.exists(r'./data/fonts'):
os.mkdir(r'./data/fonts')
if not os.path.exists("./log"):
os.mkdir("./log")
if not os.path.exists('./config'):
Expand Down
3 changes: 2 additions & 1 deletion core/fun/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from core.fun.silence_toggle import *
from core.fun.welcome import *
from core.fun.admin_controller import *
from core.fun.ping import *
from core.fun.ping import *
from core.fun.gethelp import *
84 changes: 82 additions & 2 deletions core/fun/admin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
:Version: 0.0.1
"""


import re

from mirai import FriendMessage, Plain
from mirai import FriendMessage, Plain, GroupMessage

from core import bot, master, commandpre, commands_map, config, admin
from utils.MessageChainBuilder import messagechain_builder
from utils.MessageChainSender import sendMsgChain
from utils.cfg_loader import w_cfg_to_file

_whitelist = config['whitelist']

_black_list = dict(user=config['blacklist'], group=config['mutegrouplist'])

__all__ = ['addblacklist', 'addwhitelist', 'addadmin', 'deladmin', 'delblacklist', 'getbotinfo', 'getsyslog']


@bot.on(FriendMessage)
async def addadmin(event: FriendMessage):
Expand Down Expand Up @@ -55,3 +60,78 @@ async def deladmin(event: FriendMessage):
else:
await bot.send(event, messagechain_builder(text="抱歉,您无权这么做哦", rndimg=True))
return


@bot.on(FriendMessage)
async def getbotinfo(event: FriendMessage):
"""获取bot信息"""
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
m = re.match(fr"^{commandpre}{commands_map['sys']['getbotinfo']}", msg.strip())
if m:
if userid in admin:
return await bot.send(event,
f"机器人设置:{config}\n白名单用户:{_whitelist}\n黑名单用户:{_black_list['user']}\n屏蔽群组:{_black_list['group']}")


@bot.on(GroupMessage)
async def addwhitelist(event: GroupMessage):
"""添加白名单,目前没用"""
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
m = re.match(fr"^{commandpre}{commands_map['sys']['addwhitelist']}", msg.strip())
if m:
if userid in admin and userid not in _whitelist:

_whitelist.append(int(m.group(1)))
w_cfg_to_file(content=config, path=r'./config/config.yml')
print(m)
return await bot.send(event, "添加成功")
else:
return await bot.send(event, "添加失败,用户已存在")


@bot.on(FriendMessage)
async def addblacklist(event: FriendMessage):
"""添加黑名单,目前没用"""
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
m = re.match(fr"^{commandpre}{commands_map['sys']['addblacklist']}", msg.strip())
if m:
if userid in admin:
if int(m.group(1)) in admin:
return await bot.send(event, "请不要将管理员加入黑名单")
_black_list['user'].append(int(m.group(1)))

w_cfg_to_file(content=config, path=r'./config/config.yml')
print(m)
return await bot.send(event, "添加成功")
else:
return await bot.send(event, "添加失败,用户已存在")


@bot.on(FriendMessage)
async def delblacklist(event: FriendMessage):
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
m = re.match(fr"^{commandpre}{commands_map['sys']['delblacklist']}", msg.strip())
if m:
if userid in admin:
delperson = int(m.group(1))
if delperson in _black_list['user']:
_black_list['user'].remove(delperson)

w_cfg_to_file(content=config, path=r'./config/config.yml')
return await bot.send(event, "删除成功")
else:
return await bot.send(event, "删除失败,用户不存在")


@bot.on(FriendMessage)
async def getsyslog(event: FriendMessage):
if event.sender.id in admin:
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}{commands_map['sys']['log']}", msg.strip())
if m:
return await bot.send(event, "日志功能开发中")
38 changes: 38 additions & 0 deletions core/fun/gethelp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
:Author: NekoRabi
:Create: 2022/8/18 2:19
:Update: /
:Describe: 获取机器人帮助,或者说是呼出指令面板
:Version: 0.0.1
"""

import re
from mirai import MessageEvent, Plain, Image
from core import bot, commandpre, commands_map, config
from utils.MessageChainBuilder import messagechain_builder

_settings = config.get('settings')

__all__ = ['getsyshelp', 'getprojectlink']


@bot.on(MessageEvent)
async def getsyshelp(event: MessageEvent):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}{commands_map['sys']['help']}", msg.strip())
if m and _settings['help']:
# if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'help')):
# return bot.send(event, messagechain_builder()(text="帮助文档刚刚才发过哦~", rndimg=True, at=event.sender.id))
return await bot.send(event, Image(path="./images/grouphelp.png"))


@bot.on(MessageEvent)
async def getprojectlink(event: MessageEvent):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr"^{commandpre}项目地址\s*$", msg.strip())
if m:
return await bot.send(event, messagechain_builder(text="Github : https://github.com/NekoRabi/Majsoul-QQBot\n"
"如果觉得好可以点个star⭐"))

# 与机器人互动
174 changes: 7 additions & 167 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import datetime
import logging
import re

import nest_asyncio
import websockets.exceptions
from apscheduler.triggers.cron import CronTrigger
from mirai import GroupMessage, At, Image, MessageEvent, Voice, MessageChain
from mirai import MessageEvent, Voice, FriendMessage, Plain, GroupMessage
from mirai.models import FlashImage

from core import *
from plugin import *
from utils.MessageChainBuilder import messagechain_builder
from utils.bufferpool import cmdbuffer
from utils.cfg_loader import w_cfg_to_file
from utils.file_cleaner import cleaner
from utils.text_to_voice import VoiceCreater

Expand All @@ -23,9 +24,6 @@
create_helpimg()
qqlogger = getQQlogger()
rootLogger = create_logger(config['loglevel'])

black_list = dict(user=config['blacklist'], group=config['mutegrouplist'])
whiteList = config['whitelist']
admin: list = config['admin']
master = config['master']
settings = config['settings']
Expand All @@ -52,7 +50,7 @@ def getbase64voice(text):
# 聊天记录存储

@bot.on(MessageEvent)
def addEventLog(event: MessageEvent):
def add_event_log(event: MessageEvent):
if event.type == 'GroupMessage':
# infodict = dict(type=event.type,senderid=event.sender.id,sendername=event.sender.get_name(),
# groupname=event.group.name,groupid=event.group.id,message=event.message_chain)
Expand All @@ -64,169 +62,11 @@ def addEventLog(event: MessageEvent):



'''获取日志'''
'''{commands_map['sys']['']}'''


@bot.on(FriendMessage)
async def getsyslog(event: FriendMessage):
if event.sender.id in admin:
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}{commands_map['sys']['log']}", msg.strip())
if m:
return await bot.send(event, "日志功能开发中")
# if m.group(1):
# if m.group(2):
# return
# else:
# return
# else:
# return
# return


# PING



# 强制复读

@bot.on(FriendMessage)
async def sendmsgtogroup(event: FriendMessage):
if event.sender.id in admin:
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}{commands_map['sys']['sendmsgtogroup']}", msg.strip())
if m:
return await bot.send_group_message(int(m.group(1)), m.group(2))


@bot.on(GroupMessage)
async def groupAt(event: GroupMessage):
if event.sender.id in admin:
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}at::\s*([\u4e00-\u9fa5\w%&',@;=?!^.$\x22,。?!]+)\s*$", msg.strip())
if m:
if At in event.message_chain:
target = event.message_chain.get_first(At).target
return await bot.send(event, MessageChain([At(target), Plain(f" {m.group(1)}")]))


# 色图

@bot.on(MessageEvent)
async def getsyshelp(event: MessageEvent):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(
fr"^{commandpre}{commands_map['sys']['help']}", msg.strip())
if m and settings['help']:
# if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'help')):
# return bot.send(event, messagechain_builder()(text="帮助文档刚刚才发过哦~", rndimg=True, at=event.sender.id))
return await bot.send(event, Image(path="./images/grouphelp.png"))


'''获取机器人信息'''


@bot.on(FriendMessage)
async def getbotinfo(event: FriendMessage):
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
# 匹配指令
m = re.match(fr"^{commandpre}{commands_map['sys']['getbotinfo']}", msg.strip())
if m:
if userid in admin:
return await bot.send(event,
f"机器人设置:{config}\n白名单用户:{whiteList}\n黑名单用户:{black_list['user']}\n屏蔽群组:{black_list['group']}")


'''沉默机器人'''


# 添加白名单

@bot.on(GroupMessage)
async def addwhitelist(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
# 匹配指令
m = re.match(fr"^{commandpre}{commands_map['sys']['addwhitelist']}", msg.strip())
if m:
if userid in admin and userid not in whiteList:

whiteList.append(int(m.group(1)))
w_cfg_to_file(content=config, path=r'./config/config.yml')
print(m)
return await bot.send(event, "添加成功")
else:
return await bot.send(event, "添加失败,用户已存在")


# 添加黑名单

@bot.on(FriendMessage)
async def addblacklist(event: FriendMessage):
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
# 匹配指令
m = re.match(fr"^{commandpre}{commands_map['sys']['addblacklist']}", msg.strip())
if m:
if userid in admin:
if int(m.group(1)) in admin:
return await bot.send(event, "请不要将管理员加入黑名单")
black_list['user'].append(int(m.group(1)))
print(black_list['user'])

w_cfg_to_file(content=config, path=r'./config/config.yml')
print(m)
return await bot.send(event, "添加成功")
else:
return await bot.send(event, "添加失败,用户已存在")


# 移出黑名单

@bot.on(FriendMessage)
async def delblacklist(event: FriendMessage):
msg = "".join(map(str, event.message_chain[Plain]))
userid = event.sender.id
# 匹配指令
m = re.match(fr"^{commandpre}{commands_map['sys']['delblacklist']}", msg.strip())
if m:
if userid in admin:
delperson = int(m.group(1))
if delperson in black_list['user']:
black_list['user'].remove(delperson)

w_cfg_to_file(content=config, path=r'./config/config.yml')
return await bot.send(event, "删除成功")
else:
return await bot.send(event, "删除失败,用户不存在")


# 获取项目地址

@bot.on(MessageEvent)
async def getprojectlink(event: MessageEvent):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr"^{commandpre}项目地址\s*$", msg.strip())
if m:
return await bot.send(event, MessageChain([Plain(
"Github : https://github.com/NekoRabi/Majsoul-QQBot\n"
"如果觉得好可以点个star⭐")]))

# 与机器人互动



# 天凤相关

'''通用功能'''

@bot.on(GroupMessage)
async def sendGroupVoice(event: GroupMessage):
async def send_group_voice(event: GroupMessage):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr"^{commandpre}{commands_map['sendvoice']['sendvoice']}", msg.strip())
if m:
Expand All @@ -245,7 +85,7 @@ async def sendGroupVoice(event: GroupMessage):


@bot.on(FriendMessage)
async def sendVoiceToGroup(event: FriendMessage):
async def send_voice_to_group(event: FriendMessage):
msg = "".join(map(str, event.message_chain[Plain]))
m = re.match(fr"^{commandpre}{commands_map['sendvoice']['sendgroupvoice']}", msg.strip())
if m:
Expand All @@ -265,7 +105,7 @@ async def sendVoiceToGroup(event: FriendMessage):


@bot.on(MessageEvent)
async def saveFlashImage(event: MessageEvent):
async def save_flashimage(event: MessageEvent):
if event is GroupMessage or FriendMessage:
if FlashImage in event.message_chain and settings['saveflashimg']:
flashimg = event.message_chain.get_first(FlashImage)
Expand Down
Loading

0 comments on commit 3511734

Please sign in to comment.