Add playtop, swap and move commands and related back-end

This commit is contained in:
Choco
2023-03-08 10:38:28 +08:00
parent f99c373946
commit 305894f4e0
7 changed files with 85 additions and 11 deletions

View File

@@ -222,6 +222,40 @@ class Basic(commands.Cog):
if not player.is_playing:
await player.do_next()
@commands.hybrid_command(name="playtop", aliases=get_aliases("playtop"))
@app_commands.describe(
query="Input the name of the song.",
)
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
async def playtop(self, ctx: commands.Context, query: str):
"Adds a song with the given url or query on the top of the queue."
player: voicelink.Player = ctx.guild.voice_client
if not player:
player = await connect_channel(ctx)
if ctx.author not in player.channel.members:
if not ctx.author.guild_permissions.manage_guild:
return await ctx.send(player.get_msg('notInChannel').format(ctx.author.mention, player.channel.mention), ephemeral=True)
tracks = await player.get_tracks(query, requester=ctx.author)
if not tracks:
return await ctx.send(player.get_msg('noTrackFound'))
try:
if isinstance(tracks, voicelink.Playlist):
index = await player.add_track(tracks.tracks, at_font=True)
await ctx.send(player.get_msg('playlistLoad').format(tracks.name, index))
else:
position = await player.add_track(tracks[0], at_font=True)
await ctx.send((f"`{player.get_msg('live')}`" if tracks[0].is_stream else "") + (player.get_msg('trackLoad_pos').format(tracks[0].title, tracks[0].author, tracks[0].formatLength, position) if position >= 1 and player.is_playing else player.get_msg('trackLoad').format(tracks[0].title, tracks[0].author, tracks[0].formatLength)))
except voicelink.QueueFull as e:
await ctx.send(e)
finally:
if not player.is_playing:
await player.do_next()
@commands.hybrid_command(name="pause", aliases=get_aliases("pause"))
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
async def pause(self, ctx: commands.Context):
@@ -640,13 +674,35 @@ class Basic(commands.Cog):
player.shuffle_votes.clear()
await ctx.send(player.get_msg('shuffled'))
@commands.hybrid_command(name="move", aliases=get_aliases("move"))
@commands.hybrid_command(name="swap", aliases=get_aliases("swap"))
@app_commands.describe(
position1="The track to move. Example: 2",
position2="The new position to move the track to. Exmaple: 1"
position1="The track to swap. Example: 2",
position2="The track to swap with position1. Exmaple: 1"
)
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
async def move(self, ctx: commands.Context, position1: int, position2: int):
async def swap(self, ctx: commands.Context, position1: int, position2: int):
"Swaps the specified song to the specified song."
player: voicelink.Player = ctx.guild.voice_client
if not player:
return await ctx.send(get_lang(ctx.guild.id, 'noPlayer'), ephemeral=True)
if ctx.author not in player.channel.members:
if not ctx.author.guild_permissions.manage_guild:
return await ctx.send(player.get_msg('notInChannel').format(ctx.author.mention, player.channel.mention), ephemeral=True)
if not await player.is_privileged(ctx.author):
return await ctx.send(player.get_msg('missingPerms_pos'), ephemeral=True)
track1, track2 = player.queue.swap(position1, position2)
await ctx.send(player.get_msg('swapped').format(track1.title, track2.title))
@commands.hybrid_command(name="move", aliases=get_aliases("move"))
@app_commands.describe(
target="The track to move. Example: 2",
to="The new position to move the track to. Exmaple: 1"
)
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
async def move(self, ctx: commands.Context, target: int, to: int):
"Moves the specified song to the specified position."
player: voicelink.Player = ctx.guild.voice_client
if not player:
@@ -659,8 +715,8 @@ class Basic(commands.Cog):
if not await player.is_privileged(ctx.author):
return await ctx.send(player.get_msg('missingPerms_pos'), ephemeral=True)
player.queue.swap(position1, position2)
await ctx.send(player.get_msg('moved').format(position1, position2))
moved_track = player.queue.move(target, to)
await ctx.send(player.get_msg('moved').format(moved_track.title, to))
@commands.hybrid_command(name="lyrics", aliases=get_aliases("lyrics"))
@app_commands.describe(name="Searches for your query and displays the reutned lyrics.")

