diff --git a/app/__init__.py b/app/__init__.py index 016e5c8..1eda48d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -76,7 +76,12 @@ async def start(e: events.NewMessage.Event): Button.url('Link Spotify', get_spotify_link(enc_user_id)), Button.url('Link Yandex music', get_ymusic_link(enc_user_id)), ] - await e.respond("Hi! I can help you share music you listen on Spotify or Yandex muisc\n\nPress button below to authorize your account first", + await e.respond("""Hi! I can help you share music you listen on Spotify or Yandex music. +To use just type @now_listening_bot and select track. + +Press button below to authorize your account first + +""", buttons=buttons) diff --git a/app/callback_listener.py b/app/callback_listener.py index 7a39dd4..55e8bc7 100644 --- a/app/callback_listener.py +++ b/app/callback_listener.py @@ -1,7 +1,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI, Depends, Request from sqlalchemy.ext.asyncio import AsyncSession -from fastapi.responses import FileResponse +from fastapi.responses import FileResponse, RedirectResponse from fastapi.staticfiles import StaticFiles import uvicorn from telethon import TelegramClient @@ -15,6 +15,7 @@ from config import config, OauthCreds from app.MusicProvider.auth import get_oauth_creds client = TelegramClient('nowplaying_callback', config.api_id, config.api_hash) +client.parse_mode = 'html' @asynccontextmanager @@ -34,7 +35,7 @@ class LinkException(Exception): @app.exception_handler(LinkException) async def link_exception_handler(request: Request, exc: LinkException): - return FileResponse('static/error.html', status_code=400) + return FileResponse('app/static/error.html', media_type='text/html') async def code_to_token(code: str, uri: str, creds: OauthCreds) -> tuple[str, str, int]: @@ -61,6 +62,12 @@ def get_decoded_id(string: str): except: raise LinkException() +second_provider_notification = """ +\n\nYou just added second service, it will be used as default. +If you want to use other one time just type y for Yandex music. or s for Spotify. +You can change default service using /default command. +""" + @app.get('/spotify_callback') async def spotify_callback(code: str, state: str, session: AsyncSession = Depends(get_session)): @@ -78,8 +85,12 @@ async def spotify_callback(code: str, state: str, session: AsyncSession = Depend ) session.add(user) await session.commit() - await client.send_message(user_id, "Account linked!") - return FileResponse('static/success.html', media_type='text/html') + reply = "Account linked!" + if user.spotify_auth: + reply += second_provider_notification + await client.send_message(user_id, reply) + return FileResponse('app/static/success.html', media_type='text/html') + @app.get('/ym_callback') @@ -98,8 +109,11 @@ async def ym_callback(state: str, code: str, cid: str, session: AsyncSession = D ) session.add(user) await session.commit() - await client.send_message(user_id, "Account linked!") - return FileResponse('static/success.html', media_type='text/html') + reply = "Account linked! Note, that currently bot only allows to share tracks from Liked playlist." + if user.spotify_auth: + reply += second_provider_notification + await client.send_message(user_id, reply) + return FileResponse('app/static/success.html', media_type='text/html') if __name__ == '__main__': diff --git a/compose.yml b/compose.yml index dd68825..8a7ea32 100644 --- a/compose.yml +++ b/compose.yml @@ -7,7 +7,7 @@ services: - .env.production restart: unless-stopped command: > - sh -c "ls && python -m alembic upgrade head && python app/__main__.py" + sh -c "python -m alembic upgrade head && python app/__main__.py" callback_listener: