mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Cv progress
This commit is contained in:
parent
00d98805dd
commit
937c1861a0
4 changed files with 174 additions and 123 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Imports go here!
|
# Imports go here!
|
||||||
from .ciaoruozi import CiaoruoziCommand
|
from .ciaoruozi import CiaoruoziCommand
|
||||||
from .color import ColorCommand
|
from .color import ColorCommand
|
||||||
# from .cv import CvCommand
|
from .cv import CvCommand
|
||||||
from .diario import DiarioCommand
|
from .diario import DiarioCommand
|
||||||
# from .rage import RageCommand
|
# from .rage import RageCommand
|
||||||
# from .reminder import ReminderCommand
|
# from .reminder import ReminderCommand
|
||||||
|
@ -29,7 +29,7 @@ from .peertube import PeertubeCommand
|
||||||
available_commands = [
|
available_commands = [
|
||||||
CiaoruoziCommand,
|
CiaoruoziCommand,
|
||||||
ColorCommand,
|
ColorCommand,
|
||||||
# CvCommand,
|
CvCommand,
|
||||||
DiarioCommand,
|
DiarioCommand,
|
||||||
# RageCommand,
|
# RageCommand,
|
||||||
# ReminderCommand,
|
# ReminderCommand,
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
import discord
|
|
||||||
import typing
|
|
||||||
from royalnet.commands import *
|
from royalnet.commands import *
|
||||||
from royalnet.utils import andformat
|
|
||||||
from royalnet.bots import DiscordBot
|
|
||||||
|
|
||||||
|
|
||||||
class CvCommand(Command):
|
class CvCommand(Command):
|
||||||
|
@ -12,119 +8,110 @@ class CvCommand(Command):
|
||||||
|
|
||||||
syntax: str = "[guildname] [all]"
|
syntax: str = "[guildname] [all]"
|
||||||
|
|
||||||
@staticmethod
|
# @staticmethod
|
||||||
async def _legacy_cv_handler(bot: DiscordBot, guild_name: typing.Optional[str], everyone: bool):
|
# async def _legacy_cv_handler(bot: DiscordBot, guild_name: typing.Optional[str], everyone: bool):
|
||||||
# Find the matching guild
|
# # Find the matching guild
|
||||||
if guild_name:
|
# if guild_name:
|
||||||
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(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:
|
# else:
|
||||||
message += member.name
|
# guilds = bot.client.guilds
|
||||||
# Game or stream
|
# if len(guilds) == 0:
|
||||||
if member.activity is not None:
|
# raise CommandError("No guilds with the specified name found.")
|
||||||
if member.activity.type == discord.ActivityType.playing:
|
# if len(guilds) > 1:
|
||||||
message += f" | 🎮 {member.activity.name}"
|
# raise CommandError("Multiple guilds with the specified name found.")
|
||||||
# Rich presence
|
# guild = list(bot.client.guilds)[0]
|
||||||
try:
|
# # Edit the message, sorted by channel
|
||||||
if member.activity.state is not None:
|
# discord_members = list(guild.members)
|
||||||
message += f" ({member.activity.state}" \
|
# channels = {0: None}
|
||||||
f" | {member.activity.details})"
|
# members_in_channels = {0: []}
|
||||||
except AttributeError:
|
# message = ""
|
||||||
pass
|
# # Find all the channels
|
||||||
elif member.activity.type == discord.ActivityType.streaming:
|
# for member in discord_members:
|
||||||
message += f" | 📡 {member.activity.url}"
|
# if member.voice is not None:
|
||||||
elif member.activity.type == discord.ActivityType.listening:
|
# channel = members_in_channels.get(member.voice.channel.id)
|
||||||
if isinstance(member.activity, discord.Spotify):
|
# if channel is None:
|
||||||
if member.activity.title == member.activity.album:
|
# members_in_channels[member.voice.channel.id] = list()
|
||||||
message += f" | 🎧 {member.activity.title} ({andformat(member.activity.artists, final=' e ')})"
|
# channel = members_in_channels[member.voice.channel.id]
|
||||||
else:
|
# channels[member.voice.channel.id] = member.voice.channel
|
||||||
message += f" | 🎧 {member.activity.title} ({member.activity.album} | {andformat(member.activity.artists, final=' e ')})"
|
# channel.append(member)
|
||||||
else:
|
# else:
|
||||||
message += f" | 🎧 {member.activity.name}"
|
# members_in_channels[0].append(member)
|
||||||
elif member.activity.type == discord.ActivityType.watching:
|
# # Edit the message, sorted by channel
|
||||||
message += f" | 📺 {member.activity.name}"
|
# for channel in sorted(channels, key=lambda c: -c):
|
||||||
else:
|
# members_in_channels[channel].sort(key=lambda x: x.nick if x.nick is not None else x.name)
|
||||||
message += f" | ❓ {member.activity.state}"
|
# if channel == 0 and len(members_in_channels[0]) > 0:
|
||||||
message += "\n"
|
# message += "[b]Non in chat vocale:[/b]\n"
|
||||||
message += "\n"
|
# else:
|
||||||
return {"response": message}
|
# message += f"[b]In #{channels[channel].name}:[/b]\n"
|
||||||
|
# for member in members_in_channels[channel]:
|
||||||
_event_name = "_legacy_cv"
|
# 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}
|
||||||
|
|
||||||
def __init__(self, interface: CommandInterface):
|
def __init__(self, interface: CommandInterface):
|
||||||
super().__init__(interface)
|
super().__init__(interface)
|
||||||
if interface.name == "discord":
|
|
||||||
interface.register_herald_action(self._event_name, self._legacy_cv_handler)
|
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
# noinspection PyTypeChecker
|
response = await self.interface.call_herald_event("discord", "discord_cv")
|
||||||
guild_name, everyone = args.match(r"(?:\[(.+)])?\s*(\S+)?\s*")
|
breakpoint()
|
||||||
response = await self.interface.call_herald_action("discord", self._event_name, {
|
|
||||||
"guild_name": guild_name,
|
|
||||||
"everyone": everyone
|
|
||||||
})
|
|
||||||
await data.reply(response["response"])
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# Imports go here!
|
# Imports go here!
|
||||||
|
from .discord_cv import DiscordCvEvent
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_events = [
|
available_events = [
|
||||||
|
DiscordCvEvent,
|
||||||
]
|
]
|
||||||
|
|
||||||
# noinspection PyUnreachableCode
|
# noinspection PyUnreachableCode
|
||||||
|
|
|
@ -7,11 +7,75 @@ from royalnet.commands import *
|
||||||
class DiscordCvEvent(Event):
|
class DiscordCvEvent(Event):
|
||||||
name = "discord_cv"
|
name = "discord_cv"
|
||||||
|
|
||||||
def run(self, guild_id: int, **kwargs):
|
async def run(self, guild_id: Optional[int] = None, **kwargs):
|
||||||
if not self.interface.name == "discord":
|
if not self.interface.name == "discord":
|
||||||
raise UnsupportedError()
|
raise UnsupportedError()
|
||||||
|
|
||||||
|
# noinspection PyTypeChecker
|
||||||
serf: DiscordSerf = self.interface.serf
|
serf: DiscordSerf = self.interface.serf
|
||||||
|
|
||||||
client: discord.Client = serf.client
|
client: discord.Client = serf.client
|
||||||
|
|
||||||
|
if guild_id is None:
|
||||||
|
guilds: List[discord.Guild] = client.guilds
|
||||||
|
if len(guilds) == 0:
|
||||||
|
raise ConfigurationError("Il bot non è in nessun Server.")
|
||||||
|
elif len(guilds) > 1:
|
||||||
|
raise UserError("Non hai specificato di quale Server vuoi vedere le informazioni!")
|
||||||
|
else:
|
||||||
|
guild = guilds[0]
|
||||||
|
else:
|
||||||
guild: discord.Guild = client.get_guild(guild_id)
|
guild: discord.Guild = client.get_guild(guild_id)
|
||||||
members: List[discord.Member] = guild.members
|
|
||||||
...
|
members: List[Union[discord.User, discord.Member]] = guild.members
|
||||||
|
channels: List[discord.VoiceChannel] = guild.voice_channels
|
||||||
|
|
||||||
|
results = []
|
||||||
|
|
||||||
|
for member in members:
|
||||||
|
data = {
|
||||||
|
"id": member.id,
|
||||||
|
"name": member.name,
|
||||||
|
"discriminator": member.discriminator,
|
||||||
|
"nick": member.nick,
|
||||||
|
"bot": member.bot,
|
||||||
|
"voice": {
|
||||||
|
"channel": {
|
||||||
|
"id": member.voice.channel.id,
|
||||||
|
"name": member.voice.channel.name,
|
||||||
|
"position": member.voice.channel.position,
|
||||||
|
"category": {
|
||||||
|
"id": member.voice.channel.category_id,
|
||||||
|
"name": member.voice.channel.category.name,
|
||||||
|
},
|
||||||
|
"bitrate": member.voice.channel.bitrate,
|
||||||
|
"user_limit": member.voice.channel.user_limit,
|
||||||
|
},
|
||||||
|
"server_mute": member.voice.mute,
|
||||||
|
"server_deaf": member.voice.deaf,
|
||||||
|
"self_mute": member.voice.self_mute,
|
||||||
|
"self_deaf": member.voice.self_deaf,
|
||||||
|
"video": member.voice.self_video,
|
||||||
|
"golive": member.voice.self_stream,
|
||||||
|
"afk": member.voice.afk,
|
||||||
|
} if member.voice is not None else None,
|
||||||
|
"status": {
|
||||||
|
"main": member.status,
|
||||||
|
"desktop": member.desktop_status,
|
||||||
|
"mobile": member.mobile_status,
|
||||||
|
"web": member.web_status,
|
||||||
|
},
|
||||||
|
"activities": [activity.to_dict() for activity in member.activities if activity is not None],
|
||||||
|
"roles": [{
|
||||||
|
"id": role.id,
|
||||||
|
"name": role.name,
|
||||||
|
"hoist": role.hoist,
|
||||||
|
"position": role.position,
|
||||||
|
"managed": role.managed,
|
||||||
|
"mentionable": role.mentionable,
|
||||||
|
} for role in member.roles]
|
||||||
|
}
|
||||||
|
|
||||||
|
results.append(data)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
Loading…
Reference in a new issue