@@ -66,14 +66,11 @@ def __init__(self, content, reply=False, delete_after=0):
66
66
67
67
class MusicBot (discord .Client ):
68
68
def __init__ (self , config_file = ConfigDefaults .options_file , perms_file = PermissionsDefaults .perms_file ):
69
- super ().__init__ ()
70
-
71
69
self .players = {}
72
70
self .the_voice_clients = {}
73
71
self .locks = defaultdict (asyncio .Lock )
74
72
self .voice_client_connect_lock = asyncio .Lock ()
75
73
self .voice_client_move_lock = asyncio .Lock ()
76
- self .aiosession = aiohttp .ClientSession (loop = self .loop )
77
74
78
75
self .config = Config (config_file )
79
76
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
83
80
self .downloader = downloader .Downloader (download_folder = 'audio_cache' )
84
81
85
82
self .exit_signal = None
83
+ self .init_ok = False
84
+ self .cached_client_id = None
86
85
87
86
if not self .autoplaylist :
88
87
print ("Warning: Autoplaylist is empty, disabling." )
89
88
self .config .auto_playlist = False
90
89
91
- self .http .user_agent += ' MusicBot/%s' % BOTVERSION
92
-
93
90
# TODO: Do these properly
94
91
ssd_defaults = {'last_np_msg' : None , 'auto_paused' : False }
95
92
self .server_specific_data = defaultdict (lambda : dict (ssd_defaults ))
96
93
94
+ super ().__init__ ()
95
+ self .aiosession = aiohttp .ClientSession (loop = self .loop )
96
+ self .http .user_agent += ' MusicBot/%s' % BOTVERSION
97
+
97
98
# TODO: Add some sort of `denied` argument for a message to send when someone else tries to use it
98
99
def owner_only (func ):
99
100
@wraps (func )
@@ -209,6 +210,13 @@ async def _check_ignore_non_voice(self, msg):
209
210
raise exceptions .PermissionsError (
210
211
"you cannot use this command when not in the voice channel (%s)" % vc .name , expire_in = 30 )
211
212
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
+
212
220
async def get_voice_client (self , channel ):
213
221
if isinstance (channel , Object ):
214
222
channel = self .get_channel (channel .id )
@@ -595,6 +603,8 @@ async def on_ready(self):
595
603
"The OwnerID is the id of the owner, not the bot. "
596
604
"Figure out which one is which and use the correct information." )
597
605
606
+ self .init_ok = True
607
+
598
608
self .safe_print ("Bot: %s/%s#%s" % (self .user .id , self .user .name , self .user .discriminator ))
599
609
600
610
owner = self ._get_owner (voice = True ) or self ._get_owner ()
@@ -611,8 +621,12 @@ async def on_ready(self):
611
621
[self .safe_print (' - ' + s .name ) for s in self .servers ]
612
622
613
623
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 ("\n To 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 ())
616
630
617
631
print ()
618
632
@@ -814,10 +828,9 @@ async def cmd_joinserver(self, message, server_link=None):
814
828
"""
815
829
816
830
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 ()
819
832
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 ) ,
821
834
reply = True , delete_after = 30
822
835
)
823
836
@@ -843,7 +856,7 @@ async def cmd_play(self, player, channel, author, permissions, leftover_args, so
843
856
844
857
if permissions .max_songs and player .playlist .count_for_user (author ) >= permissions .max_songs :
845
858
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
847
860
)
848
861
849
862
await self .send_typing (channel )
@@ -1039,6 +1052,7 @@ async def _cmd_play_playlist_async(self, player, channel, author, permissions, p
1039
1052
channel , "Processing %s songs..." % num_songs ) # TODO: From playlist_title
1040
1053
await self .send_typing (channel )
1041
1054
1055
+ entries_added = 0
1042
1056
if extractor_type == 'youtube:playlist' :
1043
1057
try :
1044
1058
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
1391
1405
if not player .current_entry :
1392
1406
if player .playlist .peek ():
1393
1407
if player .playlist .peek ()._is_downloading :
1394
- print (player .playlist .peek ()._waiting_futures [0 ].__dict__ )
1408
+ # print(player.playlist.peek()._waiting_futures[0].__dict__)
1395
1409
return Response ("The next song (%s) is downloading, please wait." % player .playlist .peek ().title )
1396
1410
1397
1411
elif player .playlist .peek ().is_downloaded :
@@ -1403,7 +1417,10 @@ async def cmd_skip(self, player, channel, author, message, permissions, voice_ch
1403
1417
print ("Something strange is happening. "
1404
1418
"You might want to restart the bot if it doesn't start working." )
1405
1419
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
+
1407
1424
player .skip () # check autopause stuff here
1408
1425
await self ._manual_delete_check (message )
1409
1426
return
0 commit comments