diff --git a/poetry.lock b/poetry.lock index 02380619..230884e0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -406,7 +406,7 @@ sentry = ["sentry_sdk (~0.13.2)"] telegram = ["python_telegram_bot (^12.2.0)"] [package.source] -reference = "491301b6811a41bd02192209ae75de861332aca4" +reference = "f1803f2ffd5507827be1a430d2b09996decfc098" type = "git" url = "https://github.com/Steffo99/royalnet/" @@ -873,24 +873,13 @@ websockets = [ {file = "websockets-8.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:3762791ab8b38948f0c4d281c8b2ddfa99b7e510e46bd8dfa942a5fff621068c"}, {file = "websockets-8.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:3db87421956f1b0779a7564915875ba774295cc86e81bc671631379371af1170"}, {file = "websockets-8.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4f9f7d28ce1d8f1295717c2c25b732c2bc0645db3215cf757551c392177d7cb8"}, - {file = "websockets-8.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:295359a2cc78736737dd88c343cd0747546b2174b5e1adc223824bcaf3e164cb"}, - {file = "websockets-8.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:1d3f1bf059d04a4e0eb4985a887d49195e15ebabc42364f4eb564b1d065793f5"}, {file = "websockets-8.1-cp36-cp36m-win32.whl", hash = "sha256:2db62a9142e88535038a6bcfea70ef9447696ea77891aebb730a333a51ed559a"}, {file = "websockets-8.1-cp36-cp36m-win_amd64.whl", hash = "sha256:0e4fb4de42701340bd2353bb2eee45314651caa6ccee80dbd5f5d5978888fed5"}, {file = "websockets-8.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:9b248ba3dd8a03b1a10b19efe7d4f7fa41d158fdaa95e2cf65af5a7b95a4f989"}, {file = "websockets-8.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:ce85b06a10fc65e6143518b96d3dca27b081a740bae261c2fb20375801a9d56d"}, {file = "websockets-8.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:965889d9f0e2a75edd81a07592d0ced54daa5b0785f57dc429c378edbcffe779"}, - {file = "websockets-8.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:751a556205d8245ff94aeef23546a1113b1dd4f6e4d102ded66c39b99c2ce6c8"}, - {file = "websockets-8.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3ef56fcc7b1ff90de46ccd5a687bbd13a3180132268c4254fc0fa44ecf4fc422"}, {file = "websockets-8.1-cp37-cp37m-win32.whl", hash = "sha256:7ff46d441db78241f4c6c27b3868c9ae71473fe03341340d2dfdbe8d79310acc"}, {file = "websockets-8.1-cp37-cp37m-win_amd64.whl", hash = "sha256:20891f0dddade307ffddf593c733a3fdb6b83e6f9eef85908113e628fa5a8308"}, - {file = "websockets-8.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:c1ec8db4fac31850286b7cd3b9c0e1b944204668b8eb721674916d4e28744092"}, - {file = "websockets-8.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:5c01fd846263a75bc8a2b9542606927cfad57e7282965d96b93c387622487485"}, - {file = "websockets-8.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:9bef37ee224e104a413f0780e29adb3e514a5b698aabe0d969a6ba426b8435d1"}, - {file = "websockets-8.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:d705f8aeecdf3262379644e4b55107a3b55860eb812b673b28d0fbc347a60c55"}, - {file = "websockets-8.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:c8a116feafdb1f84607cb3b14aa1418424ae71fee131642fc568d21423b51824"}, - {file = "websockets-8.1-cp38-cp38-win32.whl", hash = "sha256:e898a0863421650f0bebac8ba40840fc02258ef4714cb7e1fd76b6a6354bda36"}, - {file = "websockets-8.1-cp38-cp38-win_amd64.whl", hash = "sha256:f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b"}, {file = "websockets-8.1.tar.gz", hash = "sha256:5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f"}, ] yarl = [ diff --git a/royalpack/commands/cv.py b/royalpack/commands/cv.py index ab6ee15d..b6b98009 100644 --- a/royalpack/commands/cv.py +++ b/royalpack/commands/cv.py @@ -7,108 +7,7 @@ class CvCommand(Command): description: str = "Elenca le persone attualmente connesse alla chat vocale." - syntax: str = "[guildname] [all]" - - # @staticmethod - # async def _legacy_cv_handler(bot: DiscordBot, guild_name: typing.Optional[str], everyone: bool): - # # Find the matching guild - # if guild_name: - # guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(guild_name) - # else: - # guilds = bot.client.guilds - # if len(guilds) == 0: - # raise CommandError("No guilds with the specified name found.") - # if len(guilds) > 1: - # raise CommandError("Multiple guilds with the specified name found.") - # guild = list(bot.client.guilds)[0] - # # Edit the message, sorted by channel - # discord_members = list(guild.members) - # channels = {0: None} - # members_in_channels = {0: []} - # message = "" - # # Find all the channels - # for member in discord_members: - # if member.voice is not None: - # channel = members_in_channels.get(member.voice.channel.id) - # if channel is None: - # members_in_channels[member.voice.channel.id] = list() - # channel = members_in_channels[member.voice.channel.id] - # channels[member.voice.channel.id] = member.voice.channel - # channel.append(member) - # else: - # members_in_channels[0].append(member) - # # Edit the message, sorted by channel - # for channel in sorted(channels, key=lambda c: -c): - # members_in_channels[channel].sort(key=lambda x: x.nick if x.nick is not None else x.name) - # if channel == 0 and len(members_in_channels[0]) > 0: - # message += "[b]Non in chat vocale:[/b]\n" - # else: - # message += f"[b]In #{channels[channel].name}:[/b]\n" - # for member in members_in_channels[channel]: - # member: typing.Union[discord.User, discord.Member] - # # Ignore not-connected non-notable members - # if not everyone and channel == 0 and len(member.roles) < 2: - # continue - # # Ignore offline members - # if member.status == discord.Status.offline and member.voice is None: - # continue - # # Online status emoji - # if member.bot: - # message += "🤖 " - # elif member.status == discord.Status.online: - # message += "🔵 " - # elif member.status == discord.Status.idle: - # message += "⚫ " - # elif member.status == discord.Status.dnd: - # message += "🔴 " - # elif member.status == discord.Status.offline: - # message += "⚪ " - # # Voice - # if channel != 0: - # # Voice status - # if member.voice.afk: - # message += "💤 " - # elif member.voice.self_deaf or member.voice.deaf: - # message += "🔇 " - # elif member.voice.self_mute or member.voice.mute: - # message += "🔈 " - # elif member.voice.self_video or member.voice.self_stream: - # message += "🖥 " - # else: - # message += "🔊 " - # # Nickname - # # if member.nick is not None: - # # message += f"[i]{member.nick}[/i]" - # # else: - # message += member.name - # # Game or stream - # if member.activity is not None: - # if member.activity.type == discord.ActivityType.playing: - # message += f" | 🎮 {member.activity.name}" - # # Rich presence - # try: - # if member.activity.state is not None: - # message += f" ({member.activity.state}" \ - # f" | {member.activity.details})" - # except AttributeError: - # pass - # elif member.activity.type == discord.ActivityType.streaming: - # message += f" | 📡 {member.activity.url}" - # elif member.activity.type == discord.ActivityType.listening: - # if isinstance(member.activity, discord.Spotify): - # if member.activity.title == member.activity.album: - # message += f" | 🎧 {member.activity.title} ({andformat(member.activity.artists, final=' e ')})" - # else: - # message += f" | 🎧 {member.activity.title} ({member.activity.album} | {andformat(member.activity.artists, final=' e ')})" - # else: - # message += f" | 🎧 {member.activity.name}" - # elif member.activity.type == discord.ActivityType.watching: - # message += f" | 📺 {member.activity.name}" - # else: - # message += f" | ❓ {member.activity.state}" - # message += "\n" - # message += "\n" - # return {"response": message} + syntax: str = "[a][o][n][d][h]" def __init__(self, interface: CommandInterface): super().__init__(interface) @@ -155,8 +54,11 @@ class CvCommand(Command): activity = "" for mact in member["activities"]: + # Spotify + if "type" not in mact: + activity += f" | 🎧 {mact['details']} ({mact['state']})" # Playing - if mact["type"] == 0: + elif mact["type"] == 0: activity += f" | 🎮 {mact['name']}" if "state" in mact and "details" in mact: activity += f" ({mact['state']} | {mact['details']})" @@ -164,13 +66,20 @@ class CvCommand(Command): activity += f" ({mact['state']})" elif "details" in mact: activity += f" ({mact['details']})" - activity += "\n" + # Streaming + elif mact["type"] == 1: + activity += f" | 🎥 {mact['name']}" + # Listening + elif mact["type"] == 2: + activity += f" | 🎧 {mact['name']}" + # Watching + elif mact["type"] == 3: + activity += f" | 📺 {mact['name']}" # Custom Status elif mact["type"] == 4: activity += f" | ❓ {mact['state']}" else: - # TODO: what other activity types are there? - breakpoint() + raise ExternalError(f"Unknown Discord activity type: {mact['type']}") return f"{status}{voice} {name}{activity}\n" @@ -182,6 +91,7 @@ class CvCommand(Command): display_discrim = "d" in flags display_only_role = "a" not in flags display_only_online = "o" not in flags + display_not_connected = "h" not in flags # Find all categories categories = [] @@ -240,7 +150,7 @@ class CvCommand(Command): message += "\n" - if len(not_connected_members) >= 0: + if display_not_connected and len(not_connected_members) >= 0: message += "[b][Non in chat vocale][/b]\n" for member in not_connected_members: