mirror of https://gitlab.com/litecord/litecord.git
add manage.py
This commit is contained in:
parent
04d89a2214
commit
a1a914dc87
|
|
@ -21,6 +21,7 @@ Presence = Dict[str, Any]
|
|||
|
||||
@dataclass
|
||||
class GroupInfo:
|
||||
"""Store information about a specific group."""
|
||||
gid: GroupID
|
||||
name: str
|
||||
position: int
|
||||
|
|
@ -29,6 +30,7 @@ class GroupInfo:
|
|||
|
||||
@dataclass
|
||||
class MemberList:
|
||||
"""Total information on the guild's member list."""
|
||||
groups: List[GroupInfo] = None
|
||||
group_info: Dict[GroupID, GroupInfo] = None
|
||||
data: Dict[GroupID, Presence] = None
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from manage.main import main
|
||||
|
||||
import config
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(config))
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
from run import init_app_managers, init_app_db
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeApp:
|
||||
"""Fake app instance."""
|
||||
config: dict
|
||||
db = None
|
||||
loop: asyncio.BaseEventLoop = None
|
||||
ratelimiter = None
|
||||
state_manager = None
|
||||
storage = None
|
||||
dispatcher = None
|
||||
presence = None
|
||||
|
||||
|
||||
def main(config):
|
||||
"""Start the script"""
|
||||
loop = asyncio.get_event_loop()
|
||||
cfg = getattr(config, config.MODE)
|
||||
app = FakeApp(cfg.__dict__)
|
||||
|
||||
loop.run_until_complete(init_app_db(app))
|
||||
init_app_managers(app)
|
||||
|
||||
print(app)
|
||||
21
run.py
21
run.py
|
|
@ -143,16 +143,14 @@ async def app_set_ratelimit_headers(resp):
|
|||
return resp
|
||||
|
||||
|
||||
@app.before_serving
|
||||
async def app_before_serving():
|
||||
log.info('opening db')
|
||||
async def init_app_db(app):
|
||||
"""Connect to databases"""
|
||||
app.db = await asyncpg.create_pool(**app.config['POSTGRES'])
|
||||
|
||||
g.app = app
|
||||
|
||||
def init_app_managers(app):
|
||||
"""Initialize singleton classes."""
|
||||
app.loop = asyncio.get_event_loop()
|
||||
g.loop = asyncio.get_event_loop()
|
||||
|
||||
app.ratelimiter = RatelimitManager()
|
||||
app.state_manager = StateManager()
|
||||
app.storage = Storage(app.db)
|
||||
|
|
@ -162,6 +160,17 @@ async def app_before_serving():
|
|||
app.state_manager, app.dispatcher)
|
||||
app.storage.presence = app.presence
|
||||
|
||||
|
||||
@app.before_serving
|
||||
async def app_before_serving():
|
||||
log.info('opening db')
|
||||
await init_app_db(app)
|
||||
|
||||
g.app = app
|
||||
g.loop = asyncio.get_event_loop()
|
||||
|
||||
init_app_managers(app)
|
||||
|
||||
# start the websocket, etc
|
||||
host, port = app.config['WS_HOST'], app.config['WS_PORT']
|
||||
log.info(f'starting websocket at {host} {port}')
|
||||
|
|
|
|||
Loading…
Reference in New Issue