allboot commited on
Commit
31e0883
ยท
verified ยท
1 Parent(s): be23b6f

Upload facebook_bridge.py

Browse files
Files changed (1) hide show
  1. facebook_bridge.py +277 -0
facebook_bridge.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ facebook_bridge.py
3
+ ==================
4
+ ู…ุฑุงู‚ุจุฉ ู‚ู†ุงุฉ ุชูŠู„ูŠุฌุฑุงู… @CastleInfoiq ูˆู†ุดุฑ ุงู„ู…ู†ุดูˆุฑุงุช ุงู„ุฌุฏูŠุฏุฉ ุนู„ู‰ ููŠุณุจูˆูƒ.
5
+ ู…ุณุชู‚ู„ 100% ุนู† app.py โ€” ู„ุง ูŠู„ู…ุณู‡ ูˆู„ุง ูŠุชุฃุซุฑ ุจู‡.
6
+ """
7
+
8
+ import os
9
+ import json
10
+ import asyncio
11
+ import logging
12
+ import tempfile
13
+ import time
14
+ import requests
15
+ from datetime import datetime, timezone
16
+
17
+ import pytz
18
+ from pyrogram import Client, filters
19
+ from pyrogram.types import Message
20
+
21
+ # โ”€โ”€โ”€ ุฅุนุฏุงุฏ ุงู„ุชุณุฌูŠู„ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
22
+
23
+ logging.basicConfig(
24
+ level=logging.INFO,
25
+ format="%(asctime)s [%(levelname)s] %(name)s โ€” %(message)s",
26
+ datefmt="%Y-%m-%d %H:%M:%S",
27
+ )
28
+ log = logging.getLogger("facebook_bridge")
29
+
30
+ # โ”€โ”€โ”€ ุงู„ุฅุนุฏุงุฏุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
31
+
32
+ API_ID = int(os.environ["API_ID"])
33
+ API_HASH = os.environ["API_HASH"]
34
+ SESSION_STRING = os.environ["SESSION_STRING"]
35
+ TELEGRAM_CHANNEL = "@CastleInfoiq"
36
+
37
+ FACEBOOK_PAGE_ID = os.environ.get("FACEBOOK_PAGE_ID", "1207551039107566")
38
+ FB_TOKEN = os.environ["FACEBOOK_PAGE_ACCESS_TOKEN"]
39
+ FB_API_BASE = "https://graph.facebook.com/v19.0"
40
+
41
+ BAGHDAD_TZ = pytz.timezone("Asia/Baghdad")
42
+ PUBLISH_HOUR_START = 9 # 09:00 ุตุจุงุญุงู‹
43
+ PUBLISH_HOUR_END = 23 # 23:00 ู…ุณุงุกู‹
44
+
45
+ # ู…ู„ู ุชุชุจุน ุงู„ู…ู†ุดูˆุฑุงุช ุงู„ู…ู†ุดูˆุฑุฉ ู…ุณุจู‚ุงู‹
46
+ POSTS_DB_FILE = "facebook_posts.json"
47
+
48
+ # ุงู„ู†ุต ุงู„ุฐูŠ ูŠูุญุฐู ู‚ุจู„ ุงู„ู†ุดุฑ
49
+ TEXT_TO_REMOVE = "ุงุดุชู€ู€ู€ุฑูƒ ุงู„ุขู† :- https://t.me/CastleInfoiq"
50
+
51
+ # โ”€โ”€โ”€ ู‚ุงุนุฏุฉ ุจูŠุงู†ุงุช ุงู„ู…ู†ุดูˆุฑุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
52
+
53
+ def load_published_ids() -> set:
54
+ """ุชุญู…ูŠู„ ู…ุนุฑู‘ูุงุช ุงู„ุฑุณุงุฆู„ ุงู„ู…ู†ุดูˆุฑุฉ ู…ุณุจู‚ุงู‹."""
55
+ if not os.path.exists(POSTS_DB_FILE):
56
+ return set()
57
+ try:
58
+ with open(POSTS_DB_FILE, "r", encoding="utf-8") as f:
59
+ data = json.load(f)
60
+ return set(data.get("published_ids", []))
61
+ except Exception as e:
62
+ log.warning(f"ุชุนุฐู‘ุฑ ุชุญู…ูŠู„ {POSTS_DB_FILE}: {e}")
63
+ return set()
64
+
65
+
66
+ def save_published_id(msg_id: int, published_ids: set) -> None:
67
+ """ุญูุธ ู…ุนุฑู‘ู ุฑุณุงู„ุฉ ุฌุฏูŠุฏุฉ ููŠ ู‚ุงุนุฏุฉ ุงู„ุจูŠุงู†ุงุช."""
68
+ published_ids.add(msg_id)
69
+ try:
70
+ with open(POSTS_DB_FILE, "w", encoding="utf-8") as f:
71
+ json.dump({"published_ids": list(published_ids)}, f, ensure_ascii=False, indent=2)
72
+ except Exception as e:
73
+ log.error(f"ุชุนุฐู‘ุฑ ุญูุธ {POSTS_DB_FILE}: {e}")
74
+
75
+
76
+ # โ”€โ”€โ”€ ุงู„ุชุญู‚ู‚ ู…ู† ูˆู‚ุช ุงู„ู†ุดุฑ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
77
+
78
+ def is_within_publish_hours() -> bool:
79
+ """ู‡ู„ ุงู„ูˆู‚ุช ุงู„ุญุงู„ูŠ ุถู…ู† ู†ุงูุฐุฉ ุงู„ู†ุดุฑ ุงู„ู…ุณู…ูˆุญ ุจู‡ุงุŸ"""
80
+ now = datetime.now(BAGHDAD_TZ)
81
+ return PUBLISH_HOUR_START <= now.hour < PUBLISH_HOUR_END
82
+
83
+
84
+ # โ”€โ”€โ”€ ุชู†ุธูŠู ุงู„ู†ุต โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
85
+
86
+ def clean_text(text: str) -> str:
87
+ """ุญุฐู ุณุทุฑ ุงู„ุงุดุชุฑุงูƒ ูู‚ุท ูˆุงู„ุฅุจู‚ุงุก ุนู„ู‰ ุจู‚ูŠุฉ ุงู„ู†ุต."""
88
+ if not text:
89
+ return ""
90
+ lines = text.splitlines()
91
+ cleaned = [line for line in lines if TEXT_TO_REMOVE not in line]
92
+ return "\n".join(cleaned).strip()
93
+
94
+
95
+ # โ”€โ”€โ”€ ุงู„ู†ุดุฑ ุนู„ู‰ ููŠุณุจูˆูƒ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
96
+
97
+ def _fb_post_text(text: str) -> bool:
98
+ """ู†ุดุฑ ู†ุต ูู‚ุท ุนู„ู‰ ุตูุญุฉ ููŠุณุจูˆูƒ."""
99
+ url = f"{FB_API_BASE}/{FACEBOOK_PAGE_ID}/feed"
100
+ payload = {"message": text, "access_token": FB_TOKEN}
101
+
102
+ for attempt in range(1, 4):
103
+ try:
104
+ resp = requests.post(url, data=payload, timeout=30)
105
+ result = resp.json()
106
+ if resp.ok and "id" in result:
107
+ log.info(f"โœ… Facebook publish success (text) โ€” post_id={result['id']}")
108
+ return True
109
+ log.warning(f"โš ๏ธ ู…ุญุงูˆู„ุฉ {attempt}/3 ูุดู„ุช (ู†ุต): {result}")
110
+ except Exception as e:
111
+ log.warning(f"โš ๏ธ ู…ุญุงูˆู„ุฉ {attempt}/3 ุงุณุชุซู†ุงุก (ู†ุต): {e}")
112
+ time.sleep(5 * attempt)
113
+
114
+ log.error("โŒ Facebook publish failed (text) โ€” ุงุณุชูู†ูุฏุช ุฌู…ูŠุน ุงู„ู…ุญุงูˆู„ุงุช")
115
+ return False
116
+
117
+
118
+ def _fb_post_photo(image_path: str, text: str) -> bool:
119
+ """ุฑูุน ุตูˆุฑุฉ ูˆู†ุดุฑู‡ุง ู…ุน ุงู„ู†ุต ุนู„ู‰ ุตูุญุฉ ููŠุณุจูˆูƒ."""
120
+ url = f"{FB_API_BASE}/{FACEBOOK_PAGE_ID}/photos"
121
+
122
+ for attempt in range(1, 4):
123
+ try:
124
+ with open(image_path, "rb") as img_file:
125
+ resp = requests.post(
126
+ url,
127
+ data={"message": text, "published": "true", "access_token": FB_TOKEN},
128
+ files={"source": img_file},
129
+ timeout=60,
130
+ )
131
+ result = resp.json()
132
+ if resp.ok and ("id" in result or "post_id" in result):
133
+ pid = result.get("post_id") or result.get("id")
134
+ log.info(f"โœ… Facebook publish success (photo) โ€” post_id={pid}")
135
+ return True
136
+ log.warning(f"โš ๏ธ ู…ุญุงูˆู„ุฉ {attempt}/3 ูุดู„ุช (ุตูˆุฑุฉ): {result}")
137
+ except Exception as e:
138
+ log.warning(f"โš ๏ธ ู…ุญุงูˆู„ุฉ {attempt}/3 ุงุณุชุซู†ุงุก (ุตูˆุฑุฉ): {e}")
139
+ time.sleep(5 * attempt)
140
+
141
+ log.error("โŒ Facebook publish failed (photo) โ€” ุงุณุชูู†ูุฏุช ุฌู…ูŠุน ุงู„ู…ุญุงูˆู„ุงุช")
142
+ return False
143
+
144
+
145
+ # โ”€โ”€โ”€ ุชู†ุฒูŠู„ ุงู„ุตูˆุฑุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
146
+
147
+ async def download_photo_temp(client: Client, message: Message) -> str | None:
148
+ """
149
+ ุชู†ุฒูŠู„ ุตูˆุฑุฉ ุฅู„ู‰ ู…ู„ู ู…ุคู‚ุช ูˆุฅุนุงุฏุฉ ู…ุณุงุฑู‡.
150
+ ูŠุนูˆุฏ None ููŠ ุญุงู„ุฉ ุงู„ูุดู„.
151
+ """
152
+ try:
153
+ suffix = ".jpg"
154
+ with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
155
+ tmp_path = tmp.name
156
+ path = await client.download_media(message, file_name=tmp_path)
157
+ return path
158
+ except Exception as e:
159
+ log.error(f"ุชุนุฐู‘ุฑ ุชู†ุฒูŠู„ ุงู„ุตูˆุฑุฉ: {e}")
160
+ return None
161
+
162
+
163
+ def delete_temp_file(path: str) -> None:
164
+ """ุญุฐู ุงู„ู…ู„ู ุงู„ู…ุคู‚ุช ุจุนุฏ ุงู„ุฑูุน."""
165
+ try:
166
+ if path and os.path.exists(path):
167
+ os.remove(path)
168
+ except Exception as e:
169
+ log.warning(f"ุชุนุฐู‘ุฑ ุญุฐู ุงู„ู…ู„ู ุงู„ู…ุคู‚ุช {path}: {e}")
170
+
171
+
172
+ # โ”€โ”€โ”€ ู…ุนุงู„ุฌุฉ ุงู„ุฑุณุงุฆู„ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
173
+
174
+ published_ids: set = load_published_ids()
175
+
176
+ # ู†ุชุชุจุน grouped_ids ู„ุชุฌู†ุจ ู…ุนุงู„ุฌุฉ ุฃู„ุจูˆู… ุฃูƒุซุฑ ู…ู† ู…ุฑุฉ
177
+ _handled_media_groups: set = set()
178
+
179
+
180
+ async def process_message(client: Client, message: Message) -> None:
181
+ """
182
+ ุงู„ู…ุนุงู„ุฌ ุงู„ุฑุฆูŠุณูŠ ู„ูƒู„ ุฑุณุงู„ุฉ ูˆุงุฑุฏุฉ ู…ู† ุงู„ู‚ู†ุงุฉ.
183
+ """
184
+ global published_ids, _handled_media_groups
185
+
186
+ msg_id = message.id
187
+ log.info(f"๐Ÿ“ฉ Telegram post detected โ€” id={msg_id}")
188
+
189
+ # โ”€โ”€ ู…ู†ุน ุงู„ุชูƒุฑุงุฑ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
190
+ if msg_id in published_ids:
191
+ log.info(f"โญ๏ธ ุชุฌุงู‡ู„ โ€” ุชู… ู†ุดุฑ id={msg_id} ู…ุณุจู‚ุงู‹")
192
+ return
193
+
194
+ # โ”€โ”€ ูุญุต ุงู„ูˆู‚ุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
195
+ if not is_within_publish_hours():
196
+ now_str = datetime.now(BAGHDAD_TZ).strftime("%H:%M")
197
+ log.info(f"๐Ÿ• ุชุฌุงู‡ู„ โ€” ุฎุงุฑุฌ ู†ุงูุฐุฉ ุงู„ู†ุดุฑ (ุงู„ูˆู‚ุช ุงู„ุญุงู„ูŠ: {now_str})")
198
+ return
199
+
200
+ # โ”€โ”€ ุงุณุชุฎุฑุงุฌ ุงู„ู†ุต โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
201
+ raw_text = message.text or message.caption or ""
202
+ post_text = clean_text(raw_text)
203
+
204
+ try:
205
+ # โ”€โ”€ ุฃู„ุจูˆู… ุตูˆุฑ (media_group) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
206
+ if message.media_group_id:
207
+ group_key = message.media_group_id
208
+
209
+ if group_key in _handled_media_groups:
210
+ # ุฑุณุงู„ุฉ ุซุงู†ูŠุฉ/ุซุงู„ุซุฉ ู…ู† ู†ูุณ ุงู„ุฃู„ุจูˆู… โ€” ุชูุณุฌูŽู‘ู„ ูƒู€ published ู„ู…ู†ุน ุฅุนุงุฏุฉ ุงู„ู…ุนุงู„ุฌุฉ
211
+ save_published_id(msg_id, published_ids)
212
+ return
213
+
214
+ _handled_media_groups.add(group_key)
215
+ log.info(f"๐Ÿ–ผ๏ธ ุฃู„ุจูˆู… id={group_key} โ€” ุณู†ุฃุฎุฐ ุฃูˆู„ ุตูˆุฑุฉ ูู‚ุท")
216
+
217
+ # ู†ุฒู‘ู„ ุตูˆุฑุฉ ู‡ุฐู‡ ุงู„ุฑุณุงู„ุฉ (ุฃูˆู„ ุฑุณุงู„ุฉ ููŠ ุงู„ุฃู„ุจูˆู…)
218
+ tmp_path = await download_photo_temp(client, message)
219
+ if tmp_path:
220
+ success = _fb_post_photo(tmp_path, post_text)
221
+ delete_temp_file(tmp_path)
222
+ else:
223
+ # ูุดู„ ุงู„ุชู†ุฒูŠู„ โ€” ู†ุดุฑ ุงู„ู†ุต ูˆุญุฏู‡
224
+ success = _fb_post_text(post_text) if post_text else False
225
+
226
+ # โ”€โ”€ ุตูˆุฑุฉ ู…ู†ูุฑุฏุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
227
+ elif message.photo or message.document:
228
+ log.info("๐Ÿ–ผ๏ธ ุตูˆุฑุฉ ู…ู†ูุฑุฏุฉ")
229
+ tmp_path = await download_photo_temp(client, message)
230
+ if tmp_path:
231
+ success = _fb_post_photo(tmp_path, post_text)
232
+ delete_temp_file(tmp_path)
233
+ else:
234
+ success = _fb_post_text(post_text) if post_text else False
235
+
236
+ # โ”€โ”€ ู†ุต ูู‚ุท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
237
+ elif post_text:
238
+ log.info("๐Ÿ“ ู†ุต ูู‚ุท")
239
+ success = _fb_post_text(post_text)
240
+
241
+ else:
242
+ log.info("โญ๏ธ ุฑุณุงู„ุฉ ุจุฏูˆู† ู…ุญุชูˆู‰ ู‚ุงุจู„ ู„ู„ู†ุดุฑ โ€” ุชุฌุงู‡ู„")
243
+ save_published_id(msg_id, published_ids)
244
+ return
245
+
246
+ if success:
247
+ save_published_id(msg_id, published_ids)
248
+
249
+ except Exception as e:
250
+ log.error(f"โŒ ุฎุทุฃ ุบูŠุฑ ู…ุชูˆู‚ุน ุฃุซู†ุงุก ู…ุนุงู„ุฌุฉ id={msg_id}: {e}", exc_info=True)
251
+
252
+
253
+ # โ”€โ”€โ”€ ุชุดุบูŠู„ Pyrogram โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
254
+
255
+ def main() -> None:
256
+ log.info("๐Ÿš€ ุจุฏุก ุชุดุบูŠู„ facebook_bridge ...")
257
+
258
+ app = Client(
259
+ name="facebook_bridge_session",
260
+ api_id=API_ID,
261
+ api_hash=API_HASH,
262
+ session_string=SESSION_STRING,
263
+ )
264
+
265
+ @app.on_message(filters.channel & filters.chat(TELEGRAM_CHANNEL))
266
+ async def on_new_post(client: Client, message: Message):
267
+ await process_message(client, message)
268
+
269
+ log.info(f"๐Ÿ‘‚ ู…ุฑุงู‚ุจุฉ ุงู„ู‚ู†ุงุฉ: {TELEGRAM_CHANNEL}")
270
+ log.info(f"โฐ ู†ุงูุฐุฉ ุงู„ู†ุดุฑ: {PUBLISH_HOUR_START:02d}:00 โ€“ {PUBLISH_HOUR_END:02d}:00 (Baghdad)")
271
+ log.info(f"๐Ÿ“˜ ุตูุญุฉ ุงู„ููŠุณุจูˆูƒ: {FACEBOOK_PAGE_ID}")
272
+
273
+ app.run()
274
+
275
+
276
+ if __name__ == "__main__":
277
+ main()