used black

This commit is contained in:
hhh
2024-11-02 00:10:24 +02:00
parent 1b1f217b75
commit e0a3d256d5
79 changed files with 658 additions and 733 deletions

View File

@@ -1,6 +1,8 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio,
InlineKeyboardMarkup, InlineKeyboardButton
InlineQueryResultDocument,
InlineQueryResultCachedAudio,
InlineKeyboardMarkup,
InlineKeyboardButton,
)
from bot.modules.database.db import DBDict
@@ -10,37 +12,38 @@ from bot.modules.common.song import BaseSongItem
from typing import TypeVar
BaseSongT = TypeVar('BaseSongT', bound=BaseSongItem)
BaseSongT = TypeVar("BaseSongT", bound=BaseSongItem)
async def get_common_search_result(
audio: BaseSongT,
db_table: DBDict,
service_id: str,
settings: UserSettings
audio: BaseSongT, db_table: DBDict, service_id: str, settings: UserSettings
) -> InlineQueryResultDocument | InlineQueryResultCachedAudio:
return (
InlineQueryResultDocument(
id=f'{service_id}::' + audio.id,
id=f"{service_id}::" + audio.id,
title=audio.name,
description=audio.all_artists,
thumb_url=audio.thumbnail,
document_url=(audio.preview_url or audio.thumbnail) if
settings['search_preview'].value == 'preview' else audio.thumbnail,
mime_type='application/zip',
document_url=(
(audio.preview_url or audio.thumbnail)
if settings["search_preview"].value == "preview"
else audio.thumbnail
),
mime_type="application/zip",
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text='Downloading...', callback_data='.')]
[InlineKeyboardButton(text="Downloading...", callback_data=".")]
]
),
caption=audio.full_name,
) if audio.id not in list(db_table.keys()) else
InlineQueryResultCachedAudio(
id=f'{service_id}c::' + audio.id,
)
if audio.id not in list(db_table.keys())
else InlineQueryResultCachedAudio(
id=f"{service_id}c::" + audio.id,
audio_file_id=db_table[audio.id],
reply_markup=InlineKeyboardMarkup(
inline_keyboard=[
[InlineKeyboardButton(text='Verifying...', callback_data='.')]
[InlineKeyboardButton(text="Verifying...", callback_data=".")]
]
),
)

View File

@@ -1,4 +1,4 @@
from .search import get_deezer_search_results
__all__ = ['get_deezer_search_results']
__all__ = ["get_deezer_search_results"]

View File

@@ -1,6 +1,4 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio
)
from aiogram.types import InlineQueryResultDocument, InlineQueryResultCachedAudio
from bot.modules.deezer import deezer
from bot.modules.database import db
@@ -9,15 +7,12 @@ from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_deezer_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
async def get_deezer_search_results(
query: str, settings: UserSettings
) -> list[InlineQueryResultDocument | InlineQueryResultCachedAudio]:
return [
await get_common_search_result(
audio=audio,
db_table=db.deezer,
service_id='deez',
settings=settings
audio=audio, db_table=db.deezer, service_id="deez", settings=settings
)
for audio in await deezer.songs.search(query, limit=50)
]

View File

