libs.commands.help.entry
libs/commands/help/entry.py
1""" 2libs/commands/help/entry.py 3""" 4 5import textwrap 6from typing import TYPE_CHECKING 7 8import libs.global_value as g 9from libs.bootstrap.section import SubCommands 10from libs.functions import lookup 11from libs.types import CommandType, StyleOptions 12from libs.utils import dictutil 13from libs.utils.timekit import ExtendedDatetime as ExtDt 14 15if TYPE_CHECKING: 16 from integrations.protocols import MessageParserProtocol 17 18 19class HelpConfig(SubCommands): 20 """helpセクション処理""" 21 22 def __init__(self) -> None: 23 self.default_commandword: str = "麻雀ヘルプ" 24 self.section: str = str(CommandType.HELP) 25 self.default_reset() 26 27 28def main(m: "MessageParserProtocol") -> None: 29 """ 30 ヘルプ処理エントリーポイント 31 32 Args: 33 m (MessageParserProtocol): メッセージデータ 34 35 """ 36 m.status.command_type = CommandType.HELP 37 g.params = dictutil.placeholder(g.cfg.help, m) 38 39 help_message(m) 40 m.post.ts = m.data.event_ts 41 m.post.thread_title = "ヘルプメッセージ" 42 43 44def help_message(m: "MessageParserProtocol") -> None: 45 """ 46 呼び出しキーワードヘルプメッセージ 47 48 Args: 49 m (MessageParserProtocol): メッセージデータ 50 51 """ 52 g.params.update_from_dict( 53 { 54 "source": g.cfg.resolve_channel_id(m.status.source), 55 "separate": lookup.resolve_separate_flag(m), 56 } 57 ) 58 g.cfg.rule.status_update(g.params.placeholder()) 59 g.params.update_setting(g.cfg.config_file, "default_rule", str) 60 61 m.set_message( 62 textwrap.dedent(f"""\ 63 使い方:<呼び出しワード> [検索範囲] [対象メンバー] [オプション] 64 集計対象ルール識別子:{g.params.rule_version} 65 """), 66 StyleOptions(title="機能呼び出し"), 67 ) 68 m.set_message( 69 textwrap.dedent(f"""\ 70 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.RESULTS))} 71 検索範囲デフォルト:{g.cfg.results.aggregation_range} 72 """), 73 StyleOptions(title="成績サマリ", indent=1, sub_title=True), 74 ) 75 m.set_message( 76 textwrap.dedent(f"""\ 77 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.GRAPH))} 78 検索範囲デフォルト:{g.cfg.graph.aggregation_range} 79 """), 80 StyleOptions(title="成績グラフ", indent=1, sub_title=True), 81 ) 82 m.set_message( 83 textwrap.dedent(f"""\ 84 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.RANKING))} 85 検索範囲デフォルト:{g.cfg.ranking.aggregation_range} 86 規定打数デフォルト:全体ゲーム数 × {g.cfg.ranking.stipulated_rate} + 1 87 出力制限デフォルト:上位 {g.cfg.ranking.ranked} 名 88 """), 89 StyleOptions(title="ランキング", indent=1, sub_title=True), 90 ) 91 m.set_message( 92 textwrap.dedent(f"""\ 93 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.REPORT))} 94 検索範囲デフォルト:{g.cfg.report.aggregation_range} 95 """), 96 StyleOptions(title="レポート", indent=1, sub_title=True), 97 ) 98 m.set_message( 99 f"呼び出しワード:{'、'.join(lookup.resolve_commands(g.params.rule_version, CommandType.MEMBER_LIST))}", 100 StyleOptions(title="メンバー一覧", indent=1, sub_title=True), 101 ) 102 m.set_message( 103 f"呼び出しワード:{'、'.join(lookup.resolve_commands(g.params.rule_version, CommandType.TEAM_LIST))}", 104 StyleOptions(title="チーム一覧", indent=1, sub_title=True), 105 ) 106 m.set_message( # 検索範囲 107 ExtDt.print_range(), 108 StyleOptions(title="検索範囲に指定できるワード"), 109 ) 110 111 # メモ機能 112 remarks_type1: str = "" 113 if words := lookup.regulation_list(1, g.params.rule_version): 114 remarks_type1 += "個別カウントワード:" + "、".join(words) 115 else: 116 if g.cfg.rule.get_undefined_word(g.params.default_rule) == 1: 117 remarks_type1 += "個別カウントワード:未登録ワードのすべてを個別にカウント" 118 119 remarks_type0: str = "" 120 if words := lookup.regulation_list(0, g.params.rule_version): 121 remarks_type0 += "役満カウントワード:" + "、".join(words) 122 else: 123 if g.cfg.rule.get_undefined_word(g.params.default_rule) == 0: 124 remarks_type0 += "役満カウントワード:未登録ワードのすべてを役満としてカウント" 125 126 m.set_message( 127 textwrap.dedent(f"""\ 128 使い方:<メモ記録ワード> <対象メンバー> <内容> 129 メモ記録ワード:{"、".join(g.cfg.rule.data[g.params.rule_version].remarks)} 130 131 {remarks_type1} 132 {remarks_type0} 133 """), 134 StyleOptions(title="メモ機能", keep_blank=True), 135 ) 136 137 # ルールセット 138 m.set_message( 139 g.cfg.rule.print(g.params.rule_version), 140 StyleOptions(title="ルールセット情報"), 141 ) 142 143 # レギュレーション 144 regulation: str = "" 145 if words := lookup.regulation_list(2, g.params.rule_version): 146 regulation += "卓外清算ワード(個人):\n" 147 for word in words: 148 regulation += f"\t{word}\n" 149 regulation += "\n" 150 151 if words := lookup.regulation_list(3, g.params.rule_version): 152 regulation += "卓外清算ワード(チーム):\n" 153 for word in words: 154 regulation += f"\t{word}\n" 155 regulation += "\n" 156 if regulation: 157 m.set_message(regulation, StyleOptions(title="レギュレーション", keep_blank=True, keep_indent=True)) 158 159 # その他 160 channel_config = g.params.channel_config 161 m.set_message( 162 textwrap.dedent(f"""\ 163 チャンネル識別子:{g.params.source} 164 デフォルトルール識別子:{g.params.default_rule} 165 チャンネル個別設定:{channel_config.name if channel_config else "---"} 166 セパレート機能:{"有効" if g.params.separate else "無効"} 167 """), 168 StyleOptions(title="チャンネル設定情報"), 169 ) 170 171 # 非表示項目を削除 172 for msg, option in m.post.message: 173 if option.title in g.cfg.rule.dropitems(g.params.rule_version): 174 m.post.message.remove((msg, option))
20class HelpConfig(SubCommands): 21 """helpセクション処理""" 22 23 def __init__(self) -> None: 24 self.default_commandword: str = "麻雀ヘルプ" 25 self.section: str = str(CommandType.HELP) 26 self.default_reset()
helpセクション処理
Inherited Members
29def main(m: "MessageParserProtocol") -> None: 30 """ 31 ヘルプ処理エントリーポイント 32 33 Args: 34 m (MessageParserProtocol): メッセージデータ 35 36 """ 37 m.status.command_type = CommandType.HELP 38 g.params = dictutil.placeholder(g.cfg.help, m) 39 40 help_message(m) 41 m.post.ts = m.data.event_ts 42 m.post.thread_title = "ヘルプメッセージ"
ヘルプ処理エントリーポイント
Arguments:
- m (MessageParserProtocol): メッセージデータ
45def help_message(m: "MessageParserProtocol") -> None: 46 """ 47 呼び出しキーワードヘルプメッセージ 48 49 Args: 50 m (MessageParserProtocol): メッセージデータ 51 52 """ 53 g.params.update_from_dict( 54 { 55 "source": g.cfg.resolve_channel_id(m.status.source), 56 "separate": lookup.resolve_separate_flag(m), 57 } 58 ) 59 g.cfg.rule.status_update(g.params.placeholder()) 60 g.params.update_setting(g.cfg.config_file, "default_rule", str) 61 62 m.set_message( 63 textwrap.dedent(f"""\ 64 使い方:<呼び出しワード> [検索範囲] [対象メンバー] [オプション] 65 集計対象ルール識別子:{g.params.rule_version} 66 """), 67 StyleOptions(title="機能呼び出し"), 68 ) 69 m.set_message( 70 textwrap.dedent(f"""\ 71 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.RESULTS))} 72 検索範囲デフォルト:{g.cfg.results.aggregation_range} 73 """), 74 StyleOptions(title="成績サマリ", indent=1, sub_title=True), 75 ) 76 m.set_message( 77 textwrap.dedent(f"""\ 78 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.GRAPH))} 79 検索範囲デフォルト:{g.cfg.graph.aggregation_range} 80 """), 81 StyleOptions(title="成績グラフ", indent=1, sub_title=True), 82 ) 83 m.set_message( 84 textwrap.dedent(f"""\ 85 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.RANKING))} 86 検索範囲デフォルト:{g.cfg.ranking.aggregation_range} 87 規定打数デフォルト:全体ゲーム数 × {g.cfg.ranking.stipulated_rate} + 1 88 出力制限デフォルト:上位 {g.cfg.ranking.ranked} 名 89 """), 90 StyleOptions(title="ランキング", indent=1, sub_title=True), 91 ) 92 m.set_message( 93 textwrap.dedent(f"""\ 94 呼び出しワード:{"、".join(lookup.resolve_commands(g.params.rule_version, CommandType.REPORT))} 95 検索範囲デフォルト:{g.cfg.report.aggregation_range} 96 """), 97 StyleOptions(title="レポート", indent=1, sub_title=True), 98 ) 99 m.set_message( 100 f"呼び出しワード:{'、'.join(lookup.resolve_commands(g.params.rule_version, CommandType.MEMBER_LIST))}", 101 StyleOptions(title="メンバー一覧", indent=1, sub_title=True), 102 ) 103 m.set_message( 104 f"呼び出しワード:{'、'.join(lookup.resolve_commands(g.params.rule_version, CommandType.TEAM_LIST))}", 105 StyleOptions(title="チーム一覧", indent=1, sub_title=True), 106 ) 107 m.set_message( # 検索範囲 108 ExtDt.print_range(), 109 StyleOptions(title="検索範囲に指定できるワード"), 110 ) 111 112 # メモ機能 113 remarks_type1: str = "" 114 if words := lookup.regulation_list(1, g.params.rule_version): 115 remarks_type1 += "個別カウントワード:" + "、".join(words) 116 else: 117 if g.cfg.rule.get_undefined_word(g.params.default_rule) == 1: 118 remarks_type1 += "個別カウントワード:未登録ワードのすべてを個別にカウント" 119 120 remarks_type0: str = "" 121 if words := lookup.regulation_list(0, g.params.rule_version): 122 remarks_type0 += "役満カウントワード:" + "、".join(words) 123 else: 124 if g.cfg.rule.get_undefined_word(g.params.default_rule) == 0: 125 remarks_type0 += "役満カウントワード:未登録ワードのすべてを役満としてカウント" 126 127 m.set_message( 128 textwrap.dedent(f"""\ 129 使い方:<メモ記録ワード> <対象メンバー> <内容> 130 メモ記録ワード:{"、".join(g.cfg.rule.data[g.params.rule_version].remarks)} 131 132 {remarks_type1} 133 {remarks_type0} 134 """), 135 StyleOptions(title="メモ機能", keep_blank=True), 136 ) 137 138 # ルールセット 139 m.set_message( 140 g.cfg.rule.print(g.params.rule_version), 141 StyleOptions(title="ルールセット情報"), 142 ) 143 144 # レギュレーション 145 regulation: str = "" 146 if words := lookup.regulation_list(2, g.params.rule_version): 147 regulation += "卓外清算ワード(個人):\n" 148 for word in words: 149 regulation += f"\t{word}\n" 150 regulation += "\n" 151 152 if words := lookup.regulation_list(3, g.params.rule_version): 153 regulation += "卓外清算ワード(チーム):\n" 154 for word in words: 155 regulation += f"\t{word}\n" 156 regulation += "\n" 157 if regulation: 158 m.set_message(regulation, StyleOptions(title="レギュレーション", keep_blank=True, keep_indent=True)) 159 160 # その他 161 channel_config = g.params.channel_config 162 m.set_message( 163 textwrap.dedent(f"""\ 164 チャンネル識別子:{g.params.source} 165 デフォルトルール識別子:{g.params.default_rule} 166 チャンネル個別設定:{channel_config.name if channel_config else "---"} 167 セパレート機能:{"有効" if g.params.separate else "無効"} 168 """), 169 StyleOptions(title="チャンネル設定情報"), 170 ) 171 172 # 非表示項目を削除 173 for msg, option in m.post.message: 174 if option.title in g.cfg.rule.dropitems(g.params.rule_version): 175 m.post.message.remove((msg, option))
呼び出しキーワードヘルプメッセージ
Arguments:
- m (MessageParserProtocol): メッセージデータ