improvement: no points giving when stream is off
This commit is contained in:
parent
53b4419ed4
commit
4c3d2cc734
|
@ -2,7 +2,7 @@ import os
|
|||
from flask import Flask
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from tlapbot.db import get_db
|
||||
from tlapbot.owncast_helpers import give_points_to_chat
|
||||
from tlapbot.owncast_helpers import is_stream_live, give_points_to_chat
|
||||
|
||||
def create_app(test_config=None):
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
|
@ -24,7 +24,7 @@ def create_app(test_config=None):
|
|||
|
||||
def proxy_job():
|
||||
with app.app_context():
|
||||
#TODO: make this not give points when stream is offline lol
|
||||
if is_stream_live():
|
||||
give_points_to_chat(get_db())
|
||||
|
||||
points_giver = BackgroundScheduler()
|
||||
|
|
|
@ -2,6 +2,31 @@ from flask import current_app
|
|||
import requests
|
||||
from sqlite3 import Error
|
||||
|
||||
|
||||
# # # requests stuff # # #
|
||||
def is_stream_live():
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/status'
|
||||
r = requests.post(url)
|
||||
print(r.json()["online"])
|
||||
return r.json()["online"]
|
||||
|
||||
def give_points_to_chat(db):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.post(url, headers=headers)
|
||||
for user_object in r.json():
|
||||
give_points_to_user(db,
|
||||
user_object["user"]["id"],
|
||||
current_app.config['POINTS_AMOUNT_GIVEN'])
|
||||
|
||||
def send_chat(message):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.post(url, headers=headers, json={"body": message})
|
||||
return r.json()
|
||||
|
||||
|
||||
# # # db stuff # # #
|
||||
def read_users_points(db, user_id):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
|
@ -37,15 +62,6 @@ def use_points(db, user_id, points):
|
|||
print("From user:", user_id, " amount of points:", points)
|
||||
return False
|
||||
|
||||
def give_points_to_chat(db):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.post(url, headers=headers)
|
||||
for user_object in r.json():
|
||||
give_points_to_user(db,
|
||||
user_object["user"]["id"],
|
||||
current_app.config['POINTS_AMOUNT_GIVEN'])
|
||||
|
||||
def user_exists(db, user_id):
|
||||
try:
|
||||
cursor = db.execute(
|
||||
|
@ -87,11 +103,7 @@ def change_display_name(db, user_id, new_name):
|
|||
print("Error occured changing display name:", e.args[0])
|
||||
print("To user:", user_id, new_name)
|
||||
|
||||
def send_chat(message):
|
||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
|
||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||
r = requests.post(url, headers=headers, json={"body": message})
|
||||
return r.json()
|
||||
|
||||
|
||||
def add_to_redeem_queue(db, user_id, redeem_name):
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue