From 0f44e6afe9dd5e55372f2777f9acaa0823a0c91c Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Wed, 22 Mar 2023 19:32:42 +0800 Subject: [PATCH] Add repeat track in dashboard --- cogs/basic.py | 2 -- web/ipc/methods.py | 6 +++--- web/static/js/action.js | 4 ++++ web/static/js/objects.js | 30 ++++++++++++++++++++++++++---- web/templates/index.html | 4 +++- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/cogs/basic.py b/cogs/basic.py index 3f4b9f8..b946366 100644 --- a/cogs/basic.py +++ b/cogs/basic.py @@ -463,8 +463,6 @@ class Basic(commands.Cog): if not player.is_privileged(ctx.author): return await ctx.send(player.get_msg('missingPerms_mode'), ephemeral=True) - if mode.lower() not in ['off', 'track', 'queue']: - mode = "off" await player.set_repeat(mode) await ctx.send(player.get_msg('repeat').format(mode.capitalize())) diff --git a/web/ipc/methods.py b/web/ipc/methods.py index ad69f9e..2d762ea 100644 --- a/web/ipc/methods.py +++ b/web/ipc/methods.py @@ -20,6 +20,7 @@ async def initPlayer(player, member: Member, data: dict): "name": member.name } for member in player.channel.members ], "tracks": [ track.toDict() for track in player.queue._queue ], + "repeat_mode": player.queue.repeat.lower(), "current_queue_position": player.queue._position if player.is_playing else player.queue._position + 1, "current_position": 0 or player.position if player.is_playing else 0, "is_playing": player.is_playing, @@ -147,13 +148,12 @@ async def process_methods(websocket, bot: commands.Bot, data: dict) -> None: if not method: return - guild = None - member = None + guild, member = None, None guild_id = data.get("guild_id", None) user_id = data.get("user_id", None) if guild_id is None: user = bot.get_user(user_id) - if not user: + if not user: return for g in user.mutual_guilds: diff --git a/web/static/js/action.js b/web/static/js/action.js index b17c516..c6a1a43 100644 --- a/web/static/js/action.js +++ b/web/static/js/action.js @@ -91,6 +91,10 @@ $(document).ready(function () { player.seekTo($(this).val()); }) + $("#repeat-button").on('click', function () { + player.repeatMode(); + }) + $("#shuffle-button").on('click', function () { player.shuffle(); }) diff --git a/web/static/js/objects.js b/web/static/js/objects.js index 206d156..24f6bda 100644 --- a/web/static/js/objects.js +++ b/web/static/js/objects.js @@ -36,6 +36,7 @@ const actions = { player.isDJ = data['is_dj']; player.is_paused = data['is_paused']; player.current_position = data['current_position']; + player.repeat = data['repeat_mode']; data["users"].forEach(user => { player.addUser(user); }) @@ -151,7 +152,7 @@ const actions = { player.showToast(data["requester_id"], `Moved ${element.title} to ${newPosition}`) }, - shuffleTrack: function(player, data) { + shuffleTrack: function (player, data) { var tracks = data["tracks"]; if (tracks != undefined) { player.queue = []; @@ -163,6 +164,11 @@ const actions = { player.initSortable(); player.showToast(data["requester_id"], "The queue is shuffled.") } + }, + + repeatTrack: function (player, data) { + player.repeat = data["repeatMode"]; + }, } } @@ -188,7 +194,8 @@ class Player { this.date = new Date(); this.queue = []; this.users = {}; - this.searchList = [] + this.searchList = []; + this.repeat = "off"; this.currentTrack = null; this.current_queue_position = 0; this.current_position = 0; @@ -239,7 +246,7 @@ class Player { } addUser(user) { - this.users[user['user_id']] = { "avatar_url": user["avatar_url"], "name": user["name"] }; + this.users[user['user_id']] = { avatar_url: user["avatar_url"], name: user["name"] }; } addTrack(tracks) { @@ -282,6 +289,10 @@ class Player { } } + repeatMode() { + this.send({ "op": "repeatTrack" }) + } + send(payload) { var json = JSON.stringify(payload) this.socket.send(json); @@ -356,7 +367,8 @@ class Player { $("#image").attr("src", currentTrack.imageUrl); $("#largeImage").attr("src", currentTrack.imageUrl); } - var play_pause_btn = $("#play-pause-button") + var play_pause_btn = $("#play-pause-button"); + var repeat_btn = $("#repeat-button"); if (this.is_paused || currentTrack == undefined) { play_pause_btn.removeClass('fa-pause').addClass('fa-play'); if (this.timer.getIsRunning()) { @@ -366,5 +378,15 @@ class Player { play_pause_btn.removeClass('fa-play').addClass('fa-pause'); this.timer.start(); } + + repeat_btn.removeClass("fa-repeat-1").addClass("fa-repeat") + if (this.repeat == "off") { + console.log("running"); + repeat_btn.css('color', ''); + } else if (this.repeat == "track") { + repeat_btn.css('color', '#fff'); + } else { + repeat_btn.removeClass("fa-repeat").addClass("fa-repeat-1"); + } } } \ No newline at end of file diff --git a/web/templates/index.html b/web/templates/index.html index a6d29a4..c1d0230 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -34,7 +34,8 @@
+