-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
64 lines (49 loc) · 1.64 KB
/
manage.py
File metadata and controls
64 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import asyncio
import os
import uvicorn
from src import create_app
import unittest
import json
# Import settings from .env file
if os.path.exists(".env"):
print("Importing environment from .env file")
for line in open(".env"):
var = line.strip().split("=")
os.environ[var[0]] = var[1]
# Get the mode
mode = os.getenv("FAST_API_CONFIG") or "development"
token = os.getenv("DISCORD_TOKEN")
if not os.path.exists('channels.json'):
print("ERROR: channels.json file does not exist failing the script.")
sys.exit("FAILED TO RUN SCRIPT MISSING channels.json")
f = open('channels.json')
json_threads = json.load(f)
app, bot = create_app(mode, json_threads['channels'], token)
# Runs the tests
def test():
"""
Run the tests
"""
api_tests = unittest.TestLoader().discover("./tests/api")
unittest.TextTestRunner(verbosity=2).run(api_tests)
int_tests = unittest.TestLoader().discover("./tests/integrations")
unittest.TextTestRunner(verbosity=2).run(int_tests)
unit_tests = unittest.TestLoader().discover("./tests/unit")
unittest.TextTestRunner(verbosity=2).run(unit_tests)
@app.on_event("startup")
async def startup_event():
asyncio.create_task(bot.start(token))
await asyncio.sleep(4)
print(f"{bot.user} has connected to Discord!")
@app.get("/user")
async def user():
return {"User": "{}".format(bot.user)}
# Setup to run the app in debug mode
if __name__ == "__main__":
if mode == "development":
# bot.run(token)
uvicorn.run(app, host="127.0.0.1", port=8000)
elif mode == "testing":
test()
elif mode == "production":
print()