Просмотр исходного кода

Goal, milestone and follower alerts functional

deadtom 5 дней назад
Родитель
Сommit
ab5365b7e8

+ 2 - 0
TODO.md

@@ -1,3 +1,5 @@
+* Put followHook info in readme
+* Put full link to each alert source somewhere in the mgmt panel
 * Figure out how to use CSS to center text over alert images
 * I'm pretty sure this is resolved, so get this out of the logs "[2026-01-21 09:32:15 -0700] [1644] [INFO] <Response [200]>"
 * Make fulfilled rewards disappear at the beginning of stream

+ 7 - 6
ownchatbot/bot_messages.py

@@ -74,16 +74,17 @@ def do_reward(message, user_id):  # Parse the chat command
         elif add_to_goal(db, user_id, reward, int(contribution)):
             send_chat(f'{username} contributed {porps(contribution)} to the \"{prefix}{reward}\" goal.')
             wmr = was_milestone_reached(db, reward)
-            if wmr:
-                alerts_dict['m_name'] = username
-                alerts_dict['m_reward'] = wmr
-                save_alerts(alerts_dict)
-                send_chat(f'{wmr} milestone reached!')
-            if was_goal_reached(db, reward):
+            if was_goal_reached(db, reward):  # Was a goal reached?
                 alerts_dict['g_name'] = username
                 alerts_dict['g_reward'] = reward
                 save_alerts(alerts_dict)
                 send_chat(f'\"{prefix}{reward}\" target reached! 🎉')
+            else:  # If goal wasn't reached, was a milestone passed?
+                if wmr:
+                    alerts_dict['m_name'] = username
+                    alerts_dict['m_reward'] = wmr
+                    save_alerts(alerts_dict)
+                    send_chat(f'{wmr} milestone reached!')
         else:
             send_private_chat(user_id, f'Couldn\'t contribute to the \"{prefix}{reward}\" goal for {username}, for some highly technical reason.')
         return

+ 1 - 1
ownchatbot/defaults/alerts.py

@@ -1,2 +1,2 @@
-ALERTS = {'m_name': '', 'm_reward': '', 'g_name': '', 'g_reward': ''}
+ALERTS = {'m_name': '', 'm_reward': '', 'g_name': '', 'g_reward': '', 'follower': ''}
 

BIN
ownchatbot/static/Shunda.ttf


+ 38 - 0
ownchatbot/static/alertstyle.css

@@ -0,0 +1,38 @@
+body {
+            background-color: transparent;
+            position: relative; /* Ensure relative positioning for absolute children */
+            width: 200px;
+            margin: 0 auto; 
+            text-align: center; 
+        }
+        
+        img {
+            margin: 0 auto;
+        }
+        
+        video {
+            margin: 0 auto;
+        }
+
+        #alertVid {
+            display: none;
+            max-height: 190px;
+            max-width: 190px;
+            position: relative;
+            z-index: 1; /* Ensure it's below nameBox */
+        }
+
+        #alertImg {
+            display: none;
+            max-height: 190px;
+            max-width: 190px;
+            position: relative;
+            z-index: 1; /* Ensure it's below nameBox */
+        }
+
+        #textBox {
+            display: none;
+            position: absolute;
+            transform: translateX(-50%); /* Center */
+            z-index: 2; /* Ensure it appears above alertImg and alertVid */
+        }

+ 1 - 31
ownchatbot/templates/donation.html

@@ -5,38 +5,8 @@ the alert is displayed for ten seconds. -->
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="{{ url_for('static', filename='alertstyle.css') }}">
     <title>New Donation Alert</title>
-    <style>
-        body {
-            background-color: transparent;
-            position: relative; /* Ensure relative positioning for absolute children */
-        }
-
-        #alertVid {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning with top, left, etc. */
-            z-index: 1; /* Ensure it's below textBox */
-        }
-
-        #alertImg {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning */
-            z-index: 1; /* Ensure it's below textBox */
-        }
-
-        #textBox {
-            display: none;
-            position: absolute;
-            top: 20%; /* Adjust as needed */
-            left: 50%; /* Center horizontally */
-            transform: translateX(-50%); /* Center */
-            color: black;
-            z-index: 2; /* Ensure it appears above alertImg and alertVid */
-            font-size: 20px; /* Adjust as needed */
-        }
-    </style>
 </head>
 <body>
     {% if not alert_name %}

