Skip to content

Update 1.9.5_2 #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 29, 2016
25 changes: 18 additions & 7 deletions config/example_options.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@
; The bot must be restarted for edits to take effect, but a reload command will be created in the future.
; Currently the bot does not overwrite any settings, but this may change in a future update.


; HOW TO GET VARIOUS IDS:
; http://i.imgur.com/GhKpBMQ.gif
; Enable developer mode (options, settings, appearance), right click the object you want the id of, and click Copy ID
; This works for basically everything you would want the id of (channels and users). For roles you have to right click a role mention.


[Credentials]
; The bot needs its own account to run on (not yours)
Email = bot_discord@email
Password = bot_discord_password
; If you have a bot account, use this line instead. Comment or remove the Email/Password options and uncomment the Token line.
;Token = bot_token
; Put your token here. Not "secret". The secret is not the token.
Token = bot_token
; If you want to use a normal user account instead of a bot account, use these lines instead.
; Comment the token line and uncomment the Email/Password lines.
;Email = bot_discord@email
;Password = bot_discord_password

[Permissions]
; This need to be your id, not the bot's id. The bot does not own the bot. You do.
; If you don't know how to get this, join the help server (link in the readme) *with the owner's account* and type !id in chat
; This number should be your id. It gives you full permissions. You do not put the bot's id here. That's silly.
; If you don't know how to get this, scroll up a bit and read the part that says "HOW TO GET VARIOUS IDS"
; If you can't do that for some reason, join the help server (invite in the readme) and type this in chat: !id
; If you still don't understand, watch this https://streamable.com/4w8e and may your respective deity have mercy on your soul.
; I don't want any more "how do I get the OwnerID" questions.
OwnerID = 000000000000000000

[Chat]
Expand Down
43 changes: 30 additions & 13 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ def __init__(self, content, reply=False, delete_after=0):

class MusicBot(discord.Client):
def __init__(self, config_file=ConfigDefaults.options_file, perms_file=PermissionsDefaults.perms_file):
super().__init__()

self.players = {}
self.the_voice_clients = {}
self.locks = defaultdict(asyncio.Lock)
self.voice_client_connect_lock = asyncio.Lock()
self.voice_client_move_lock = asyncio.Lock()
self.aiosession = aiohttp.ClientSession(loop=self.loop)

self.config = Config(config_file)
self.permissions = Permissions(perms_file, grant_all=[self.config.owner_id])
Expand All @@ -83,17 +80,21 @@ def __init__(self, config_file=ConfigDefaults.options_file, perms_file=Permissio
self.downloader = downloader.Downloader(download_folder='audio_cache')

self.exit_signal = None
self.init_ok = False
self.cached_client_id = None

if not self.autoplaylist:
print("Warning: Autoplaylist is empty, disabling.")
self.config.auto_playlist = False

self.http.user_agent += ' MusicBot/%s' % BOTVERSION

# TODO: Do these properly
ssd_defaults = {'last_np_msg': None, 'auto_paused': False}
self.server_specific_data = defaultdict(lambda: dict(ssd_defaults))

super().__init__()
self.aiosession = aiohttp.ClientSession(loop=self.loop)
self.http.user_agent += ' MusicBot/%s' % BOTVERSION

# TODO: Add some sort of `denied` argument for a message to send when someone else tries to use it
def owner_only(func):
@wraps(func)
Expand Down Expand Up @@ -209,6 +210,13 @@ async def _check_ignore_non_voice(self, msg):
raise exceptions.PermissionsError(
"you cannot use this command when not in the voice channel (%s)" % vc.name, expire_in=30)

async def generate_invite_link(self, *, permissions=None, server=None):
if not self.cached_client_id:
appinfo = await self.application_info()
self.cached_client_id = appinfo.id

return discord.utils.oauth_url(self.cached_client_id, permissions=permissions, server=server)

async def get_voice_client(self, channel):
if isinstance(channel, Object):
channel = self.get_channel(channel.id)
Expand Down Expand Up @@ -595,6 +603,8 @@ async def on_ready(self):
"The OwnerID is the id of the owner, not the bot. "
"Figure out which one is which and use the correct information.")

self.init_ok = True

self.safe_print("Bot: %s/%s#%s" % (self.user.id, self.user.name, self.user.discriminator))

owner = self._get_owner(voice=True) or self._get_owner()
Expand All @@ -611,8 +621,12 @@ async def on_ready(self):
[self.safe_print(' - ' + s.name) for s in self.servers]

else:
print("Owner unavailable, bot is not on any servers.")
# if bot: post help link, else post something about invite links
print("Owner unknown, bot is not on any servers.")
if self.user.bot:
print("\nTo make the bot join a server, paste this link in your browser.")
print("Note: You should be logged into your main account and have \n"
"manage server permissions on the server you want the bot to join.\n")
print(" " + await self.generate_invite_link())

print()

Expand Down Expand Up @@ -814,10 +828,9 @@ async def cmd_joinserver(self, message, server_link=None):
"""

if self.user.bot:
appinfo = await self.application_info()
url = discord.utils.oauth_url(appinfo.id)
url = await self.generate_invite_link()
return Response(
"Bot accounts can't use invite links! Click here to invite me: \n%s" % url,
"Bot accounts can't use invite links! Click here to invite me: \n{}".format(url),
reply=True, delete_after=30
)

Expand All @@ -843,7 +856,7 @@ async def cmd_play(self, player, channel, author, permissions, leftover_args, so

if permissions.max_songs and player.playlist.count_for_user(author) >= permissions.max_songs:
raise exceptions.PermissionsError(
"You have reached your playlist item limit (%s)" % permissions.max_songs, expire_in=30
"You have reached your enqueued song limit (%s)" % permissions.max_songs, expire_in=30
)

await self.send_typing(channel)
Expand Down Expand Up @@ -1039,6 +1052,7 @@ async def _cmd_play_playlist_async(self, player, channel, author, permissions, p
channel, "Processing %s songs..." % num_songs) # TODO: From playlist_title
await self.send_typing(channel)

entries_added = 0
if extractor_type == 'youtube:playlist':
try:
entries_added = await player.playlist.async_process_youtube_playlist(
Expand Down Expand Up @@ -1391,7 +1405,7 @@ async def cmd_skip(self, player, channel, author, message, permissions, voice_ch
if not player.current_entry:
if player.playlist.peek():
if player.playlist.peek()._is_downloading:
print(player.playlist.peek()._waiting_futures[0].__dict__)
# print(player.playlist.peek()._waiting_futures[0].__dict__)
return Response("The next song (%s) is downloading, please wait." % player.playlist.peek().title)

elif player.playlist.peek().is_downloaded:
Expand All @@ -1403,7 +1417,10 @@ async def cmd_skip(self, player, channel, author, message, permissions, voice_ch
print("Something strange is happening. "
"You might want to restart the bot if it doesn't start working.")

if author.id == self.config.owner_id or permissions.instaskip:
if author.id == self.config.owner_id \
or permissions.instaskip \
or author == player.current_entry.meta.get('author', None):

player.skip() # check autopause stuff here
await self._manual_delete_check(message)
return
Expand Down
2 changes: 1 addition & 1 deletion musicbot/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path

MAIN_VERSION = '1.9.5_1'
MAIN_VERSION = '1.9.5_2'
SUB_VERSION = ''
VERSION = MAIN_VERSION + SUB_VERSION

Expand Down
Loading