Skip to content

Commit

Permalink
Merge pull request #11 from ChocoMeow/beta
Browse files Browse the repository at this point in the history
Vocard v2.6.5a Update: bug fixes, and code clean-up
  • Loading branch information
ChocoMeow authored Jul 22, 2023
2 parents ef55050 + 9bbe6b6 commit be2901c
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 114 deletions.
21 changes: 12 additions & 9 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import traceback
import function as func

from typing import Tuple
from discord import app_commands
from discord.ext import commands
from function import (
Expand All @@ -25,7 +26,7 @@ def __init__(self, bot) -> None:
self.bot = bot
self.description = "This category is only available to admin permissions on the server."

def get_settings(self, ctx: commands.Context) -> dict:
def get_settings(self, ctx: commands.Context) -> Tuple[voicelink.Player, dict]:
player: voicelink.Player = ctx.guild.voice_client
if not player:
settings = get_settings(ctx.guild.id)
Expand All @@ -34,9 +35,11 @@ def get_settings(self, ctx: commands.Context) -> dict:

return player, settings

@commands.hybrid_group(name="settings",
aliases=get_aliases("settings"),
invoke_without_command=True)
@commands.hybrid_group(
name="settings",
aliases=get_aliases("settings"),
invoke_without_command=True
)
async def settings(self, ctx: commands.Context):
view = HelpView(self.bot, ctx.author)
embed = view.build_embed(self.qualified_name)
Expand Down Expand Up @@ -101,8 +104,8 @@ async def dj(self, ctx: commands.Context, role: discord.Role = None):
async def queue(self, ctx: commands.Context, mode: str):
"Change to another type of queue mode."
player, settings = self.get_settings(ctx)
if mode.capitalize() not in ["FairQueue", "Queue"]:
mode = "Queue"

mode = "FairQueue" if mode.lower() == "fairqueue" else "Queue"
settings["queueType"] = mode
update_settings(ctx.guild.id, {"queueType": mode})
await ctx.send(get_lang(ctx.guild.id, "setqueue").format(mode))
Expand Down Expand Up @@ -211,10 +214,10 @@ async def duplicatetrack(self, ctx: commands.Context):
player, settings = self.get_settings(ctx)
toggle = settings.get('duplicateTrack', False)
if player:
player.queue._duplicateTrack = not toggle
player.queue._allow_duplicate = not toggle

update_settings(ctx.guild.id, {'duplicateTrack': not toggle})
toggle = get_lang(ctx.guild.id, "enabled" if not toggle else "disabled")
toggle = get_lang(ctx.guild.id, "enabled" if toggle else "disabled")
return await ctx.send(get_lang(ctx.guild.id, "toggleDuplicateTrack").format(toggle))

@settings.command(name="customcontroller", aliases=get_aliases("customcontroller"))
Expand All @@ -234,7 +237,7 @@ async def debug(self, interaction: discord.Interaction):
if interaction.user.id not in func.settings.bot_access_user:
return await interaction.response.send_message("You are not able to use this command!")

def clear_code(content):
def clear_code(content: str):
if content.startswith("```") and content.endswith("```"):
return "\n".join(content.split("\n")[1:])[:-3]
else:
Expand Down
11 changes: 6 additions & 5 deletions cogs/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ async def skip(self, ctx: commands.Context, index: int = 0):

await ctx.send(player.get_msg('skipped').format(ctx.author))

if player.queue._repeat == 1:
await player.queue.set_repeat("off")
if player.queue._repeat.mode == voicelink.LoopType.track:
await player.set_repeat(voicelink.LoopType.off.name)

await player.stop()

@commands.hybrid_command(name="back", aliases=get_aliases("back"))
Expand Down Expand Up @@ -357,8 +358,8 @@ async def back(self, ctx: commands.Context, index: int = 1):

await ctx.send(player.get_msg('backed').format(ctx.author))

if player.queue._repeat == 1:
await player.queue.set_repeat("off")
if player.queue._repeat.mode == voicelink.LoopType.track:
await player.set_repeat(voicelink.LoopType.off.name)

@commands.hybrid_command(name="seek", aliases=get_aliases("seek"))
@app_commands.describe(position="Input position. Exmaple: 1:20.")
Expand Down Expand Up @@ -456,7 +457,7 @@ async def _import(self, ctx: commands.Context, attachment: discord.Attachment):
track_ids = bytes.split(b"\n")[-1]
track_ids = track_ids.decode().split(",")

tracks = [voicelink.Track(track_id=track_id, info=voicelink.decode(track_id), requester=ctx.author) for track_id in track_ids]
tracks = (voicelink.Track(track_id=track_id, info=voicelink.decode(track_id), requester=ctx.author) for track_id in track_ids)
if not tracks:
return await ctx.send(player.get_msg('noTrackFound'))

Expand Down
3 changes: 3 additions & 0 deletions function.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
try:
mongodb = MongoClient(host=tokens.mongodb_url, serverSelectionTimeoutMS=5000)
mongodb.server_info()
if tokens.mongodb_name not in mongodb.list_database_names():
raise Exception(f"{tokens.mongodb_name} does not exist in your mongoDB!")
print("Successfully connected to MongoDB!")

except Exception as e:
raise Exception("Not able to connect MongoDB! Reason:", e)

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def on_command_error(self, ctx: commands.Context, exception, /) -> None:
elif isinstance(error, (commands.CommandOnCooldown, commands.MissingPermissions, commands.RangeError, commands.BadArgument)):
pass

elif isinstance(error, commands.MissingRequiredArgument, commands.MissingRequiredAttachment):
elif isinstance(error, (commands.MissingRequiredArgument, commands.MissingRequiredAttachment)):
command = f" Correct Usage: {ctx.prefix}" + (f"{ctx.command.parent.qualified_name} " if ctx.command.parent else "") + f"{ctx.command.name} {ctx.command.signature}"
position = command.find(f"<{ctx.current_parameter.name}>") + 1
error = f"```css\n[You are missing argument!]\n{command}\n" + " " * position + "^" * len(ctx.current_parameter.name) + "```"
Expand Down
2 changes: 1 addition & 1 deletion update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

root_dir = os.path.dirname(os.path.abspath(__file__))
install_pack_dir = os.path.join(root_dir, "Vocard.zip")
__version__ = "v2.6.5"
__version__ = "v2.6.5a"

def checkVersion(withMsg = False):
resp = requests.get("https://api.github.com/repos/ChocoMeow/Vocard/releases/latest")
Expand Down
41 changes: 21 additions & 20 deletions views/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

import discord
import voicelink
import function as func

from discord.ext import commands
Expand All @@ -40,7 +41,7 @@ def key(interaction: discord.Interaction):

class Back(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏮️", label=player.get_msg('buttonBack'), style=style, disabled=False if self.player.queue.history() or not self.player.current else True, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -63,12 +64,12 @@ async def callback(self, interaction: discord.Interaction):

await interaction.response.send_message(self.player.get_msg("backed").format(interaction.user))

if self.player.queue._repeat == 1:
await self.player.set_repeat("off")
if self.player.queue._repeat.mode == voicelink.LoopType.track:
await self.player.set_repeat(voicelink.LoopType.off.name)

class Resume(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏸️", label=player.get_msg('buttonPause'), style=style, disabled=False if self.player.current else True, row=row)

async def callback(self, interaction: discord.Interaction):
Expand Down Expand Up @@ -107,7 +108,7 @@ async def callback(self, interaction: discord.Interaction):

class Skip(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏭️", label=player.get_msg('buttonSkip'), style=style, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -127,13 +128,13 @@ async def callback(self, interaction: discord.Interaction):

await interaction.response.send_message(self.player.get_msg("skipped").format(interaction.user))

if self.player.queue._repeat == 1:
await self.player.set_repeat("off")
if self.player.queue._repeat.mode == voicelink.LoopType.track:
await self.player.set_repeat(voicelink.LoopType.off.name)
await self.player.stop()

class Stop(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏹️", label=player.get_msg('buttonLeave'), style=style, row=row)
async def callback(self, interaction: discord.Interaction):
if not self.player.is_privileged(interaction.user):
Expand All @@ -151,7 +152,7 @@ async def callback(self, interaction: discord.Interaction):

class Add(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="❤️", style=style, disabled=False if self.player.current else True, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -177,7 +178,7 @@ async def callback(self, interaction: discord.Interaction):

class Loop(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="🔁", label=player.get_msg('buttonLoop'), style=style, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -189,7 +190,7 @@ async def callback(self, interaction: discord.Interaction):

class VolumeUp(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="🔊", label=player.get_msg('buttonVolumeUp'), style=style, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -203,7 +204,7 @@ async def callback(self, interaction: discord.Interaction):

class VolumeDown(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="🔉", label=player.get_msg('buttonVolumeDown'), style=style, row=row)

async def callback(self, interaction: discord.Interaction):
Expand All @@ -217,7 +218,7 @@ async def callback(self, interaction: discord.Interaction):

class VolumeMute(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="🔇" if player.volume else "🔈",
label=player.get_msg('buttonVolumeMute' if player.volume else "buttonVolumeUnmute"),
style=style, row=row)
Expand All @@ -241,7 +242,7 @@ async def callback(self, interaction: discord.Interaction):

class AutoPlay(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="💡",
label=player.get_msg('buttonAutoPlay'),
style=style, row=row)
Expand All @@ -259,7 +260,7 @@ async def callback(self, interaction: discord.Interaction):

class Shuffle(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="🔀",
label=player.get_msg('buttonShuffle'),
style=style, row=row)
Expand All @@ -280,7 +281,7 @@ async def callback(self, interaction: discord.Interaction):

class Forward(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏩",
label=player.get_msg('buttonForward'),
disabled=False if self.player.current else True,
Expand All @@ -298,7 +299,7 @@ async def callback(self, interaction: discord.Interaction):

class Rewind(discord.ui.Button):
def __init__(self, player, style, row):
self.player = player
self.player: voicelink.Player = player
super().__init__(emoji="⏪",
label=player.get_msg('buttonRewind'),
disabled=False if self.player.current else True,
Expand All @@ -319,7 +320,7 @@ async def callback(self, interaction: discord.Interaction):
class Tracks(discord.ui.Select):
def __init__(self, player, style, row):

self.player = player
self.player: voicelink.Player = player

options = []
for index, track in enumerate(self.player.queue.tracks(), start=1):
Expand Down Expand Up @@ -370,7 +371,7 @@ class InteractiveController(discord.ui.View):
def __init__(self, player):
super().__init__(timeout=None)

self.player = player
self.player: voicelink.Player = player
for row, btnRow in enumerate(func.settings.controller.get("default_buttons")):
for btn in btnRow:
color = ""
Expand All @@ -385,7 +386,7 @@ def __init__(self, player):

self.cooldown = commands.CooldownMapping.from_cooldown(2.0, 10.0, key)

async def interaction_check(self, interaction):
async def interaction_check(self, interaction: discord.Interaction):
if not self.player.node._available:
await interaction.response.send_message(self.player.get_msg("nodeReconnect"), ephemeral=True)
return False
Expand Down
2 changes: 1 addition & 1 deletion voicelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__license__ = "MIT"
__copyright__ = "Copyright 2023 (c) Vocard Development, Choco"

from .enums import SearchType
from .enums import SearchType, LoopType
from .events import *
from .exceptions import *
from .filters import *
Expand Down
12 changes: 12 additions & 0 deletions voicelink/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@

from enum import Enum, auto

class LoopType(Enum):
"""The enum for the different loop types for Voicelink
LoopType.off: 1
LoopType.track: 2
LoopType.queue: 3
"""

off = auto()
track = auto()
queue = auto()

class SearchType(Enum):
"""The enum for the different search types for Voicelink.
Expand Down
Loading

0 comments on commit be2901c

Please sign in to comment.