+ 9 - 38
ownchatbot/templates/follower.html

@@ -5,38 +5,8 @@ the alert is displayed for ten seconds. -->
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="{{ url_for('static', filename='alertstyle.css') }}">
     <title>New Follower Alert</title>
-    <style>
-        body {
-            background-color: transparent;
-            position: relative; /* Ensure relative positioning for absolute children */
-        }
-
-        #alertVid {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning with top, left, etc. */
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #alertImg {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning */
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #nameBox {
-            display: none;
-            position: absolute;
-            top: 20%; /* Adjust as needed */
-            left: 50%; /* Center horizontally */
-            transform: translateX(-50%); /* Center */
-            color: black;
-            z-index: 2; /* Ensure it appears above alertImg and alertVid */
-            font-size: 20px; /* Adjust as needed */
-        }
-    </style>
 </head>
 <body>
     {% if not alert_name %}
@@ -52,7 +22,7 @@ the alert is displayed for ten seconds. -->
         <img id="alertImg" src="{{ url_for('web_panels.alerts', alert_name=alert_name) }}">
     {% endif %}
 
-    <div id="nameBox"></div>
+    <div id="textBox"></div>
 
     <script>
         setInterval(function() {
@@ -62,14 +32,15 @@ the alert is displayed for ten seconds. -->
                     if (data) {
                         const alertVid = document.getElementById('alertVid');
                         const alertImg = document.getElementById('alertImg');
-                        const nameBox = document.getElementById('nameBox');
+                        const textBox = document.getElementById('textBox');
 
-                        const followerName = data.eventData.name;
+                        const followerName = data.name;
+                        const rewardName = data.reward;
 
-                        nameBox.innerHTML = `
-                            ${followerName}
+                        textBox.innerHTML = `
+                            ${rewardName}<br>${followerName}
                         `;
-                        nameBox.style.display = 'block';
+                        textBox.style.display = 'block';
 
                         alertVid.style.display = 'block';
                         alertImg.style.display = 'block';
@@ -77,7 +48,7 @@ the alert is displayed for ten seconds. -->
                         setTimeout(() => {
                             alertVid.style.display = 'none';
                             alertImg.style.display = 'none';
-                            nameBox.style.display = 'none';
+                            textBox.style.display = 'none';
                         }, 10000); // Visible for 10 seconds
                     }
                 });

+ 1 - 1
ownchatbot/templates/queue.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en">
 <head>
-    <title>Rewards Queue Management</title>
+    <title>Queue Manager</title>
     <link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
     <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
     <script>

+ 8 - 37
ownchatbot/templates/rgoal.html

@@ -5,38 +5,8 @@ the alert is displayed for ten seconds. -->
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="{{ url_for('static', filename='alertstyle.css') }}">
     <title>Goal Reached Alert</title>
-    <style>
-        body {
-            background-color: transparent;
-            position: relative; /* Ensure relative positioning for absolute children */
-        }
-
-        #alertVid {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning with top, left, etc. */
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #alertImg {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning */
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #nameBox {
-            display: none;
-            position: absolute;
-            top: 20%; /* Adjust as needed */
-            left: 50%; /* Center horizontally */
-            transform: translateX(-50%); /* Center */
-            color: black;
-            z-index: 2; /* Ensure it appears above alertImg and alertVid */
-            font-size: 20px; /* Adjust as needed */
-        }
-    </style>
 </head>
 <body>
     {% if not alert_name %}
@@ -52,7 +22,7 @@ the alert is displayed for ten seconds. -->
         <img id="alertImg" src="{{ url_for('web_panels.alerts', alert_name=alert_name) }}">
     {% endif %}
 
-    <div id="nameBox"></div>
+    <div id="textBox"></div>
 
     <script>
         setInterval(function() {
@@ -62,14 +32,15 @@ the alert is displayed for ten seconds. -->
                     if (data) {
                         const alertVid = document.getElementById('alertVid');
                         const alertImg = document.getElementById('alertImg');
-                        const nameBox = document.getElementById('nameBox');
+                        const textBox = document.getElementById('textBox');
 
                         const alertName = data.name;
+                        const rewardName = data.reward;
 
-                        nameBox.innerHTML = `
-                            ${alertName}
+                        textBox.innerHTML = `
+                            ${rewardName}<br>${alertName}
                         `;
-                        nameBox.style.display = 'block';
+                        textBox.style.display = 'block';
 
                         alertVid.style.display = 'block';
                         alertImg.style.display = 'block';
@@ -77,7 +48,7 @@ the alert is displayed for ten seconds. -->
                         setTimeout(() => {
                             alertVid.style.display = 'none';
                             alertImg.style.display = 'none';
-                            nameBox.style.display = 'none';
+                            textBox.style.display = 'none';
                         }, 10000); // Visible for 10 seconds
                     }
                 });

