Spaces:
Running
Running
Update news.py
Browse files
news.py
CHANGED
|
@@ -139,22 +139,48 @@ def run_job():
|
|
| 139 |
|
| 140 |
|
| 141 |
def main():
|
| 142 |
-
|
| 143 |
|
| 144 |
while True:
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|
|
|
|
| 139 |
|
| 140 |
|
| 141 |
def main():
|
| 142 |
+
processed = set()
|
| 143 |
|
| 144 |
while True:
|
| 145 |
+
try:
|
| 146 |
+
messages = fetch_channel_messages()
|
| 147 |
+
|
| 148 |
+
if not messages:
|
| 149 |
+
time.sleep(10)
|
| 150 |
+
continue
|
| 151 |
+
|
| 152 |
+
latest = messages[-1]
|
| 153 |
+
msg_id = latest.get("id")
|
| 154 |
+
person_id = latest.get("personId")
|
| 155 |
+
|
| 156 |
+
# すでに処理済み
|
| 157 |
+
if msg_id in processed:
|
| 158 |
+
time.sleep(10)
|
| 159 |
+
continue
|
| 160 |
+
|
| 161 |
+
# ★ アシスタント発言ならGPTに送らず待機
|
| 162 |
+
if person_id == ASSISTANT_PERSON_ID:
|
| 163 |
+
time.sleep(10)
|
| 164 |
+
continue
|
| 165 |
+
|
| 166 |
+
# GPT用メッセージ構築
|
| 167 |
+
chat_messages = build_chat_messages(messages)
|
| 168 |
+
|
| 169 |
+
if not chat_messages:
|
| 170 |
+
processed.add(msg_id)
|
| 171 |
+
continue
|
| 172 |
+
|
| 173 |
+
reply = call_chat_api(chat_messages)
|
| 174 |
+
send_to_channel(reply)
|
| 175 |
+
|
| 176 |
+
processed.add(msg_id)
|
| 177 |
+
print("送信完了")
|
| 178 |
+
|
| 179 |
+
except Exception as e:
|
| 180 |
+
print("エラー:", e)
|
| 181 |
+
|
| 182 |
+
time.sleep(15)
|
| 183 |
+
|
| 184 |
|
| 185 |
|
| 186 |
if __name__ == "__main__":
|