Skip to content

Commit 9567f91

Browse files
1 parent 16c1630 commit 9567f91

File tree

9 files changed

+321
-267
lines changed

9 files changed

+321
-267
lines changed

config/example_options.ini

+18-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@
66
; The bot must be restarted for edits to take effect, but a reload command will be created in the future.
77
; Currently the bot does not overwrite any settings, but this may change in a future update.
88

9+
10+
; HOW TO GET VARIOUS IDS:
11+
; http://i.imgur.com/GhKpBMQ.gif
12+
; Enable developer mode (options, settings, appearance), right click the object you want the id of, and click Copy ID
13+
; This works for basically everything you would want the id of (channels and users). For roles you have to right click a role mention.
14+
15+
916
[Credentials]
10-
; The bot needs its own account to run on (not yours)
11-
Email = bot_discord@email
12-
Password = bot_discord_password
13-
; If you have a bot account, use this line instead. Comment or remove the Email/Password options and uncomment the Token line.
14-
;Token = bot_token
17+
; Put your token here. Not "secret". The secret is not the token.
18+
Token = bot_token
19+
; If you want to use a normal user account instead of a bot account, use these lines instead.
20+
; Comment the token line and uncomment the Email/Password lines.
21+
;Email = bot_discord@email
22+
;Password = bot_discord_password
1523

1624
[Permissions]
17-
; This need to be your id, not the bot's id. The bot does not own the bot. You do.
18-
; 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
25+
; This number should be your id. It gives you full permissions. You do not put the bot's id here. That's silly.
26+
; If you don't know how to get this, scroll up a bit and read the part that says "HOW TO GET VARIOUS IDS"
27+
; If you can't do that for some reason, join the help server (invite in the readme) and type this in chat: !id
28+
; If you still don't understand, watch this https://streamable.com/4w8e and may your respective deity have mercy on your soul.
29+
; I don't want any more "how do I get the OwnerID" questions.
1930
OwnerID = 000000000000000000
2031

2132
[Chat]

musicbot/bot.py

+30-13
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ def __init__(self, content, reply=False, delete_after=0):
6666

6767
class MusicBot(discord.Client):
6868
def __init__(self, config_file=ConfigDefaults.options_file, perms_file=PermissionsDefaults.perms_file):
69-
super().__init__()
70-
7169
self.players = {}
7270
self.the_voice_clients = {}
7371
self.locks = defaultdict(asyncio.Lock)
7472
self.voice_client_connect_lock = asyncio.Lock()
7573
self.voice_client_move_lock = asyncio.Lock()
76-
self.aiosession = aiohttp.ClientSession(loop=self.loop)
7774

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

8582
self.exit_signal = None
83+
self.init_ok = False
84+
self.cached_client_id = None
8685

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

91-
self.http.user_agent += ' MusicBot/%s' % BOTVERSION
92-
9390
# TODO: Do these properly
9491
ssd_defaults = {'last_np_msg': None, 'auto_paused': False}
9592
self.server_specific_data = defaultdict(lambda: dict(ssd_defaults))
9693

94+
super().__init__()
95+
self.aiosession = aiohttp.ClientSession(loop=self.loop)
96+
self.http.user_agent += ' MusicBot/%s' % BOTVERSION
97+
9798
# TODO: Add some sort of `denied` argument for a message to send when someone else tries to use it
9899
def owner_only(func):
99100
@wraps(func)
@@ -209,6 +210,13 @@ async def _check_ignore_non_voice(self, msg):
209210
raise exceptions.PermissionsError(
210211
"you cannot use this command when not in the voice channel (%s)" % vc.name, expire_in=30)
211212

213+
async def generate_invite_link(self, *, permissions=None, server=None):
214+
if not self.cached_client_id:
215+
appinfo = await self.application_info()
216+
self.cached_client_id = appinfo.id
217+
218+
return discord.utils.oauth_url(self.cached_client_id, permissions=permissions, server=server)
219+
212220
async def get_voice_client(self, channel):
213221
if isinstance(channel, Object):
214222
channel = self.get_channel(channel.id)
@@ -595,6 +603,8 @@ async def on_ready(self):
595603
"The OwnerID is the id of the owner, not the bot. "
596604
"Figure out which one is which and use the correct information.")
597605

606+
self.init_ok = True
607+
598608
self.safe_print("Bot: %s/%s#%s" % (self.user.id, self.user.name, self.user.discriminator))
599609

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

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

617631
print()
618632

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

816830
if self.user.bot:
817-
appinfo = await self.application_info()
818-
url = discord.utils.oauth_url(appinfo.id)
831+
url = await self.generate_invite_link()
819832
return Response(
820-
"Bot accounts can't use invite links! Click here to invite me: \n%s" % url,
833+
"Bot accounts can't use invite links! Click here to invite me: \n{}".format(url),
821834
reply=True, delete_after=30
822835
)
823836

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

844857
if permissions.max_songs and player.playlist.count_for_user(author) >= permissions.max_songs:
845858
raise exceptions.PermissionsError(
846-
"You have reached your playlist item limit (%s)" % permissions.max_songs, expire_in=30
859+
"You have reached your enqueued song limit (%s)" % permissions.max_songs, expire_in=30
847860
)
848861

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

1055+
entries_added = 0
10421056
if extractor_type == 'youtube:playlist':
10431057
try:
10441058
entries_added = await player.playlist.async_process_youtube_playlist(
@@ -1391,7 +1405,7 @@ async def cmd_skip(self, player, channel, author, message, permissions, voice_ch
13911405
if not player.current_entry:
13921406
if player.playlist.peek():
13931407
if player.playlist.peek()._is_downloading:
1394-
print(player.playlist.peek()._waiting_futures[0].__dict__)
1408+
# print(player.playlist.peek()._waiting_futures[0].__dict__)
13951409
return Response("The next song (%s) is downloading, please wait." % player.playlist.peek().title)
13961410

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

1406-
if author.id == self.config.owner_id or permissions.instaskip:
1420+
if author.id == self.config.owner_id \
1421+
or permissions.instaskip \
1422+
or author == player.current_entry.meta.get('author', None):
1423+
14071424
player.skip() # check autopause stuff here
14081425
await self._manual_delete_check(message)
14091426
return

musicbot/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os.path
22

3-
MAIN_VERSION = '1.9.5_1'
3+
MAIN_VERSION = '1.9.5_2'
44
SUB_VERSION = ''
55
VERSION = MAIN_VERSION + SUB_VERSION
66

0 commit comments

Comments
 (0)