diff --git a/OlivaDiceCore/console.py b/OlivaDiceCore/console.py index 5bf9b67..fffe684 100644 --- a/OlivaDiceCore/console.py +++ b/OlivaDiceCore/console.py @@ -92,7 +92,16 @@ def readConsoleSwitch(): dictConsoleSwitch[botHash].update(json.loads(consoleSwitchPath_f.read())) except: pass - + +def setMasterListAppend(botHash, dataList): + global dictConsoleSwitch + if botHash in dictConsoleSwitch: + if 'masterList' not in dictConsoleSwitch[botHash]: + dictConsoleSwitch[botHash]['masterList'] = [] + if type(dictConsoleSwitch[botHash]['masterList']) != list: + dictConsoleSwitch[botHash]['masterList'] = [] + dictConsoleSwitch[botHash]['masterList'].append(dataList) + def releaseDir(dir_path): if not os.path.exists(dir_path): os.makedirs(dir_path) diff --git a/OlivaDiceCore/data.py b/OlivaDiceCore/data.py index 842cc01..572ca9d 100644 --- a/OlivaDiceCore/data.py +++ b/OlivaDiceCore/data.py @@ -17,6 +17,7 @@ import sys import platform import os +import uuid OlivaDiceCore_ver = '3.0.7' @@ -38,4 +39,8 @@ bot_summary += str(platform.processor()) + '\n' bot_summary += str(os.name) + ':' + str(platform.platform()) +bot_content = { + 'masterKey': str(uuid.uuid4()) +} + dataDirRoot = './plugin/data/OlivaDice' diff --git a/OlivaDiceCore/msgCustom.py b/OlivaDiceCore/msgCustom.py index c05c6e8..dca915e 100644 --- a/OlivaDiceCore/msgCustom.py +++ b/OlivaDiceCore/msgCustom.py @@ -19,7 +19,12 @@ dictStrCustomDict = {} +dictStrCustomUpdateDict = {} + dictStrCustom = { + 'strSetStr': '回复词[{tStrName}]已更新', + 'strBecomeMaster': '口令正确,[{tName}]已成为Master', + 'strCantBecomeMaster': '口令错误,拒绝认证', 'strNeedMaster': '需要Master权限', 'strHello': '欢迎使用本机器人! 请使用[.help]查看帮助', 'strBot': '欢迎使用本机器人! 请使用[.help]查看帮助', @@ -107,6 +112,7 @@ } dictStrConst = { + 'strToBeMaster' : '请使用[{tInitMasterKey}]指令以获取Master权限', 'strInitData' : '[{tInitDataCount}]条[{tInitDataType}]数据已加载', 'strInitBakData' : '[{tInitDataCount}]条[{tInitDataType}]数据已备份', 'strSaveData' : '[{tInitDataCount}]条[{tInitDataType}]数据已写入' @@ -118,6 +124,7 @@ dictTValue = { 'tName' : 'N/A', + 'tStrName' : 'N/A', 'tUserId' : 'N/A', 'tGroupName' : '私聊', 'tGroupId' : '私聊', @@ -148,6 +155,7 @@ 'tPcTempName' : '', 'tPcTempRuleName' : '', 'tInitDataCount' : '0', + 'tInitMasterKey': '不可用', 'tInitDataType': '未知', 'tHelpDocResult': 'N/A', 'tDrawDeckResult': 'N/A' diff --git a/OlivaDiceCore/msgCustomManager.py b/OlivaDiceCore/msgCustomManager.py index 1a496f2..6387263 100644 --- a/OlivaDiceCore/msgCustomManager.py +++ b/OlivaDiceCore/msgCustomManager.py @@ -22,6 +22,7 @@ def initMsgCustom(bot_info_dict): for bot_info_dict_this in bot_info_dict: + OlivaDiceCore.msgCustom.dictStrCustomDict[bot_info_dict_this] = {} OlivaDiceCore.msgCustom.dictStrCustomDict[bot_info_dict_this] = OlivaDiceCore.msgCustom.dictStrCustom.copy() releaseDir(OlivaDiceCore.data.dataDirRoot) botHash_list = os.listdir(OlivaDiceCore.data.dataDirRoot) @@ -34,10 +35,30 @@ def initMsgCustom(bot_info_dict): customReplyPath = customReplyDir + '/' + customReplyFile try: with open(customReplyPath, 'r', encoding = 'utf-8') as customReplyPath_f: - OlivaDiceCore.msgCustom.dictStrCustomDict[botHash].update(json.loads(customReplyPath_f.read())) + OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash] = json.loads(customReplyPath_f.read()) + OlivaDiceCore.msgCustom.dictStrCustomDict[botHash].update( + OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash] + ) except: continue +def saveMsgCustom(bot_info_dict): + for botHash in bot_info_dict: + saveMsgCustomByBotHash(botHash) + +def saveMsgCustomByBotHash(botHash): + releaseDir(OlivaDiceCore.data.dataDirRoot + '/' + botHash) + releaseDir(OlivaDiceCore.data.dataDirRoot + '/' + botHash + '/console') + customReplyDir = OlivaDiceCore.data.dataDirRoot + '/' + botHash + '/console' + customReplyFile = 'customReply.json' + customReplyPath = customReplyDir + '/' + customReplyFile + if botHash not in OlivaDiceCore.msgCustom.dictStrCustomUpdateDict: + OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash] = {} + if type(OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash]) != dict: + OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash] = {} + with open(customReplyPath, 'w', encoding = 'utf-8') as customReplyPath_f: + customReplyPath_f.write(json.dumps(OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[botHash], ensure_ascii = False, indent = 4)) + def releaseDir(dir_path): if not os.path.exists(dir_path): os.makedirs(dir_path) diff --git a/OlivaDiceCore/msgReply.py b/OlivaDiceCore/msgReply.py index 8e4395b..b3ed54b 100644 --- a/OlivaDiceCore/msgReply.py +++ b/OlivaDiceCore/msgReply.py @@ -18,6 +18,7 @@ import OlivaDiceCore import time +import uuid def logProc(Proc, level, message, segment): Proc.log( @@ -36,6 +37,7 @@ def unity_init(plugin_event, Proc): OlivaDiceCore.console.readConsoleSwitch() OlivaDiceCore.console.saveConsoleSwitch() OlivaDiceCore.msgCustomManager.initMsgCustom(Proc.Proc_data['bot_info_dict']) + OlivaDiceCore.msgCustomManager.saveMsgCustom(Proc.Proc_data['bot_info_dict']) OlivaDiceCore.helpDoc.initHelpDoc(Proc.Proc_data['bot_info_dict']) OlivaDiceCore.drawCard.initDeck(Proc.Proc_data['bot_info_dict']) OlivaDiceCore.pcCard.dataPcCardLoadAll() @@ -56,6 +58,13 @@ def unity_init(plugin_event, Proc): ('OlivaDice', 'default'), ('Init', 'default') ]) + #显示Master认主信息 + dictTValue['tInitMasterKey'] = '.master %s' % OlivaDiceCore.data.bot_content['masterKey'] + tmp_log_str = dictStrConst['strToBeMaster'].format(**dictTValue) + logProc(Proc, 2, tmp_log_str, [ + ('OlivaDice', 'default'), + ('Init', 'default') + ]) def unity_save(plugin_event, Proc): dictTValue = OlivaDiceCore.msgCustom.dictTValue.copy() @@ -63,6 +72,7 @@ def unity_save(plugin_event, Proc): dictGValue = OlivaDiceCore.msgCustom.dictGValue dictTValue.update(dictGValue) #save start + OlivaDiceCore.msgCustomManager.saveMsgCustom(Proc.Proc_data['bot_info_dict']) OlivaDiceCore.userConfig.releaseUnityMsgCount([], None, True) total_count = OlivaDiceCore.userConfig.dataUserConfigTotalCount() dictTValue['tInitDataCount'] = str(total_count) @@ -81,6 +91,7 @@ def poke_reply(plugin_event, Proc): def unity_reply(plugin_event, Proc): OlivaDiceCore.userConfig.setMsgCount() + dictStrConst = OlivaDiceCore.msgCustom.dictStrConst dictTValue = OlivaDiceCore.msgCustom.dictTValue.copy() dictTValue['tName'] = plugin_event.data.sender['nickname'] dictStrCustom = OlivaDiceCore.msgCustom.dictStrCustomDict[plugin_event.bot_info.hash] @@ -287,12 +298,50 @@ def unity_reply(plugin_event, Proc): replyMsg(plugin_event, tmp_reply_str) return return + elif isMatchWordStart(tmp_reast_str, 'str'): + tmp_reast_str = tmp_reast_str.strip(' ') + tmp_reast_list = tmp_reast_str.split(' ') + if len(tmp_reast_list) == 1: + if tmp_reast_list[0] in OlivaDiceCore.msgCustom.dictStrCustomDict[plugin_event.bot_info.hash]: + tmp_reply_str = OlivaDiceCore.msgCustom.dictStrCustomDict[plugin_event.bot_info.hash][tmp_reast_list[0]] + replyMsg(plugin_event, tmp_reply_str) + elif len(tmp_reast_list) >= 2: + tmp_new_str = ' '.join(tmp_reast_list[1:]) + OlivaDiceCore.msgCustom.dictStrCustomUpdateDict[plugin_event.bot_info.hash][tmp_reast_list[0]] = tmp_new_str + OlivaDiceCore.msgCustom.dictStrCustomDict[plugin_event.bot_info.hash][tmp_reast_list[0]] = tmp_new_str + OlivaDiceCore.msgCustomManager.saveMsgCustomByBotHash(plugin_event.bot_info.hash) + dictTValue['tStrName'] = tmp_reast_list[0] + tmp_reply_str = dictStrCustom['strSetStr'].format(**dictTValue) + replyMsg(plugin_event, tmp_reply_str) + return + else: + if isMatchWordStart(tmp_reast_str, 'master'): + tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'master') + tmp_reast_str = skipSpaceStart(tmp_reast_str) + tmp_reast_str = tmp_reast_str.strip(' ') + if tmp_reast_str == OlivaDiceCore.data.bot_content['masterKey']: + OlivaDiceCore.data.bot_content['masterKey'] = str(uuid.uuid4()) + OlivaDiceCore.console.setMasterListAppend(plugin_event.bot_info.hash, [plugin_event.data.user_id, plugin_event.platform['platform']]) + OlivaDiceCore.console.saveConsoleSwitch() + tmp_reply_str = dictStrCustom['strBecomeMaster'].format(**dictTValue) + replyMsg(plugin_event, tmp_reply_str) + #显示Master认主信息 + dictTValue['tInitMasterKey'] = '.master %s' % OlivaDiceCore.data.bot_content['masterKey'] + tmp_log_str = dictStrConst['strToBeMaster'].format(**dictTValue) + logProc(Proc, 2, tmp_log_str, [ + ('OlivaDice', 'default'), + ('reply', 'default') + ]) + else: + tmp_reply_str = dictStrCustom['strCantBecomeMaster'].format(**dictTValue) + replyMsg(plugin_event, tmp_reply_str) + return if isMatchWordStart(tmp_reast_str, 'bot'): tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'bot') tmp_reast_str = skipSpaceStart(tmp_reast_str) if isMatchWordStart(tmp_reast_str, 'on'): if flag_is_from_group: - if flag_is_from_group_have_admin and flag_is_from_group_admin or not flag_is_from_group_have_admin: + if (flag_is_from_group_have_admin and flag_is_from_group_admin or not flag_is_from_group_have_admin) or flag_is_from_master: if flag_groupEnable != True: if flag_is_from_host: if flag_hostEnable: @@ -341,7 +390,7 @@ def unity_reply(plugin_event, Proc): replyMsg(plugin_event, tmp_reply_str) elif isMatchWordStart(tmp_reast_str, 'off'): if flag_is_from_group: - if flag_is_from_group_have_admin and flag_is_from_group_admin or not flag_is_from_group_have_admin: + if (flag_is_from_group_have_admin and flag_is_from_group_admin or not flag_is_from_group_have_admin) or flag_is_from_master: if flag_groupEnable != False: if flag_is_from_host: if flag_hostEnable: @@ -736,14 +785,15 @@ def unity_reply(plugin_event, Proc): tmp_skill_name = None if tmp_skill_value == '': tmp_skill_value = None - if len(tmp_skill_value) > 1 and tmp_skill_value[0] == '+': - tmp_skill_update_flag = '+' - tmp_skill_value_update = tmp_skill_value[1:] - elif len(tmp_skill_value) > 1 and tmp_skill_value[0] == '-': - tmp_skill_update_flag = '-' - tmp_skill_value_update = tmp_skill_value[1:] - else: - tmp_skill_value = None + if tmp_skill_value != None: + if len(tmp_skill_value) > 1 and tmp_skill_value[0] == '+': + tmp_skill_update_flag = '+' + tmp_skill_value_update = tmp_skill_value[1:] + elif len(tmp_skill_value) > 1 and tmp_skill_value[0] == '-': + tmp_skill_update_flag = '-' + tmp_skill_value_update = tmp_skill_value[1:] + else: + tmp_skill_value = None if tmp_skill_name != None and tmp_skill_value != None: tmp_skill_name = tmp_skill_name.strip() tmp_skill_name = tmp_skill_name.upper()