Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
BabyBoySnow committed Oct 19, 2024
1 parent 3526846 commit 3e5655e
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 42 deletions.
5 changes: 3 additions & 2 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7560,13 +7560,14 @@ async def cmd_makeini(
self.config.register.write_default_ini(pathlib.Path("./config/ex_opts.ini"))

if cfg == "perms":
self.permissions.register.write_default_ini(pathlib.Path("./config/ex_perms.ini"))
self.permissions.register.write_default_ini(
pathlib.Path("./config/ex_perms.ini")
)

return Response(
"Saved the requested INI file to disk. Go check it", delete_after=20
)


@owner_only
@command_helper(
desc="Display the current bot version and check for updates to MusicBot or dependencies.\n",
Expand Down
102 changes: 76 additions & 26 deletions musicbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="no_nowplaying_auto",
default=ConfigDefaults.no_nowplaying_auto,
getter="getboolean",
comment=_X("Disable now playing messages for songs played via auto playlist."),
comment=_X(
"Disable now playing messages for songs played via auto playlist."
),
)
self.nowplaying_channels: Set[int] = self.register.init_option(
section="Chat",
Expand Down Expand Up @@ -375,7 +377,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="save_videos",
default=ConfigDefaults.save_videos,
getter="getboolean",
comment=_X("Allow MusicBot to keep downloaded media, or delete it right away."),
comment=_X(
"Allow MusicBot to keep downloaded media, or delete it right away."
),
)
self.storage_limit_bytes: int = self.register.init_option(
section="MusicBot",
Expand All @@ -384,7 +388,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
default=ConfigDefaults.storage_limit_bytes,
getter="getdatasize",
# TRANSLATORS: SaveVideos is not translated.
comment=_X("If SaveVideos is enabled, set a limit on how much storage space should be used."),
comment=_X(
"If SaveVideos is enabled, set a limit on how much storage space should be used."
),
)
self.storage_limit_days: int = self.register.init_option(
section="MusicBot",
Expand All @@ -393,7 +399,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
default=ConfigDefaults.storage_limit_days,
getter="getint",
# TRANSLATORS: SaveVideos should not be translated.
comment=_X("If SaveVideos is enabled, set a limit on how long files should be kept."),
comment=_X(
"If SaveVideos is enabled, set a limit on how long files should be kept."
),
)
self.storage_retain_autoplay: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -402,7 +410,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
default=ConfigDefaults.storage_retain_autoplay,
getter="getboolean",
# TRANSLATORS: SaveVideos should not be translated
comment=_X("If SaveVideos is enabled, never purge auto playlist songs from the cache regardless of limits."),
comment=_X(
"If SaveVideos is enabled, never purge auto playlist songs from the cache regardless of limits."
),
)
self.now_playing_mentions: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -428,7 +438,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="auto_playlist",
default=ConfigDefaults.auto_playlist,
getter="getboolean",
comment=_X("Enable MusicBot to automatically play music from the auto playlist when the queue is empty."),
comment=_X(
"Enable MusicBot to automatically play music from the auto playlist when the queue is empty."
),
)
self.auto_playlist_random: bool = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -456,7 +468,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="auto_playlist_remove_on_block",
default=ConfigDefaults.auto_playlist_remove_on_block,
getter="getboolean",
comment=_X("Remove songs from the auto playlist if they are found in the song blocklist."),
comment=_X(
"Remove songs from the auto playlist if they are found in the song blocklist."
),
)
self.auto_pause: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -472,7 +486,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="delete_messages",
default=ConfigDefaults.delete_messages,
getter="getboolean",
comment=_X("Allow MusicBot to automatically delete messages it sends, after a short delay."),
comment=_X(
"Allow MusicBot to automatically delete messages it sends, after a short delay."
),
)
# TODO: add a means of setting the above delay period.
# The DeleteInvoking should be tied to this same delay.
Expand All @@ -490,7 +506,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="persistent_queue",
default=ConfigDefaults.persistent_queue,
getter="getboolean",
comment=_X("Allow MusicBot to save the song queue, so queued songs will survive restarts."),
comment=_X(
"Allow MusicBot to save the song queue, so queued songs will survive restarts."
),
)
self.pre_download_next_song: bool = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -529,7 +547,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="status_include_paused",
default=ConfigDefaults.status_include_paused,
getter="getboolean",
comment=_X("If enabled, status messages will report info on paused players."),
comment=_X(
"If enabled, status messages will report info on paused players."
),
)
self.write_current_song: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -538,15 +558,19 @@ def __init__(self, config_file: pathlib.Path) -> None:
default=ConfigDefaults.write_current_song,
getter="getboolean",
# TRANSLATORS: [Server ID] is a descriptive placeholder and may be translated.
comment=_X("If enabled, MusicBot will save the track title to: data/[Server ID]/current.txt"),
comment=_X(
"If enabled, MusicBot will save the track title to: data/[Server ID]/current.txt"
),
)
self.allow_author_skip: bool = self.register.init_option(
section="MusicBot",
option="AllowAuthorSkip",
dest="allow_author_skip",
default=ConfigDefaults.allow_author_skip,
getter="getboolean",
comment=_X("Allow the member who requested the song to skip it, bypassing votes."),
comment=_X(
"Allow the member who requested the song to skip it, bypassing votes."
),
)
self.use_experimental_equalization: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -573,15 +597,19 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="queue_length",
default=ConfigDefaults.queue_length,
getter="getint",
comment=_X("The number of entries to show per-page when using q command to list the queue."),
comment=_X(
"The number of entries to show per-page when using q command to list the queue."
),
)
self.remove_ap: bool = self.register.init_option(
section="MusicBot",
option="RemoveFromAPOnError",
dest="remove_ap",
default=ConfigDefaults.remove_ap,
getter="getboolean",
comment=_X("Enable MusicBot to automatically remove unplayable entries from tha auto playlist."),
comment=_X(
"Enable MusicBot to automatically remove unplayable entries from tha auto playlist."
),
)
self.show_config_at_start: bool = self.register.init_option(
section="MusicBot",
Expand All @@ -598,15 +626,19 @@ def __init__(self, config_file: pathlib.Path) -> None:
default=ConfigDefaults.legacy_skip,
getter="getboolean",
# TRANSLATORS: InstaSkip should not be translated.
comment=_X("Enable users with the InstaSkip permission to bypass skip voting and force skips."),
comment=_X(
"Enable users with the InstaSkip permission to bypass skip voting and force skips."
),
)
self.leavenonowners: bool = self.register.init_option(
section="MusicBot",
option="LeaveServersWithoutOwner",
dest="leavenonowners",
default=ConfigDefaults.leavenonowners,
getter="getboolean",
comment=_X("If enabled, MusicBot will leave servers if the owner is not in their member list."),
comment=_X(
"If enabled, MusicBot will leave servers if the owner is not in their member list."
),
)
self.usealias: bool = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -636,7 +668,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="self_deafen",
default=ConfigDefaults.self_deafen,
getter="getboolean",
comment=_X("MusicBot will automatically deafen itself when entering a voice channel."),
comment=_X(
"MusicBot will automatically deafen itself when entering a voice channel."
),
)
self.leave_inactive_channel: bool = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -668,7 +702,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="leave_after_queue_empty",
default=ConfigDefaults.leave_after_queue_empty,
getter="getboolean",
comment=_X("If enabled, MusicBot will leave the channel immediately when the song queue is empty."),
comment=_X(
"If enabled, MusicBot will leave the channel immediately when the song queue is empty."
),
)
self.leave_player_inactive_for: float = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -764,7 +800,10 @@ def __init__(self, config_file: pathlib.Path) -> None:
comment=_X(
"Enable saving songs played per-server to a playlist file: %(basename)s[Server ID]%(ext)s"
),
comment_args={"basename": f"{DEFAULT_PLAYLIST_DIR}{hist_file.stem}", "ext": hist_file.suffix},
comment_args={
"basename": f"{DEFAULT_PLAYLIST_DIR}{hist_file.stem}",
"ext": hist_file.suffix,
},
)

