mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
[V3 Audio] Fix repeat, Message deletions (#1379)
* Fix repeat Also remove restriction on if the player is playing. * Auto-delete existing Now Playing message * Auto-delete existing notify message * Wrap line on Now Playing message * Add connected duration to audiostats _dynamic_time based on a function written by Redjumpman * Return negative seek past song start as 00:00:00 * Version number
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# Lavalink.py cog for Red v3 beta 7+
|
# Lavalink.py cog for Red v3 beta 7+
|
||||||
# Cog base thanks to Kromatic's example cog.
|
# Cog base thanks to Kromatic's example cog.
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import datetime
|
||||||
import discord
|
import discord
|
||||||
import heapq
|
import heapq
|
||||||
import lavalink
|
import lavalink
|
||||||
@@ -8,7 +9,7 @@ import math
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from redbot.core import Config, checks
|
from redbot.core import Config, checks
|
||||||
|
|
||||||
__version__ = "2.0.2.9.a"
|
__version__ = "2.0.2.9.b"
|
||||||
__author__ = ["aikaterna", "billy/bollo/ati"]
|
__author__ = ["aikaterna", "billy/bollo/ati"]
|
||||||
|
|
||||||
|
|
||||||
@@ -75,10 +76,15 @@ class Audio:
|
|||||||
c = player.fetch('channel')
|
c = player.fetch('channel')
|
||||||
if c:
|
if c:
|
||||||
c = self.bot.get_channel(c)
|
c = self.bot.get_channel(c)
|
||||||
if c:
|
if player.fetch('notify_message') is not None:
|
||||||
embed = discord.Embed(colour=c.guild.me.top_role.colour, title='Now Playing',
|
try:
|
||||||
description='**[{}]({})**'.format(player.current.title, player.current.uri))
|
await player.fetch('notify_message').delete()
|
||||||
await c.send(embed=embed)
|
except discord.errors.NotFound:
|
||||||
|
pass
|
||||||
|
embed = discord.Embed(colour=c.guild.me.top_role.colour, title='Now Playing',
|
||||||
|
description='**[{}]({})**'.format(player.current.title, player.current.uri))
|
||||||
|
notify_message = await c.send(embed=embed)
|
||||||
|
player.store('notify_message', notify_message)
|
||||||
|
|
||||||
if event == 'TrackStartEvent' and status:
|
if event == 'TrackStartEvent' and status:
|
||||||
if playing_servers > 1:
|
if playing_servers > 1:
|
||||||
@@ -154,12 +160,18 @@ class Audio:
|
|||||||
server_num = await self._get_playing()
|
server_num = await self._get_playing()
|
||||||
server_ids = self.bot.lavalink.players._players
|
server_ids = self.bot.lavalink.players._players
|
||||||
server_list = []
|
server_list = []
|
||||||
|
|
||||||
for k, v in server_ids.items():
|
for k, v in server_ids.items():
|
||||||
guild_id = k
|
guild_id = k
|
||||||
player = v
|
player = v
|
||||||
|
connect_start = v.fetch('connect')
|
||||||
try:
|
try:
|
||||||
server_list.append(
|
connect_dur = self._dynamic_time((datetime.datetime.utcnow() - connect_start).seconds)
|
||||||
self.bot.get_guild(guild_id).name + ': **[{}]({})**'.format(v.current.title, v.current.uri))
|
except TypeError:
|
||||||
|
connect_dur = 0
|
||||||
|
try:
|
||||||
|
server_list.append('{} [`{}`]: **[{}]({})**'.format(self.bot.get_guild(guild_id).name, connect_dur,
|
||||||
|
v.current.title, v.current.uri))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
servers = '\n'.join(server_list)
|
servers = '\n'.join(server_list)
|
||||||
@@ -220,9 +232,15 @@ class Audio:
|
|||||||
req_user = self.bot.get_user(player.current.requester)
|
req_user = self.bot.get_user(player.current.requester)
|
||||||
song = '**[{}]({})**\nRequested by: **{}**\n\n{}`{}`/`{}`'.format(player.current.title, player.current.uri,
|
song = '**[{}]({})**\nRequested by: **{}**\n\n{}`{}`/`{}`'.format(player.current.title, player.current.uri,
|
||||||
req_user, arrow, pos, dur)
|
req_user, arrow, pos, dur)
|
||||||
|
if player.fetch('np_message') is not None:
|
||||||
|
try:
|
||||||
|
await player.fetch('np_message').delete()
|
||||||
|
except discord.errors.NotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, title='Now Playing', description=song)
|
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, title='Now Playing', description=song)
|
||||||
message = await ctx.send(embed=embed)
|
message = await ctx.send(embed=embed)
|
||||||
|
player.store('np_message', message)
|
||||||
|
|
||||||
def check(r, u):
|
def check(r, u):
|
||||||
return r.message.id == message.id and u == ctx.message.author
|
return r.message.id == message.id and u == ctx.message.author
|
||||||
@@ -320,6 +338,7 @@ class Audio:
|
|||||||
await self._data_check(ctx)
|
await self._data_check(ctx)
|
||||||
|
|
||||||
if not player.is_connected:
|
if not player.is_connected:
|
||||||
|
player.store('connect', datetime.datetime.utcnow())
|
||||||
await player.connect(ctx.author.voice.channel.id)
|
await player.connect(ctx.author.voice.channel.id)
|
||||||
|
|
||||||
query = query.strip('<>')
|
query = query.strip('<>')
|
||||||
@@ -414,13 +433,12 @@ class Audio:
|
|||||||
if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)):
|
if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)):
|
||||||
return await self._embed_msg(ctx, 'You must be in the voice channel to toggle repeat.')
|
return await self._embed_msg(ctx, 'You must be in the voice channel to toggle repeat.')
|
||||||
|
|
||||||
if not player.is_playing:
|
|
||||||
return await self._embed_msg(ctx, 'Nothing playing.')
|
|
||||||
|
|
||||||
repeat = await self.config.guild(ctx.guild).repeat()
|
repeat = await self.config.guild(ctx.guild).repeat()
|
||||||
await self.config.guild(ctx.guild).repeat.set(not repeat)
|
await self.config.guild(ctx.guild).repeat.set(not repeat)
|
||||||
get_repeat = await self.config.guild(ctx.guild).repeat()
|
repeat = await self.config.guild(ctx.guild).repeat()
|
||||||
await self._embed_msg(ctx, 'Repeat songs: {}.'.format(get_repeat))
|
if player.repeat != repeat:
|
||||||
|
player.repeat = repeat
|
||||||
|
await self._embed_msg(ctx, 'Repeat songs: {}.'.format(repeat))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def remove(self, ctx, index: int):
|
async def remove(self, ctx, index: int):
|
||||||
@@ -461,6 +479,7 @@ class Audio:
|
|||||||
if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)):
|
if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)):
|
||||||
return await self._embed_msg(ctx, 'You must be in the voice channel to enqueue songs.')
|
return await self._embed_msg(ctx, 'You must be in the voice channel to enqueue songs.')
|
||||||
if not player.is_connected:
|
if not player.is_connected:
|
||||||
|
player.store('connect', datetime.datetime.utcnow())
|
||||||
await player.connect(ctx.author.voice.channel.id)
|
await player.connect(ctx.author.voice.channel.id)
|
||||||
|
|
||||||
query = query.strip('<>')
|
query = query.strip('<>')
|
||||||
@@ -560,7 +579,10 @@ class Audio:
|
|||||||
else:
|
else:
|
||||||
time_sec = seconds * 1000
|
time_sec = seconds * 1000
|
||||||
seek = player.position + time_sec
|
seek = player.position + time_sec
|
||||||
await self._embed_msg(ctx, 'Moved {}s to {}'.format(seconds, lavalink.Utils.format_time(seek)))
|
if abs(time_sec) > player.position:
|
||||||
|
await self._embed_msg(ctx, 'Moved {}s to 00:00:00'.format(seconds))
|
||||||
|
else:
|
||||||
|
await self._embed_msg(ctx, 'Moved {}s to {}'.format(seconds, lavalink.Utils.format_time(seek)))
|
||||||
return await player.seek(seek)
|
return await player.seek(seek)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
@@ -715,6 +737,31 @@ class Audio:
|
|||||||
msg += bar
|
msg += bar
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
def _dynamic_time(self, time):
|
||||||
|
m, s = divmod(time, 60)
|
||||||
|
h, m = divmod(m, 60)
|
||||||
|
d, h = divmod(h, 24)
|
||||||
|
|
||||||
|
if d > 0:
|
||||||
|
msg = "{0}d"
|
||||||
|
if h > 0 and m > 0 and s > 0:
|
||||||
|
msg += " {1}h"
|
||||||
|
elif m > 0 and d == 0 and h == 0 and s == 0:
|
||||||
|
pass
|
||||||
|
elif s > 0 and d == 0 and h == 0 and m == 0:
|
||||||
|
pass
|
||||||
|
elif d == 0 and m == 0 and h == 0 and s == 0:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
msg += " {1}h"
|
||||||
|
elif d == 0 and h > 0:
|
||||||
|
msg = "{1}h 0m" if m == 0 else "{1}h {2}m"
|
||||||
|
elif d == 0 and h == 0 and m > 0:
|
||||||
|
msg = "{2}m 0s" if s == 0 else "{2}m {3}s"
|
||||||
|
elif d == 0 and h == 0 and m == 0 and s > 0:
|
||||||
|
msg = "{3}s"
|
||||||
|
return msg.format(d, h, m, s)
|
||||||
|
|
||||||
async def _embed_msg(self, ctx, title):
|
async def _embed_msg(self, ctx, title):
|
||||||
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, title=title)
|
embed = discord.Embed(colour=ctx.guild.me.top_role.colour, title=title)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|||||||
Reference in New Issue
Block a user