first version of passive mode

seems to work fine
This commit is contained in:
Lili (Tlapka) 2023-03-13 15:22:40 +01:00
parent 189ffcc1a8
commit 82d9088c18
4 changed files with 72 additions and 60 deletions

View File

@ -3,6 +3,7 @@ OWNCAST_ACCESS_TOKEN=''
OWNCAST_INSTANCE_URL='http://localhost:8080' OWNCAST_INSTANCE_URL='http://localhost:8080'
POINTS_CYCLE_TIME=600 POINTS_CYCLE_TIME=600
POINTS_AMOUNT_GIVEN=10 POINTS_AMOUNT_GIVEN=10
PASSIVE=False
LIST_REDEEMS=False LIST_REDEEMS=False
ACTIVE_CATEGORIES=[] ACTIVE_CATEGORIES=[]
GUNICORN=False GUNICORN=False

View File

@ -21,6 +21,7 @@ def dashboard():
counters=all_counters(db), counters=all_counters(db),
redeems=current_app.config['REDEEMS'], redeems=current_app.config['REDEEMS'],
prefix=current_app.config['PREFIX'], prefix=current_app.config['PREFIX'],
passive=current_app.config['PASSIVE'],
username=username, username=username,
users=users, users=users,
utc_timezone=utc_timezone) utc_timezone=utc_timezone)

View File

@ -30,26 +30,27 @@ def owncast_webhook():
if data["eventData"]["user"]["authenticated"]: if data["eventData"]["user"]["authenticated"]:
remove_duplicate_usernames(db, user_id, new_name) remove_duplicate_usernames(db, user_id, new_name)
elif data["type"] == "CHAT": elif data["type"] == "CHAT":
prefix = current_app.config['PREFIX'] if not current_app.config['PASSIVE']:
user_id = data["eventData"]["user"]["id"] prefix = current_app.config['PREFIX']
display_name = data["eventData"]["user"]["displayName"] user_id = data["eventData"]["user"]["id"]
current_app.logger.debug(f'New chat message from {display_name}:') display_name = data["eventData"]["user"]["displayName"]
current_app.logger.debug(f'{data["eventData"]["body"]}') current_app.logger.debug(f'New chat message from {display_name}:')
if data["eventData"]["body"].startswith(f"{prefix}help"): current_app.logger.debug(f'{data["eventData"]["body"]}')
send_help() if data["eventData"]["body"].startswith(f"{prefix}help"):
elif data["eventData"]["body"].startswith(f"{prefix}points"): send_help()
points = read_users_points(db, user_id) elif data["eventData"]["body"].startswith(f"{prefix}points"):
if points is None: points = read_users_points(db, user_id)
send_chat("Error reading points.") if points is None:
else: send_chat("Error reading points.")
send_chat(f"{display_name}'s points: {points}") else:
elif data["eventData"]["body"].startswith(f"{prefix}name_update"): send_chat(f"{display_name}'s points: {points}")
# Forces name update in case bot didn't catch the NAME_CHANGE elif data["eventData"]["body"].startswith(f"{prefix}name_update"):
# event. Also removes saved usernames from users with same name # Forces name update in case bot didn't catch the NAME_CHANGE
# if user is authenticated. # event. Also removes saved usernames from users with same name
change_display_name(db, user_id, display_name) # if user is authenticated.
if data["eventData"]["user"]["authenticated"]: change_display_name(db, user_id, display_name)
remove_duplicate_usernames(db, user_id, display_name) if data["eventData"]["user"]["authenticated"]:
elif data["eventData"]["body"].startswith(prefix): remove_duplicate_usernames(db, user_id, display_name)
handle_redeem(data["eventData"]["body"], user_id) elif data["eventData"]["body"].startswith(prefix):
handle_redeem(data["eventData"]["body"], user_id)
return data return data

View File

@ -10,7 +10,9 @@
<div class="tab"> <div class="tab">
<button class="tablinks" onclick="openTab(event, 'dashboard')", id="defaultOpen">Tlapbot dashboard</button> <button class="tablinks" onclick="openTab(event, 'dashboard')", id="defaultOpen">Tlapbot dashboard</button>
{% if not passive %}
<button class="tablinks" onclick="openTab(event, 'redeems-list')">Redeems help</button> <button class="tablinks" onclick="openTab(event, 'redeems-list')">Redeems help</button>
{% endif %}
</div> </div>
<div id='dashboard' class="tabcontent"> <div id='dashboard' class="tabcontent">
@ -32,46 +34,53 @@
</table> </table>
{% endif %} {% endif %}
{% if counters %} {% if passive %}
<table> <h3>Tlapbot is currently in passive mode.</h3>
<thead> <p>You can't make any redeems, but you will receive points for watching.</p>
<tr>
<th>Active counters</th>
</tr>
</thead>
{% for counter in counters %}
<tbody>
<td> {{ counter[0] }} </td>
<td> {{ counter[1] }} </td>
</tbody>
{% endfor %}
</table>
{% endif %} {% endif %}
{% if queue %} {% if not passive %}
<table> {% if counters %}
<thead> <table>
<tr> <thead>
<th>Recent redeems</th> <tr>
</tr> <th>Active counters</th>
<tr> </tr>
<th>Time</th> </thead>
<th>Redeem</th> {% for counter in counters %}
<th>Redeemer</th> <tbody>
<th>Note</th> <td> {{ counter[0] }} </td>
</tr> <td> {{ counter[1] }} </td>
</thead> </tbody>
{% for row in queue %} {% endfor %}
<tbody> </table>
<td>{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}</td> {% endif %}
<td>{{ row[1] }}</td>
<td>{{ row[3] }}</td> {% if queue %}
{% if row[2] %} <table>
<td>{{ row[2] }}</td> <thead>
{% endif %} <tr>
</tbody> <th>Recent redeems</th>
{% endfor %} </tr>
</table> <tr>
<th>Time</th>
<th>Redeem</th>
<th>Redeemer</th>
<th>Note</th>
</tr>
</thead>
{% for row in queue %}
<tbody>
<td>{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }}</td>
<td>{{ row[1] }}</td>
<td>{{ row[3] }}</td>
{% if row[2] %}
<td>{{ row[2] }}</td>
{% endif %}
</tbody>
{% endfor %}
</table>
{% endif %}
{% endif %} {% endif %}
</body> </body>
</div> </div>