+ 9 - 49
ownchatbot/templates/rmilestone.html

@@ -5,49 +5,8 @@ the alert is displayed for ten seconds. -->
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Milestone Reached Alert</title>
-    <style>
-        body {
-            background-color: transparent;
-            position: relative; /* Ensure relative positioning for absolute children */
-            width: 300;
-            margin: 0 auto; 
-            text-align: center; 
-        }
-        
-        img {
-            margin: 0 auto;
-        }
-        
-        video {
-            margin: 0 auto;
-        }
-
-        #alertVid {
-            display: none;
-            max-height: 100px;
-            position: relative;
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #alertImg {
-            display: none;
-            max-height: 100px;
-            position: relative;
-            z-index: 1; /* Ensure it's below nameBox */
-        }
-
-        #nameBox {
-            display: none;
-            position: absolute;
-            top: 20%; /* Adjust as needed */
-            left: 50%; /* Center horizontally */
-            transform: translateX(-50%); /* Center */
-            color: black;
-            z-index: 2; /* Ensure it appears above alertImg and alertVid */
-            font-size: 20px; /* Adjust as needed */
-        }
-    </style>
+    <link rel="stylesheet" href="{{ url_for('static', filename='alertstyle.css') }}">
+    <title>Milestone Reached Alert</title>    
 </head>
 <body>
     {% if not alert_name %}
@@ -63,7 +22,7 @@ the alert is displayed for ten seconds. -->
         <img id="alertImg" src="{{ url_for('web_panels.alerts', alert_name=alert_name) }}">
     {% endif %}
 
