change function names to snake_case

This commit is contained in:
Lili (Tlapka) 2022-08-24 13:45:13 +02:00
parent 2ab85bfb6d
commit 23ebe015b9
2 changed files with 11 additions and 10 deletions

View File

@ -2,7 +2,8 @@ from flask import current_app
import requests
from sqlite3 import Error
def userExists(user_id, db):
def user_exists(user_id, db):
try:
cursor = db.execute(
"SELECT points FROM points WHERE id = ?",
@ -16,7 +17,7 @@ def userExists(user_id, db):
print("To user:", user_id)
# only adds user if they aren't already in.
def addUserToDatabase(user_id, db):
def add_user_to_database(user_id, db):
try:
cursor = db.execute(
"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("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'
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
r = requests.post(url, headers=headers, json={"body": message})

View File

@ -1,17 +1,17 @@
from flask import Flask,request,json,Blueprint
from sqlite3 import Error
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'])
def owncastWebhook():
def owncast_webhook():
data = request.json
db = get_db()
if data["type"] == "USER_JOINED":
user_id = data["eventData"]["user"]["id"]
addUserToDatabase(user_id, db)
add_user_to_database(user_id, db)
elif data["type"] == "CHAT":
display_name = data["eventData"]["user"]["displayName"]
print("New chat message:")
@ -19,8 +19,8 @@ def owncastWebhook():
print(f'{data["eventData"]["body"]}')
user_id = data["eventData"]["user"]["id"]
if "!points" in data["eventData"]["body"]:
if not userExists(user_id, db):
addUserToDatabase(user_id, db)
if not user_exists(user_id, db):
add_user_to_database(user_id, db)
try:
cursor = db.execute(
"SELECT points FROM points WHERE id = ?",
@ -28,7 +28,7 @@ def owncastWebhook():
)
message = "{}'s points: {}".format(display_name, cursor.fetchone()[0])
print(message)
sendChat(message)
send_chat(message)
except Error as e:
print("Error occured reading points:", e.args[0])
print("To user:", user_id)