Skip to content

Commit

Permalink
版本推进至3.0.6
Browse files Browse the repository at this point in the history
+ rules 规则速查(包括DND与COC)
  • Loading branch information
lunzhiPenxil committed Oct 2, 2022
1 parent b1da960 commit 50708cb
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 6 deletions.
4 changes: 2 additions & 2 deletions OlivaDiceOdyssey/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"namespace" : "OlivaDiceOdyssey",
"message_mode" : "old_string",
"info" : "本模块为OlivaDice的高阶模块,提供了一些涉及第三方合作的功能,它们或许是调用了第三方数据库,要么是涉及版权授权,又或者是单纯的过于依赖网络,总之这些功能由于第三方的参与很可能无法由插件开发者保证可靠性,但仍然很强大。例如魔都模组功能。",
"version" : "3.0.5",
"svn" : 6,
"version" : "3.0.6",
"svn" : 7,
"compatible_svn" : 101,
"priority" : 20040,
"support" : [
Expand Down
2 changes: 2 additions & 0 deletions OlivaDiceOdyssey/cnmodsData.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
strCnmodsMain = 'https://www.cnmods.net/index/moduleListPage.do'

strCnmodsIndex = 'https://www.cnmods.net/#/moduleDetail/index?keyId='

strRulesMain = 'https://api.oliva.icu/rules'
4 changes: 2 additions & 2 deletions OlivaDiceOdyssey/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
'''


OlivaDiceOdyssey_ver = '3.0.5'
OlivaDiceOdyssey_svn = 6
OlivaDiceOdyssey_ver = '3.0.6'
OlivaDiceOdyssey_svn = 7
OlivaDiceOdyssey_ver_short = '%s(%s)' % (str(OlivaDiceOdyssey_ver), str(OlivaDiceOdyssey_svn))
6 changes: 5 additions & 1 deletion OlivaDiceOdyssey/msgCustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

dictStrCustom = {
'strOdysseyCnmodsSearch': '魔都模组搜索结果如下:\n{tCnmodsResult}',
'strOdysseyCnmodsLuck': '魔都模组推荐如下:\n{tCnmodsResult}'
'strOdysseyCnmodsLuck': '魔都模组推荐如下:\n{tCnmodsResult}',
'strOdysseyRulesNone': '没有找到合适的规则',
'strOdysseyRulesShow': '规则速查结果如下:\n{tResult}',
'strOdysseyRulesList': '规则速查找到如下待选结果:\n{tResult}\n输入序号以查看对应结果',
'strOdysseyRulesError': '规则速查发生错误:\n{tResult}'
}

dictStrConst = {
Expand Down
137 changes: 136 additions & 1 deletion OlivaDiceOdyssey/msgReply.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def unity_init(plugin_event, Proc):

def data_init(plugin_event, Proc):
OlivaDiceOdyssey.msgCustomManager.initMsgCustom(Proc.Proc_data['bot_info_dict'])
if 'replyContextFliter' in OlivaDiceCore.crossHook.dictHookList:
OlivaDiceCore.crossHook.dictHookList['replyContextFliter'].append('rules')
OlivaDiceCore.crossHook.dictHookList['replyContextFliter'].append('rule')

def unity_reply(plugin_event, Proc):
OlivaDiceCore.userConfig.setMsgCount()
Expand Down Expand Up @@ -150,7 +153,19 @@ def unity_reply(plugin_event, Proc):
#此群关闭时中断处理
if not flag_groupEnable and not flag_force_reply:
return
if isMatchWordStart(tmp_reast_str, 'cnmods') or isMatchWordStart(tmp_reast_str, 'mdmz'):
if isMatchWordStart(tmp_reast_str, 'rules') or isMatchWordStart(tmp_reast_str, 'rule'):
OlivaDiceOdyssey.msgReply.replyRULES_command(
plugin_event = plugin_event,
Proc = Proc,
tmp_reast_str = tmp_reast_str,
isMatchWordStart = isMatchWordStart,
getMatchWordStartRight = getMatchWordStartRight,
skipSpaceStart = skipSpaceStart,
dictStrCustom = dictStrCustom,
dictTValue = dictTValue,
replyMsg = replyMsg
)
elif isMatchWordStart(tmp_reast_str, 'cnmods') or isMatchWordStart(tmp_reast_str, 'mdmz') or isMatchWordStart(tmp_reast_str, 'modu'):
if isMatchWordStart(tmp_reast_str, 'cnmods'):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'cnmods')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
Expand All @@ -159,6 +174,10 @@ def unity_reply(plugin_event, Proc):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'mdmz')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
tmp_reast_str = tmp_reast_str.rstrip(' ')
elif isMatchWordStart(tmp_reast_str, 'modu'):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'modu')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
tmp_reast_str = tmp_reast_str.rstrip(' ')
if isMatchWordStart(tmp_reast_str, 'search'):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'search')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
Expand Down Expand Up @@ -379,3 +398,119 @@ def unity_reply(plugin_event, Proc):
else:
OlivaDiceCore.msgReply.replyMsgLazyHelpByEvent(plugin_event, 'cnmods')
return

def replyRULES_command(
plugin_event,
Proc,
tmp_reast_str,
isMatchWordStart,
getMatchWordStartRight,
skipSpaceStart,
dictStrCustom,
dictTValue,
replyMsg
):
tmp_hagID = None
tmp_bothash = plugin_event.bot_info.hash
tmp_userID = plugin_event.data.user_id
if isMatchWordStart(tmp_reast_str, 'rules'):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'rules')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
tmp_reast_str = tmp_reast_str.rstrip(' ')
elif isMatchWordStart(tmp_reast_str, 'rule'):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'rule')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
tmp_reast_str = tmp_reast_str.rstrip(' ')
if tmp_reast_str != '':
tmp_keyword = tmp_reast_str
tmp_res = OlivaDiceOdyssey.webTool.getRulesReq(key = tmp_keyword)
if (
type(tmp_res) == dict and 'code' in tmp_res and 'status' in tmp_res
) and (
tmp_res['code'] == 0 and tmp_res['status'] == 200
):
if 'data' in tmp_res and 'result' in tmp_res['data'] and type(tmp_res['data']['result']) == list:
if len(tmp_res['data']['result']) == 0:
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesNone'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
elif len(tmp_res['data']['result']) == 1:
data_this = tmp_res['data']['result'][0]
replyRULES_command_getResult(
data_this = data_this,
plugin_event = plugin_event,
dictStrCustom = dictStrCustom,
dictTValue = dictTValue,
replyMsg = replyMsg
)
elif len(tmp_res['data']['result']) > 1:
data_list = tmp_res['data']['result']
if len(data_list) > 8:
data_list = data_list[:8]
result_list = []
count = 1
for data_list_this in data_list:
tmp_data_list_this_rule = 'N/A'
tmp_data_list_this_keyword = 'N/A'
tmp_data_list_this_content = 'N/A'
if type(data_list_this) == dict and 'rule' in data_list_this and 'keyword' in data_list_this and 'content' in data_list_this:
tmp_data_list_this_rule = data_list_this['rule']
tmp_data_list_this_keyword = data_list_this['keyword']
tmp_data_list_this_content = data_list_this['content']
result_list.append(
'%d. [%s]%s' % (
count,
tmp_data_list_this_rule,
tmp_data_list_this_keyword
)
)
count += 1
dictTValue['tResult'] = '\n'.join(result_list)
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesList'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
tmp_select:str = OlivaDiceCore.msgReplyModel.replyCONTEXT_regWait(
plugin_event = plugin_event,
flagBlock = 'allowCommand',
hash = OlivaDiceCore.msgReplyModel.contextRegHash([None, tmp_userID])
)
if tmp_select == None:
pass
elif type(tmp_select) == str:
if tmp_select.isdigit():
tmp_select = int(tmp_select)
if tmp_select >= 1 and tmp_select <= 8:
data_this = tmp_res['data']['result'][tmp_select - 1]
replyRULES_command_getResult(
data_this = data_this,
plugin_event = plugin_event,
dictStrCustom = dictStrCustom,
dictTValue = dictTValue,
replyMsg = replyMsg
)
else:
dictTValue['tResult'] = '超出范围'
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesError'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
else:
dictTValue['tResult'] = '请输入数字'
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesError'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
else:
dictTValue['tResult'] = 'API连接失败'
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesError'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)

def replyRULES_command_getResult(
data_this,
plugin_event,
dictStrCustom,
dictTValue,
replyMsg
):
if type(data_this) == dict and 'rule' in data_this and 'keyword' in data_this and 'content' in data_this:
dictTValue['tResult'] = '[%s] - %s\n%s' % (
data_this['rule'],
data_this['keyword'],
data_this['content']
)
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesShow'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
21 changes: 21 additions & 0 deletions OlivaDiceOdyssey/webTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ def getCnmodsReq(title = None, page = None):
except:
pass
return res

def getRulesReq(key = None):
res = None
tmp_res = None
tmp_value = {}
send_url = OlivaDiceOdyssey.cnmodsData.strRulesMain
if key != None:
tmp_value['key'] = str(key)
if key != None:
send_url += '?' + urlencode(tmp_value)
headers = {
'User-Agent': OlivaDiceCore.data.bot_version_short_header
}
try:
msg_res = req.request("GET", send_url, headers = headers)
res_text = str(msg_res.text)
tmp_res = json.loads(res_text)
res = tmp_res
except:
pass
return res

0 comments on commit 50708cb

Please sign in to comment.