소스 검색

Fixed index out of range error when new list of announcements is smaller than the old list

allens 4 일 전
부모
커밋
b7edb0017b
1개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 8 3
      ownchatbot/__init__.py

+ 8 - 3
ownchatbot/__init__.py

@@ -47,9 +47,14 @@ def create_app(test_config=None):
         global current_index
         app.config.from_pyfile('announce.py', silent=True)
         announcements = app.config['ANNOUNCEMENTS']
-        message = announcements[current_index]
-        send_system_chat(message)
-        current_index = (current_index + 1) % len(announcements)
+        if current_index >= len(announcements):  # If reached the last announement, reset index
+            current_index = 0
+        try:
+            message = announcements[current_index]
+            send_system_chat(message)
+            current_index = (current_index + 1) % len(announcements)
+        except Exception as a_error:
+            app.logger.error(f'Couldn\'t make announcement: {a_error.args[0]}')
                 
     def award_job():
         with app.app_context():