Let's shut the fxxk up
This commit is contained in:
parent
c2edf730b7
commit
cf26736977
4 changed files with 60 additions and 2 deletions
|
@ -85,6 +85,9 @@ async def parser(msg: MessageSession):
|
||||||
msg.trigger_msg = command # 触发该命令的消息,去除消息前缀
|
msg.trigger_msg = command # 触发该命令的消息,去除消息前缀
|
||||||
command_first_word = command_spilt[0].lower()
|
command_first_word = command_spilt[0].lower()
|
||||||
sudo = False
|
sudo = False
|
||||||
|
mute = False
|
||||||
|
if command_first_word == 'mute':
|
||||||
|
mute = True
|
||||||
if command_first_word == 'sudo':
|
if command_first_word == 'sudo':
|
||||||
if not msg.checkSuperUser():
|
if not msg.checkSuperUser():
|
||||||
return await msg.sendMessage('你不是本机器人的超级管理员,无法使用sudo命令。')
|
return await msg.sendMessage('你不是本机器人的超级管理员,无法使用sudo命令。')
|
||||||
|
@ -93,6 +96,11 @@ async def parser(msg: MessageSession):
|
||||||
command_first_word = command_spilt[0].lower()
|
command_first_word = command_spilt[0].lower()
|
||||||
msg.trigger_msg = ' '.join(command_spilt)
|
msg.trigger_msg = ' '.join(command_spilt)
|
||||||
if senderInfo.query.isInBlockList and not senderInfo.query.isInAllowList and not sudo: # 如果是以 sudo 执行的命令,则不检查是否已 ban
|
if senderInfo.query.isInBlockList and not senderInfo.query.isInAllowList and not sudo: # 如果是以 sudo 执行的命令,则不检查是否已 ban
|
||||||
|
ExecutionLockList.remove(msg)
|
||||||
|
return
|
||||||
|
in_mute = BotDBUtil.Muting(msg).check()
|
||||||
|
if in_mute and not mute:
|
||||||
|
ExecutionLockList.remove(msg)
|
||||||
return
|
return
|
||||||
if command_first_word in ModulesAliases:
|
if command_first_word in ModulesAliases:
|
||||||
command_spilt[0] = ModulesAliases[command_first_word]
|
command_spilt[0] = ModulesAliases[command_first_word]
|
||||||
|
@ -133,7 +141,10 @@ async def parser(msg: MessageSession):
|
||||||
await msg.sendMessage(f'{command_first_word}模块未启用,请发送~enable {command_first_word}启用本模块。')
|
await msg.sendMessage(f'{command_first_word}模块未启用,请发送~enable {command_first_word}启用本模块。')
|
||||||
continue
|
continue
|
||||||
elif module.required_admin:
|
elif module.required_admin:
|
||||||
if not await msg.checkPermission():
|
if not await msg.checkPermission() and not mute:
|
||||||
|
if in_mute:
|
||||||
|
ExecutionLockList.remove(msg)
|
||||||
|
continue
|
||||||
await msg.sendMessage(f'{command_first_word}命令仅能被该群组的管理员所使用,请联系管理员执行此命令。')
|
await msg.sendMessage(f'{command_first_word}命令仅能被该群组的管理员所使用,请联系管理员执行此命令。')
|
||||||
continue
|
continue
|
||||||
if not module.match_list.set:
|
if not module.match_list.set:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from config import Config
|
||||||
from core.elements.message import MessageSession
|
from core.elements.message import MessageSession
|
||||||
from core.elements.temp import EnabledModulesCache, SenderInfoCache
|
from core.elements.temp import EnabledModulesCache, SenderInfoCache
|
||||||
from database.orm import DBSession
|
from database.orm import DBSession
|
||||||
from database.tables import EnabledModules, SenderInfo, TargetAdmin, CommandTriggerTime, GroupAllowList
|
from database.tables import EnabledModules, MuteList, SenderInfo, TargetAdmin, CommandTriggerTime, GroupAllowList
|
||||||
|
|
||||||
cache = Config('db_cache')
|
cache = Config('db_cache')
|
||||||
|
|
||||||
|
@ -226,4 +226,33 @@ class BotDBUtil:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Muting:
|
||||||
|
@retry(stop=stop_after_attempt(3))
|
||||||
|
@auto_rollback_error
|
||||||
|
def __init__(self, msg: MessageSession):
|
||||||
|
self.msg = msg
|
||||||
|
self.targetId = msg.target.targetId
|
||||||
|
self.query = session.query(MuteList).filter_by(targetId=self.targetId).first()
|
||||||
|
|
||||||
|
@retry(stop=stop_after_attempt(3))
|
||||||
|
@auto_rollback_error
|
||||||
|
def check(self):
|
||||||
|
if self.query is not None:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@retry(stop=stop_after_attempt(3))
|
||||||
|
@auto_rollback_error
|
||||||
|
def add(self):
|
||||||
|
session.add(MuteList(targetId=self.targetId))
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
@retry(stop=stop_after_attempt(3))
|
||||||
|
@auto_rollback_error
|
||||||
|
def remove(self):
|
||||||
|
if self.query is not None:
|
||||||
|
session.delete(self.query)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["BotDBUtil", "auto_rollback_error", "session"]
|
__all__ = ["BotDBUtil", "auto_rollback_error", "session"]
|
||||||
|
|
|
@ -30,6 +30,11 @@ class TargetAdmin(Base):
|
||||||
targetId = Column(String(512))
|
targetId = Column(String(512))
|
||||||
|
|
||||||
|
|
||||||
|
class MuteList(Base):
|
||||||
|
"""禁言列表"""
|
||||||
|
__tablename__ = "MuteList"
|
||||||
|
targetId = Column(String(512), primary_key=True)
|
||||||
|
|
||||||
class CommandTriggerTime(Base):
|
class CommandTriggerTime(Base):
|
||||||
"""命令触发时间"""
|
"""命令触发时间"""
|
||||||
__tablename__ = "CommandTriggerTime"
|
__tablename__ = "CommandTriggerTime"
|
||||||
|
|
|
@ -577,3 +577,16 @@ async def _(msg: MessageSession):
|
||||||
else:
|
else:
|
||||||
target.edit('disable_typing', False)
|
target.edit('disable_typing', False)
|
||||||
await msg.sendMessage('成功打开输入提示。')
|
await msg.sendMessage('成功打开输入提示。')
|
||||||
|
|
||||||
|
|
||||||
|
mute = on_command('mute', developers=['Dianliang233'], base=True, required_admin=True)
|
||||||
|
|
||||||
|
|
||||||
|
@mute.handle()
|
||||||
|
async def _(msg: MessageSession):
|
||||||
|
if BotDBUtil.Muting(msg).check():
|
||||||
|
BotDBUtil.Muting(msg).remove()
|
||||||
|
await msg.sendMessage('成功取消禁言。')
|
||||||
|
else:
|
||||||
|
BotDBUtil.Muting(msg).add()
|
||||||
|
await msg.sendMessage('成功禁言。')
|
||||||
|
|
Reference in a new issue