async def main(bot, message): player = bot.players[message.guild] try: pickno = int(message.content.split()[1]) except ValueError: await SMexHandler.handle( bot, ServerManPrettyException("", "Invalid Input!", message.channel)) return if pickno - 1 < 0 or pickno > len(player.playlist.entries): await SMexHandler.handle( bot, ServerManPrettyException( "Value can only be between 1 and %s" % len(player.playlist.entries), "Invalid Value!", message.channel)) return player.index = pickno - 1 if not player.voice_client.is_playing( ) and not player.state == "paused": bot.loop.create_task(player.prepare_entry()) await message.channel.send("Jumping to **%s**!" % pickno) else: player.justjumped = 1 await message.channel.send( "Will jump to **%s** after the current track finishes playing!" % pickno)
async def main(bot, message): player = bot.players[message.guild] duration = player.current_entry['duration'] timelist = shlex.split(message.content)[1].split(':') if not len(timelist) == 3: await SMexHandler.handle(bot,ServerManPrettyException( "Read ;help seek\nto find out how to use this command","Incorrect format!", message.channel)) seek_seconds = int(timelist[0])*60*60 + int(timelist[1])*60 + int(timelist[2]) print(seek_seconds,duration) if int(seek_seconds)>duration: await SMexHandler.handle(bot,ServerManPrettyException( "Value can only be between 00:00:00 and %s" % str(timedelta(seconds=duration)),"Invalid Value!", message.channel)) return player.state = "seeking" player.justseeked = 1 player.voice_client.stop() bot.loop.create_task(player.play(message.content.split(' ')[1],int(seek_seconds))) await message.channel.send("Seeking to %s" % message.content.split(' ')[1])
async def listmenu(bot, message, optionlist, title, subtext, timeout=None, returnmode='index'): print("menu") msg = "```py\n" for number, option in enumerate(optionlist): msg += "{0}. {1}\n".format(number + 1, option) msg += "\n\nType 'exit' to leave the menu\n```" def check(m): return m.author == message.author and m.channel == message.channel s_msg = await bot.send_message(message.channel, msg) response = await bot.wait_for_message(check=check, timeout=timeout) await bot.delete_message(s_msg) try: if response.content.lower() == 'exit': return if returnmode == 'index': x = optionlist[int(response.content) - 1] return int(response.content) - 1 else: a = optionlist[int(response.content) - 1] return a except: print("exception") await SMexHandler.handle( bot, ServerManPrettyException("Invalid Option!", "Error!", message.channel))
async def main(bot, message): player = bot.players[message.guild] volume = float(shlex.split(message.content)[1]) if volume<=2.0 and volume>=0: player.volume = volume await send(bot,"Volume changed!", ":loud_sound: New volume is %s"%volume,0xCCD6DD,message.channel) if player.voice_client.is_playing(): player.justvoledit = 1 player.voice_client.stop() seektm = datetime.datetime.fromtimestamp(player.accu_progress) - datetime.timedelta(hours=5,minutes=30) bot.loop.create_task(player.play(str(seektm.strftime('%H:%M:%S.%f')),player.accu_progress)) else: await SMexHandler.handle(bot,ServerManPrettyException( "Volume value can only range from 0.0-2.0","Invalid Value!", message.channel))
async def main(bot, message, url=None): if message.attachments: thing = message.attachments[0]['url'] else: thing = url.strip('<>') try: with aiohttp.Timeout(10): async with bot.aiosession.get(thing) as res: await bot.user.edit(avatar=await res.read()) except Exception as e: await SMexHandler.handle( bot, channel, ServerManPrettyException("Wasn't able to change avatar!", "Error!", channel)) await message.channel.send(":ok_hand:")
async def main(bot, message): effects = { 'pop': 'Pop', 'classic': 'Classic', 'jazz': 'Jazz', 'rock': 'Rock', 'bb': 'Bass Boost', 'normal': 'Normal', 'vocals': 'Vocals' } player = bot.players[message.guild] eq = message.content.split()[1] eq = 'normal' if eq.lower() == 'reset' else eq if not eq.lower() in effects.keys(): await SMexHandler.handle( bot, ServerManPrettyException("%s, is not a valid EQ effect." % eq, "Invalid EQ effect!", message.channel)) return player.EQ = eq.lower() if player.voice_client.is_playing(): player.justvoledit = 1 player.voice_client.stop() seektm = datetime.datetime.fromtimestamp( player.accu_progress) - datetime.timedelta(hours=5, minutes=30) bot.loop.create_task( player.play(str(seektm.strftime('%H:%M:%S.%f')), player.accu_progress)) print( str( time.strftime('%H:%M:%S', time.gmtime(player.accu_progress)))) await send( bot, "Equalizer", ":loud_sound: Equalizer has been set to %s." % effects[eq.lower()], 0xCCD6DD, message.channel)
async def main(bot, message): try: player = bot.players[message.guild] except KeyError: player = None track_names = list() track_urls = list() printlines = {0: []} d = bot.ses if len(message.content.split()) == 1 or not message.content.split( )[1] in ['dump', 'add', 'clear', 'play', 'reorder']: for user in d.query(User): if int(message.author.id) == int(user.id): if user.playlist is None: await message.channel.send(":notes: Empty playlist") else: st = eval(user.playlist) break for x in st.keys(): track_names.append(st[x][0]) track_urls.append(st[x][1]) for counter, track in enumerate(track_names): nextline = '%s. %s - [Link](%s)\n' % ( (counter + 1), str( track_names[counter]), track_urls[counter]) currentlinesum = sum(len(x) + 1 for x in printlines[0]) if currentlinesum + len(nextline) + 600 > 2000: for pg in range(1, 25): try: if sum(len(x) + 1 for x in printlines[pg]) + 800 > 2000: continue else: printlines[pg].append(nextline) break except IndexError: printlines[pg] = [] printlines[pg].append(nextline) break else: printlines[0].append(nextline) counter += 1 if len(message.content.split()) == 1: pg_index = 1 # ⬅ ➡ else: pg_index = int(message.content.split()[1]) total_pgs = len(printlines.keys()) if pg_index < 1 or pg_index > total_pgs: await SMexHandler.handle( bot, ServerManPrettyException( "Your playlist only has %s page(s)!\nPlease a supply a value between 1 and %s." % (total_pgs, total_pgs), "Invalid Value!", message.channel)) return if total_pgs == 1 and pg_index == 1: msg = "" msg = '\n\n'.join(printlines[0]) await message.channel.send('```py\n%s\nPage: 1/1\n```' % msg) return while True: msg = "" msg = '\n\n'.join(printlines[pg_index - 1]) try: await q_msg.edit( content= """```py\n"%s's Playlist"\n%s\nPage: %s/%s\n```""" % (message.author.name, msg, pg_index, total_pgs)) except NameError: q_msg = await message.channel.send( """```py\n"%s's Playlist"\n%s\nPage: %s/%s\n```""" % (message.author.name, msg, pg_index, total_pgs)) if pg_index == 1: await q_msg.add_reaction('➡') def chk(reaction, user): return user == message.author and str( reaction.emoji) == '➡' and reaction.message == q_msg res, user = await bot.wait_for('reaction_add') if str(res.emoji) == '➡': try: await q_msg.remove_reaction('➡', message.author) except: pass pg_index += 1 continue elif pg_index == total_pgs: await q_msg.add_reaction('⬅') def chk(reaction, user): return user == message.author and str( reaction.emoji ) == '⬅' and reaction.message == q_msg res, user = await bot.wait_for('reaction_add') if str(res.emoji) == '⬅': try: await q_msg.remove_reaction('⬅', message.author) except: pass pg_index -= 1 continue else: await q_msg.add_reaction('⬅') await q_msg.add_reaction('➡') def chk(reaction, user): return user == message.author and str( reaction.emoji) in ['⬅', '➡' ] and reaction.message == q_msg res, user = await bot.wait_for('reaction_add') if str(res.emoji) == '⬅': try: await q_msg.remove_reaction('⬅', message.author) except: pass pg_index -= 1 continue elif str(res.emoji) == '➡': try: await q_msg.remove_reaction('➡', message.author) except: pass pg_index += 1 continue elif message.content.split()[1].lower() == 'dump': full_deque = player.playlist.getlist() for user in d.query(User): if int(message.author.id) == int(user.id): if user.playlist is None: lst = {} else: lst = eval(str(user.playlist)) new_index = len(lst) player_dict = {} try: new_index += 1 player_dict[new_index] = list() player_dict[new_index].append(player.current_entry['title']) player_dict[new_index].append(player.current_entry['url']) except: pass for m in full_deque: new_index += 1 player_dict[new_index] = list() player_dict[new_index].append(m['title']) player_dict[new_index].append(m['url']) lst.update(player_dict) await message.channel.send( ":notes: Added the full queue to your playlist") for user in d.query(User): if int(message.author.id) == int(user.id): ex = User.__table__.update().where( User.id == user.id).values(playlist=str(lst)) d.execute(ex) d.commit() break elif message.content.split()[1].lower() == 'add': song_index = message.content.split()[2].lower() if len(song_index) > 3: await message.channel.send( "I never thought someone would make a playlist so big, but here you are, I just made a precautionary block for above 100, but well i might have to get rid of this, thanks, %s" % message.author.name) return if song_index == ('np'): m_title = player.current_entry['title'] m_url = player.current_entry['url'] await message.channel.send( ":notes: Added **%s**, to your playlist!" % m_title) else: m = player.playlist.gettrack(int(song_index)) m_title = m['title'] m_url = m['url'] await message.channel.send( ":notes: Added **%s**, to your playlist!" % m_title) for user in d.query(User): if int(message.author.id) == user.id: if user.playlist is None: lst = {} else: lst = eval(str(user.playlist)) new_index = len(lst) + 1 player_dict = {} player_dict[new_index] = list() player_dict[new_index].append(m_title) player_dict[new_index].append(m_url) lst.update(player_dict) for user in d.query(User): if int(message.author.id) == int(user.id): ex = User.__table__.update().where( User.id == user.id).values(playlist=str(lst)) d.execute(ex) d.commit() break elif message.content.split()[1] == 'clear': await message.channel.send(":put_litter_in_its_place: Cleared!") for user in d.query(User): if int(message.author.id) == int(user.id): ex = User.__table__.update().where( User.id == user.id).values(playlist='{}') d.execute(ex) d.commit() break elif message.content.split()[1] == 'play': if not player: try: vc = bot.vc_clients[message.guild] except: vc = await message.author.voice.channel.connect( timeout=6, reconnect=True) bot.vc_clients[message.guild] = vc pl = playlist.Playlist(bot) player = ply.Player(bot, vc, pl) bot.players[message.guild] = player for user in d.query(User): if int(message.author.id) == int(user.id): if user.playlist is None: lst = {} else: lst = eval(str(user.playlist)) break for x in lst.keys(): track_names.append(lst[x][0]) track_urls.append(lst[x][1]) if '-' in message.content.split()[2].lower(): msg = message.content.split()[2] from_index = msg[:msg.find('-')] to_index = msg[msg.find('-') + 1:] if not from_index.isdigit() and not to_index.isdigit(): await message.channel.send( "Please provide the numbers from your playlist as start and end points" ) return from_index = int(from_index) to_index = int(to_index) for play_index in range(from_index, to_index): try: info = await bot.downloader.extract_info( bot.loop, track_urls[play_index - 1], download=False, process=False, retry_on_error=True) entry, position = player.playlist.add( info['webpage_url'], message.author, message.channel, info['title'], info['duration']) except: pass if player.state == 'stopped': bot.loop.create_task(player.prepare_entry()) await message.channel.send( ":notes: Queued songs from **%s-%s**, from your saved playlist" % (from_index, to_index)) elif message.content.split()[2].lower() > 0: if not message.content.split()[2].isdigit(): await message.channel.send( "Please provide a number from your playlist to play") return play_index = int(message.content.split()[2]) await message.channel.send( ":notes: Playing **%s**, from your saved playlist" % track_names[play_index - 1]) info = await bot.downloader.extract_info( bot.loop, track_urls[play_index - 1], download=False, process=False, retry_on_error=True) entry, position = player.playlist.add(info['webpage_url'], message.author, message.channel, info['title'], info['duration']) if player.state == 'stopped': await player.prepare_entry() else: await message.channel.send(":notes: Playing full playlist") for track in track_urls: info = await bot.downloader.extract_info( bot.loop, track, download=False, process=False, retry_on_error=True) entry, position = player.playlist.add( info['webpage_url'], message.author, message.channel, info['title'], info['duration']) if player.state == 'stopped': bot.loop.create_task(player.prepare_entry()) elif message.content.split()[1] == 'reorder': song_index = message.content.split()[2] from_index = int(song_index.split('>')[0]) to_index = int(song_index.split('>')[1]) if len(song_index) > 3: return for user in d.query(User): if int(message.author.id) == user.id: if user.playlist is None: lst = {} else: lst = eval(str(user.playlist)) temp = lst[from_index] from_data = lst[to_index] to_data = temp player_dict = {} player_dict[from_index] = from_data player_dict[to_index] = to_data lst.update(player_dict) await message.channel.send("%s :arrows_counterclockwise: %s" % (from_index, to_index)) for user in d.query(User): if int(message.author.id) == int(user.id): ex = User.__table__.update().where( User.id == user.id).values(playlist=str(lst)) d.execute(ex) d.commit() break elif message.content.split()[1] == 'delete': if not message.content.split()[2].isdigit(): await message.channel.send( "Please provide a number from your playlist to delete") return song_index = int(message.content.split()[2]) for user in d.query(User): if int(message.author.id) == user.id: if user.playlist is None: lst = {} else: lst = eval(str(user.playlist)) new_lst = lst deleted_name = new_lst[song_index][0] for x in range(song_index, len(lst) + 1): if x == len(lst): lst.pop(x, None) break lst[x] = new_lst[x + 1] await message.channel.send( ":notes: **%s**, was deleted from your playlist." % deleted_name) for user in d.query(User): if int(message.author.id) == int(user.id): ex = User.__table__.update().where( User.id == user.id).values(playlist=str(lst)) d.execute(ex) d.commit() break
async def checklist(bot, author, channel, optionlist, title, subtext, timeout=None): msg = "```py\n" optiondictlist = [] for option in optionlist: x = {'option': option, 'selected': False} optiondictlist.append(x) for number, option in enumerate(optiondictlist): if option['selected'] == True: msg += "{2} {0}. {1}\n".format(number + 1, option['option'], '✅') else: msg += "{2} {0}. {1}\n".format(number + 1, option['option'], '⬜') msg += "\n```" def check(m): return m.author == author and m.channel == channel s_msg = await channel.send(msg) response = await bot.wait_for('message', check=check, timeout=timeout) try: val = optiondictlist[int(response.content) - 1] except: await SMexHandler.handle( bot, channel, ServerManPrettyException("Invalid Option!", "Error!", channel)) pass while response.content.lower() != "ok": try: val = optiondictlist[int(response.content) - 1] except: await SMexHandler.handle( bot, channel, ServerManPrettyException("Invalid Option!", "Error!", channel)) response = await bot.wait_for('message', check=check, timeout=timeout) continue if optiondictlist[int(response.content) - 1]['selected'] == True: optiondictlist[int(response.content) - 1]['selected'] = False else: optiondictlist[int(response.content) - 1]['selected'] = True msg = "```py\n" for number, option in enumerate(optiondictlist): if option['selected'] == True: msg += "{2} {0}. {1}\n".format(number + 1, option['option'], '✅') else: msg += "{2} {0}. {1}\n".format(number + 1, option['option'], '⬜') msg += "\n```" await s_msg.edit(content=msg) response = await bot.wait_for('message', check=check, timeout=timeout) optionlist = [] for option in optiondictlist: if option['selected'] == True: optionlist.append(option['option']) await s_msg.delete() return optionlist