database rewrite

This commit is contained in:
2021-11-19 21:10:29 +01:00
parent 998749f1ef
commit ebb07960bf
18 changed files with 435 additions and 76 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
-35
View File
@@ -1,35 +0,0 @@
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)
+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: