Added sources functionality + pre-commit

This commit is contained in:
2021-11-18 21:59:37 +01:00
parent 2e007a6fb3
commit 316f3bacc9
11 changed files with 170 additions and 21 deletions
+3 -2
View File
@@ -1,8 +1,9 @@
from typing import Optional, Union
from typing import Optional
from typing import Union
import discord
from discord.ext.commands import Context
from discord import Embed
from discord.ext.commands import Context
class EmbedGenerator:
+2
View File
@@ -1,5 +1,7 @@
from typing import Dict
from discord.ext.commands import Cog
from bot import TuneBot
+22
View File
@@ -33,3 +33,25 @@ class Playlist:
@staticmethod
async def random(redis: Redis, amount: Optional[int] = 1) -> List[str]:
return await redis.srandmember(f"{redis_prefix}:playlist", amount)
@staticmethod
async def add_bulk(redis: Redis, urls: list[str]):
await redis.sadd(f"{redis_prefix}:playlist", *urls)
@staticmethod
async def clear(redis: Redis):
await redis.delete(f"{redis_prefix}:playlist")
class PlaylistSource:
@staticmethod
async def get_all(redis: Redis) -> list[str]:
return await redis.smembers(f"{redis_prefix}:sources")
@staticmethod
async def add(redis: Redis, source_url: str):
await redis.sadd(f"{redis_prefix}:sources", source_url)
@staticmethod
async def remove(redis: Redis, source_url: str) -> bool:
return await redis.srem(f"{redis_prefix}:sources", source_url)
+2 -1
View File
@@ -1,7 +1,8 @@
from discord.embeds import Embed
from context import CustomContext
from discord.ext.commands import CommandError
from context import CustomContext
class EmbeddedCommandException(CommandError):
def __init__(self, embed: Embed) -> None: