mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 19:57:48 +00:00
Migrated settings cog
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import typing
|
||||
from dataclasses import dataclass
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from aioredis import Redis
|
||||
from bot import TuneBot
|
||||
from discord import Interaction
|
||||
from context import CustomContext
|
||||
|
||||
|
||||
@dataclass
|
||||
class ContextLike:
|
||||
redis: "Redis"
|
||||
bot: "TuneBot"
|
||||
guild_id: int
|
||||
|
||||
@staticmethod
|
||||
def from_discord_context(ctx: "CustomContext") -> "ContextLike":
|
||||
return ContextLike(redis=ctx.redis, bot=ctx.bot, guild_id=ctx.guild.id)
|
||||
|
||||
@staticmethod
|
||||
def from_discord_interaction(ctx: "Interaction") -> "ContextLike":
|
||||
return ContextLike(
|
||||
redis=ctx.client._redis_client, bot=ctx.client, guild_id=ctx.guild_id
|
||||
)
|
||||
|
||||
|
||||
__all__ = ("ContextLike",)
|
||||
@@ -22,20 +22,20 @@ class RedisAutoJoin(RedisContextEntity, AutoJoin):
|
||||
voice_channel_id (int): [description]
|
||||
text_channel_id (int): [description]
|
||||
"""
|
||||
if not self.ctx.guild:
|
||||
if not self.ctx.guild_id:
|
||||
raise Exception("This method can only be invoked inside of a guild.")
|
||||
|
||||
value = f"{voice_channel_id}:{text_channel_id}"
|
||||
await self.redis.hset(self.key("autojoin"), self.ctx.guild.id, value)
|
||||
await self.redis.hset(self.key("autojoin"), self.ctx.guild_id, value)
|
||||
|
||||
async def disable(self):
|
||||
"""
|
||||
Removes the AutoJoin configuration of a guild.
|
||||
"""
|
||||
if not self.ctx.guild:
|
||||
if not self.ctx.guild_id:
|
||||
raise Exception("This method can only be invoked inside of a guild.")
|
||||
|
||||
await self.redis.hdel(self.key("autojoin"), self.ctx.guild.id)
|
||||
await self.redis.hdel(self.key("autojoin"), self.ctx.guild_id)
|
||||
|
||||
|
||||
__all__ = ("GlobalRedisAutoJoin", "RedisAutoJoin")
|
||||
|
||||
@@ -3,7 +3,7 @@ from abc import abstractmethod
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from context import CustomContext
|
||||
from tunebot.context import ContextLike
|
||||
|
||||
from aioredis.client import Redis
|
||||
|
||||
@@ -34,7 +34,7 @@ class RedisBotEntity(RedisEntity):
|
||||
|
||||
|
||||
class RedisContextEntity(RedisEntity):
|
||||
def __init__(self, ctx: "CustomContext") -> None:
|
||||
def __init__(self, ctx: "ContextLike") -> None:
|
||||
self.ctx = ctx
|
||||
super().__init__()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user