mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:07:48 +00:00
Merge pull request #40 from strNophix/source-manager-setting
Source manager decorator
This commit is contained in:
+6
-5
@@ -6,6 +6,7 @@ from discord.message import Message
|
||||
from bot import TuneBot
|
||||
from context import CustomContext
|
||||
from utils.classes import BaseCog
|
||||
from utils.decorators import source_manager_only
|
||||
from utils.EmbedGenerator import EmbedGenerator
|
||||
|
||||
|
||||
@@ -47,7 +48,7 @@ class SettingsCog(BaseCog, name="Settings"):
|
||||
embed.title = f"AutoJoin disabled"
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.is_owner()
|
||||
@source_manager_only()
|
||||
@commands.group(
|
||||
name="source",
|
||||
aliases=["src"],
|
||||
@@ -63,7 +64,7 @@ class SettingsCog(BaseCog, name="Settings"):
|
||||
embed.description = f"```{prefix}source list\n{prefix}source add <url>\n{prefix}source remove <url>\n{prefix}source sync```"
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.is_owner()
|
||||
@source_manager_only()
|
||||
@source.command(name="remove")
|
||||
async def source_remove(self, ctx: CustomContext, source_url: str):
|
||||
"""Removes a source from the bot"""
|
||||
@@ -81,7 +82,7 @@ class SettingsCog(BaseCog, name="Settings"):
|
||||
embed.title = "Could not remove source, the specified source might not exist"
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.is_owner()
|
||||
@source_manager_only()
|
||||
@source.command(name="add")
|
||||
async def source_add(self, ctx: CustomContext, source_url: str):
|
||||
"""
|
||||
@@ -117,7 +118,7 @@ class SettingsCog(BaseCog, name="Settings"):
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.is_owner()
|
||||
@source_manager_only()
|
||||
@source.command(name="list", aliases=["ls"])
|
||||
async def source_list(self, ctx: CustomContext):
|
||||
"""Display a list of sources"""
|
||||
@@ -133,7 +134,7 @@ class SettingsCog(BaseCog, name="Settings"):
|
||||
embed.description = description
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.is_owner()
|
||||
@source_manager_only()
|
||||
@source.command(name="sync")
|
||||
async def source_sync(self, ctx: CustomContext):
|
||||
"""Forcefully resyncs all sources"""
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"token": "",
|
||||
"owner_ids": [194545408960102400, 190875175460405249],
|
||||
"manager_ids": [],
|
||||
"prefixes": ["ck!"],
|
||||
"redis_url": "",
|
||||
"redis_prefix": "",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from typing import Callable
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TypeVar
|
||||
|
||||
from discord.ext.commands import check
|
||||
from discord.ext.commands.errors import NotOwner
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from context import CustomContext
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def source_manager_only() -> Callable[[T], T]:
|
||||
"""
|
||||
A :func:`.check` that checks if the person invoking this command is allowed to modify the radio sources.
|
||||
"""
|
||||
|
||||
async def predicate(ctx: "CustomContext") -> bool:
|
||||
is_manager = ctx.author.id in ctx.bot.config["manager_ids"]
|
||||
is_owner = await ctx.bot.is_owner(ctx.author)
|
||||
if not is_manager and not is_owner:
|
||||
raise NotOwner("You are not allowed to modify the sources.")
|
||||
|
||||
return True
|
||||
|
||||
return check(predicate)
|
||||
Reference in New Issue
Block a user