self.enable_local_media: bool = self.register.init_option(
Expand All @@ -787,7 +826,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="auto_unpause_on_play",
default=ConfigDefaults.auto_unpause_on_play,
getter="getboolean",
comment=_X("Allow MusicBot to automatically unpause when play commands are used."),
comment=_X(
"Allow MusicBot to automatically unpause when play commands are used."
),
)

# This is likely to turn into one option for each separate part.
Expand Down Expand Up @@ -866,15 +907,19 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="user_blocklist_enabled",
default=ConfigDefaults.user_blocklist_enabled,
getter="getboolean",
comment=_X("Toggle the user block list feature, without emptying the block list."),
comment=_X(
"Toggle the user block list feature, without emptying the block list."
),
)
self.user_blocklist_file: pathlib.Path = self.register.init_option(
section="Files",
option="UserBlocklistFile",
dest="user_blocklist_file",
default=ConfigDefaults.user_blocklist_file,
getter="getpathlike",
comment=_X("An optional file path to a text file listing Discord User IDs, one per line."),
comment=_X(
"An optional file path to a text file listing Discord User IDs, one per line."
),
)
self.user_blocklist: UserBlocklist = UserBlocklist(self.user_blocklist_file)

Expand All @@ -884,7 +929,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="song_blocklist_enabled",
default=ConfigDefaults.song_blocklist_enabled,
getter="getboolean",
comment=_X("Enable the song block list feature, without emptying the block list."),
comment=_X(
"Enable the song block list feature, without emptying the block list."
),
)
self.song_blocklist_file: pathlib.Path = self.register.init_option(
section="Files",
Expand Down Expand Up @@ -945,7 +992,9 @@ def __init__(self, config_file: pathlib.Path) -> None:
dest="audio_cache_path",
default=ConfigDefaults.audio_cache_path,
getter="getpathlike",
comment=_X("An optional directory path where MusicBot will store long and short-term cache for playback."),
comment=_X(
"An optional directory path where MusicBot will store long and short-term cache for playback."
),
)

