migrate to docker
This commit is contained in:
@@ -3,11 +3,11 @@ from rich.console import Console
|
||||
|
||||
from bot.modules.fsm import InDbStorage
|
||||
|
||||
from .utils.config import config
|
||||
from .utils import env
|
||||
|
||||
bot = Bot(token=config.telegram.bot_token)
|
||||
bot = Bot(token=env.BOT_TOKEN)
|
||||
dp = Dispatcher(storage=InDbStorage())
|
||||
console = Console()
|
||||
|
||||
|
||||
__all__ = ["bot", "dp", "config", "console"]
|
||||
__all__ = ["bot", "dp", "console"]
|
||||
|
||||
@@ -8,7 +8,7 @@ from aiogram.types import (
|
||||
|
||||
from bot.modules.database import db
|
||||
from bot.modules.deezer import DeezerBytestream, deezer
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -20,7 +20,7 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
).to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
|
||||
@@ -6,7 +6,7 @@ from aiogram.types import BufferedInputFile, ChosenInlineResult, InputMediaAudio
|
||||
from bot.modules.database import db
|
||||
from bot.modules.settings import UserSettings
|
||||
from bot.modules.youtube.downloader import YouTubeBytestream
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -42,7 +42,7 @@ async def on_cached_chosen(
|
||||
)
|
||||
|
||||
message = await bot.forward_message(
|
||||
config.telegram.files_chat, config.telegram.files_chat, db.recoded[song_id]
|
||||
env.FILES_CHAT, env.FILES_CHAT, db.recoded[song_id]
|
||||
)
|
||||
|
||||
song_io: BytesIO = await bot.download( # type: ignore
|
||||
@@ -60,7 +60,7 @@ async def on_cached_chosen(
|
||||
await bytestream.rerender()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
|
||||
@@ -8,7 +8,7 @@ from aiogram.types import (
|
||||
|
||||
from bot.modules.database import db
|
||||
from bot.modules.soundcloud import SoundCloudBytestream, soundcloud
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -22,7 +22,7 @@ async def on_new_chosen(chosen_result: ChosenInlineResult, bot: Bot):
|
||||
).to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
|
||||
@@ -12,7 +12,7 @@ from bot.modules.settings import UserSettings
|
||||
from bot.modules.spotify import spotify
|
||||
from bot.modules.youtube import AgeRestrictedError, youtube
|
||||
from bot.modules.youtube.song import SongItem
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -55,7 +55,7 @@ async def on_new_chosen(
|
||||
bytestream = await yt_song.to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
@@ -87,7 +87,7 @@ async def on_new_chosen(
|
||||
).to_bytestream()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
@@ -130,7 +130,7 @@ async def on_new_chosen(
|
||||
await bytestream.rerender()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
|
||||
@@ -9,7 +9,7 @@ from aiogram.types import (
|
||||
from bot.modules.database import db
|
||||
from bot.modules.settings import UserSettings
|
||||
from bot.modules.youtube import AgeRestrictedError, youtube
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -32,7 +32,7 @@ async def on_new_chosen(
|
||||
return
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
@@ -61,7 +61,7 @@ async def on_new_chosen(
|
||||
await bytestream.rerender()
|
||||
|
||||
audio = await bot.send_audio(
|
||||
chat_id=config.telegram.files_chat,
|
||||
chat_id=env.FILES_CHAT,
|
||||
audio=BufferedInputFile(
|
||||
file=bytestream.file,
|
||||
filename=bytestream.filename,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from sqlitedict import SqliteDict
|
||||
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
|
||||
class DBDict(SqliteDict):
|
||||
def __init__(self, tablename: str):
|
||||
super().__init__(config.local.db_path, tablename=tablename, autocommit=True)
|
||||
super().__init__(env.DB_PATH, tablename=tablename, autocommit=True)
|
||||
F
|
||||
@@ -1,10 +1,10 @@
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
from .deezer import Deezer
|
||||
from .downloader import DeezerBytestream
|
||||
|
||||
deezer = Deezer(
|
||||
arl=config.tokens.deezer.arl,
|
||||
arl=env.DEEZER_ARL,
|
||||
)
|
||||
|
||||
__all__ = ["deezer", "DeezerBytestream"]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
from .downloader import SoundCloudBytestream
|
||||
from .soundcloud import SoundCloud
|
||||
|
||||
soundcloud = SoundCloud(
|
||||
client_id=config.tokens.soundcloud.client_id,
|
||||
client_id=env.SOUNDCLOUD_CLIENT_ID,
|
||||
)
|
||||
|
||||
__all__ = ["soundcloud", "SoundCloudBytestream"]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from bot.utils.config import config
|
||||
from bot.utils import env
|
||||
|
||||
from .spotify import Spotify
|
||||
|
||||
spotify = Spotify(
|
||||
client_id=config.tokens.spotify.client_id,
|
||||
client_secret=config.tokens.spotify.client_secret,
|
||||
client_id=env.SPOTIFY_CLIENT_ID,
|
||||
client_secret=env.SPOTIFY_CLIENT_SECRET,
|
||||
)
|
||||
|
||||
__all__ = ["spotify"]
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .config import config
|
||||
|
||||
26
bot/utils/env.py
Normal file
26
bot/utils/env.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
try:
|
||||
load_dotenv()
|
||||
|
||||
BOT_TOKEN = os.environ["BOT_TOKEN"]
|
||||
FILES_CHAT = os.environ["FILES_CHAT"]
|
||||
ADMIN_ID = os.environ["ADMIN_ID"]
|
||||
|
||||
DB_PATH = os.environ["DB_PATH"]
|
||||
|
||||
SPOTIFY_CLIENT_ID = os.environ["SPOTIFY_CLIENT_ID"]
|
||||
SPOTIFY_CLIENT_SECRET = os.environ["SPOTIFY_CLIENT_SECRET"]
|
||||
|
||||
DEEZER_ARL = os.environ["DEEZER_ARL"]
|
||||
|
||||
SOUNDCLOUD_CLIENT_ID = os.environ["SOUNDCLOUD_CLIENT_ID"]
|
||||
|
||||
GENIUS_CLIENT_ACCESS = os.environ["GENIUS_CLIENT_ACCESS"]
|
||||
|
||||
except KeyError as e:
|
||||
print("Can't parse environment", e)
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user