From 6bb2180c6bc3d3d8c65cb125936d3ab7d43a65af Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Thu, 4 May 2023 19:52:04 +0800 Subject: [PATCH] Added forward and rewind button --- langs/CH.json | 2 ++ langs/DE.json | 2 ++ langs/EN.json | 2 ++ langs/ES.json | 2 ++ langs/JA.json | 2 ++ langs/KO.json | 2 ++ views/controller.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 54 insertions(+), 1 deletion(-) diff --git a/langs/CH.json b/langs/CH.json index ec4758c..6394e6d 100644 --- a/langs/CH.json +++ b/langs/CH.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "取消靜音", "buttonAutoPlay": "自動播放", "buttonShuffle": "隨機播放", + "buttonForward": "前進", + "buttonRewind": "後退", "nowplayingDesc": "**現在播放:**\n```{0}```", "nowplayingField": "接下來播放:", diff --git a/langs/DE.json b/langs/DE.json index 1365766..249364d 100644 --- a/langs/DE.json +++ b/langs/DE.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "Stummschaltung aufheben", "buttonAutoPlay": "Autoplay", "buttonShuffle": "Mischen", + "buttonForward": "Vorwärts", + "buttonRewind": "Rückwärts", "nowplayingDesc": "**Jetzt abspielen:**\n```{0}```", "nowplayingField": "Als nächstes:", diff --git a/langs/EN.json b/langs/EN.json index e00adea..af79269 100644 --- a/langs/EN.json +++ b/langs/EN.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "Unmute", "buttonAutoPlay": "Autoplay", "buttonShuffle": "Shuffle", + "buttonForward": "Forward", + "buttonRewind": "Rewind", "nowplayingDesc": "**Now Playing:**\n```{0}```", "nowplayingField": "Up Next:", diff --git a/langs/ES.json b/langs/ES.json index 98b8552..3b7e0c2 100644 --- a/langs/ES.json +++ b/langs/ES.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "Activar Sonido", "buttonAutoPlay": "Reproducción Automática", "buttonShuffle": "Aleatorio", + "buttonForward": "Adelante", + "buttonRewind": "Atrás", "nowplayingDesc": "**Reproduciendo ahora:**\n```{0}```", "nowplayingField": "A continuación:", diff --git a/langs/JA.json b/langs/JA.json index 8618c34..827e735 100644 --- a/langs/JA.json +++ b/langs/JA.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "消音を解除", "buttonAutoPlay": "自動再生", "buttonShuffle": "シャッフル", + "buttonForward": "進む", + "buttonRewind": "戻る", "nowplayingDesc": "**現在再生中:**\n```{0}```", "nowplayingField": "次に再生する曲:", diff --git a/langs/KO.json b/langs/KO.json index 454da54..7912bc2 100644 --- a/langs/KO.json +++ b/langs/KO.json @@ -120,6 +120,8 @@ "buttonVolumeUnmute": "음소거 해제", "buttonAutoPlay": "자동재생", "buttonShuffle": "셔플", + "buttonForward": "앞으로", + "buttonRewind": "뒤로", "nowplayingDesc": "**현재 재생중인 곡:**\n```{0}```", "nowplayingField": "다음 곡:", diff --git a/views/controller.py b/views/controller.py index 4f2dcb4..5fc19c3 100644 --- a/views/controller.py +++ b/views/controller.py @@ -31,6 +31,7 @@ from function import ( update_playlist, create_account, checkroles, + formatTime ) from typing import Dict @@ -282,6 +283,44 @@ class Shuffle(discord.ui.Button): await self.player.shuffle("queue", interaction.user) await interaction.response.send_message(self.player.get_msg('shuffled')) +class Forward(discord.ui.Button): + def __init__(self, player, style, row): + self.player = player + super().__init__(emoji="⏩", + label=player.get_msg('buttonForward'), + disabled=False if self.player.current else True, + style=style, row=row) + + async def callback(self, interaction: discord.Interaction): + if not self.player.is_privileged(interaction.user): + return await interaction.response.send_message(self.player.get_msg('missingPerms_pos'), ephemeral=True) + + if not self.player.current: + return await interaction.response.send_message(self.player.get_msg('noTrackPlaying'), ephemeral=True) + + await self.player.seek(self.player.position + 10000) + await interaction.response.send_message(self.player.get_msg('forward').format(func.time(self.player.position + 10000))) + +class Rewind(discord.ui.Button): + def __init__(self, player, style, row): + self.player = player + super().__init__(emoji="⏪", + label=player.get_msg('buttonRewind'), + disabled=False if self.player.current else True, + style=style, row=row) + + async def callback(self, interaction: discord.Interaction): + if not self.player.is_privileged(interaction.user): + return await interaction.response.send_message(self.player.get_msg('missingPerms_pos'), ephemeral=True) + + if not self.player.current: + return await interaction.response.send_message(self.player.get_msg('noTrackPlaying'), ephemeral=True) + + position = 0 if (value := (self.player.position - 10000)) <= 0 else value + + await self.player.seek(position) + await interaction.response.send_message(self.player.get_msg('rewind').format(func.time(position))) + class Tracks(discord.ui.Select): def __init__(self, player, style, row): @@ -320,7 +359,9 @@ btnType = { "volumemute": VolumeMute, "tracks": Tracks, "autoplay": AutoPlay, - "shuffle": Shuffle + "shuffle": Shuffle, + "forward": Forward, + "rewind": Rewind } btnColor = {