libs.functions.events.message_event
libs/functions/events/message_event.py
1""" 2libs/functions/events/message_event.py 3""" 4 5import logging 6import re 7 8import libs.commands.graph.slackpost 9import libs.commands.ranking.slackpost 10import libs.commands.report.slackpost 11import libs.commands.results.slackpost 12import libs.global_value as g 13from libs.data import comparison, lookup, modify 14from libs.functions import message, slack_api 15from libs.utils import validator 16 17 18def main(client, body): 19 """ポストされた内容で処理を分岐 20 21 Args: 22 client (slack_bolt.App.client): slack_boltオブジェクト 23 body (dict): ポストされたデータ 24 """ 25 26 logging.trace(body) # type: ignore 27 g.msg.parser(body) 28 g.msg.client = client 29 logging.info( 30 "status=%s, event_ts=%s, thread_ts=%s, in_thread=%s, keyword=%s, user_id=%s,", 31 g.msg.status, g.msg.event_ts, g.msg.thread_ts, g.msg.in_thread, g.msg.keyword, g.msg.user_id, 32 ) 33 34 # 許可されていないユーザのポストは処理しない 35 if g.msg.user_id in g.cfg.setting.ignore_userid: 36 logging.trace("event skip[ignore user]: %s", g.msg.user_id) # type: ignore 37 return 38 39 # 投稿済みメッセージが削除された場合 40 if g.msg.status == "message_deleted": 41 if re.match(rf"^{g.cfg.cw.remarks_word}", g.msg.keyword): # 追加メモ 42 modify.remarks_delete(g.msg.event_ts) 43 else: 44 modify.db_delete(g.msg.event_ts) 45 return 46 47 # キーワード処理 48 match g.msg.keyword: 49 # ヘルプ 50 case x if re.match(rf"^{g.cfg.cw.help}$", x): 51 # ヘルプメッセージ 52 slack_api.post_message(message.help_message(), g.msg.event_ts) 53 # メンバーリスト 54 title, msg = lookup.textdata.get_members_list() 55 slack_api.post_text(g.msg.event_ts, title, msg) 56 57 # 成績管理系コマンド 58 case x if re.match(rf"^{g.cfg.cw.results}$", x): 59 libs.commands.results.slackpost.main() 60 case x if re.match(rf"^{g.cfg.cw.graph}$", x): 61 libs.commands.graph.slackpost.main() 62 case x if re.match(rf"^{g.cfg.cw.ranking}$", x): 63 libs.commands.ranking.slackpost.main() 64 case x if re.match(rf"^{g.cfg.cw.report}$", x): 65 libs.commands.report.slackpost.main() 66 67 # データベース関連コマンド 68 case x if re.match(rf"^{g.cfg.cw.check}$", x): 69 comparison.main() 70 case x if re.match(rf"^Reminder: {g.cfg.cw.check}$", str(g.msg.text)): # Reminderによる突合 71 logging.notice("Reminder: %s", g.cfg.cw.check) # type: ignore 72 comparison.main() 73 74 # メンバーリスト/チームリスト 75 case x if re.match(rf"^{g.cfg.cw.member}$", x): 76 title, msg = lookup.textdata.get_members_list() 77 slack_api.post_text(g.msg.event_ts, title, msg) 78 case x if re.match(rf"^{g.cfg.cw.team}$", x): 79 title = "チーム一覧" 80 msg = lookup.textdata.get_team_list() 81 slack_api.post_text(g.msg.event_ts, title, msg) 82 83 case _ as x: 84 other_words(x) 85 86 87def other_words(word: str): 88 """コマンド以外のワードの処理 89 90 Args: 91 word (str): 入力ワード 92 """ 93 94 if re.match(rf"^{g.cfg.cw.remarks_word}$", word) and g.msg.in_thread: # 追加メモ 95 if lookup.db.exsist_record(g.msg.thread_ts).has_valid_data(): 96 modify.check_remarks() 97 else: 98 record_data = lookup.db.exsist_record(g.msg.event_ts) 99 if (detection := validator.pattern(str(g.msg.text))): # 結果報告フォーマットに一致したポストの処理 100 match g.msg.status: 101 case "message_append": 102 if (g.cfg.setting.thread_report == g.msg.in_thread) or not float(g.msg.thread_ts): 103 modify.db_insert(detection) 104 else: 105 slack_api.post_message(message.reply(message="inside_thread"), g.msg.event_ts) 106 logging.notice("append: skip update(inside thread). event_ts=%s, thread_ts=%s", g.msg.event_ts, g.msg.thread_ts) # type: ignore 107 case "message_changed": 108 if detection.to_dict() == record_data.to_dict(): # スコア比較 109 return # 変更箇所がなければ何もしない 110 if (g.cfg.setting.thread_report == g.msg.in_thread) or (g.msg.event_ts == g.msg.thread_ts): 111 if record_data.has_valid_data(): 112 if record_data.rule_version == g.cfg.mahjong.rule_version: 113 modify.db_update(detection) 114 else: 115 logging.notice("changed: skip update(rule_version not match). event_ts=%s", g.msg.event_ts) # type: ignore 116 else: 117 modify.db_insert(detection) 118 modify.reprocessing_remarks() 119 else: 120 slack_api.post_message(message.reply(message="inside_thread"), g.msg.event_ts) 121 logging.notice("skip update(inside thread). event_ts=%s, thread_ts=%s", g.msg.event_ts, g.msg.thread_ts) # type: ignore 122 else: 123 if record_data and g.msg.status == "message_changed": 124 modify.db_delete(g.msg.event_ts) 125 for icon in lookup.api.reactions_status(): 126 slack_api.call_reactions_remove(icon)
def
main(client, body):
19def main(client, body): 20 """ポストされた内容で処理を分岐 21 22 Args: 23 client (slack_bolt.App.client): slack_boltオブジェクト 24 body (dict): ポストされたデータ 25 """ 26 27 logging.trace(body) # type: ignore 28 g.msg.parser(body) 29 g.msg.client = client 30 logging.info( 31 "status=%s, event_ts=%s, thread_ts=%s, in_thread=%s, keyword=%s, user_id=%s,", 32 g.msg.status, g.msg.event_ts, g.msg.thread_ts, g.msg.in_thread, g.msg.keyword, g.msg.user_id, 33 ) 34 35 # 許可されていないユーザのポストは処理しない 36 if g.msg.user_id in g.cfg.setting.ignore_userid: 37 logging.trace("event skip[ignore user]: %s", g.msg.user_id) # type: ignore 38 return 39 40 # 投稿済みメッセージが削除された場合 41 if g.msg.status == "message_deleted": 42 if re.match(rf"^{g.cfg.cw.remarks_word}", g.msg.keyword): # 追加メモ 43 modify.remarks_delete(g.msg.event_ts) 44 else: 45 modify.db_delete(g.msg.event_ts) 46 return 47 48 # キーワード処理 49 match g.msg.keyword: 50 # ヘルプ 51 case x if re.match(rf"^{g.cfg.cw.help}$", x): 52 # ヘルプメッセージ 53 slack_api.post_message(message.help_message(), g.msg.event_ts) 54 # メンバーリスト 55 title, msg = lookup.textdata.get_members_list() 56 slack_api.post_text(g.msg.event_ts, title, msg) 57 58 # 成績管理系コマンド 59 case x if re.match(rf"^{g.cfg.cw.results}$", x): 60 libs.commands.results.slackpost.main() 61 case x if re.match(rf"^{g.cfg.cw.graph}$", x): 62 libs.commands.graph.slackpost.main() 63 case x if re.match(rf"^{g.cfg.cw.ranking}$", x): 64 libs.commands.ranking.slackpost.main() 65 case x if re.match(rf"^{g.cfg.cw.report}$", x): 66 libs.commands.report.slackpost.main() 67 68 # データベース関連コマンド 69 case x if re.match(rf"^{g.cfg.cw.check}$", x): 70 comparison.main() 71 case x if re.match(rf"^Reminder: {g.cfg.cw.check}$", str(g.msg.text)): # Reminderによる突合 72 logging.notice("Reminder: %s", g.cfg.cw.check) # type: ignore 73 comparison.main() 74 75 # メンバーリスト/チームリスト 76 case x if re.match(rf"^{g.cfg.cw.member}$", x): 77 title, msg = lookup.textdata.get_members_list() 78 slack_api.post_text(g.msg.event_ts, title, msg) 79 case x if re.match(rf"^{g.cfg.cw.team}$", x): 80 title = "チーム一覧" 81 msg = lookup.textdata.get_team_list() 82 slack_api.post_text(g.msg.event_ts, title, msg) 83 84 case _ as x: 85 other_words(x)
ポストされた内容で処理を分岐
Arguments:
- client (slack_bolt.App.client): slack_boltオブジェクト
- body (dict): ポストされたデータ
def
other_words(word: str):
88def other_words(word: str): 89 """コマンド以外のワードの処理 90 91 Args: 92 word (str): 入力ワード 93 """ 94 95 if re.match(rf"^{g.cfg.cw.remarks_word}$", word) and g.msg.in_thread: # 追加メモ 96 if lookup.db.exsist_record(g.msg.thread_ts).has_valid_data(): 97 modify.check_remarks() 98 else: 99 record_data = lookup.db.exsist_record(g.msg.event_ts) 100 if (detection := validator.pattern(str(g.msg.text))): # 結果報告フォーマットに一致したポストの処理 101 match g.msg.status: 102 case "message_append": 103 if (g.cfg.setting.thread_report == g.msg.in_thread) or not float(g.msg.thread_ts): 104 modify.db_insert(detection) 105 else: 106 slack_api.post_message(message.reply(message="inside_thread"), g.msg.event_ts) 107 logging.notice("append: skip update(inside thread). event_ts=%s, thread_ts=%s", g.msg.event_ts, g.msg.thread_ts) # type: ignore 108 case "message_changed": 109 if detection.to_dict() == record_data.to_dict(): # スコア比較 110 return # 変更箇所がなければ何もしない 111 if (g.cfg.setting.thread_report == g.msg.in_thread) or (g.msg.event_ts == g.msg.thread_ts): 112 if record_data.has_valid_data(): 113 if record_data.rule_version == g.cfg.mahjong.rule_version: 114 modify.db_update(detection) 115 else: 116 logging.notice("changed: skip update(rule_version not match). event_ts=%s", g.msg.event_ts) # type: ignore 117 else: 118 modify.db_insert(detection) 119 modify.reprocessing_remarks() 120 else: 121 slack_api.post_message(message.reply(message="inside_thread"), g.msg.event_ts) 122 logging.notice("skip update(inside thread). event_ts=%s, thread_ts=%s", g.msg.event_ts, g.msg.thread_ts) # type: ignore 123 else: 124 if record_data and g.msg.status == "message_changed": 125 modify.db_delete(g.msg.event_ts) 126 for icon in lookup.api.reactions_status(): 127 slack_api.call_reactions_remove(icon)
コマンド以外のワードの処理
Arguments:
- word (str): 入力ワード