|
|
@@ -3,11 +3,10 @@ from ownchatbot.db import get_db
|
|
|
from ownchatbot.owncast_com import send_chat, send_private_chat
|
|
|
from ownchatbot.user_handlers import add_user_to_points, change_name, get_users_points, remove_duplicates, get_email_code, set_email_code, award_chat_points, user_in_points, get_all_users_with_user_id
|
|
|
from ownchatbot.bot_messages import do_reward, help_message
|
|
|
-from ownchatbot.reward_handlers import all_active_goals, all_active_votes, all_active_rewards
|
|
|
+from ownchatbot.reward_handlers import all_active_goals, all_active_votes, all_active_rewards, save_alerts
|
|
|
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__)
|
|
|
@@ -165,60 +164,62 @@ 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)
|
|
|
+ last_follower = followers.clear()
|
|
|
return jsonify(last_follower)
|
|
|
else:
|
|
|
- current_app.logger.info(f'No new followers')
|
|
|
+ current_app.logger.debug(f'No new followers')
|
|
|
return jsonify(None)
|
|
|
|
|
|
|
|
|
-@ocb.route('/checkGoals') # Polled by follower.html template to check for new followers
|
|
|
+@ocb.route('/checkGoals') # Polled by ocbalert.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)
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
+ rgoals = {'name': alerts_dict['g_name'], 'reward': alerts_dict['g_reward']}
|
|
|
+ if rgoals['name']:
|
|
|
+ current_app.logger.debug(f'\n\n{format(rgoals)}\n\n')
|
|
|
+ alerts_dict['g_name'] = ''
|
|
|
+ alerts_dict['g_reward'] = ''
|
|
|
+ save_alerts(alerts_dict)
|
|
|
+ return jsonify(rgoals)
|
|
|
else:
|
|
|
- current_app.logger.info(f'No new goals reached')
|
|
|
- return jsonify(None)
|
|
|
+ current_app.logger.debug(f'No new goals reached')
|
|
|
return jsonify(None)
|
|
|
|
|
|
|
|
|
-@ocb.route('/checkMilestones') # Polled by follower.html template to check for new followers
|
|
|
+@ocb.route('/checkMilestones') # Polled by ocbalert.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)
|
|
|
+ alerts_dict = current_app.config['ALERTS']
|
|
|
+ rmilestones = {'name': alerts_dict['m_name'], 'reward': alerts_dict['m_reward']}
|
|
|
+ if rmilestones['name']:
|
|
|
+ current_app.logger.info(f'\n\n{format(rmilestones)}\n\n')
|
|
|
+ alerts_dict['m_name'] = ''
|
|
|
+ alerts_dict['m_reward'] = ''
|
|
|
+ save_alerts(alerts_dict)
|
|
|
+ return jsonify(rmilestones)
|
|
|
else:
|
|
|
- current_app.logger.info(f'No new milestones passed')
|
|
|
+ current_app.logger.debug(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)
|
|
|
+ current_app.logger.info(f'\n\n{format(donations)}\n\n')
|
|
|
+ last_donation = donations.clear()
|
|
|
return jsonify(last_donation)
|
|
|
else:
|
|
|
- current_app.logger.info(f'No new donations')
|
|
|
+ current_app.logger.debug(f'No new donations')
|
|
|
return jsonify(None)
|
|
|
|
|
|
|
|
|
@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)
|
|
|
+ current_app.logger.info(f'\n\n{format(subscribers)}\n\n')
|
|
|
+ last_subscriber = subscribers.clear()
|
|
|
return jsonify(last_subscriber)
|
|
|
else:
|
|
|
- current_app.logger.info(f'No new subscribers')
|
|
|
+ current_app.logger.debug(f'No new subscribers')
|
|
|
return jsonify(None)
|