-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcog.py
More file actions
74 lines (63 loc) · 2.51 KB
/
cog.py
File metadata and controls
74 lines (63 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from __future__ import annotations
from pathlib import Path
from typing import Any, Literal
import discord
from discord import AppCommandType
from expiringdict import ExpiringDict
from redbot.core import Config
from redbot.core.i18n import Translator, cog_i18n
from pylav.extension.red.utils import CompositeMetaClass
from pylav.type_hints.bot import DISCORD_BOT_TYPE
from audio.config_commands import ConfigCommands
from audio.context_menus import ContextMenus
from audio.hybrid_commands import HybridCommands
from audio.player_commands import PlayerCommands
from audio.slash_commands import SlashCommands
from audio.utility_commands import UtilityCommands
_ = Translator("PyLavPlayer", Path(__file__))
@cog_i18n(_)
class PyLavPlayer(
HybridCommands,
UtilityCommands,
PlayerCommands,
ConfigCommands,
ContextMenus,
SlashCommands,
metaclass=CompositeMetaClass,
):
"""A Media player using the PyLav library"""
__version__ = "1.0.0"
def __init__(self, bot: DISCORD_BOT_TYPE, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
self.bot = bot
self._config = Config.get_conf(self, identifier=208903205982044161)
self._config.register_guild(enable_slash=True, enable_context=True)
self._config.register_global(
enable_slash=False,
enable_context=False,
)
self.context_user_play = discord.app_commands.ContextMenu(
name=_("Play from activity"),
callback=self._context_user_play,
type=AppCommandType.user,
extras={"red_force_enable": True},
)
self.context_message_play = discord.app_commands.ContextMenu(
name=_("Play from message"),
callback=self._context_message_play,
type=AppCommandType.message,
extras={"red_force_enable": True},
)
self.bot.tree.add_command(self.context_user_play)
self.bot.tree.add_command(self.context_message_play)
self._track_cache = ExpiringDict(max_len=float("inf"), max_age_seconds=60) # type: ignore
async def cog_unload(self) -> None:
self.bot.tree.remove_command(self.context_user_play, type=AppCommandType.user)
self.bot.tree.remove_command(self.context_message_play, type=AppCommandType.message)
async def red_delete_data_for_user(
self,
*,
requester: Literal["discord_deleted_user", "owner", "user", "user_strict"],
user_id: int,
) -> None:
await self._config.user_from_id(user_id).clear()