فهرست منبع

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

allens 10 ماه پیش
والد
کامیت
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():