This commit is contained in:
2024-04-09 00:53:50 +02:00
parent 54f74907e8
commit e186c81be7
2 changed files with 66 additions and 48 deletions
+2 -48
View File
@@ -38,9 +38,7 @@ import requests
import spotipy
import tiktoken
from discord.ext import commands, tasks
from flask import Flask, jsonify, request
from spotipy.oauth2 import SpotifyClientCredentials
from waitress import serve
import yt_dlp
from spotify_dl import spotify
@@ -2212,59 +2210,15 @@ async def krecimy_pornola(ctx):
else:
ctx.reply("Jak ładnie szefa poprosisz.")
app = Flask(__name__)
@app.route("/mp3", methods=["GET"])
def get_music_list():
"""
The function `get_music_list` returns a JSON object containing a list of music files.
:return: A JSON response containing a key "music_file_list" with the value of the variable
`music_file_list`.
"""
return jsonify({"music_file_list": MASTER_TIMEOUT})
@app.route("/conjurer", methods=["GET"])
def answer_external_command():
#record = json.loads(request.data)
#logger.info(record)
#answer_data = "TXT"
#if "UUID" in record and "QUERY" in record and "AUTHOR" in record:
# answer_data = "Query logged"
#return_data = (
# jsonify(isError=False, message="Success", statusCode=200, data=answer_data),
# 200,
#)
#return return_data
return jsonify("SUCCESS")
def flask_debug(_logger):
"""
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
Do not use for production for fucks sake.
"""
# trunk-ignore(bandit/B201)
_logger.info("Attempt debug")
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS, logger=_logger)
def waitress_run(_logger):
"""
The `waitress_run` function serves the `app` on host "0.0.0.0"
and port 5000 using the Waitress WSGI server.
"""
_logger.info("Attempt waitress")
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS, logger=_logger)
t2 = threading.Thread(target=flask_debug, args=(logger,))
t2.start()
t2.join()
# *================================== Run
if __name__ == "__main__":
# TODO: wpakowac kondzia w wątki odpalic asynchronicznie rownolegle z flaskiem do sterowania nim
logger.info("Starting discord bot")
threads = []
t1 = threading.Thread(target=client.run, args=(TOKEN,))
t1.start()
t1.join()
threads.append(threading.Thread(target=client.run, args=(TOKEN,)))
# widok - generuje się 5 stron po 4 linki
# odśwież - zamienić na "dalej" - zaciąga kolejne 20 rezultatów