izuemon commited on
Commit
73c24ae
·
verified ·
1 Parent(s): eeae785

Update news.py

Browse files
Files changed (1) hide show
  1. news.py +40 -14
news.py CHANGED
@@ -139,22 +139,48 @@ def run_job():
139
 
140
 
141
  def main():
142
- last_run = load_last_run()
143
 
144
  while True:
145
- now = datetime.now()
146
- now_key = now.strftime("%Y-%m-%d %H:%M")
147
- now_time = now.strftime("%H:%M")
148
-
149
- if now_time in TARGET_TIMES and last_run != now_key:
150
- print(f"{now_time} 実行開始")
151
- try:
152
- run_job()
153
- save_last_run(now_key)
154
- except Exception as e:
155
- print("エラー:", e)
156
-
157
- time.sleep(60) # 1分ごとにチェック
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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__":