View File

@@ -171,7 +171,8 @@
"forward": "將播放器轉發到 **{0}**",
"rewind": "將播放器倒回至 **{0}**",
"replay": "重播當前歌曲。",
"moved": "{0} 和 {1} 被交換",
"swapped": "`{0}``{1}` 被交換",
"moved": "將 `{0}` 移動到 `{1}`",
"autoplay": "現在是自動播放模式 **{0}**",
"notdj": "你不是 DJ。 當前 DJ 是 {0}。",

View File

@@ -171,7 +171,8 @@
"forward": "Leite den Spieler an **{0}** weiter",
"rewind": "Spulen Sie den Player auf **{0}** zurück",
"replay": "Wiederholen des aktuellen Songs.",
"moved": "{0} und {1} sind vertauscht",
"swapped": "`{0}` und `{1}` sind vertauscht",
"moved": "`{0}` nach `{1}` verschoben",
"autoplay": "Der Autoplay-Modus ist jetzt **{0}**",
"notdj": "Du bist kein DJ. Der aktuelle DJ ist {0}.",

View File

@@ -171,7 +171,8 @@
"forward": "Forward the player to **{0}**",
"rewind": "Rewind the player to **{0}**",
"replay": "Replaying the current song.",
"moved": "{0} and {1} are Swapped",
"swapped": "`{0}` and `{1}` are swapped",
"moved": "Moved `{0}` to `{1}`",
"autoplay": "Autoplay mode is now **{0}**",
"notdj": "You are not DJ. The current DJ is {0}.",

View File

@@ -171,7 +171,8 @@
"forward": "プレーヤーを **{0}** に転送します",
"rewind": "プレーヤーを **{0}** に巻き戻します",
"replay": "現在の曲を再生します。",
"moved": "{0}{1}は入れ替えられます",
"swapped": "`{0}` と `{1}`は入れ替えられます",
"moved": "`{0}` を `{1}` に移動しました",
"autoplay": "自動再生モードが **{0}** になりました",
"notdj": "あなたはDJではありません。 現在のDJは{0}です。",

View File

@@ -171,7 +171,8 @@
"forward": "플레이어를 **{0}**로 전달",
"rewind": "플레이어를 **{0}**으로 되감기",
"replay": "현재 노래를 재생합니다.",
"moved": "{0} 및 {1}이(가) 바뀌었습니다.",
"swapped": "`{0}``{1}`이(가) 바뀌었습니다.",
"moved": "`{0}`을(를) `{1}`(으)로 이동했습니다.",
"autoplay": "자동재생 모드는 이제 **{0}**입니다.",
"notdj": "당신은 DJ가 아닙니다. 현재 DJ는 {0}입니다.",

View File

@@ -122,9 +122,22 @@ class Queue:
try:
pos = self._position - 1
self._queue[pos + num1], self._queue[pos + num2] = self._queue[pos + num2], self._queue[pos + num1]
return self._queue[pos + num1], self._queue[pos + num2]
except IndexError:
raise OutofList(self.get_msg("voicelinkOutofList"))
def move(self, target:int, to:int):
if not 0 < target <= self.count or not 0 < to:
raise OutofList(self.get_msg("voicelinkOutofList"))
try:
moveItem = self._queue[self._position + target - 1]
self._queue.remove(moveItem)
self.put_at_index(to, moveItem)
return moveItem
except:
raise OutofList(self.get_msg("voicelinkOutofList"))
def remove(self, index:int, index2:int, member: Member = None):
pos = self._position - 1
if not index2: