Refactor IPC client payload
change naming style from snake_case to camelCase
This commit is contained in:
@@ -102,13 +102,13 @@ class Listeners(commands.Cog):
|
||||
await self.bot.ipc.send({
|
||||
"op": "updateGuild",
|
||||
"user": {
|
||||
"user_id": str(member.id),
|
||||
"avatar_url": member.display_avatar.url,
|
||||
"userId": str(member.id),
|
||||
"avatarUrl": member.display_avatar.url,
|
||||
"name": member.name,
|
||||
},
|
||||
"channel_name": member.voice.channel.name if is_joined else "",
|
||||
"guild_id": str(member.guild.id),
|
||||
"is_joined": is_joined
|
||||
"channelName": member.voice.channel.name if is_joined else "",
|
||||
"guildId": str(member.guild.id),
|
||||
"isJoined": is_joined
|
||||
})
|
||||
|
||||
async def setup(bot: commands.Bot) -> None:
|
||||
|
||||
175
ipc/methods.py
175
ipc/methods.py
@@ -54,9 +54,9 @@ def require_permission(only_admin: bool = False):
|
||||
def error_msg(msg: str, *, user_id: int = None, guild_id: int = None, level: str = "info") -> Dict:
|
||||
payload = {"op": "errorMsg", "level": level, "msg": msg}
|
||||
if user_id:
|
||||
payload["user_id"] = str(user_id)
|
||||
payload["userId"] = str(user_id)
|
||||
if guild_id:
|
||||
payload["guild_id"] = str(guild_id)
|
||||
payload["guildId"] = str(guild_id)
|
||||
|
||||
return payload
|
||||
|
||||
@@ -68,13 +68,13 @@ async def connect_channel(member: Member, bot: commands.Bot) -> Player:
|
||||
try:
|
||||
settings = await func.get_settings(channel.guild.id)
|
||||
player: Player = await channel.connect(cls=Player(bot, channel, TempCtx(member, channel), settings))
|
||||
await player.send_ws({"op": "createPlayer", "member_ids": [str(member.id) for member in channel.members]})
|
||||
await player.send_ws({"op": "createPlayer", "memberIds": [str(member.id) for member in channel.members]})
|
||||
return player
|
||||
except:
|
||||
return
|
||||
|
||||
async def initBot(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
user = bot.get_user(user_id)
|
||||
if not user:
|
||||
user = await bot.fetch_user(user_id)
|
||||
@@ -82,14 +82,14 @@ async def initBot(bot: commands.Bot, data: Dict) -> Dict:
|
||||
if user:
|
||||
return {
|
||||
"op": "initBot",
|
||||
"user_id": str(user_id),
|
||||
"bot_name": bot.user.display_name,
|
||||
"bot_avatar": bot.user.display_avatar.url,
|
||||
"bot_id": str(bot.user.id)
|
||||
"userId": str(user_id),
|
||||
"botName": bot.user.display_name,
|
||||
"botAvatar": bot.user.display_avatar.url,
|
||||
"botId": str(bot.user.id)
|
||||
}
|
||||
|
||||
async def initUser(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
data = await func.get_user(user_id)
|
||||
|
||||
for mail in data.get("inbox"):
|
||||
@@ -100,11 +100,11 @@ async def initUser(bot: commands.Bot, data: Dict) -> Dict:
|
||||
if not sender:
|
||||
data.get("inbox").remove(mail)
|
||||
|
||||
mail["sender"] = {"avatar_url": sender.display_avatar.url, "name": sender.display_name, "id": str(sender.id)}
|
||||
mail["sender"] = {"avatarUrl": sender.display_avatar.url, "name": sender.display_name, "id": str(sender.id)}
|
||||
|
||||
return {
|
||||
"op": "initUser",
|
||||
"user_id": str(user_id),
|
||||
"userId": str(user_id),
|
||||
"data": data
|
||||
}
|
||||
|
||||
@@ -117,29 +117,29 @@ async def initPlayer(player: Player, member: Member, data: Dict) -> Dict:
|
||||
|
||||
return {
|
||||
"op": "initPlayer",
|
||||
"guild_id": str(player.guild.id),
|
||||
"user_id": str(data.get("user_id")),
|
||||
"guildId": str(player.guild.id),
|
||||
"userId": str(data.get("userId")),
|
||||
"users": [{
|
||||
"user_id": str(member.id),
|
||||
"avatar_url": member.display_avatar.url,
|
||||
"userId": str(member.id),
|
||||
"avatarUrl": member.display_avatar.url,
|
||||
"name": member.name
|
||||
} for member in player.channel.members ],
|
||||
"tracks": [ {"track_id": track.track_id, "requester_id": str(track.requester.id)} for track in player.queue._queue ],
|
||||
"repeat_mode": player.queue.repeat.lower(),
|
||||
"channel_name": player.channel.name,
|
||||
"current_queue_position": player.queue._position + (0 if player.is_playing else 1),
|
||||
"current_position": 0 or player.position if player.is_playing else 0,
|
||||
"is_playing": player.is_playing,
|
||||
"is_paused": player.is_paused,
|
||||
"is_dj": player.is_privileged(member, check_user_join=False),
|
||||
"tracks": [ {"trackId": track.track_id, "requesterId": str(track.requester.id)} for track in player.queue._queue ],
|
||||
"repeatMode": player.queue.repeat.lower(),
|
||||
"channelName": player.channel.name,
|
||||
"currentQueuePosition": player.queue._position + (0 if player.is_playing else 1),
|
||||
"currentPosition": 0 or player.position if player.is_playing else 0,
|
||||
"isPlaying": player.is_playing,
|
||||
"isPaused": player.is_paused,
|
||||
"isDj": player.is_privileged(member, check_user_join=False),
|
||||
"autoplay": player.settings.get("autoplay", False),
|
||||
"volume": player.volume,
|
||||
"filters": [{"tag": filter.tag, "scope": filter.scope, "payload": filter.payload} for filter in player.filters.get_filters()],
|
||||
"available_filters": available_filters
|
||||
"availableFilters": available_filters
|
||||
}
|
||||
|
||||
async def closeConnection(bot: commands.Bot, data: Dict) -> None:
|
||||
guild_id = int(data.get("guild_id"))
|
||||
guild_id = int(data.get("guildId"))
|
||||
guild = bot.get_guild(guild_id)
|
||||
player: Player = guild.voice_client
|
||||
if player:
|
||||
@@ -150,13 +150,13 @@ async def getRecommendation(bot: commands.Bot, data: Dict) -> None:
|
||||
if not node:
|
||||
return
|
||||
|
||||
track_data = decode(track_id := data.get("track_id"))
|
||||
track_data = decode(track_id := data.get("trackId"))
|
||||
track = Track(track_id=track_id, info=track_data, requester=bot.user)
|
||||
tracks: List[Track] = await node.get_recommendations(track, limit=60)
|
||||
|
||||
return {
|
||||
"op": "getRecommendation",
|
||||
"user_id": str(data.get("user_id")),
|
||||
"userId": str(data.get("userId")),
|
||||
"callback": data.get("callback"),
|
||||
"tracks": [track.track_id for track in tracks] if tracks else []
|
||||
}
|
||||
@@ -238,7 +238,7 @@ async def getTracks(bot: commands.Bot, data: Dict) -> Dict:
|
||||
query = data.get("query", None)
|
||||
|
||||
if query:
|
||||
payload = {"op": "getTracks", "user_id": data.get("user_id"), "callback": data.get("callback")}
|
||||
payload = {"op": "getTracks", "userId": data.get("userId"), "callback": data.get("callback")}
|
||||
tracks = await NodePool.get_node().get_tracks(query=query, requester=None)
|
||||
if not tracks:
|
||||
return payload
|
||||
@@ -268,7 +268,7 @@ async def removeTrack(player: Player, member: Member, data: Dict) -> None:
|
||||
|
||||
@require_permission()
|
||||
async def clearQueue(player: Player, member: Member, data: Dict) -> None:
|
||||
queue_type = data.get("queue_type", "").lower()
|
||||
queue_type = data.get("queueType", "").lower()
|
||||
await player.clear_queue(queue_type, member)
|
||||
|
||||
@require_permission(only_admin=True)
|
||||
@@ -316,8 +316,8 @@ async def toggleAutoplay(player: Player, member: Member, data: Dict) -> Dict:
|
||||
return {
|
||||
"op": "toggleAutoplay",
|
||||
"status": check,
|
||||
"guild_id": player.guild.id,
|
||||
"requester_id": str(member.id)
|
||||
"guildId": player.guild.id,
|
||||
"requesterId": str(member.id)
|
||||
}
|
||||
|
||||
@require_permission()
|
||||
@@ -374,30 +374,33 @@ async def _getPlaylist(user_id: int, playlist_id: str) -> Dict:
|
||||
return playlist
|
||||
|
||||
async def getPlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
playlist_id = str(data.get("playlist_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
playlist_id = str(data.get("playlistId"))
|
||||
|
||||
payload = {"op": "loadPlaylist", "playlist_id": playlist_id, "user_id": str(user_id)}
|
||||
payload = {"op": "loadPlaylist", "playlistId": playlist_id, "userId": str(user_id)}
|
||||
playlist = await _getPlaylist(user_id, playlist_id)
|
||||
payload["tracks"] = playlist["tracks"] if playlist else []
|
||||
|
||||
return payload
|
||||
|
||||
async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
playlist_id = str(data.get("playlist_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
playlist_id = str(data.get("playlistId"))
|
||||
_type = data.get("type")
|
||||
|
||||
if not playlist_id and not _type == "createPlaylist":
|
||||
return error_msg("Unable to process this request without a playlist ID.", user_id=user_id, level="error")
|
||||
|
||||
rank, max_p, max_t = func.check_roles()
|
||||
if _type == "createPlaylist":
|
||||
name, playlist_url = data.get("name"), data.get("playlist_url")
|
||||
name, playlist_url = data.get("playlistName"), data.get("playlistUrl")
|
||||
if not name:
|
||||
return {
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"You must enter name for this field!",
|
||||
"field": "create-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
playlist = await func.get_user(user_id, "playlist")
|
||||
@@ -406,8 +409,8 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"You cannot create more than '{max_p}' playlists!",
|
||||
"field": "create-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
for playlist_data in playlist.values():
|
||||
@@ -416,8 +419,8 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"Playlist '{name}' already exists.",
|
||||
"field": "create-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
if playlist_url:
|
||||
@@ -427,8 +430,8 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"Please enter a valid link or public spotify or youtube playlist link.",
|
||||
"field": "create-playlist-url",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistUrl",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
assgined_playlist_id = _assign_playlist_id(list(playlist.keys()))
|
||||
@@ -437,9 +440,9 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return {
|
||||
"op": "updatePlaylist",
|
||||
"status": "created",
|
||||
"playlist_id": assgined_playlist_id,
|
||||
"playlistId": assgined_playlist_id,
|
||||
"msg": f"You have created '{name}' playlist.",
|
||||
"user_id": str(user_id),
|
||||
"userId": str(user_id),
|
||||
"data": data
|
||||
}
|
||||
|
||||
@@ -454,9 +457,9 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return {
|
||||
"op": "updatePlaylist",
|
||||
"status": "deleted",
|
||||
"playlist_id": playlist_id,
|
||||
"playlistId": playlist_id,
|
||||
"msg": f"You have removed playlist '{playlist['name']}'",
|
||||
"user_id": str(user_id)
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
elif _type == "renamePlaylist":
|
||||
@@ -466,8 +469,8 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"You must enter name for this field!",
|
||||
"field": "rename-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
playlist = await func.get_user(user_id, "playlist")
|
||||
@@ -477,8 +480,8 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "error",
|
||||
"msg": f"Playlist '{data['name']}' already exists.",
|
||||
"field": "rename-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
await func.update_user(user_id, {"$set": {f'playlist.{playlist_id}.name': name}})
|
||||
@@ -486,14 +489,14 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"op": "updatePlaylist",
|
||||
"status": "renamed",
|
||||
"name": name,
|
||||
"playlist_id": playlist_id,
|
||||
"playlistId": playlist_id,
|
||||
"msg": f"You have renamed the playlist to '{name}'.",
|
||||
"field": "rename-playlist-name",
|
||||
"user_id": str(user_id)
|
||||
"field": "playlistName",
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
elif _type == "addTrack":
|
||||
track_id = data.get("track_id")
|
||||
track_id = data.get("trackId")
|
||||
if not track_id:
|
||||
return error_msg("No track ID could be located.", user_id=user_id, level='error')
|
||||
|
||||
@@ -513,18 +516,21 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return {
|
||||
"op": "updatePlaylist",
|
||||
"status": "addTrack",
|
||||
"playlist_id": playlist_id,
|
||||
"track_id": track_id,
|
||||
"playlistId": playlist_id,
|
||||
"trackId": track_id,
|
||||
"msg": f"Added {decoded_track.title} into '{playlist['name']}' playlist.",
|
||||
"user_id": str(user_id)
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
elif _type == "removeTrack":
|
||||
track_id, track_position = data.get("track_id"), data.get("track_position", 0)
|
||||
track_id, track_position = data.get("trackId"), data.get("trackPosition", 0)
|
||||
if not track_id:
|
||||
return error_msg("No track ID could be located.", user_id=user_id, level='error')
|
||||
|
||||
playlist = await _getPlaylist(user_id, playlist_id)
|
||||
if not playlist:
|
||||
return error_msg("Playlist not found!", user_id=user_id, level='error')
|
||||
|
||||
if playlist['type'] in ['share', 'link']:
|
||||
return error_msg("You cannot remove songs from a linked playlist through Vocard.", user_id=user_id, level='error')
|
||||
|
||||
@@ -540,11 +546,11 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return {
|
||||
"op": "updatePlaylist",
|
||||
"status": "removeTrack",
|
||||
"playlist_id": playlist_id,
|
||||
"track_position": track_position,
|
||||
"track_id": track_id,
|
||||
"playlistId": playlist_id,
|
||||
"trackPosition": track_position,
|
||||
"trackId": track_id,
|
||||
"msg": f"Removed '{decoded_track['title']}' from '{playlist['name']}' playlist.",
|
||||
"user_id": str(user_id)
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
elif _type == "updateInbox":
|
||||
@@ -554,11 +560,11 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
if is_accpet and len(list(user.get("playlist").keys())) >= max_p:
|
||||
return error_msg(f"You cannot create more than '{max_p}' playlists!", user_id=user_id, level = "error")
|
||||
|
||||
info = data.get("refer_id", "").split("-")
|
||||
info = data.get("referId", "").split("-")
|
||||
sender_id, refer_id = info[0], info[1]
|
||||
inbox = user.get("inbox")
|
||||
|
||||
payload = {"op": "updatePlaylist", "status": "updateInbox", "user_id": str(user_id), "accpet": is_accpet, "sender_id": sender_id, "refer_id": refer_id}
|
||||
payload = {"op": "updatePlaylist", "status": "updateInbox", "userId": str(user_id), "accpet": is_accpet, "senderId": sender_id, "referId": refer_id}
|
||||
for index, mail in enumerate(inbox.copy()):
|
||||
if not (str(mail.get("sender")) == sender_id and mail.get("referId") == refer_id):
|
||||
continue
|
||||
@@ -587,7 +593,7 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
}})
|
||||
|
||||
payload.update({
|
||||
"playlist_id": assgined_playlist_id,
|
||||
"playlistId": assgined_playlist_id,
|
||||
"msg": f"You have created '{playlist_name}' playlist.",
|
||||
"data": share_playlist,
|
||||
})
|
||||
@@ -596,14 +602,14 @@ async def updatePlaylist(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return payload
|
||||
|
||||
async def getMutualGuilds(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
|
||||
payload = {"op": "getMutualGuilds", "mutualGuilds": {}, "inviteGuilds": {}, "user_id": str(user_id)}
|
||||
payload = {"op": "getMutualGuilds", "mutualGuilds": {}, "inviteGuilds": {}, "userId": str(user_id)}
|
||||
for guild_id, guild_info in data.get("guilds", {}).items():
|
||||
if guild := bot.get_guild(int(guild_id)):
|
||||
payload["mutualGuilds"][guild_id] = {
|
||||
**guild_info,
|
||||
"member_count": guild.member_count
|
||||
"memberCount": guild.member_count
|
||||
}
|
||||
else:
|
||||
payload["inviteGuilds"][guild_id] = {**guild_info}
|
||||
@@ -611,8 +617,8 @@ async def getMutualGuilds(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return payload
|
||||
|
||||
async def getSettings(bot: commands.Bot, data: Dict) -> Dict:
|
||||
user_id = int(data.get("user_id"))
|
||||
guild_id = int(data.get("guild_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
guild_id = int(data.get("guildId"))
|
||||
|
||||
guild = bot.get_guild(guild_id)
|
||||
if not guild:
|
||||
@@ -636,7 +642,7 @@ async def getSettings(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"settings": settings,
|
||||
"options": {
|
||||
"languages": list(func.LANGS.keys()),
|
||||
"queue_modes": ["Queue", "FairQueue"],
|
||||
"queueModes": ["Queue", "FairQueue"],
|
||||
"roles": [role.name for role in guild.roles]
|
||||
},
|
||||
"guild": {
|
||||
@@ -644,7 +650,7 @@ async def getSettings(bot: commands.Bot, data: Dict) -> Dict:
|
||||
"name": guild.name,
|
||||
"id": str(guild_id)
|
||||
},
|
||||
"user_id": str(user_id)
|
||||
"userId": str(user_id)
|
||||
}
|
||||
|
||||
async def getLyrics(bot: commands.Bot, data: Dict) -> Dict:
|
||||
@@ -655,7 +661,10 @@ async def getLyrics(bot: commands.Bot, data: Dict) -> Dict:
|
||||
song: dict[str, str] = await lyricsPlatform.get(platform)().get_lyrics(title, artist)
|
||||
payload = {
|
||||
"op": "getLyrics",
|
||||
"user_id": data.get("user_id"),
|
||||
"userId": data.get("userId"),
|
||||
"title": title,
|
||||
"artist": artist,
|
||||
"platform": platform,
|
||||
"lyrics": {_: re.findall(r'.*\n(?:.*\n){,22}', v) for _, v in song.items()} if song else {},
|
||||
"callback": data.get("callback")
|
||||
}
|
||||
@@ -663,8 +672,8 @@ async def getLyrics(bot: commands.Bot, data: Dict) -> Dict:
|
||||
return payload
|
||||
|
||||
async def updateSettings(bot: commands.Bot, data: Dict) -> None:
|
||||
user_id = int(data.get("user_id"))
|
||||
guild_id = int(data.get("guild_id"))
|
||||
user_id = int(data.get("userId"))
|
||||
guild_id = int(data.get("guildId"))
|
||||
|
||||
guild = bot.get_guild(guild_id)
|
||||
if not guild:
|
||||
@@ -721,7 +730,7 @@ METHODS: Dict[str, Union[SystemMethod, PlayerMethod]] = {
|
||||
async def process_methods(ipc_client, bot: commands.Bot, data: Dict) -> None:
|
||||
op: str = data.get("op", "")
|
||||
method = METHODS.get(op)
|
||||
if not method or not (user_id := data.get("user_id")):
|
||||
if not method or not (user_id := data.get("userId")):
|
||||
return
|
||||
|
||||
user_id = int(user_id)
|
||||
@@ -730,7 +739,7 @@ async def process_methods(ipc_client, bot: commands.Bot, data: Dict) -> None:
|
||||
|
||||
else:
|
||||
if RATELIMIT_COUNTER[user_id]["count"] >= 100:
|
||||
return await ipc_client.send({"op": "rateLimited", "user_id": str(user_id)})
|
||||
return await ipc_client.send({"op": "rateLimited", "userId": str(user_id)})
|
||||
RATELIMIT_COUNTER[user_id]["count"] += method.credit
|
||||
|
||||
try:
|
||||
@@ -739,7 +748,7 @@ async def process_methods(ipc_client, bot: commands.Bot, data: Dict) -> None:
|
||||
|
||||
params = method.params
|
||||
if not (type(method) == SystemMethod):
|
||||
if guild_id := data.get("guild_id"):
|
||||
if guild_id := data.get("guildId"):
|
||||
if (guild := bot.get_guild(int(guild_id))):
|
||||
env["guild"] = guild
|
||||
|
||||
@@ -778,10 +787,12 @@ async def process_methods(ipc_client, bot: commands.Bot, data: Dict) -> None:
|
||||
await ipc_client.send(resp)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
payload = {
|
||||
"op": "errorMsg",
|
||||
"level": "error",
|
||||
"msg": str(e),
|
||||
"user_id": str(user_id)
|
||||
"userId": str(user_id)
|
||||
}
|
||||
await ipc_client.send(payload)
|
||||
@@ -72,7 +72,7 @@ async def connect_channel(ctx: Union[commands.Context, Interaction], channel: Vo
|
||||
))
|
||||
|
||||
if ctx.bot.ipc.is_connected:
|
||||
await player.send_ws({"op": "createPlayer", "member_ids": [str(member.id) for member in channel.members]})
|
||||
await player.send_ws({"op": "createPlayer", "memberIds": [str(member.id) for member in channel.members]})
|
||||
|
||||
return player
|
||||
|
||||
@@ -299,9 +299,9 @@ class Player(VoiceProtocol):
|
||||
if self.is_ipc_connected:
|
||||
await self.send_ws({
|
||||
"op": "playerUpdate",
|
||||
"last_update": self._last_update,
|
||||
"is_connected": self._is_connected,
|
||||
"last_position": self._last_position
|
||||
"lastUpdate": self._last_update,
|
||||
"isConnected": self._is_connected,
|
||||
"lastPosition": self._last_position
|
||||
})
|
||||
|
||||
async def _dispatch_voice_update(self, voice_data: Dict[str, Any] = None):
|
||||
@@ -405,9 +405,9 @@ class Player(VoiceProtocol):
|
||||
if self.is_ipc_connected:
|
||||
await self.send_ws({
|
||||
"op": "trackUpdate",
|
||||
"current_queue_position": self.queue._position if track else self.queue._position + 1,
|
||||
"track_id": track.track_id if track else None,
|
||||
"is_paused": self._paused
|
||||
"currentQueuePosition": self.queue._position if track else self.queue._position + 1,
|
||||
"trackId": track.track_id if track else None,
|
||||
"isPaused": self._paused
|
||||
})
|
||||
|
||||
async def invoke_controller(self):
|
||||
@@ -639,7 +639,7 @@ class Player(VoiceProtocol):
|
||||
await self.send_ws({
|
||||
"op": "removeTrack",
|
||||
"indexes": list(removed_tracks.keys()),
|
||||
"first_track_id": list(removed_tracks.values())[0].track_id
|
||||
"firstTrackId": list(removed_tracks.values())[0].track_id
|
||||
}, requester=requester)
|
||||
|
||||
return removed_tracks
|
||||
@@ -692,8 +692,8 @@ class Player(VoiceProtocol):
|
||||
if self.is_ipc_connected:
|
||||
await self.send_ws({
|
||||
"op": "shuffleTrack",
|
||||
"tracks": [{"track_id": track.track_id, "requester_id": str(track.requester.id)} for track in replacement],
|
||||
"queue_type": queue_type
|
||||
"tracks": [{"trackId": track.track_id, "requesterId": str(track.requester.id)} for track in replacement],
|
||||
"queueType": queue_type
|
||||
}, requester)
|
||||
|
||||
self._logger.debug(f"Player in {self.guild.name}({self.guild.id}) has been shuffled the queue.")
|
||||
@@ -767,7 +767,7 @@ class Player(VoiceProtocol):
|
||||
if self.is_ipc_connected:
|
||||
await self.send_ws({
|
||||
"op": "clearQueue",
|
||||
"queue_type": queue_type
|
||||
"queueType": queue_type
|
||||
}, requester)
|
||||
|
||||
async def remove_filter(self, filter_tag: str, requester: Member = None, fast_apply: bool = False) -> Filters:
|
||||
@@ -863,7 +863,7 @@ class Player(VoiceProtocol):
|
||||
|
||||
async def send_ws(self, payload, requester: Member = None):
|
||||
"""Sends a WebSocket payload to the bot's IPC (Inter-Process Communication) system."""
|
||||
payload['guild_id'] = str(self.guild.id)
|
||||
payload['guildId'] = str(self.guild.id)
|
||||
if requester:
|
||||
payload['requester_id'] = str(requester.id)
|
||||
payload['requesterId'] = str(requester.id)
|
||||
await self.bot.ipc.send(payload)
|
||||
Reference in New Issue
Block a user