Преглед изворни кода

Set up alert lists as globals

allens пре 1 недеља
родитељ
комит
912a81b1b7
2 измењених фајлова са 37 додато и 7 уклоњено
  1. 6 0
      ownchatbot/__init__.py
  2. 31 7
      ownchatbot/webhooks.py

+ 6 - 0
ownchatbot/__init__.py

@@ -8,6 +8,12 @@ from apscheduler.schedulers.background import BackgroundScheduler
 
 current_index = 0
 
+followers = []
+donations = []
+subscribers = []
+rgoal = []
+rmilestone = []
+
 
 def create_app(test_config=None):
     app = Flask(__name__, instance_relative_config=True)

+ 31 - 7
ownchatbot/webhooks.py

@@ -7,16 +7,12 @@ from ownchatbot.reward_handlers import all_active_goals, all_active_votes, all_a
 from ownchatbot.kofi_handlers import accept_donation, accept_sub
 import json
 import random
+from ownchatbot import followers, donations, subscribers, rgoal, rmilestone
 
 
 ocb = Blueprint('webhooks', __name__)
 
 
-followers = []
-donations = []
-subscribers = []
-
-
 def format(rawjson):  # Make data legible
     formatted_data = json.dumps(rawjson, indent=4)
     return formatted_data
@@ -169,6 +165,7 @@ def kofi_hook():
 
 @ocb.route('/checkFollows')  # Polled by follower.html template to check for new followers
 def check_follows():
+    global followers
     if followers:
         current_app.logger.debug(f'\n\n{format(followers[0])}\n\n')
         last_follower = followers.pop(0)
@@ -178,8 +175,34 @@ def check_follows():
     return jsonify(None)
 
 
-@ocb.route('/checkDonations')  # Polled by follower.html template to check for new followers
+@ocb.route('/checkGoals')  # Polled by follower.html template to check for new followers
+def check_goals():
+    global rgoals
+    if rgoals:
+        current_app.logger.debug(f'\n\n{format(rgoals[0])}\n\n')
+        last_goal = rgoals.pop(0)
+        return jsonify(last_goal)
+    else:
+        current_app.logger.info(f'No new goals reached')
+    return jsonify(None)
+    return jsonify(None)
+
+
+@ocb.route('/checkMilestones')  # Polled by follower.html template to check for new followers
+def check_milestones():
+    global rmilestones
+    if rmilestones:
+        current_app.logger.debug(f'\n\n{format(rmilestones[0])}\n\n')
+        last_milestone = rmilestones.pop(0)
+        return jsonify(last_milestone)
+    else:
+        current_app.logger.info(f'No new milestones passed')
+    return jsonify(None)
+
+
+@ocb.route('/checkDonations')  # Polled by donation.html template to check for new kofi donations
 def check_donations():
+    global donations
     if donations:
         current_app.logger.info(f'\n\n{format(donations[0])}\n\n')
         last_donation = donations.pop(0)
@@ -189,8 +212,9 @@ def check_donations():
     return jsonify(None)
 
 
-@ocb.route('/checkSubscribers')  # Polled by subscriber.html template to check for new followers
+@ocb.route('/checkSubscribers')  # Polled by subscriber.html template to check for new kofi subscribers
 def check_subscribers():
+    global subscribers
     if subscribers:
         current_app.logger.info(f'\n\n{format(subscribers[0])}\n\n')
         last_subscriber = subscribers.pop(0)