Skip to content

Commit

Permalink
rules功能细节实现
Browse files Browse the repository at this point in the history
+ 翻页
+ 分隔符可配置
+ 页面长度可配置
+ closed #2 closed #1
  • Loading branch information
lunzhiPenxil committed Oct 3, 2022
1 parent 50708cb commit 89acd91
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
7 changes: 7 additions & 0 deletions OlivaDiceOdyssey/msgCustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
import OlivaDiceCore
import OlivaDiceOdyssey

dictConsoleSwitchTemplate = {
'default' : {
'odysseyRulesItemLimit': 8
}
}

dictStrCustomDict = {}

dictStrCustom = {
Expand All @@ -26,6 +32,7 @@
'strOdysseyRulesNone': '没有找到合适的规则',
'strOdysseyRulesShow': '规则速查结果如下:\n{tResult}',
'strOdysseyRulesList': '规则速查找到如下待选结果:\n{tResult}\n输入序号以查看对应结果',
'strOdysseyRulesSplit': '\n',
'strOdysseyRulesError': '规则速查发生错误:\n{tResult}'
}

Expand Down
8 changes: 8 additions & 0 deletions OlivaDiceOdyssey/msgCustomManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ def initMsgCustom(bot_info_dict):
OlivaDiceCore.msgCustom.dictGValue.update(OlivaDiceOdyssey.msgCustom.dictGValue)
OlivaDiceCore.msgCustom.dictTValue.update(OlivaDiceOdyssey.msgCustom.dictTValue)
OlivaDiceCore.userConfig.dictUserConfigNoteDefault.update(OlivaDiceOdyssey.msgCustom.dictUserConfigNoteDefault)
for dictConsoleSwitchTemplate_this in OlivaDiceOdyssey.msgCustom.dictConsoleSwitchTemplate:
if dictConsoleSwitchTemplate_this in OlivaDiceCore.console.dictConsoleSwitchTemplate:
OlivaDiceCore.console.dictConsoleSwitchTemplate[dictConsoleSwitchTemplate_this].update(
OlivaDiceOdyssey.msgCustom.dictConsoleSwitchTemplate[dictConsoleSwitchTemplate_this]
)
OlivaDiceCore.console.initConsoleSwitchByBotDict(bot_info_dict)
OlivaDiceCore.console.readConsoleSwitch()
OlivaDiceCore.console.saveConsoleSwitch()
36 changes: 30 additions & 6 deletions OlivaDiceOdyssey/msgReply.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,35 @@ def replyRULES_command(
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)

[tmp_keyword, tmp_page] = OlivaDiceCore.msgReply.getNumberPara(tmp_reast_str, reverse = True)
if tmp_page == '' or not tmp_page.isdigit():
tmp_page = 1
else:
tmp_page = int(tmp_page)
if tmp_page < 1:
tmp_page = 1
tmp_keyword = tmp_keyword.rstrip(' ')
tmp_item_max = 8
tmp_item_max = OlivaDiceCore.console.getConsoleSwitchByHash(
'odysseyRulesItemLimit',
tmp_bothash
)
if not type(tmp_item_max) == int:
tmp_item_max = 8
if tmp_item_max < 1:
tmp_item_max = 8
tmp_total_page = 0
if tmp_keyword != '':
tmp_res = OlivaDiceOdyssey.webTool.getRulesReq(key = tmp_keyword, page = tmp_page - 1, item_max = tmp_item_max)
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 'total' in tmp_res['data'] and type(tmp_res['data']['total']) == int:
tmp_total_page = int(tmp_res['data']['total'] / tmp_item_max) + 1
if len(tmp_res['data']['result']) == 0:
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesNone'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
Expand All @@ -444,8 +464,8 @@ def replyRULES_command(
)
elif len(tmp_res['data']['result']) > 1:
data_list = tmp_res['data']['result']
if len(data_list) > 8:
data_list = data_list[:8]
if len(data_list) > tmp_item_max:
data_list = data_list[:tmp_item_max]
result_list = []
count = 1
for data_list_this in data_list:
Expand All @@ -464,7 +484,11 @@ def replyRULES_command(
)
)
count += 1
dictTValue['tResult'] = '\n'.join(result_list)
dictTValue['tResult'] = '%s\n====[第%d/%d页]====' % (
OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesSplit'], dictTValue).join(result_list),
tmp_page,
tmp_total_page
)
tmp_reply_str = OlivaDiceCore.msgCustomManager.formatReplySTR(dictStrCustom['strOdysseyRulesList'], dictTValue)
replyMsg(plugin_event, tmp_reply_str)
tmp_select:str = OlivaDiceCore.msgReplyModel.replyCONTEXT_regWait(
Expand Down
6 changes: 5 additions & 1 deletion OlivaDiceOdyssey/webTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ def getCnmodsReq(title = None, page = None):
pass
return res

def getRulesReq(key = None):
def getRulesReq(key = None, page = None, item_max = None):
res = None
tmp_res = None
tmp_value = {}
send_url = OlivaDiceOdyssey.cnmodsData.strRulesMain
if key != None:
tmp_value['key'] = str(key)
if page != None:
tmp_value['page'] = str(page)
if item_max != None:
tmp_value['item_max'] = str(item_max)
if key != None:
send_url += '?' + urlencode(tmp_value)
headers = {
Expand Down

0 comments on commit 89acd91

Please sign in to comment.