integrations.slack.config
integrations/slack/config.py
1""" 2integrations/slack/config.py 3""" 4 5import logging 6from dataclasses import dataclass, field 7from typing import TYPE_CHECKING, Any 8 9from integrations.base.interface import IntegrationsConfig 10from integrations.slack.events import comparison, slash 11from libs.bootstrap.section import BaseSection 12 13if TYPE_CHECKING: 14 from pathlib import Path # noqa: F401 15 16 17@dataclass 18class SvcConfig(BaseSection, IntegrationsConfig): 19 """slack用個別設定値""" 20 21 slash_command: str = field(default="/mahjong") 22 """スラッシュコマンド名""" 23 24 comparison_word: str = field(default="成績チェック") 25 """データ突合コマンド呼び出しキーワード""" 26 comparison_alias: list[str] = field(default_factory=list) 27 """データ突合スラッシュコマンド別名(カンマ区切りで設定)""" 28 29 search_channel: list[str] = field(default_factory=list) 30 """テータ突合時に成績記録ワードを検索するチャンネル名(カンマ区切りで設定)""" 31 search_after: int = field(default=7) 32 """データ突合時対象にする日数""" 33 search_wait: int = field(default=180) 34 """指定秒数以内にポストされているデータを突合対象から除外する""" 35 36 thread_report: bool = field(default=True) 37 """スレッド内にある得点報告の扱い 38 39 - *True*: スレッド内の点数報告も取り込む 40 - *False*: スレッド内の点数報告は無視する 41 """ 42 43 # リアクション文字列 44 reaction_ok: str = field(default="ok") 45 """DBに取り込んだ時に付けるリアクション""" 46 reaction_ng: str = field(default="ng") 47 """DBに取り込んだが正確な値ではない可能性があるときに付けるリアクション""" 48 49 # 制限 50 ignore_userid: list[str] = field(default_factory=list) 51 """投稿を無視するユーザのリスト(カンマ区切りで設定)""" 52 channel_limitations: list[str] = field(default_factory=list) 53 """SQLが実行できるチャンネルリスト(カンマ区切りで設定) 54 55 未定義はすべてのチャンネルでSQLが実行できる 56 """ 57 58 bot_id: str = field(default="") 59 """ボットID""" 60 61 tab_var: dict[str, Any] = field(default_factory=dict) 62 """ホームタブ用初期値""" 63 64 def __post_init__(self) -> None: 65 assert self.main_conf 66 self.main_parser = self.main_conf 67 self.section = "slack" 68 super().__init__(self) 69 logging.debug("slack: %s", self) 70 71 # スラッシュコマンドはスラッシュ始まり 72 if not self.slash_command.startswith("/"): 73 self.slash_command = f"/{self.slash_command}" 74 75 # スラッシュコマンド登録 76 self._command_dispatcher.update({"help": slash.command_help}) 77 self._command_dispatcher.update({"check": comparison.main}) 78 for alias in self.comparison_alias: 79 self._command_dispatcher.update({alias: comparison.main}) 80 81 # 個別コマンド登録 82 self._keyword_dispatcher.update( 83 { 84 self.comparison_word: comparison.main, 85 f"Reminder: {self.comparison_word}": comparison.main, 86 } 87 )
@dataclass
class
SvcConfig18@dataclass 19class SvcConfig(BaseSection, IntegrationsConfig): 20 """slack用個別設定値""" 21 22 slash_command: str = field(default="/mahjong") 23 """スラッシュコマンド名""" 24 25 comparison_word: str = field(default="成績チェック") 26 """データ突合コマンド呼び出しキーワード""" 27 comparison_alias: list[str] = field(default_factory=list) 28 """データ突合スラッシュコマンド別名(カンマ区切りで設定)""" 29 30 search_channel: list[str] = field(default_factory=list) 31 """テータ突合時に成績記録ワードを検索するチャンネル名(カンマ区切りで設定)""" 32 search_after: int = field(default=7) 33 """データ突合時対象にする日数""" 34 search_wait: int = field(default=180) 35 """指定秒数以内にポストされているデータを突合対象から除外する""" 36 37 thread_report: bool = field(default=True) 38 """スレッド内にある得点報告の扱い 39 40 - *True*: スレッド内の点数報告も取り込む 41 - *False*: スレッド内の点数報告は無視する 42 """ 43 44 # リアクション文字列 45 reaction_ok: str = field(default="ok") 46 """DBに取り込んだ時に付けるリアクション""" 47 reaction_ng: str = field(default="ng") 48 """DBに取り込んだが正確な値ではない可能性があるときに付けるリアクション""" 49 50 # 制限 51 ignore_userid: list[str] = field(default_factory=list) 52 """投稿を無視するユーザのリスト(カンマ区切りで設定)""" 53 channel_limitations: list[str] = field(default_factory=list) 54 """SQLが実行できるチャンネルリスト(カンマ区切りで設定) 55 56 未定義はすべてのチャンネルでSQLが実行できる 57 """ 58 59 bot_id: str = field(default="") 60 """ボットID""" 61 62 tab_var: dict[str, Any] = field(default_factory=dict) 63 """ホームタブ用初期値""" 64 65 def __post_init__(self) -> None: 66 assert self.main_conf 67 self.main_parser = self.main_conf 68 self.section = "slack" 69 super().__init__(self) 70 logging.debug("slack: %s", self) 71 72 # スラッシュコマンドはスラッシュ始まり 73 if not self.slash_command.startswith("/"): 74 self.slash_command = f"/{self.slash_command}" 75 76 # スラッシュコマンド登録 77 self._command_dispatcher.update({"help": slash.command_help}) 78 self._command_dispatcher.update({"check": comparison.main}) 79 for alias in self.comparison_alias: 80 self._command_dispatcher.update({alias: comparison.main}) 81 82 # 個別コマンド登録 83 self._keyword_dispatcher.update( 84 { 85 self.comparison_word: comparison.main, 86 f"Reminder: {self.comparison_word}": comparison.main, 87 } 88 )
slack用個別設定値
SvcConfig( _parser: configparser.ConfigParser | None = None, _command_dispatcher: dict[str, typing.Any] = <factory>, _keyword_dispatcher: dict[str, typing.Any] = <factory>, main_conf: configparser.ConfigParser | None = None, channel_config: pathlib.Path | None = None, slash_command: str = '/mahjong', badge_degree: bool = False, badge_status: bool = False, badge_grade: bool = False, separate: bool = False, channel_id: str | None = None, plotting_backend: Literal['matplotlib', 'plotly'] = 'matplotlib', comparison_word: str = '成績チェック', comparison_alias: list[str] = <factory>, search_channel: list[str] = <factory>, search_after: int = 7, search_wait: int = 180, thread_report: bool = True, reaction_ok: str = 'ok', reaction_ng: str = 'ng', ignore_userid: list[str] = <factory>, channel_limitations: list[str] = <factory>, bot_id: str = '', tab_var: dict[str, typing.Any] = <factory>)