|
@@ -2,7 +2,7 @@ from flask import Flask, request, json, Blueprint, current_app, render_template,
|
|
|
from ownchatbot.db import get_db, clear_fulfilled_rewards
|
|
from ownchatbot.db import get_db, clear_fulfilled_rewards
|
|
|
from ownchatbot.owncast_com import send_chat, send_private_chat
|
|
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.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.bot_messages import do_reward, help_message, porps
|
|
|
from ownchatbot.reward_handlers import all_active_goals, all_active_votes, all_active_rewards, save_alerts
|
|
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
|
|
from ownchatbot.kofi_handlers import accept_donation, accept_sub
|
|
|
import json
|
|
import json
|
|
@@ -65,7 +65,7 @@ def chat_hook():
|
|
|
if points is None:
|
|
if points is None:
|
|
|
send_private_chat(user_id, f'{display_name}, couldn\'t get your points, for some highly technical reason.')
|
|
send_private_chat(user_id, f'{display_name}, couldn\'t get your points, for some highly technical reason.')
|
|
|
else:
|
|
else:
|
|
|
- send_private_chat(user_id, f'{display_name}, you have {points} points.')
|
|
|
|
|
|
|
+ send_private_chat(user_id, f'{display_name}, you have {points} {porps(points)}.')
|
|
|
|
|
|
|
|
elif lowercase_msg.startswith(f'{prefix}reg_mail'): # Generate a code to verify users account for email registration
|
|
elif lowercase_msg.startswith(f'{prefix}reg_mail'): # Generate a code to verify users account for email registration
|
|
|
if current_app.config['KOFI_INTEGRATION']:
|
|
if current_app.config['KOFI_INTEGRATION']:
|
|
@@ -87,9 +87,11 @@ def chat_hook():
|
|
|
if not (set(details['categories']) & set(current_app.config['ACTIVE_CAT'])): # If there are no common categories, continue
|
|
if not (set(details['categories']) & set(current_app.config['ACTIVE_CAT'])): # If there are no common categories, continue
|
|
|
continue
|
|
continue
|
|
|
if 'type' in details and details['type'] == 'goal':
|
|
if 'type' in details and details['type'] == 'goal':
|
|
|
- rewards_msg = f'{rewards_msg}<br>* {prefix}{reward} goal at {details["target"]} contributed points.'
|
|
|
|
|
|
|
+ rewards_msg = f'{rewards_msg}<br>* {prefix}{reward} goal at {details["target"]} contributed {porps(details["target"])}.'
|
|
|
|
|
+ elif 'type' in details and details['type'] == 'vote':
|
|
|
|
|
+ rewards_msg = f'{rewards_msg}<br>* {prefix}{reward} vote for {details["price"]} {porps(details["price"])}.'
|
|
|
else:
|
|
else:
|
|
|
- rewards_msg = f'{rewards_msg}<br>* {prefix}{reward} for {details["price"]} points.'
|
|
|
|
|
|
|
+ rewards_msg = f'{rewards_msg}<br>* {prefix}{reward} for {details["price"]} {porps(details["price"])}.'
|
|
|
if 'info' in details:
|
|
if 'info' in details:
|
|
|
rewards_msg = f'{rewards_msg}<br>{details["info"]}'
|
|
rewards_msg = f'{rewards_msg}<br>{details["info"]}'
|
|
|
else:
|
|
else:
|
|
@@ -129,12 +131,11 @@ def kofi_hook():
|
|
|
if type == 'Donation':
|
|
if type == 'Donation':
|
|
|
donation_info = [is_public, from_name, email, amount, message]
|
|
donation_info = [is_public, from_name, email, amount, message]
|
|
|
donation_points = current_app.config['KOFI_SETTINGS']['donation_points']
|
|
donation_points = current_app.config['KOFI_SETTINGS']['donation_points']
|
|
|
- accept_donation(donation_info, donation_points)
|
|
|
|
|
- if is_public:
|
|
|
|
|
- alert_info = {'name': from_name, 'amount': amount}
|
|
|
|
|
- else:
|
|
|
|
|
- alert_info = {'name': 'Anonymous Hero', 'amount': amount}
|
|
|
|
|
- donations.append(alert_info) # Append info to be displayed in alert
|
|
|
|
|
|
|
+ if accept_donation(donation_info, donation_points):
|
|
|
|
|
+ if is_public:
|
|
|
|
|
+ alert_info = {'name': from_name, 'amount': amount}
|
|
|
|
|
+ else:
|
|
|
|
|
+ alert_info = {'name': 'Anonymous Hero', 'amount': amount}
|
|
|
if type == 'Subscription':
|
|
if type == 'Subscription':
|
|
|
if current_app.config['KOFI_SETTINGS']['subs']: # Check that subscriptions are enabled
|
|
if current_app.config['KOFI_SETTINGS']['subs']: # Check that subscriptions are enabled
|
|
|
if first_sub:
|
|
if first_sub:
|
|
@@ -150,19 +151,22 @@ def kofi_hook():
|
|
|
|
|
|
|
|
sub_info = [is_public, from_name, email, amount, message, first_sub, tier_name]
|
|
sub_info = [is_public, from_name, email, amount, message, first_sub, tier_name]
|
|
|
sub_points = current_app.config['KOFI_SETTINGS']['sub_points']
|
|
sub_points = current_app.config['KOFI_SETTINGS']['sub_points']
|
|
|
- accept_sub(sub_info, sub_points)
|
|
|
|
|
- if is_public:
|
|
|
|
|
- alert_info = {'name': from_name, 'tiername': tier_name}
|
|
|
|
|
- else:
|
|
|
|
|
- alert_info = {'name': 'Anonymous Hero', 'teirname': tier_name}
|
|
|
|
|
- subscribers.append(alert_info) # Append info to be displayed in alert
|
|
|
|
|
|
|
+ if accept_sub(sub_info, sub_points):
|
|
|
|
|
+ if is_public:
|
|
|
|
|
+ alert_info = {'name': from_name, 'tiername': tier_name}
|
|
|
|
|
+ else:
|
|
|
|
|
+ alert_info = {'name': 'Anonymous Hero', 'teirname': tier_name}
|
|
|
else:
|
|
else:
|
|
|
current_app.logger.info(f'Kofi membership received, but subscriptions are not enabled. Doing nothing.')
|
|
current_app.logger.info(f'Kofi membership received, but subscriptions are not enabled. Doing nothing.')
|
|
|
-
|
|
|
|
|
return jsonify({'status': 'success'}), 200
|
|
return jsonify({'status': 'success'}), 200
|
|
|
else:
|
|
else:
|
|
|
current_app.logger.info(f'Token invalid. Rejecting.')
|
|
current_app.logger.info(f'Token invalid. Rejecting.')
|
|
|
return jsonify({'status': 'unauthorized'}), 401
|
|
return jsonify({'status': 'unauthorized'}), 401
|
|
|
|
|
+ else:
|
|
|
|
|
+ return jsonify({'status': 'Failed. No data'}), 400
|
|
|
|
|
+ return jsonify({'status': 'success'}), 200
|
|
|
|
|
+ else:
|
|
|
|
|
+ return jsonify({'status': 'Failed. Invalid content type'}), 400
|
|
|
|
|
|
|
|
|
|
|
|
|
@ocb.route('/checkFollows') # Polled by follower.html template to check for new followers
|
|
@ocb.route('/checkFollows') # Polled by follower.html template to check for new followers
|
|
@@ -173,7 +177,7 @@ def check_follows():
|
|
|
current_app.logger.info(f'New follower: \"{follower["name"]}\"')
|
|
current_app.logger.info(f'New follower: \"{follower["name"]}\"')
|
|
|
alerts_dict['follower'] = ''
|
|
alerts_dict['follower'] = ''
|
|
|
save_alerts(alerts_dict)
|
|
save_alerts(alerts_dict)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return jsonify(follower)
|
|
return jsonify(follower)
|
|
|
else:
|
|
else:
|
|
|
current_app.logger.debug(f'No new followers')
|
|
current_app.logger.debug(f'No new followers')
|