Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Just-Some-Bots/MusicBot
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: vonDassendorf/MusicBot
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 6 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 13, 2020

  1. Added functionality to allow bot to be restricted to specific voice c…

    …hannels in options.ini. Bot will not autojoin or be summoned to these channels.
    vonDassendorf committed Apr 13, 2020
    Copy the full SHA
    9c48432 View commit details

Commits on Aug 23, 2021

  1. Merge pull request #3 from vonDassendorf/new_search_output

    New search output
    vonDassendorf authored Aug 23, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2f91c49 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4faba6b View commit details
  3. Merge pull request #4 from vonDassendorf/restrict_voice_channel

    Added functionality to allow bot to be restricted to specific voice c…
    vonDassendorf authored Aug 23, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9420dce View commit details

Commits on Aug 24, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4e84d05 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6570d7f View commit details
Showing with 70 additions and 16 deletions.
  1. +4 −0 config/example_options.ini
  2. +50 −12 musicbot/bot.py
  3. +16 −4 musicbot/config.py
4 changes: 4 additions & 0 deletions config/example_options.ini
Original file line number Diff line number Diff line change
@@ -63,6 +63,10 @@ CommandPrefix = !
# a space.
BindToChannels =

# Restricts the bot to only join certain voice channels. To use this, add the IDs
# of the voice channels you would like the bot to join, separated by a space
RestrictToChannels =

# Changes the behavior of BindToChannels. Normally any messages sent to a channel not in
# BindToChannels will be ignored. This option allows servers that do not have any bound
# channels while other server have some defined to still use commands in any channel with
62 changes: 50 additions & 12 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
@@ -366,6 +366,11 @@ def _autopause(player):
)
continue

elif self.config.restrict_to_channels and channel not in self.restricted_to_channels:
log.info("Will not join channel \"{}\", restricted to only join specific channels:".format(channel.name))
[log.info(' - {}/{}'.format(ch.guild.name.strip(), ch.name.strip())) for ch in self.restricted_to_channels if ch]
continue

try:
player = await self.get_player(
channel, create=True, deserialize=self.config.persistent_queue
@@ -1230,14 +1235,41 @@ async def on_ready(self):
else:
log.info("Not bound to any text channels")

if self.config.restrict_to_channels:
chlist = set(self.get_channel(i) for i in self.config.restrict_to_channels if i)
chlist.discard(None)

invalids = set()
invalids.update(c for c in chlist if isinstance(c, discord.TextChannel))

chlist.difference_update(invalids)

if chlist:
log.info("Restricted to voice channels:")
[log.info(' - {}/{}'.format(ch.guild.name.strip(), ch.name.strip())) for ch in chlist if ch]

else:
log.info("Not restricted to any voice channels")

if invalids and self.config.debug_mode:
print(flush=True)
log.info("RestrictedToChannels is meant to restrict the bot to specific voice channels."
"Use BindToChannel option to restrict the bot to text channels:")
[log.info(' - {}/{}'.format(ch.guild.name.strip(), ch.name.strip())) for ch in invalids if ch]

self.restricted_to_channels = chlist
else:
log.info("Not restricted to any voice channels")
self.restricted_to_channels = set()

if self.config.autojoin_channels:
chlist = set(
self.get_channel(i) for i in self.config.autojoin_channels if i
)
chlist.discard(None)

invalids = set()
invalids.update(c for c in chlist if isinstance(c, discord.TextChannel))
invalids.update(c for c in chlist if isinstance(c, discord.TextChannel) or c not in self.restricted_to_channels)

chlist.difference_update(invalids)
self.config.autojoin_channels.difference_update(invalids)
@@ -1254,12 +1286,10 @@ async def on_ready(self):

if invalids and self.config.debug_mode:
print(flush=True)
log.info("Cannot autojoin text channels:")
[
log.info(" - {}/{}".format(ch.guild.name.strip(), ch.name.strip()))
for ch in invalids
if ch
]
log.info("Cannot autojoin following channels because they are either "
"text channels or bot is restricted:")
[log.info(' - {}/{}'.format(ch.guild.name.strip(), ch.name.strip())) for ch in invalids if ch]


self.autojoin_channels = chlist

@@ -2809,11 +2839,19 @@ async def cmd_summon(self, channel, guild, author, voice_channel):
expire_in=25,
)

player = await self.get_player(
author.voice.channel,
create=True,
deserialize=self.config.persistent_queue,
)
elif author.voice.channel not in self.restricted_to_channels:
log.info("Will not join channel '{0}/{1}', restricted to only join specific channels".format(
author.voice.channel.guild, author.voice.channel.name))
raise exceptions.CommandError(
self.str.get('cmd-summon-channel-not-permitted',
"Will not join channel `{0}/{1}`, restricted to channels:\n").format(
author.voice.channel.guild, author.voice.channel.name) +
"\n".join(['`'+c.guild.name+'/'+c.name+'`' for c in self.restricted_to_channels
if author.voice.channel.guild == c.guild]),
expire_in=25
)

player = await self.get_player(author.voice.channel, create=True, deserialize=self.config.persistent_queue)

if player.is_stopped:
player.play()
20 changes: 16 additions & 4 deletions musicbot/config.py
Original file line number Diff line number Diff line change
@@ -41,10 +41,8 @@ def __init__(self, config_file):
)

self.auth = ()

self.spotify_clientid = config.get(
"Credentials", "Spotify_ClientID", fallback=ConfigDefaults.spotify_clientid
)
self.restrict_to_channels = config.get('Chat', 'RestrictToChannels', fallback=ConfigDefaults.restrict_to_channels)
self.spotify_clientid = config.get("Credentials", "Spotify_ClientID", fallback=ConfigDefaults.spotify_clientid)
self.spotify_clientsecret = config.get(
"Credentials",
"Spotify_ClientSecret",
@@ -307,6 +305,13 @@ def run_checks(self):
)
self.bound_channels = set()

if self.restrict_to_channels:
try:
self.restrict_to_channels = set(x for x in self.restrict_to_channels.replace(',', ' ').split() if x)
except:
log.warning("RestrictToChannels data is invalid, will not restrict to any channels")
self.restrict_to_channels = set()

if self.autojoin_channels:
try:
self.autojoin_channels = set(
@@ -339,6 +344,12 @@ def run_checks(self):

self.delete_invoking = self.delete_invoking and self.delete_messages

self.bound_channels = set(int(item) for item in self.bound_channels)

self.restrict_to_channels = set(int(item) for item in self.restrict_to_channels)

self.autojoin_channels = set(int(item) for item in self.autojoin_channels)

ap_path, ap_name = os.path.split(self.auto_playlist_file)
apn_name, apn_ext = os.path.splitext(ap_name)
self.auto_playlist_removed_file = os.path.join(
@@ -478,6 +489,7 @@ class ConfigDefaults:

command_prefix = "!"
bound_channels = set()
restrict_to_channels = set()
unbound_servers = False
autojoin_channels = set()
dm_nowplaying = False