@@ -1,5 +1,6 @@
from aiogram.types import (
InlineQueryResultArticle, InputTextMessageContent,
InlineQueryResultArticle,
InputTextMessageContent,
)
from bot.modules.database import db
@@ -8,24 +9,27 @@ from bot.modules.error import Error
from bot.common import console
async def get_error_search_results(error_id: str) -> (list[InlineQueryResultArticle]
| None):
async def get_error_search_results(
error_id: str,
) -> list[InlineQueryResultArticle] | None:
error: Error = db.errors.get(error_id)
if error is None:
return []
console.print(f'{error_id} requested')
console.print(f"{error_id} requested")
console.print(error.traceback)
console.print(f'-{error_id} requested-')
console.print(f"-{error_id} requested-")
return [(
InlineQueryResultArticle(
id=error_id,
title=f'Error {error_id}',
description=error.exception.short,
input_message_content=InputTextMessageContent(
message_text=error.exception.long,
parse_mode='HTML',
),
return [
(
InlineQueryResultArticle(
id=error_id,
title=f"Error {error_id}",
description=error.exception.short,
input_message_content=InputTextMessageContent(
message_text=error.exception.long,
parse_mode="HTML",
),
)
)
)]
]

View File

@@ -1,6 +1,4 @@
from .search import get_soundcloud_search_results
__all__ = [
'get_soundcloud_search_results'
]
__all__ = ["get_soundcloud_search_results"]

View File

@@ -1,6 +1,4 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio
)
from aiogram.types import InlineQueryResultDocument, InlineQueryResultCachedAudio
from bot.modules.soundcloud import soundcloud
from bot.modules.database import db
@@ -9,15 +7,12 @@ from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_soundcloud_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
async def get_soundcloud_search_results(
query: str, settings: UserSettings
) -> list[InlineQueryResultDocument | InlineQueryResultCachedAudio]:
return [
await get_common_search_result(
audio=audio,
db_table=db.soundcloud,
service_id='sc',
settings=settings
audio=audio, db_table=db.soundcloud, service_id="sc", settings=settings
)
for audio in await soundcloud.songs.search(query, limit=50)
]

View File

@@ -1,6 +1,4 @@
from .search import get_spotify_search_results
__all__ = [
'get_spotify_search_results'
]
__all__ = ["get_spotify_search_results"]

View File

@@ -1,6 +1,4 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio
)
from aiogram.types import InlineQueryResultDocument, InlineQueryResultCachedAudio
from bot.modules.spotify import spotify
from bot.modules.database import db
@@ -9,15 +7,12 @@ from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_spotify_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
async def get_spotify_search_results(
query: str, settings: UserSettings
) -> list[InlineQueryResultDocument | InlineQueryResultCachedAudio]:
return [
await get_common_search_result(
audio=audio,
db_table=db.spotify,
service_id='spot',
settings=settings
audio=audio, db_table=db.spotify, service_id="spot", settings=settings
)
for audio in spotify.songs.search(query, limit=50)
]

View File

@@ -1,6 +1,4 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio
)
from aiogram.types import InlineQueryResultDocument, InlineQueryResultCachedAudio
from bot.modules.url import recognise_music_service, get_id
from bot.modules.settings import UserSettings
@@ -10,9 +8,9 @@ from ..common.search import get_common_search_result
import inspect
async def get_url_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
async def get_url_results(
query: str, settings: UserSettings
) -> list[InlineQueryResultDocument | InlineQueryResultCachedAudio]:
service = recognise_music_service(query)
if inspect.iscoroutinefunction(service.by_id_func):
audio = await service.by_id_func(await get_id(service))
@@ -26,6 +24,6 @@ async def get_url_results(query: str, settings: UserSettings) -> list[
audio=audio,
db_table=service.db_table,
service_id=service.name,
settings=settings
settings=settings,
)
]

View File

@@ -1,6 +1,4 @@
from .search import get_youtube_search_results
__all__ = [
'get_youtube_search_results'
]
__all__ = ["get_youtube_search_results"]

View File

@@ -1,6 +1,4 @@
from aiogram.types import (
InlineQueryResultDocument, InlineQueryResultCachedAudio
)
from aiogram.types import InlineQueryResultDocument, InlineQueryResultCachedAudio
from bot.modules.youtube import youtube
from bot.modules.database import db
@@ -9,15 +7,12 @@ from bot.modules.settings import UserSettings
from ..common.search import get_common_search_result
async def get_youtube_search_results(query: str, settings: UserSettings) -> list[
InlineQueryResultDocument | InlineQueryResultCachedAudio
]:
async def get_youtube_search_results(
query: str, settings: UserSettings
) -> list[InlineQueryResultDocument | InlineQueryResultCachedAudio]:
return [
await get_common_search_result(
audio=audio,
db_table=db.youtube,
service_id='yt',
settings=settings
audio=audio, db_table=db.youtube, service_id="yt", settings=settings
)
for audio in youtube.songs.search(query, limit=40)
]