# TODO: i18n, allow i18n format args here.
Expand Down Expand Up @@ -980,7 +1029,6 @@ def __init__(self, config_file: pathlib.Path) -> None:
# end of config registry.
#


# Convert all path constants into config as pathlib.Path objects.
self.data_path = pathlib.Path(DEFAULT_DATA_DIR).resolve()
self.server_names_path = self.data_path.joinpath(DATA_FILE_SERVERS)
Expand Down Expand Up @@ -1229,7 +1277,9 @@ def find_config(self) -> None:
else:
self.register.write_default_ini(pathlib.Path(EXAMPLE_OPTIONS_FILE))
shutil.copy(EXAMPLE_OPTIONS_FILE, self.config_file)
log.warning("Generated a new example_options.ini and copied it to options.ini")
log.warning(
"Generated a new example_options.ini and copied it to options.ini"
)

# load the config and check if settings are configured.
if not config.read(self.config_file, encoding="utf-8"):
Expand Down
44 changes: 30 additions & 14 deletions musicbot/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def can_use_command(self, command: str, sub: str = "") -> bool:
:param: command: The command name to test.
:param: sub: The sub-command argument of the command being tested.
:returns: boolean: False if not allowed, True otherwise.
"""
csub = f"{command}_{sub}"
Expand All @@ -541,20 +541,33 @@ def can_use_command(self, command: str, sub: str = "") -> bool:
terms.append(csub)

if not self.advanced_commandlists:
if self.command_whitelist and all(c not in self.command_whitelist for c in terms):
if self.command_whitelist and all(
c not in self.command_whitelist for c in terms
):
return False

if self.command_blacklist and any(c in self.command_blacklist for c in terms):

if self.command_blacklist and any(
c in self.command_blacklist for c in terms
):
return False

else:
if self.command_whitelist and all(x not in self.command_whitelist for x in terms):
if self.command_whitelist and all(
x not in self.command_whitelist for x in terms
):
return False

if sub and command in self.command_whitelist and csub in self.command_blacklist:
if (
sub
and command in self.command_whitelist
and csub in self.command_blacklist
):
return False

if any(c in self.command_blacklist and c in self.command_whitelist for c in terms):
if any(
c in self.command_blacklist and c in self.command_whitelist
for c in terms
):
return False
return True

Expand Down Expand Up @@ -731,8 +744,8 @@ def write_default_ini(self, filename: pathlib.Path) -> bool:
raise RuntimeError("Dev bug, Permissions object expcted.")

if DEFAULT_OWNER_GROUP_NAME not in self._config.groups:
self._config.groups[DEFAULT_OWNER_GROUP_NAME] = self._config._generate_permissive_group(
DEFAULT_OWNER_GROUP_NAME
self._config.groups[DEFAULT_OWNER_GROUP_NAME] = (
self._config._generate_permissive_group(DEFAULT_OWNER_GROUP_NAME)
)
if DEFAULT_PERMS_GROUP_NAME not in self._config.groups:
self._config.add_group(DEFAULT_PERMS_GROUP_NAME)
Expand All @@ -748,7 +761,10 @@ def write_default_ini(self, filename: pathlib.Path) -> bool:
# create the comment documentation and fill in defaults for each section.
docs = ""
for opt in self.option_list:
if opt.section not in [DEFAULT_OWNER_GROUP_NAME, DEFAULT_PERMS_GROUP_NAME]:
if opt.section not in [
DEFAULT_OWNER_GROUP_NAME,
DEFAULT_PERMS_GROUP_NAME,
]:
continue
dval = self.to_ini(opt, use_default=True)
cu[opt.section][opt.option] = dval
Expand All @@ -757,7 +773,9 @@ def write_default_ini(self, filename: pathlib.Path) -> bool:
comment = opt.comment % opt.comment_args
else:
comment = opt.comment
comment = "".join(f" {c}\n" for c in comment.split("\n")).rstrip()
comment = "".join(
f" {c}\n" for c in comment.split("\n")
).rstrip()
docs += f" {opt.option} = {dval}\n{comment}\n\n"

# add comments to head of file.
Expand All @@ -783,7 +801,7 @@ def write_default_ini(self, filename: pathlib.Path) -> bool:
adder.comment(line, comment_prefix=";")
adder.space()
adder.space()

# add owner section comment
owner_comment = (
"This permission group is used by the Owner only, and cannot be edited at all.\n"
Expand Down Expand Up @@ -816,5 +834,3 @@ def write_default_ini(self, filename: pathlib.Path) -> bool:
):
log.exception("Failed to save default INI file at: %s", filename)
return False


0 comments on commit 3e5655e

Please sign in to comment.