token env
This commit is contained in:
parent
555cb3d082
commit
a1c043a032
@ -1,18 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
import aiohttp
|
||||
from aiohttp import web
|
||||
|
||||
from v6d0auth.appfactory import AppFactory
|
||||
from v6d0auth.run_app import start_app
|
||||
from v6d1tokens.client import request_token
|
||||
from v6d3music.api import Api
|
||||
from v6d3music.core.set_config import set_config
|
||||
|
||||
__all__ = ("AppContext",)
|
||||
|
||||
token = os.getenv("DISCORD_APP_TOKEN", "unset")
|
||||
|
||||
|
||||
class MusicAppFactory(AppFactory):
|
||||
def __init__(self, secret: str, api: Api):
|
||||
@ -25,7 +27,8 @@ class MusicAppFactory(AppFactory):
|
||||
@routes.post("/api/")
|
||||
async def api(request: web.Request) -> web.Response:
|
||||
async with aiohttp.ClientSession() as s, s.get(
|
||||
"http://sessionservice/userid/", params={"session": request.query.get("session")}
|
||||
"http://sessionservice/userid/",
|
||||
params={"session": request.query.get("session")},
|
||||
) as response:
|
||||
user_id: int | None = await response.json()
|
||||
if user_id is None:
|
||||
@ -46,7 +49,7 @@ class AppContext:
|
||||
|
||||
async def start(self) -> tuple[web.Application, asyncio.Task[None]] | None:
|
||||
try:
|
||||
factory = MusicAppFactory(await request_token("music-client", "token"), self.api)
|
||||
factory = MusicAppFactory(token, self.api)
|
||||
await set_config("secret", factory.secret)
|
||||
await set_config("redirect", factory.redirect)
|
||||
except aiohttp.ClientConnectorError:
|
||||
@ -57,7 +60,9 @@ class AppContext:
|
||||
return app, task
|
||||
|
||||
async def __aenter__(self) -> AppContext:
|
||||
self.__task: asyncio.Task[tuple[web.Application, asyncio.Task[None]] | None] = asyncio.create_task(self.start())
|
||||
self.__task: asyncio.Task[tuple[web.Application, asyncio.Task[None]] | None] = (
|
||||
asyncio.create_task(self.start())
|
||||
)
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
|
@ -9,7 +9,6 @@ import discord
|
||||
|
||||
from ptvp35 import DbConnection
|
||||
from rainbowadn.instrument import Instrumentation
|
||||
from v6d1tokens.client import request_token
|
||||
from v6d2ctx.handle_content import handle_content
|
||||
from v6d2ctx.integration.event import Events
|
||||
from v6d2ctx.integration.targets import Targets
|
||||
@ -25,6 +24,7 @@ from v6d3music.core.set_config import set_config
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
token = os.getenv("DISCORD_TOKEN", "unset")
|
||||
|
||||
|
||||
class MusicClient(discord.Client):
|
||||
@ -47,7 +47,9 @@ _client = MusicClient(
|
||||
)
|
||||
|
||||
|
||||
banned_guilds = set(map(int, filter(bool, map(str.strip, os.getenv("banned_guilds", "").split(":")))))
|
||||
banned_guilds = set(
|
||||
map(int, filter(bool, map(str.strip, os.getenv("banned_guilds", "").split(":"))))
|
||||
)
|
||||
|
||||
|
||||
def guild_allowed(guild: discord.Guild | None) -> bool:
|
||||
@ -157,17 +159,6 @@ async def amain(client: discord.Client):
|
||||
ABlockMonitor(delta=0.5),
|
||||
):
|
||||
register_handlers(client, mainservice)
|
||||
if "guerilla" in sys.argv:
|
||||
from pathlib import Path
|
||||
|
||||
tokenpath = Path(".token.txt")
|
||||
if tokenpath.exists():
|
||||
token = tokenpath.read_text()
|
||||
else:
|
||||
token = input("token:")
|
||||
tokenpath.write_text(token)
|
||||
else:
|
||||
token = await request_token("music", "token")
|
||||
await client.login(token)
|
||||
await client.connect()
|
||||
print("exited")
|
||||
|
Loading…
Reference in New Issue
Block a user