change function names to snake_case
This commit is contained in:
parent
2ab85bfb6d
commit
23ebe015b9
|
@ -2,7 +2,8 @@ from flask import current_app
|
||||||
import requests
|
import requests
|
||||||
from sqlite3 import Error
|
from sqlite3 import Error
|
||||||
|
|
||||||
def userExists(user_id, db):
|
|
||||||
|
def user_exists(user_id, db):
|
||||||
try:
|
try:
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"SELECT points FROM points WHERE id = ?",
|
"SELECT points FROM points WHERE id = ?",
|
||||||
|
@ -16,7 +17,7 @@ def userExists(user_id, db):
|
||||||
print("To user:", user_id)
|
print("To user:", user_id)
|
||||||
|
|
||||||
# only adds user if they aren't already in.
|
# only adds user if they aren't already in.
|
||||||
def addUserToDatabase(user_id, db):
|
def add_user_to_database(user_id, db):
|
||||||
try:
|
try:
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"SELECT points FROM points WHERE id = ?",
|
"SELECT points FROM points WHERE id = ?",
|
||||||
|
@ -32,7 +33,7 @@ def addUserToDatabase(user_id, db):
|
||||||
print("Error occured adding user to db:", e.args[0])
|
print("Error occured adding user to db:", e.args[0])
|
||||||
print("To user:", user_id)
|
print("To user:", user_id)
|
||||||
|
|
||||||
def sendChat(message): # TODO: url to constant?
|
def send_chat(message): # TODO: url to constant?
|
||||||
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
|
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/chat/send'
|
||||||
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
|
||||||
r = requests.post(url, headers=headers, json={"body": message})
|
r = requests.post(url, headers=headers, json={"body": message})
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
from flask import Flask,request,json,Blueprint
|
from flask import Flask,request,json,Blueprint
|
||||||
from sqlite3 import Error
|
from sqlite3 import Error
|
||||||
from tlapbot.db import get_db
|
from tlapbot.db import get_db
|
||||||
from tlapbot.owncastHelpers import userExists, addUserToDatabase, sendChat
|
from tlapbot.owncastHelpers import user_exists, add_user_to_database, send_chat
|
||||||
|
|
||||||
bp = Blueprint('owncastWebhooks', __name__)
|
bp = Blueprint('owncast_webhooks', __name__)
|
||||||
|
|
||||||
@bp.route('/owncastWebhook',methods=['POST'])
|
@bp.route('/owncastWebhook',methods=['POST'])
|
||||||
def owncastWebhook():
|
def owncast_webhook():
|
||||||
data = request.json
|
data = request.json
|
||||||
db = get_db()
|
db = get_db()
|
||||||
if data["type"] == "USER_JOINED":
|
if data["type"] == "USER_JOINED":
|
||||||
user_id = data["eventData"]["user"]["id"]
|
user_id = data["eventData"]["user"]["id"]
|
||||||
addUserToDatabase(user_id, db)
|
add_user_to_database(user_id, db)
|
||||||
elif data["type"] == "CHAT":
|
elif data["type"] == "CHAT":
|
||||||
display_name = data["eventData"]["user"]["displayName"]
|
display_name = data["eventData"]["user"]["displayName"]
|
||||||
print("New chat message:")
|
print("New chat message:")
|
||||||
|
@ -19,8 +19,8 @@ def owncastWebhook():
|
||||||
print(f'{data["eventData"]["body"]}')
|
print(f'{data["eventData"]["body"]}')
|
||||||
user_id = data["eventData"]["user"]["id"]
|
user_id = data["eventData"]["user"]["id"]
|
||||||
if "!points" in data["eventData"]["body"]:
|
if "!points" in data["eventData"]["body"]:
|
||||||
if not userExists(user_id, db):
|
if not user_exists(user_id, db):
|
||||||
addUserToDatabase(user_id, db)
|
add_user_to_database(user_id, db)
|
||||||
try:
|
try:
|
||||||
cursor = db.execute(
|
cursor = db.execute(
|
||||||
"SELECT points FROM points WHERE id = ?",
|
"SELECT points FROM points WHERE id = ?",
|
||||||
|
@ -28,7 +28,7 @@ def owncastWebhook():
|
||||||
)
|
)
|
||||||
message = "{}'s points: {}".format(display_name, cursor.fetchone()[0])
|
message = "{}'s points: {}".format(display_name, cursor.fetchone()[0])
|
||||||
print(message)
|
print(message)
|
||||||
sendChat(message)
|
send_chat(message)
|
||||||
except Error as e:
|
except Error as e:
|
||||||
print("Error occured reading points:", e.args[0])
|
print("Error occured reading points:", e.args[0])
|
||||||
print("To user:", user_id)
|
print("To user:", user_id)
|
||||||
|
|
Loading…
Reference in New Issue