Add spotify search (only search), default menu
This commit is contained in:
@@ -2,6 +2,8 @@ from .db_model import DBDict
|
||||
import os.path
|
||||
from bot.utils.config import config
|
||||
|
||||
from random import randint
|
||||
|
||||
DB = os.path.join(config.local.db_path, 'db')
|
||||
|
||||
if not os.path.isfile(DB):
|
||||
@@ -12,6 +14,12 @@ class Db(object):
|
||||
def __init__(self):
|
||||
self.fsm = DBDict('fsm')
|
||||
self.config = DBDict('config')
|
||||
self.inline = DBDict('inline')
|
||||
self.spotify = DBDict('spotify')
|
||||
|
||||
async def write(self):
|
||||
await self.config.write()
|
||||
|
||||
async def occasionally_write(self, chance: int = 5):
|
||||
if randint(1, chance) == 1:
|
||||
await self.write()
|
||||
|
||||
@@ -24,6 +24,10 @@ class SongItem:
|
||||
def all_artists(self):
|
||||
return ', '.join(self.artists)
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return f"{self.all_artists} - {self.name}"
|
||||
|
||||
def __str__(self):
|
||||
return f"{', '.join(self.artists)} - {self.name}"
|
||||
|
||||
@@ -39,3 +43,11 @@ class Songs(object):
|
||||
return None
|
||||
|
||||
return [SongItem.from_spotify(item) for item in r['tracks']['items']]
|
||||
|
||||
def from_id(self, song_id: str) -> SongItem | None:
|
||||
r = self.spotify.track(song_id)
|
||||
|
||||
if r is None:
|
||||
return None
|
||||
|
||||
return SongItem.from_spotify(r)
|
||||
|
||||
0
bot/modules/youtube/__init__.py
Normal file
0
bot/modules/youtube/__init__.py
Normal file
Reference in New Issue
Block a user