-    <div id="nameBox"></div>
+    <div id="textBox"></div>
 
     <script>
         setInterval(function() {
@@ -73,14 +32,15 @@ the alert is displayed for ten seconds. -->
                     if (data) {
                         const alertVid = document.getElementById('alertVid');
                         const alertImg = document.getElementById('alertImg');
-                        const nameBox = document.getElementById('nameBox');
+                        const textBox = document.getElementById('textBox');
 
                         const alertName = data.name;
+                        const rewardName = data.reward;
 
-                        nameBox.innerHTML = `
-                            ${alertName}
+                        textBox.innerHTML = `
+                            ${rewardName}<br>${alertName}
                         `;
-                        nameBox.style.display = 'block';
+                        textBox.style.display = 'block';
 
                         alertVid.style.display = 'block';
                         alertImg.style.display = 'block';
@@ -88,7 +48,7 @@ the alert is displayed for ten seconds. -->
                         setTimeout(() => {
                             alertVid.style.display = 'none';
                             alertImg.style.display = 'none';
-                            nameBox.style.display = 'none';
+                            textBox.style.display = 'none';
                         }, 10000); // Visible for 10 seconds
                     }
                 });

+ 1 - 31
ownchatbot/templates/subscriber.html

@@ -5,38 +5,8 @@ the alert is displayed for ten seconds. -->
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="{{ url_for('static', filename='alertstyle.css') }}">
     <title>New Subscriber Alert</title>
-    <style>
-        body {
-            background-color: transparent;
-            position: relative; /* Ensure relative positioning for absolute children */
-        }
-
-        #alertVid {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning with top, left, etc. */
-            z-index: 1; /* Ensure it's below textBox */
-        }
-
-        #alertImg {
-            display: none;
-            max-height: 100px;
-            position: absolute; /* Allow positioning */
-            z-index: 1; /* Ensure it's below textBox */
-        }
-
-        #textBox {
-            display: none;
-            position: absolute;
-            top: 20%; /* Adjust as needed */
-            left: 50%; /* Center horizontally */
-            transform: translateX(-50%); /* Center */
-            color: black;
-            z-index: 2; /* Ensure it appears above alertImg and alertVid */
-            font-size: 20px; /* Adjust as needed */
-        }
-    </style>
 </head>
 <body>
     {% if not alert_name %}

+ 16 - 10
ownchatbot/webhooks.py

@@ -94,9 +94,11 @@ def chat_hook():
 
 @ocb.route('/followHook', methods=['POST'])  # Called by Owncast when someone follows
 def follow_hook():
+    alerts_dict = current_app.config['ALERTS']
     data = request.json
-    current_app.logger.debug(f'\n\n_______________\n/newFollow triggered!\n_______________')
-    followers.append(data)
+    current_app.logger.debug(f'\n\n_______________\n/followHook triggered!\n_______________')
+    alerts_dict['follower'] = data['eventData']['name']
+    save_alerts(alerts_dict)
     return jsonify({'status': 'success'}), 200
 
 
@@ -164,10 +166,14 @@ def kofi_hook():
 
 @ocb.route('/checkFollows')  # Polled by follower.html template to check for new followers
 def check_follows():
-    if followers:
-        current_app.logger.debug(f'\n\n{format(followers[0])}\n\n')
-        last_follower = followers.clear()
-        return jsonify(last_follower)
+    alerts_dict = current_app.config['ALERTS']
+    follower = {'name': alerts_dict['follower'], 'reward': 'New Follow!'}
+    if follower['name']:
+        current_app.logger.info(f'New follower: \"{follower["name"]}\"')
+        alerts_dict['follower'] = ''
+        save_alerts(alerts_dict)
+        
+        return jsonify(follower)
     else:
         current_app.logger.debug(f'No new followers')
     return jsonify(None)
@@ -176,9 +182,9 @@ def check_follows():
 @ocb.route('/checkGoals')  # Polled by ocbalert.html template to check for new followers
 def check_goals():
     alerts_dict = current_app.config['ALERTS']
-    rgoals = {'name': alerts_dict['g_name'], 'reward': alerts_dict['g_reward']}
+    rgoals = {'name': alerts_dict['g_name'], 'reward': 'GOAL!!'}
     if rgoals['name']:
-        current_app.logger.debug(f'\n\n{format(rgoals)}\n\n')
+        current_app.logger.debug(rgoals)
         alerts_dict['g_name'] = ''
         alerts_dict['g_reward'] = ''
         save_alerts(alerts_dict)
@@ -191,9 +197,9 @@ def check_goals():
 @ocb.route('/checkMilestones')  # Polled by ocbalert.html template to check for new followers
 def check_milestones():
     alerts_dict = current_app.config['ALERTS']
-    rmilestones = {'name': alerts_dict['m_name'], 'reward': alerts_dict['m_reward']}
+    rmilestones = {'name': alerts_dict['m_name'], 'reward': 'Milestone!'}
     if rmilestones['name']:
-        current_app.logger.info(f'\n\n{format(rmilestones)}\n\n')
+        current_app.logger.info(rmilestones)
         alerts_dict['m_name'] = ''
         alerts_dict['m_reward'] = ''
         save_alerts(alerts_dict)