Skip to content

Commit

Permalink
Master指令扩充
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Nov 30, 2021
1 parent 4718a17 commit 3a9c471
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 12 deletions.
11 changes: 10 additions & 1 deletion OlivaDiceCore/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions OlivaDiceCore/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
import platform
import os
import uuid

OlivaDiceCore_ver = '3.0.7'

Expand All @@ -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'
8 changes: 8 additions & 0 deletions OlivaDiceCore/msgCustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

dictStrCustomDict = {}

dictStrCustomUpdateDict = {}

dictStrCustom = {
'strSetStr': '回复词[{tStrName}]已更新',
'strBecomeMaster': '口令正确,[{tName}]已成为Master',
'strCantBecomeMaster': '口令错误,拒绝认证',
'strNeedMaster': '需要Master权限',
'strHello': '欢迎使用本机器人! 请使用[.help]查看帮助',
'strBot': '欢迎使用本机器人! 请使用[.help]查看帮助',
Expand Down Expand Up @@ -107,6 +112,7 @@
}

dictStrConst = {
'strToBeMaster' : '请使用[{tInitMasterKey}]指令以获取Master权限',
'strInitData' : '[{tInitDataCount}]条[{tInitDataType}]数据已加载',
'strInitBakData' : '[{tInitDataCount}]条[{tInitDataType}]数据已备份',
'strSaveData' : '[{tInitDataCount}]条[{tInitDataType}]数据已写入'
Expand All @@ -118,6 +124,7 @@

dictTValue = {
'tName' : 'N/A',
'tStrName' : 'N/A',
'tUserId' : 'N/A',
'tGroupName' : '私聊',
'tGroupId' : '私聊',
Expand Down Expand Up @@ -148,6 +155,7 @@
'tPcTempName' : '',
'tPcTempRuleName' : '',
'tInitDataCount' : '0',
'tInitMasterKey': '不可用',
'tInitDataType': '未知',
'tHelpDocResult': 'N/A',
'tDrawDeckResult': 'N/A'
Expand Down
23 changes: 22 additions & 1 deletion OlivaDiceCore/msgCustomManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
70 changes: 60 additions & 10 deletions OlivaDiceCore/msgReply.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import OlivaDiceCore

import time
import uuid

def logProc(Proc, level, message, segment):
Proc.log(
Expand All @@ -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()
Expand All @@ -56,13 +58,21 @@ 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()
dictStrConst = OlivaDiceCore.msgCustom.dictStrConst
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)
Expand All @@ -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]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3a9c471

Please sign in to comment.