General clean code
This commit is contained in:
@@ -191,8 +191,8 @@ class Basic(commands.Cog):
|
||||
embed = discord.Embed(title=player.get_msg('searchTitle').format(query), description=player.get_msg(
|
||||
'searchDesc').format(emoji_source(platform), platform, len(tracks[0:10]), query_track), color=settings.embed_color)
|
||||
view = SearchView(tracks=tracks[0:10], lang=player.get_msg)
|
||||
message = await ctx.send(embed=embed, view=view, ephemeral=True)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=embed, view=view, ephemeral=True)
|
||||
|
||||
await view.wait()
|
||||
if view.values is not None:
|
||||
msg = ""
|
||||
@@ -432,8 +432,7 @@ class Basic(commands.Cog):
|
||||
if player.queue.is_empty:
|
||||
return await nowplay(ctx, player)
|
||||
view = ListView(player=player, author=ctx.author)
|
||||
message = await ctx.send(embed=view.build_embed(), view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=view.build_embed(), view=view)
|
||||
|
||||
@queue.command(name="export", aliases=get_aliases("export"))
|
||||
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
|
||||
@@ -520,8 +519,7 @@ class Basic(commands.Cog):
|
||||
return await nowplay(ctx, player)
|
||||
|
||||
view = ListView(player=player, author=ctx.author, isQueue=False)
|
||||
message = await ctx.send(embed=view.build_embed(), view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=view.build_embed(), view=view)
|
||||
|
||||
@commands.hybrid_command(name="leave", aliases=get_aliases("leave"))
|
||||
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
|
||||
@@ -776,8 +774,7 @@ class Basic(commands.Cog):
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'lyricsNotFound'), ephemeral=True)
|
||||
|
||||
view = LyricsView(name=name, source={_: re.findall(r'.*\n(?:.*\n){,22}', v) for _, v in song.items()}, author=ctx.author)
|
||||
message = await ctx.send(embed=view.build_embed(), view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=view.build_embed(), view=view)
|
||||
|
||||
@commands.hybrid_command(name="swapdj", aliases=get_aliases("swapdj"))
|
||||
@app_commands.describe(member="Choose a member to transfer the dj role.")
|
||||
@@ -839,8 +836,7 @@ class Basic(commands.Cog):
|
||||
return await ctx.send(player.get_msg('noChaptersFound'), ephemeral=True)
|
||||
|
||||
view = ChapterView(player, chapters, author=ctx.author)
|
||||
message = await ctx.send(view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(view=view)
|
||||
|
||||
@commands.hybrid_command(name="autoplay", aliases=get_aliases("autoplay"))
|
||||
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
|
||||
|
||||
@@ -12,7 +12,7 @@ from function import (
|
||||
update_playlist,
|
||||
update_inbox,
|
||||
get_lang,
|
||||
playlist_name,
|
||||
PLAYLIST_NAME,
|
||||
settings,
|
||||
get_aliases,
|
||||
cooldown_check
|
||||
@@ -70,10 +70,10 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
self.description = "This is the Vocard playlist system. You can save your favorites and use Vocard to play on any server."
|
||||
|
||||
async def playlist_autocomplete(self, interaction: discord.Interaction, current: str) -> list:
|
||||
playlists = playlist_name.get(str(interaction.user.id), None)
|
||||
playlists = PLAYLIST_NAME.get(str(interaction.user.id), None)
|
||||
if not playlists:
|
||||
playlists_raw = await get_playlist(interaction.user.id, 'playlist')
|
||||
playlists = playlist_name[str(interaction.user.id)] = [
|
||||
playlists = PLAYLIST_NAME[str(interaction.user.id)] = [
|
||||
value['name'] for value in playlists_raw.values()] if playlists_raw else []
|
||||
if current:
|
||||
return [app_commands.Choice(name=p, value=p) for p in playlists if current in p]
|
||||
@@ -87,8 +87,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
async def playlist(self, ctx: commands.Context):
|
||||
view = HelpView(self.bot, ctx.author)
|
||||
embed = view.build_embed(self.qualified_name)
|
||||
message = await ctx.send(embed=embed, view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=embed, view=view)
|
||||
|
||||
@playlist.command(name="play", aliases=get_aliases("play"))
|
||||
@app_commands.describe(
|
||||
@@ -104,7 +103,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
return await create_account(ctx)
|
||||
if not result['playlist']:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistNotFound').format(name), ephemeral=True)
|
||||
rank, max_p, max_t = await checkroles(ctx.author.id)
|
||||
rank, max_p, max_t = await checkroles()
|
||||
if result['position'] > max_p:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistNotAccess'), ephemeral=True)
|
||||
|
||||
@@ -142,7 +141,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
user = await check_playlist(ctx, full=True)
|
||||
if not user:
|
||||
return await create_account(ctx)
|
||||
rank, max_p, max_t = await checkroles(ctx.author.id)
|
||||
rank, max_p, max_t = await checkroles()
|
||||
|
||||
results = []
|
||||
for index, data in enumerate(user, start=1):
|
||||
@@ -156,7 +155,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if share := playlist['type'] == 'share':
|
||||
playlist = await check_playlist_perms(ctx.author.id, playlist['user'], playlist['referId'])
|
||||
if not playlist:
|
||||
await update_playlist(ctx.author.id, {f"playlist.{data}": 1}, mode=False)
|
||||
await update_playlist(ctx.author.id, {f"playlist.{data}": 1}, mode="unset")
|
||||
continue
|
||||
if playlist['type'] == 'link':
|
||||
tracks = await search_playlist(playlist['uri'], requester=ctx.author)
|
||||
@@ -196,7 +195,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if len(name) > 10:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistOverText'), ephemeral=True)
|
||||
|
||||
rank, max_p, max_t = await checkroles(ctx.author.id)
|
||||
rank, max_p, max_t = await checkroles()
|
||||
user = await check_playlist(ctx, full=True)
|
||||
if not user:
|
||||
return await create_account(ctx)
|
||||
@@ -212,9 +211,8 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if not isinstance(tracks, voicelink.Playlist):
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistNotInvaildUrl'), ephemeral=True)
|
||||
|
||||
playlist_name.pop(str(ctx.author.id), None)
|
||||
data = {'uri': link, 'perms': {'read': []}, 'name': name, 'type': 'link'} if link else {'tracks': [], 'perms': {'read': [], 'write': [], 'remove': []}, 'name': name, 'type': 'playlist'}
|
||||
await update_playlist(ctx.author.id, {f"playlist.{assign_playlistId([data for data in user])}": data})
|
||||
await update_playlist(ctx.author.id, {f"playlist.{assign_playlistId([data for data in user])}": data}, update_cache=True)
|
||||
await ctx.send(get_lang(ctx.guild.id, 'playlistCreated').format(name))
|
||||
|
||||
@playlist.command(name="delete", aliases=get_aliases("delete"))
|
||||
@@ -232,10 +230,9 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistDeleteError'), ephemeral=True)
|
||||
|
||||
if result['playlist']['type'] == 'share':
|
||||
await update_playlist(result['playlist']['user'], {f"playlist.{result['playlist']['referId']}.perms.read": ctx.author.id}, pull=True, mode=False)
|
||||
await update_playlist(result['playlist']['user'], {f"playlist.{result['playlist']['referId']}.perms.read": ctx.author.id}, mode="pull")
|
||||
|
||||
playlist_name.pop(str(ctx.author.id), None)
|
||||
await update_playlist(ctx.author.id, {f"playlist.{result['id']}": 1}, mode=False)
|
||||
await update_playlist(ctx.author.id, {f"playlist.{result['id']}": 1}, mode="unset", update_cache=True)
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistRemove').format(result['playlist']['name']))
|
||||
|
||||
@playlist.command(name="share", aliases=get_aliases("share"))
|
||||
@@ -300,8 +297,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if not found:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistNotFound').format(name), ephemeral=True)
|
||||
|
||||
playlist_name.pop(str(ctx.author.id), None)
|
||||
await update_playlist(ctx.author.id, {f'playlist.{id}.name': newname})
|
||||
await update_playlist(ctx.author.id, {f'playlist.{id}.name': newname}, update_cache=True)
|
||||
await ctx.send(get_lang(ctx.guild.id, 'playlistRenamed').format(name, newname))
|
||||
|
||||
@playlist.command(name="inbox", aliases=get_aliases("inbox"))
|
||||
@@ -316,8 +312,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
|
||||
inbox = user['inbox'].copy()
|
||||
view = InboxView(ctx.author, user['inbox'])
|
||||
message = await ctx.send(embed=view.build_embed(), view=view, ephemeral=True)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=view.build_embed(), view=view, ephemeral=True)
|
||||
await view.wait()
|
||||
|
||||
if inbox == user['inbox']:
|
||||
@@ -325,13 +320,12 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
updateData, dId = {}, {dId for dId in user["playlist"]}
|
||||
for data in view.newplaylist[:(5 - len(user['playlist']))]:
|
||||
addId = assign_playlistId(dId)
|
||||
await update_playlist(data['sender'], {f"playlist.{data['referId']}.perms.read": ctx.author.id}, push=True)
|
||||
await update_playlist(data['sender'], {f"playlist.{data['referId']}.perms.read": ctx.author.id}, mode="push")
|
||||
updateData[f'playlist.{addId}'] = {'user': data['sender'], 'referId': data['referId'],
|
||||
'name': f"Share{data['time'].strftime('%M%S')}", 'type': 'share'}
|
||||
dId.add(addId)
|
||||
|
||||
playlist_name.pop(str(ctx.author.id), None)
|
||||
await update_playlist(ctx.author.id, updateData | {'inbox': view.inbox})
|
||||
await update_playlist(ctx.author.id, updateData | {'inbox': view.inbox}, update_cache=True)
|
||||
|
||||
@playlist.command(name="add", aliases=get_aliases("add"))
|
||||
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
|
||||
@@ -350,7 +344,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if result['playlist']['type'] in ['share', 'link']:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistNotAllow'), ephemeral=True)
|
||||
|
||||
rank, max_p, max_t = await checkroles(ctx.author.id)
|
||||
rank, max_p, max_t = await checkroles()
|
||||
if len(result['playlist']['tracks']) >= max_t:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistLimitTrack').format(max_t), ephemeral=True)
|
||||
|
||||
@@ -364,7 +358,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if results[0].is_stream:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistStream'), ephemeral=True)
|
||||
|
||||
await update_playlist(ctx.author.id, {f'playlist.{result["id"]}.tracks': results[0].track_id}, push=True)
|
||||
await update_playlist(ctx.author.id, {f'playlist.{result["id"]}.tracks': results[0].track_id}, mode="push")
|
||||
await ctx.send(get_lang(ctx.guild.id, 'playlistAdded').format(results[0].title, ctx.author, result['playlist']['name']))
|
||||
|
||||
@playlist.command(name="remove", aliases=get_aliases("remove"))
|
||||
@@ -386,7 +380,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if not 0 < position <= len(result['playlist']['tracks']):
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistPositionNotFound').format(position, name))
|
||||
|
||||
await update_playlist(ctx.author.id, {f'playlist.{result["id"]}.tracks': result['playlist']['tracks'][position - 1]}, pull=True, mode=False)
|
||||
await update_playlist(ctx.author.id, {f'playlist.{result["id"]}.tracks': result['playlist']['tracks'][position - 1]}, mode="pull")
|
||||
|
||||
track = voicelink.decode(result['playlist']['tracks'][position - 1])
|
||||
await ctx.send(get_lang(ctx.guild.id, 'playlistRemoved').format(track.get("title"), ctx.author, name))
|
||||
@@ -462,7 +456,7 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
if len(name) > 10:
|
||||
return await ctx.send(get_lang(ctx.guild.id, 'playlistOverText'), ephemeral=True)
|
||||
|
||||
rank, max_p, max_t = await checkroles(ctx.author.id)
|
||||
rank, max_p, max_t = await checkroles()
|
||||
user = await check_playlist(ctx, full=True)
|
||||
if not user:
|
||||
return await create_account(ctx)
|
||||
@@ -479,9 +473,8 @@ class Playlists(commands.Cog, name="playlist"):
|
||||
track_ids = bytes.split(b"\n")[-1]
|
||||
track_ids = track_ids.decode().split(",")
|
||||
|
||||
playlist_name.pop(str(ctx.author.id), None)
|
||||
data = {'tracks': track_ids, 'perms': {'read': [], 'write': [], 'remove': []}, 'name': name, 'type': 'playlist'}
|
||||
await update_playlist(ctx.author.id, {f"playlist.{assign_playlistId([data for data in user])}": data})
|
||||
await update_playlist(ctx.author.id, {f"playlist.{assign_playlistId([data for data in user])}": data}, update_cache=True)
|
||||
await ctx.send(get_lang(ctx.guild.id, 'playlistCreated').format(name))
|
||||
|
||||
except:
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import Tuple
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
from function import (
|
||||
langs,
|
||||
LANGS,
|
||||
update_settings,
|
||||
get_settings,
|
||||
get_lang,
|
||||
@@ -47,8 +47,7 @@ class Settings(commands.Cog, name="settings"):
|
||||
async def settings(self, ctx: commands.Context):
|
||||
view = HelpView(self.bot, ctx.author)
|
||||
embed = view.build_embed(self.qualified_name)
|
||||
message = await ctx.send(embed=embed, view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=embed, view=view)
|
||||
|
||||
@settings.command(name="prefix", aliases=get_aliases("prefix"))
|
||||
@commands.has_permissions(manage_guild=True)
|
||||
@@ -64,7 +63,7 @@ class Settings(commands.Cog, name="settings"):
|
||||
async def language(self, ctx: commands.Context, language: str):
|
||||
"You can choose your preferred language, the bot message will change to the language you set."
|
||||
language = language.upper()
|
||||
if language not in langs:
|
||||
if language not in LANGS:
|
||||
return await ctx.send(get_lang(ctx.guild.id, "languageNotFound"))
|
||||
|
||||
update_settings(ctx.guild.id, {'lang': language})
|
||||
@@ -73,8 +72,8 @@ class Settings(commands.Cog, name="settings"):
|
||||
@language.autocomplete('language')
|
||||
async def autocomplete_callback(self, interaction: discord.Interaction, current: str) -> list:
|
||||
if current:
|
||||
return [app_commands.Choice(name=lang, value=lang) for lang in langs.keys() if current.upper() in lang]
|
||||
return [app_commands.Choice(name=lang, value=lang) for lang in langs.keys()]
|
||||
return [app_commands.Choice(name=lang, value=lang) for lang in LANGS.keys() if current.upper() in lang]
|
||||
return [app_commands.Choice(name=lang, value=lang) for lang in LANGS.keys()]
|
||||
|
||||
@settings.command(name="dj", aliases=get_aliases("dj"))
|
||||
@commands.has_permissions(manage_guild=True)
|
||||
@@ -86,7 +85,7 @@ class Settings(commands.Cog, name="settings"):
|
||||
if not role:
|
||||
if player:
|
||||
player.settings.pop('dj', None)
|
||||
update_settings(ctx.guild.id, {'dj': ''}, mode="Unset")
|
||||
update_settings(ctx.guild.id, {'dj': ''}, mode="unset")
|
||||
else:
|
||||
if player:
|
||||
player.settings['dj'] = role.id
|
||||
@@ -229,8 +228,7 @@ class Settings(commands.Cog, name="settings"):
|
||||
controller_settings = settings.get("default_controller", func.settings.controller)
|
||||
|
||||
view = EmbedBuilderView(ctx.author, controller_settings.get("embeds").copy())
|
||||
message = await ctx.send(embed=view.build_embed(), view=view)
|
||||
view.response = message
|
||||
view.response = await ctx.send(embed=view.build_embed(), view=view)
|
||||
|
||||
@settings.command(name="controllermsg", aliases=get_aliases("controllermsg"))
|
||||
@commands.has_permissions(manage_guild=True)
|
||||
|
||||
@@ -87,8 +87,8 @@ class Task(commands.Cog):
|
||||
|
||||
@tasks.loop(hours=12.0)
|
||||
async def cache_cleaner(self):
|
||||
func.guild_settings.clear()
|
||||
func.playlist_name.clear()
|
||||
func.GUILD_SETTINGS.clear()
|
||||
func.PLAYLIST_NAME.clear()
|
||||
|
||||
errorFile = func.gen_report()
|
||||
if errorFile:
|
||||
@@ -98,7 +98,7 @@ class Task(commands.Cog):
|
||||
await report_channel.send(content=f"Report Before: <t:{round(datetime.timestamp(datetime.now()))}:F>", file=errorFile)
|
||||
except Exception as e:
|
||||
print(f"Report could not be sent (Reason: {e})")
|
||||
func.error_log.clear()
|
||||
func.ERROR_LOGS.clear()
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(Task(bot))
|
||||
|
||||
Reference in New Issue
Block a user