Added played history feature
This commit is contained in:
@@ -32,6 +32,7 @@ from function import (
|
||||
time as ctime,
|
||||
formatTime,
|
||||
get_source,
|
||||
get_user,
|
||||
get_lang,
|
||||
truncate_string,
|
||||
cooldown_check,
|
||||
@@ -90,15 +91,25 @@ class Basic(commands.Cog):
|
||||
return [app_commands.Choice(name=c.capitalize(), value=c) for c in self.bot.cogs if c not in ["Nodes", "Task"] and current in c]
|
||||
|
||||
async def play_autocomplete(self, interaction: discord.Interaction, current: str) -> list:
|
||||
if current:
|
||||
if voicelink.pool.URL_REGEX.match(current):
|
||||
return
|
||||
history: dict[str, str] = {}
|
||||
for track_id in reversed(await get_user(interaction.user.id, "history")):
|
||||
track_dict = voicelink.decode(track_id)
|
||||
history[track_dict["identifier"]] = track_dict
|
||||
|
||||
if not current:
|
||||
return [app_commands.Choice(name=f"🕒 {track['author']} - {track['title']}", value=track['uri']) for track in history.values()]
|
||||
|
||||
if voicelink.pool.URL_REGEX.match(current): return
|
||||
|
||||
node = voicelink.NodePool.get_node()
|
||||
if node and node.spotify_client:
|
||||
tracks: list[voicelink.Track] = await node.spotifySearch(current, requester=interaction.user)
|
||||
choices = [app_commands.Choice(name=f"🎵 {track.author} - {track.title}", value=f"{track.author} - {track.title}") for track in tracks]
|
||||
if history:
|
||||
choices = [app_commands.Choice(name=f"🕒 {track['author']} - {track['title']}", value=track['uri']) for track in list(history.values())[:5]] + choices
|
||||
|
||||
node = voicelink.NodePool.get_node()
|
||||
if node and node.spotify_client:
|
||||
tracks: list[voicelink.Track] = await node.spotifySearch(current, requester=interaction.user)
|
||||
return [app_commands.Choice(name=f"{track.author} - {track.title}", value=f"{track.author} - {track.title}") for track in tracks]
|
||||
|
||||
return choices
|
||||
|
||||
@commands.hybrid_command(name="connect", aliases=get_aliases("connect"))
|
||||
@app_commands.describe(channel="Provide a channel to connect.")
|
||||
@commands.dynamic_cooldown(cooldown_check, commands.BucketType.guild)
|
||||
|
||||
14
function.py
14
function.py
@@ -190,7 +190,17 @@ async def update_db(db: AsyncIOMotorCollection, tempStore: dict, filter: dict, d
|
||||
nested_data[cursors[-1]] = nested_data.get(cursors[-1], 0) + value
|
||||
|
||||
elif mode == "$push":
|
||||
nested_data.setdefault(cursors[-1], []).extend([value])
|
||||
if isinstance(value, dict) and "$each" in value:
|
||||
nested_data.setdefault(cursors[-1], []).extend(value["$each"][value.get("$slice", len(value["$each"])):])
|
||||
else:
|
||||
nested_data.setdefault(cursors[-1], []).extend([value])
|
||||
|
||||
elif mode == "$push":
|
||||
if isinstance(value, dict) and "$each" in value:
|
||||
nested_data.setdefault(cursors[-1], []).extend(value["$each"])
|
||||
nested_data[cursors[-1]] = nested_data[cursors[-1]][value.get("$slice", len(value["$each"])):]
|
||||
else:
|
||||
nested_data.setdefault(cursors[-1], []).extend([value])
|
||||
|
||||
elif mode == "$pull":
|
||||
if cursors[-1] in nested_data:
|
||||
@@ -226,7 +236,7 @@ async def get_user(user_id: int, d_type: Optional[str] = None, need_copy: bool =
|
||||
await USERS_DB.insert_one(user)
|
||||
|
||||
USERS_BUFFER[user_id] = user
|
||||
|
||||
|
||||
if d_type:
|
||||
user = user.setdefault(d_type, copy.deepcopy(USERS_BASE.get(d_type)))
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests, zipfile, os, shutil, argparse
|
||||
from io import BytesIO
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
__version__ = "v2.6.8b3"
|
||||
__version__ = "v2.6.8b4"
|
||||
|
||||
GITHUB_API_URL = "https://api.github.com/repos/ChocoMeow/Vocard/releases/latest"
|
||||
VOCARD_URL = "https://github.com/ChocoMeow/Vocard/archive/"
|
||||
|
||||
@@ -349,6 +349,11 @@ class Player(VoiceProtocol):
|
||||
await sleep(5)
|
||||
return await self.do_next()
|
||||
|
||||
if not track.requester.bot:
|
||||
await func.update_user(track.requester.id, {
|
||||
"$push": {"history": {"$each": [track.track_id], "$slice": -25}}
|
||||
})
|
||||
|
||||
if self.settings.get('controller', True):
|
||||
await self.invoke_controller()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user