from typing import Dict from typing import List from typing import Optional from aioredis import Redis from bot import redis_prefix class AutoJoin: @staticmethod async def get_channels(redis: Redis) -> Dict[str, str]: # return all channels channels = await redis.hgetall(f"{redis_prefix}:autojoin") return {key: value.split(":") for key, value in channels.items()} @staticmethod async def update_channel( redis: Redis, guild_id: int, voice_channel_id: int, text_channel_id: int ): await redis.hset( f"{redis_prefix}:autojoin", guild_id, f"{voice_channel_id}:{text_channel_id}", ) @staticmethod async def del_channel(redis: Redis, guild_id: int): await redis.hdel(f"{redis_prefix}:autojoin", guild_id) 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)