From 7c5bba0bd299d4ab4bd6b8e5d429abff9e0b0994 Mon Sep 17 00:00:00 2001 From: Mantou Date: Sat, 4 May 2024 22:14:38 +0800 Subject: [PATCH] fix: wtf is this github --- cogs/commands.py | 390 ----------------------------------------------- 1 file changed, 390 deletions(-) diff --git a/cogs/commands.py b/cogs/commands.py index 308653b..9afef87 100644 --- a/cogs/commands.py +++ b/cogs/commands.py @@ -54,7 +54,6 @@ "lowpass": LowPass, "rotation": Rotation, "equalizer": Equalizer, - "equalizer": Equalizer, } @@ -66,11 +65,6 @@ def __init__(self, bot: Bot): playlist = discord.SlashCommandGroup("playlist", "歌單") async def search(self, ctx: AutocompleteContext): - query = ctx.options["query"] - if re.match( - r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", - query, - ): query = ctx.options["query"] if re.match( r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", @@ -96,50 +90,36 @@ async def search(self, ctx: AutocompleteContext): async def playlist_search(self, ctx: AutocompleteContext): playlist = ctx.options["playlist"] - playlist = ctx.options["playlist"] choices = [] - with open( - f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" ) as f: data = json.load(f) for name in data.keys(): - value = uuid.uuid5( - uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + name - ).hex value = uuid.uuid5( uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + name ).hex choices.append( OptionChoice( name=name + f" ({len(data[name]['data']['tracks'])}首)", value=value - name=name + f" ({len(data[name]['data']['tracks'])}首)", value=value ) ) if not playlist: return choices - return choices - async def global_playlist_search(self, ctx: AutocompleteContext): playlist = ctx.options["playlist"] - playlist = ctx.options["playlist"] choices = [] if not playlist: if path.isfile(f"./playlist/{ctx.interaction.user.id}.json"): - with open( - f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" ) as f: @@ -149,37 +129,25 @@ async def global_playlist_search(self, ctx: AutocompleteContext): uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + title ).hex choices.append(OptionChoice(name=title, value=value)) - value = uuid.uuid5( - uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + title - ).hex - choices.append(OptionChoice(name=title, value=value)) return choices else: return [] - try: - title, id = await find_playlist(playlist=playlist, ctx=ctx) try: title, id = await find_playlist(playlist=playlist, ctx=ctx) value = uuid.uuid5(uuid.NAMESPACE_DNS, str(id) + title).hex - choices.append(OptionChoice(name=title, value=value)) choices.append(OptionChoice(name=title, value=value)) return choices - except (NotFound, TypeError) as e: - choices.append(OptionChoice(name="此歌單為非公開!", value=playlist)) choices.append(OptionChoice(name="此歌單為非公開!", value=playlist)) return choices - async def songs_search(self, ctx: AutocompleteContext): playlist = ctx.options["playlist"] song = ctx.options["song"] - playlist = ctx.options["playlist"] - song = ctx.options["song"] choices = [] name = "" @@ -190,14 +158,7 @@ async def songs_search(self, ctx: AutocompleteContext): with open(f"./playlist/{ctx.interaction.user.id}.json") as f: data = json.load(f) - for key in data.keys(): - if ( - uuid.uuid5( - uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + key - ).hex - == playlist - ): if ( uuid.uuid5( uuid.NAMESPACE_DNS, str(ctx.interaction.user.id) + key @@ -211,7 +172,6 @@ async def songs_search(self, ctx: AutocompleteContext): for track in result.tracks: choices.append(OptionChoice(name=track.title, value=track.position)) - choices.append(OptionChoice(name=track.title, value=track.position)) else: return [] @@ -220,65 +180,50 @@ async def songs_search(self, ctx: AutocompleteContext): return choices - @music.command(name="info", description="顯示機器人資訊") - @music.command(name="info", description="顯示機器人資訊") async def info(self, ctx: ApplicationContext): embed = Embed(title="機器人資訊", color=0x2B2D31) embed.add_field( - name="啟動時間", name="啟動時間", value=f"", inline=True, - inline=True, ) branch = get_current_branch() upstream_url = get_upstream_url(branch) embed.add_field( - name="版本資訊", name="版本資訊", value=f"{get_commit_hash()} on {branch} from {upstream_url}", ) embed.add_field(name="​", value="​", inline=True) - embed.add_field(name="CPU", value=f"{cpu_percent()}%", inline=True) embed.add_field(name="CPU", value=f"{cpu_percent()}%", inline=True) embed.add_field( - name="RAM", name="RAM", value=f"{round(bytes_to_gb(virtual_memory()[3]), 1)} GB / " f"{round(bytes_to_gb(virtual_memory()[0]), 1)} GB " f"({virtual_memory()[2]}%)", inline=True, - f"{round(bytes_to_gb(virtual_memory()[0]), 1)} GB " - f"({virtual_memory()[2]}%)", - inline=True, ) embed.add_field(name="​", value="​", inline=True) - embed.add_field(name="伺服器數量", value=len(self.bot.guilds), inline=True) embed.add_field(name="伺服器數量", value=len(self.bot.guilds), inline=True) embed.add_field( - name="播放器數量", name="播放器數量", value=len(self.bot.lavalink.player_manager.players), inline=True, - inline=True, ) embed.add_field(name="​", value="​", inline=True) await ctx.send(embed=embed) - await ctx.send(embed=embed) - @music.command(name="nowplaying", description="顯示目前正在播放的歌曲") @music.command(name="nowplaying", description="顯示目前正在播放的歌曲") async def nowplaying(self, ctx: ApplicationContext): await ctx.response.defer() @@ -323,11 +268,6 @@ async def play( query, ) results: LoadResult = await self.bot.lavalink.get_local_tracks(query) - self.bot.logger.info( - "No results found with lavalink for query %s, checking local sources", - query, - ) - results: LoadResult = await self.bot.lavalink.get_local_tracks(query) if not results or not results.tracks: # If nothing was found return await ctx.interaction.edit_original_response( @@ -358,15 +298,12 @@ async def play( case LoadType.TRACK: player.add( requester=ctx.author.id, track=results.tracks[0], index=index - requester=ctx.author.id, track=results.tracks[0], index=index ) # noinspection PyTypeChecker await ctx.interaction.edit_original_response( embeds=[SuccessEmbed("已加入播放序列", {results.tracks[0].title})] + filter_warnings - embeds=[SuccessEmbed("已加入播放序列", {results.tracks[0].title})] - + filter_warnings ) case LoadType.PLAYLIST: @@ -375,7 +312,6 @@ async def play( for iter_index, track in enumerate(results.tracks): player.add( requester=ctx.author.id, track=track, index=index + iter_index - requester=ctx.author.id, track=track, index=index + iter_index ) # noinspection PyTypeChecker @@ -398,24 +334,6 @@ async def play( ), ) ] - + filter_warnings - SuccessEmbed( - title=f"'已加入播放序列' {len(results.tracks)} / {results.playlist_info.name}", - description=( - "\n".join( - [ - f"**[{index + 1}]** {track.title}" - for index, track in enumerate( - results.tracks[:10] - ) - ] - ) - + "..." - if len(results.tracks) > 10 - else "" - ), - ) - ] + filter_warnings ) @@ -458,21 +376,13 @@ async def skip( else: player.queue = player.queue[target - 1 :] - player.queue = player.queue[target - 1 :] await player.skip() - await ctx.interaction.edit_original_response(embed=SuccessEmbed("已跳過歌曲")) await ctx.interaction.edit_original_response(embed=SuccessEmbed("已跳過歌曲")) await player.update_display(await ctx.interaction.original_response(), delay=5) - @music.command(name="remove", description="移除歌曲") - async def remove( - self, - ctx: ApplicationContext, - target: Option(int, "要移除的歌曲編號", name="target", required=True), - ): @music.command(name="remove", description="移除歌曲") async def remove( self, @@ -492,12 +402,10 @@ async def remove( player.queue.pop(target - 1) - await ctx.interaction.edit_original_response(embed=SuccessEmbed("已移除歌曲")) await ctx.interaction.edit_original_response(embed=SuccessEmbed("已移除歌曲")) await player.update_display(await ctx.interaction.original_response(), delay=5) - @music.command(name="clean", description="清除播放序列") @music.command(name="clean", description="清除播放序列") async def clean(self, ctx: ApplicationContext): await ctx.response.defer() @@ -512,7 +420,6 @@ async def clean(self, ctx: ApplicationContext): await player.update_display(await ctx.interaction.original_response(), delay=5) - @music.command(name="pause", description="暫停當前播放的歌曲") @music.command(name="pause", description="暫停當前播放的歌曲") async def pause(self, ctx: ApplicationContext): await ctx.response.defer() @@ -529,9 +436,7 @@ async def pause(self, ctx: ApplicationContext): await player.set_pause(True) await ctx.interaction.edit_original_response(embed=SuccessEmbed("已暫停歌曲")) - await ctx.interaction.edit_original_response(embed=SuccessEmbed("已暫停歌曲")) - @music.command(name="resume", description="恢復當前播放的歌曲") @music.command(name="resume", description="恢復當前播放的歌曲") async def resume(self, ctx: ApplicationContext): await ctx.response.defer() @@ -547,12 +452,10 @@ async def resume(self, ctx: ApplicationContext): await player.set_pause(False) - await ctx.interaction.edit_original_response(embed=SuccessEmbed("已繼續歌曲")) await ctx.interaction.edit_original_response(embed=SuccessEmbed("已繼續歌曲")) await player.update_display(await ctx.interaction.original_response(), delay=5) - @music.command(name="stop", description="停止播放並清空播放序列") @music.command(name="stop", description="停止播放並清空播放序列") async def stop(self, ctx: ApplicationContext): await ctx.response.defer() @@ -566,7 +469,6 @@ async def stop(self, ctx: ApplicationContext): await player.update_display(await ctx.interaction.original_response()) - @music.command(name="connect", description="連接至你當前的語音頻道") @music.command(name="connect", description="連接至你當前的語音頻道") async def connect(self, ctx: ApplicationContext): await ctx.response.defer() @@ -585,20 +487,13 @@ async def connect(self, ctx: ApplicationContext): label=str("繼續"), style=ButtonStyle.green, custom_id="continue" ) ) - view.add_item( - item=Button( - label=str("繼續"), style=ButtonStyle.green, custom_id="continue" - ) - ) await ctx.interaction.edit_original_response( embed=WarningEmbed( "警告", "機器人已經在一個頻道中了,繼續移動將會中斷對方的音樂播放,是否要繼續?", - "機器人已經在一個頻道中了,繼續移動將會中斷對方的音樂播放,是否要繼續?", ), view=view, - view=view, ) try: @@ -607,15 +502,11 @@ async def connect(self, ctx: ApplicationContext): check=lambda i: i.data["custom_id"] == "continue" and i.user.id == ctx.user.id, timeout=10, - check=lambda i: i.data["custom_id"] == "continue" - and i.user.id == ctx.user.id, - timeout=10, ) except TimeoutError: await ctx.interaction.edit_original_response( embed=ErrorEmbed("已取消"), view=None - embed=ErrorEmbed("已取消"), view=None ) return @@ -628,7 +519,6 @@ async def connect(self, ctx: ApplicationContext): await ctx.interaction.edit_original_response( embed=SuccessEmbed("已連接至語音頻道"), view=None - embed=SuccessEmbed("已連接至語音頻道"), view=None ) finally: @@ -637,7 +527,6 @@ async def connect(self, ctx: ApplicationContext): delay=5, ) - @music.command(name="disconnect", description="斷開與語音頻道的連接") @music.command(name="disconnect", description="斷開與語音頻道的連接") async def disconnect(self, ctx: ApplicationContext): await ctx.response.defer() @@ -653,7 +542,6 @@ async def disconnect(self, ctx: ApplicationContext): await player.update_display(await ctx.interaction.original_response()) - @music.command(name="queue", description="顯示播放序列") @music.command(name="queue", description="顯示播放序列") async def queue(self, ctx: ApplicationContext): await ctx.response.defer() @@ -670,10 +558,6 @@ async def queue(self, ctx: ApplicationContext): pages: list[InfoEmbed] = [] for iteration, songs_in_page in enumerate(split_list(player.queue, 10)): - pages.append( - InfoEmbed( - title="播放序列", - description="\n".join( pages.append( InfoEmbed( title="播放序列", @@ -684,29 +568,14 @@ async def queue(self, ctx: ApplicationContext): for index, track in enumerate(songs_in_page) ] ), - ), ) ) await ctx.interaction.edit_original_response( embed=pages[0], view=Paginator(pages, ctx.author.id, None) ) - await ctx.interaction.edit_original_response( - embed=pages[0], view=Paginator(pages, ctx.author.id, None) - ) @music.command(name="repeat", description="更改重複播放模式") - async def repeat( - self, - ctx: ApplicationContext, - mode: Option( - name="mode", - description="重複播放模式", - choices=[ - OptionChoice(name="關閉", value=f"{'關閉'}/0"), - OptionChoice(name="單曲", value=f"{'單曲'} 單曲/1"), - OptionChoice(name="整個序列", value=f"{'整個序列'} 整個序列/2"), - @music.command(name="repeat", description="更改重複播放模式") async def repeat( self, ctx: ApplicationContext, @@ -729,12 +598,10 @@ async def repeat( await ctx.response.send_message( embed=SuccessEmbed(f"{'成功將重複播放模式更改為'}: {mode.split('/')[0]}") - embed=SuccessEmbed(f"{'成功將重複播放模式更改為'}: {mode.split('/')[0]}") ) await player.update_display(await ctx.interaction.original_response(), delay=5) - @music.command(name="shuffle", description="切換隨機播放模式") @music.command(name="shuffle", description="切換隨機播放模式") async def shuffle(self, ctx: ApplicationContext): await ctx.response.defer() @@ -924,23 +791,7 @@ async def create( }, }, ) - data = ( - { - name: { - "public": public, - "loadType": "playlist", - "data": { - "info": {"name": name, "selectedTrack": -1}, - "pluginInfo": {}, - "tracks": [], - }, - }, - }, - ) - with open( - f"./playlist/{ctx.author.id}.json", "w", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.author.id}.json", "w", encoding="utf-8" ) as f: @@ -949,8 +800,6 @@ async def create( return await ctx.interaction.edit_original_response( embed=ErrorEmbed(f"你已經有同名的歌單了!") ) - embed=ErrorEmbed(f"你已經有同名的歌單了!") - ) else: with open(f"./playlist/{ctx.author.id}.json", "w", encoding="utf-8") as f: f.write( @@ -970,51 +819,11 @@ async def create( ensure_ascii=False, ) ) - f.write( - json.dumps( - { - name: { - "public": public, - "loadType": "playlist", - "data": { - "info": {"name": name, "selectedTrack": -1}, - "pluginInfo": {}, - "tracks": [], - }, - }, - }, - indent=4, - ensure_ascii=False, - ) - ) await ctx.interaction.edit_original_response( embed=SuccessEmbed(f"建立成功! 名稱為: `{name}`") - embed=SuccessEmbed(f"建立成功! 名稱為: `{name}`") ) - @playlist.command(name="public", description="切換歌單的公開狀態") - async def public( - self, - ctx: ApplicationContext, - playlist: Option( - str, - "清單名稱", - name="playlist", - required=True, - autocomplete=playlist_search, - ), - public: Option( - bool, - "是否公開", - name="public", - choices=[ - OptionChoice(name="True", value=True), - OptionChoice(name="False", value=False), - ], - required=True, - ), - ): @playlist.command(name="public", description="切換歌單的公開狀態") async def public( self, @@ -1045,12 +854,6 @@ async def public( playlist_info = await find_playlist(playlist=playlist, ctx=ctx) - if playlist_info is None: - return playlist_info - - name = playlist_info[0] - playlist_info = await find_playlist(playlist=playlist, ctx=ctx) - if playlist_info is None: return playlist_info @@ -1060,7 +863,6 @@ async def public( with open(f"./playlist/{ctx.author.id}.json", "w", encoding="utf-8") as f: json.dump(data, f, indent=4, ensure_ascii=False) - json.dump(data, f, indent=4, ensure_ascii=False) else: await ctx.interaction.edit_original_response(embed=ErrorEmbed(f"你沒有播放清單!")) @@ -1068,19 +870,6 @@ async def public( embed=SuccessEmbed(f"已切換公開狀態為 `{'公開' if public is True else '非公開'}`") ) - @playlist.command(name="rename", description="重命名一個歌單") - async def rename( - self, - ctx: ApplicationContext, - playlist: Option( - str, - "清單名稱", - name="playlist", - autocomplete=playlist_search, - required=True, - ), - newname: Option(str, "新名稱", name="name", required=True), - ): @playlist.command(name="rename", description="重命名一個歌單") async def rename( self, @@ -1096,9 +885,6 @@ async def rename( ): await ctx.response.defer() - await ctx.interaction.edit_original_response( - embed=LoadingEmbed(title="正在讀取中...") - ) await ctx.interaction.edit_original_response( embed=LoadingEmbed(title="正在讀取中...") ) @@ -1113,7 +899,6 @@ async def rename( else: return await ctx.interaction.edit_original_response( embed=ErrorEmbed(f"這不是你的播放清單!") - embed=ErrorEmbed(f"這不是你的播放清單!") ) data[newname] = data.pop(name) @@ -1123,7 +908,6 @@ async def rename( await ctx.interaction.edit_original_response( embed=SuccessEmbed(f"更名成功! 新的名字為 `{newname}`") - embed=SuccessEmbed(f"更名成功! 新的名字為 `{newname}`") ) @playlist.command(name="join", description="加入歌曲至指定的歌單") @@ -1150,20 +934,12 @@ async def join( ctx=ctx, ) - name, user_id = await find_playlist( - playlist=playlist, - ctx=ctx, - ) - modal = PlaylistModal(title="加入歌曲", name=name, bot=self.bot) await ctx.send_modal(modal) else: await ctx.defer() - await ctx.interaction.edit_original_response( - embed=LoadingEmbed(title="正在讀取中...") - ) await ctx.interaction.edit_original_response( embed=LoadingEmbed(title="正在讀取中...") ) @@ -1171,12 +947,7 @@ async def join( with open(f"./playlist/{ctx.user.id}.json", "r", encoding="utf-8") as f: data = json.load(f) - for key in data.keys(): - if ( - uuid.uuid5(uuid.NAMESPACE_DNS, str(ctx.user.id) + key).hex - == playlist - ): if ( uuid.uuid5(uuid.NAMESPACE_DNS, str(ctx.user.id) + key).hex == playlist @@ -1187,9 +958,6 @@ async def join( result: LoadResult = await self.bot.lavalink.get_tracks( query, check_local=True ) - result: LoadResult = await self.bot.lavalink.get_tracks( - query, check_local=True - ) for track in result.tracks: data[name]["data"]["tracks"].append( @@ -1212,29 +980,8 @@ async def join( "userData": track.user_data, }, ) - data[name]["data"]["tracks"].append( - { - "encoded": track.track, - "info": { - "identifier": track.identifier, - "isSeekable": track.is_seekable, - "author": track.author, - "length": track.duration, - "isStream": track.is_stream, - "position": track.position, - "title": track.title, - "uri": track.uri, - "sourceName": track.source_name, - "artworkUrl": track.artwork_url, - "isrc": track.isrc, - }, - "pluginInfo": track.plugin_info, - "userData": track.user_data, - }, - ) data[name]["data"]["tracks"] = data[name]["data"]["tracks"] - data[name]["data"]["tracks"] = data[name]["data"]["tracks"] with open(f"./playlist/{ctx.user.id}.json", "w", encoding="utf-8") as f: json.dump(data, f, indent=4, ensure_ascii=False) @@ -1243,10 +990,6 @@ async def join( embed=SuccessEmbed(title=f"添加成功!") ) - await ctx.interaction.edit_original_response( - embed=SuccessEmbed(title=f"添加成功!") - ) - @playlist.command(name="remove", description="移除歌曲至指定的歌單") async def remove( self, @@ -1258,16 +1001,10 @@ async def remove( ): await ctx.defer() - await ctx.interaction.edit_original_response( - embed=LoadingEmbed(title="正在讀取中...") - ) await ctx.interaction.edit_original_response( embed=LoadingEmbed(title="正在讀取中...") ) - with open( - f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" ) as f: @@ -1278,36 +1015,17 @@ async def remove( ctx=ctx, ) - name, user_id = await find_playlist( - playlist=playlist, - ctx=ctx, - ) - - del data[name]["data"]["tracks"][song] del data[name]["data"]["tracks"][song] - with open( - f"./playlist/{ctx.interaction.user.id}.json", "w", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "w", encoding="utf-8" ) as f: json.dump(data, f, indent=4, ensure_ascii=False) - await ctx.interaction.edit_original_response( embed=SuccessEmbed(title="成功從歌單移除歌曲") - embed=SuccessEmbed(title="成功從歌單移除歌曲") ) - @playlist.command(name="delete", description="移除指定的歌單") - async def delete( - self, - ctx: ApplicationContext, - playlist: Option( - str, "歌單", name="playlist", required=True, autocomplete=playlist_search - ), - ): @playlist.command(name="delete", description="移除指定的歌單") async def delete( self, @@ -1318,17 +1036,11 @@ async def delete( ): await ctx.defer() - await ctx.interaction.edit_original_response( - embed=LoadingEmbed(title="正在讀取中...") - ) await ctx.interaction.edit_original_response( embed=LoadingEmbed(title="正在讀取中...") ) name = "" - with open( - f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "r", encoding="utf-8" ) as f: @@ -1339,16 +1051,8 @@ async def delete( ctx=ctx, ) - name, user_id = await find_playlist( - playlist=playlist, - ctx=ctx, - ) - del data[name] - with open( - f"./playlist/{ctx.interaction.user.id}.json", "w", encoding="utf-8" - ) as f: with open( f"./playlist/{ctx.interaction.user.id}.json", "w", encoding="utf-8" ) as f: @@ -1385,22 +1089,7 @@ async def playlist_play( with open(f"./playlist/{user_id}.json", "r", encoding="utf-8") as f: data = json.load(f) - await ctx.interaction.edit_original_response( - embed=LoadingEmbed(title="正在讀取中...") - ) - result = await find_playlist(playlist=playlist, ctx=ctx) - - if result is None: - return result - - name = result[0] - user_id = result[1] - - with open(f"./playlist/{user_id}.json", "r", encoding="utf-8") as f: - data = json.load(f) - - if not data[name]["data"]["tracks"]: if not data[name]["data"]["tracks"]: return await ctx.interaction.edit_original_response( embed=InfoEmbed("歌單", "歌單中沒有歌曲") @@ -1410,24 +1099,6 @@ async def playlist_play( player: LavaPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id) - filter_warnings = ( - [ - InfoEmbed( - title="提醒", - description=str( - "偵測到 效果器正在運作中,\n" - "這可能會造成音樂聲音有變形(加速、升高等)的情形產生,\n" - "如果這不是你期望的,可以透過效果器的指令來關閉它們\n" - "指令名稱通常等於效果器名稱,例如 `/timescale` 就是控制 Timescale 效果器\n\n" - "以下是正在運行的效果器:" - ), - ) - + " " - + ", ".join([key.capitalize() for key in player.filters]) - ] - if player.filters - else [] - ) filter_warnings = ( [ InfoEmbed( @@ -1457,8 +1128,6 @@ async def playlist_play( player.add( requester=ctx.author.id, track=track, index=index + iter_index ) - requester=ctx.author.id, track=track, index=index + iter_index - ) await ctx.interaction.edit_original_response( embeds=[ @@ -1475,22 +1144,9 @@ async def playlist_play( if len(results.tracks) > 10 else "" ), - description=( - "\n".join( - [ - f"**[{index + 1}]** {track.title}" - for index, track in enumerate(results.tracks[:10]) - ] - ) - + "..." - if len(results.tracks) > 10 - else "" - ), ) ] + filter_warnings - ] - + filter_warnings ) # If the player isn't already playing, start it. @@ -1501,7 +1157,6 @@ async def playlist_play( await ctx.interaction.original_response(), delay=5 ) - except TypeError as e: except TypeError as e: pass @@ -1521,20 +1176,6 @@ async def info( result = await find_playlist(playlist=playlist, ctx=ctx) - if result is None: - return result - else: - name = result[0] - user_id = result[1] - - if ctx.author.id == user_id: - try: - with open( - f"./playlist/{ctx.author.id}.json", "r", encoding="utf-8" - ) as f: - data = json.load(f) - result = await find_playlist(playlist=playlist, ctx=ctx) - if result is None: return result else: @@ -1548,19 +1189,13 @@ async def info( ) as f: data = json.load(f) - if not data[name]["data"]["tracks"]: - return await ctx.interaction.edit_original_response( - embed=InfoEmbed("歌單", "歌單中沒有歌曲") - ) if not data[name]["data"]["tracks"]: return await ctx.interaction.edit_original_response( embed=InfoEmbed("歌單", "歌單中沒有歌曲") ) results = LoadResult.from_dict(data[name]) - results = LoadResult.from_dict(data[name]) - pages: list[InfoEmbed] = [] pages: list[InfoEmbed] = [] for iteration, songs_in_page in enumerate( @@ -1585,42 +1220,17 @@ async def info( else: name, user_id = await find_playlist(playlist=playlist, ctx=ctx) - with open(f"./playlist/{user_id}.json", "r", encoding="utf-8") as f: with open(f"./playlist/{user_id}.json", "r", encoding="utf-8") as f: data = json.load(f) - if not data[name]["data"]["tracks"]: - return await ctx.interaction.edit_original_response( - embed=InfoEmbed("歌單", "歌單中沒有歌曲") - ) if not data[name]["data"]["tracks"]: return await ctx.interaction.edit_original_response( embed=InfoEmbed("歌單", "歌單中沒有歌曲") ) results = LoadResult.from_dict(data[name]) - results = LoadResult.from_dict(data[name]) pages: list[InfoEmbed] = [] - pages: list[InfoEmbed] = [] - - for iteration, songs_in_page in enumerate( - split_list(results.tracks, 10) - ): - pages.append( - InfoEmbed( - title=f"{name} - 歌單資訊 by {self.bot.get_user(int(user_id)).name}", - description="\n".join( - [ - f"**[{index + 1 + (iteration * 10)}]** {track.title}" - for index, track in enumerate(songs_in_page) - ] - ), - ).set_footer(text=f"ID: {playlist}") - ) - await ctx.interaction.edit_original_response( - embed=pages[0], view=Paginator(pages, ctx.author.id, None) - ) for iteration, songs_in_page in enumerate( split_list(results.tracks, 10)