izuemon commited on
Commit
37f221f
·
verified ·
1 Parent(s): 1d842be

Update join.py

Browse files
Files changed (1) hide show
  1. join.py +33 -2
join.py CHANGED
@@ -26,8 +26,36 @@ HEADERS = {
26
  "content-type": "application/json",
27
  "x-account": X_ACCOUNT,
28
  }
29
-
30
- WELCOME_TEXT = "こんにちは。ITRSAにようこそ。自動でいくつかの部屋に招待しています。"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  BOT_PERSON_ID = "599642"
33
 
@@ -35,6 +63,8 @@ INVITE_GROUPS = [
35
  519217,
36
  536194,
37
  534868,
 
 
38
  ]
39
 
40
  # ===== API操作 =====
@@ -45,6 +75,7 @@ def fetch_messages() -> List[Dict[str, Any]]:
45
 
46
 
47
  def post_welcome_message() -> None:
 
48
  payload = {
49
  "requestId": f"welcome-{int(time.time() * 1000)}",
50
  "blocks": [{"type": "text", "value": WELCOME_TEXT}],
 
26
  "content-type": "application/json",
27
  "x-account": X_ACCOUNT,
28
  }
29
+ TXT_WELCOME = """
30
+ こんにちは。ITRSAにようこそ。自動でいくつかの部屋に招待しています。\n
31
+ <b>使い方:</b>左側のメニューから、部屋(グループ)を開くことができます。\n
32
+ ・Youtubeダウンローダーは、URLを送ると自動でYoutubeをダウンロードしてくれる部屋
33
+ ・チャッピーは、ChatGPTと話せる部屋
34
+ ・幹部と裁判所からの報告はここを管理する幹部や裁判所から通知が来る部屋
35
+ ・{get_group_title(200605)}
36
+ """
37
+
38
+ def get_group_title(group_id: int) -> str | None:
39
+ url = f"https://desk-api.channel.io/desk/channels/{group_id}/groups?limit=1000"
40
+ response = requests.get(url)
41
+ response.raise_for_status()
42
+ data = response.json()
43
+ groups = data.get("groups", [])
44
+ for group in groups:
45
+ if group.get("id") == group_id:
46
+ return group.get("title")
47
+ return None
48
+
49
+ # 文字列内の {get_group_title(...)} を置換する関数
50
+ def replace_titles_in_text(text: str) -> str:
51
+ pattern = r"\{get_group_title\((\d+)\)\}"
52
+
53
+ def replacer(match):
54
+ group_id = int(match.group(1))
55
+ title = get_group_title(group_id)
56
+ return title if title else "タイトルなし"
57
+
58
+ return re.sub(pattern, replacer, text)
59
 
60
  BOT_PERSON_ID = "599642"
61
 
 
63
  519217,
64
  536194,
65
  534868,
66
+ 521995,
67
+ 530062
68
  ]
69
 
70
  # ===== API操作 =====
 
75
 
76
 
77
  def post_welcome_message() -> None:
78
+ WELCOME_TEXT = replace_titles_in_text(TXT_WELCOME)
79
  payload = {
80
  "requestId": f"welcome-{int(time.time() * 1000)}",
81
  "blocks": [{"type": "text", "value": WELCOME_TEXT}],