Răsfoiți Sursa

Added success and failure messages when registering email address. Refined some bot messages.

deadtom 2 săptămâni în urmă
părinte
comite
7b37e44517

+ 1 - 1
README.md

@@ -136,7 +136,7 @@ You need to create a button on your Owncast page, so your viewers can access the
     ```
     https://<your_external.ownchatbot.url>/userpanel
     ```
-4. Set the third field (action title) to whatever you want the button to be named.
+4. Set the third field (action title) to "Stream Rewards".
     Example:
     ```
     Action Title: Stream Rewards

+ 1 - 2
TODO.md

@@ -1,2 +1 @@
-* Add flash to mail input form for success or failure
-* Find some way to refresh the page when switching tabs in mgmt panel
+

+ 11 - 8
ownchatbot/bot_messages.py

@@ -128,16 +128,19 @@ def help_message(user_id):
     prefix = current_app.config['PREFIX']
     kofi_settings = current_app.config['KOFI_SETTINGS']
     kofi_integration = current_app.config['KOFI_INTEGRATION']
-    message = f'You get {current_app.config["POINTS_AWARD"]} points for every {current_app.config["POINTS_INTERVAL"]} seconds you\'re in chat.<br> \
+    message = f'You get {current_app.config["POINTS_AWARD"]} points for every {current_app.config["POINTS_INTERVAL"]} minutes you\'re in chat.<br> \
             You can see your points, the rewards queue, and other helpful information by clicking on the \"Points Rewards\" button.<br><br> \
-            Chat commands:<br> \
-            {prefix}help to see this help message.<br> \
-            {prefix}points to see your points.<br> \
-            {prefix}rewards to see a list of currently active rewards.<br>'
-    if kofi_integration and kofi_settings['tips']:
+            <b><u>Chat commands:</u></b><br> \
+            <b>{prefix}help</b> to see this help message.<br> \
+            <b>{prefix}points</b> to see your points.<br> \
+            <b>{prefix}rewards</b> to see a list of currently active rewards.'
+    if kofi_integration:
+        message = f'{message}<br><br>\
+            Kofi is enabled! <br>\
+            Authenticated with Owncast, and enter your email address into the Stream Rewards Info page to get Kofi perks.'
+    if kofi_settings['tips']:
         message = f'{message}<br>\
-        Kofi is enabled! Once you\'ve authenticated with Owncast, you\'ll recieve\
-        {kofi_settings["tip_points"]} points for every dollar you tip on Kofi.'
+        You\'ll recieve {kofi_settings["tip_points"]} points for every dollar you tip on Kofi.'
     send_private_chat(user_id, message)
 
 

+ 14 - 0
ownchatbot/templates/userpanel.html

@@ -44,6 +44,20 @@
                         You are awarded {{ kofi_settings['tip_points'] }} {{ points_label }} for every dollar you tip on Kofi.<br>
                     {% endif %}
                     OwnchatBot recognizes your Kofi account by your email address. In order for OwnchatBot to award your tip points, you must enter the email address associated with your Kofi account here.<br><br>
+                    
+                    {% with messages = get_flashed_messages(with_categories=true) %}
+                        {% if messages %}
+                            {% for category, message in messages %}
+                                {% if category == 'failure' %}
+                                    <span style="color: red;">{{ message }}</span>
+                                {% endif %}
+                                {% if category == 'success' %}
+                                    <span style="color: green;">{{ message }}</span>
+                                {% endif %}
+                            {% endfor %}
+                        {% endif %}
+                    {% endwith %}
+                    
                     <form method="POST" action="/set_viewer_email">
                         <label for="code">Type !reg_mail into the chat, and enter the code it gives you here:</label>
                         <input type="number" name="code" size="6" required><br>                        

+ 15 - 2
ownchatbot/user_handlers.py

@@ -15,7 +15,7 @@ def get_users_points(db, user_id):  # Look up one user's points by user id
         current_app.logger.error(f'Couldn\'t look up points for {user_id}: {guperror.args[0]}')
 
 
-def get_email_code(db, user_id):  # Get user's reg_code
+def get_email_code(db, user_id):  # Get user's verification code
     try:
         cursor = db.execute(
             "SELECT code FROM points WHERE id = ?",
@@ -86,7 +86,7 @@ def award_chat_points(db, user_id, points):  # Award points to user by user id
         return False
 
 
-def set_email_code(db, user_id, reg_code):  # Award points to user by user id
+def set_email_code(db, user_id, reg_code):  # Set verification code
     try:
         db.execute(
             "UPDATE points SET code = ? WHERE id = ?",
@@ -99,6 +99,19 @@ def set_email_code(db, user_id, reg_code):  # Award points to user by user id
         return False
 
 
+def del_email_code(db, user_id):  # Delete verification code
+    try:
+        db.execute(
+            "UPDATE points SET code = NULL WHERE id = ?",
+            (user_id,)
+        )
+        db.commit()
+        return True
+    except Error as decerror:
+        current_app.logger.error(f'Couldn\'t remove reg code for {user_id}: {decerror.args[0]}')
+        return False
+
+
 def adjust_points(db, user_id, points):  # For streamer to manually adjust a user's points
     try:
         db.execute(

+ 6 - 1
ownchatbot/web_panels.py

@@ -2,8 +2,9 @@ from flask import flash, render_template, Blueprint, current_app, redirect, requ
 from datetime import timezone
 from ownchatbot.db import get_db, reread_goals, reread_votes, rem_vote, reset_vote, reset_goal, clear_fulfilled_rewards, clear_reward_queue, rem_cool, rem_from_queue
 from ownchatbot.reward_handlers import all_active_votes, all_active_goals, all_active_rewards, get_queue, fulfill_reward, save_rewards, activate_category, deactivate_category, refund_reward, reread_categories, save_config
-from ownchatbot.user_handlers import get_all_users, get_all_users_by_name, refund_points, adjust_points, change_email, get_email_code
+from ownchatbot.user_handlers import get_all_users, get_all_users_by_name, refund_points, adjust_points, change_email, get_email_code, del_email_code
 from ownchatbot.bot_messages import save_announce
+from ownchatbot.owncast_com import send_private_chat
 import json
 import emoji
 from ownchatbot.kofi_handlers import save_kofi_settings, kofi_pngs
@@ -391,8 +392,12 @@ def set_viewer_email():
     user_name = request.form['user_name']
     if mail_reg_code == db_mail_reg_code:
         if change_email(db, user_id, new_email):
+            del_email_code(db, user_id)
+            flash(f"Email Address \"{new_email}\" successfully registered.", "success")
+            send_private_chat(user_id, f'{user_name}, thanks for registering for Kofi perks! I appreciate your support!')
             current_app.logger.info(f'Changed {user_id}\'s email to {new_email}')
     else:
+        flash(f"Incorrect code. Email Address \"{new_email}\" was not registered.", "failure")
         current_app.logger.info(f'The code entered, \"{mail_reg_code}\", does not match \"{db_mail_reg_code}\" found in database.')
     return redirect(url_for('web_panels.user_panel', instance=instance, username=user_name))
 

+ 10 - 7
ownchatbot/webhooks.py

@@ -104,13 +104,16 @@ def chat_hook():
                 send_private_chat(user_id, f'{display_name}, you have {points} points.')
             
         elif lowercase_msg.startswith(f'{prefix}reg_mail'):  # Generate a code to verify users account for email registration
-            mail_reg_code = get_email_code(db, user_id)
-            if mail_reg_code:  # If the viewer already has a code waiting
-                send_private_chat(user_id, f'{display_name}, your code is {mail_reg_code}. Enter it into the form, with your email address, to enable Kofi perks!')
-            else:  # if not
-                mail_reg_code = random.randint(100000, 999999)
-                if set_email_code(db, user_id, mail_reg_code):
-                    send_private_chat(user_id, f'{display_name}, your code is {mail_reg_code}. Enter it into the form on the , with your email address, to enable Kofi perks!')
+            if current_app.config['KOFI_INTEGRATION']:
+                mail_reg_code = get_email_code(db, user_id)
+                if mail_reg_code:  # If the viewer already has a code waiting
+                    send_private_chat(user_id, f'{display_name}, your code is {mail_reg_code}. Enter it into the form on the Stream Rewards Info page, with your email address, to enable Kofi perks!')
+                else:  # if not
+                    mail_reg_code = random.randint(100000, 999999)
+                    if set_email_code(db, user_id, mail_reg_code):
+                        send_private_chat(user_id, f'{display_name}, your code is {mail_reg_code}. Enter it into the form on the Stream Rewards Info page, with your email address, to enable Kofi perks!')
+            else:
+                send_chat(f'{display_name}, Kofi integration is not enabled on this stream.')                
                 
         elif lowercase_msg.startswith(f'{prefix}rewards'):  # Send rewards list
             if current_app.config['REWARDS']: