2 Коміти 1cf3e612fd ... 564a1bf044

Автор SHA1 Опис Дата
  allens 564a1bf044 Added img tag blurb and link to announcements page 4 днів тому
  allens b7edb0017b Fixed index out of range error when new list of announcements is smaller than the old list 4 днів тому
2 змінених файлів з 9 додано та 4 видалено
  1. 8 3
      ownchatbot/__init__.py
  2. 1 1
      ownchatbot/templates/mgmt.html

+ 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():

+ 1 - 1
ownchatbot/templates/mgmt.html

@@ -361,7 +361,7 @@
                         <td>
                             <textarea name="announcements" rows="5" cols="50">{{ announcements | join('\n') }}</textarea>
                         </td>
-                        <td>Enter your announcements, one per line.</td>
+                        <td>Enter your announcements, one per line. May contain html <a href=https://www.w3schools.com/tags/tag_img.asp>IMG tags</a> to display images.</td>
                     </tr>
                 </table>
                 <br><button class="button button2" type="submit">Save Changes</button><br>