2019-11-28 14:21:03 +00:00
|
|
|
import discord
|
|
|
|
from typing import *
|
|
|
|
from royalnet.serf.discord.discordserf import DiscordSerf
|
2020-08-21 00:34:29 +00:00
|
|
|
import royalnet.commands as rc
|
2019-11-28 14:21:03 +00:00
|
|
|
|
|
|
|
|
2020-08-21 00:34:29 +00:00
|
|
|
class DiscordCvEvent(rc.HeraldEvent):
|
2019-11-28 14:21:03 +00:00
|
|
|
name = "discord_cv"
|
|
|
|
|
2019-11-29 01:43:28 +00:00
|
|
|
async def run(self, guild_id: Optional[int] = None, **kwargs) -> dict:
|
2020-08-21 00:34:29 +00:00
|
|
|
if not isinstance(self.parent, DiscordSerf):
|
|
|
|
raise rc.UnsupportedError()
|
2019-11-28 16:54:36 +00:00
|
|
|
|
|
|
|
# noinspection PyTypeChecker
|
2020-08-21 00:34:29 +00:00
|
|
|
serf: DiscordSerf = self.parent
|
2019-11-28 16:54:36 +00:00
|
|
|
|
2019-11-28 14:21:03 +00:00
|
|
|
client: discord.Client = serf.client
|
2019-11-28 16:54:36 +00:00
|
|
|
|
|
|
|
if guild_id is None:
|
|
|
|
guilds: List[discord.Guild] = client.guilds
|
|
|
|
if len(guilds) == 0:
|
2020-08-21 00:34:29 +00:00
|
|
|
raise rc.ConfigurationError("Il bot non è in nessun Server.")
|
2019-11-28 16:54:36 +00:00
|
|
|
elif len(guilds) > 1:
|
2020-08-21 00:34:29 +00:00
|
|
|
raise rc.UserError("Non hai specificato di quale Server vuoi vedere le informazioni!")
|
2019-11-28 16:54:36 +00:00
|
|
|
else:
|
|
|
|
guild = guilds[0]
|
|
|
|
else:
|
|
|
|
guild: discord.Guild = client.get_guild(guild_id)
|
|
|
|
|
|
|
|
members: List[Union[discord.User, discord.Member]] = guild.members
|
|
|
|
|
|
|
|
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,
|
2019-11-29 01:43:28 +00:00
|
|
|
"position": member.voice.channel.category.position,
|
|
|
|
} if member.voice.channel.category is not None else {
|
|
|
|
"id": None,
|
|
|
|
"name": None,
|
|
|
|
"position": -1,
|
2019-11-28 16:54:36 +00:00
|
|
|
},
|
|
|
|
"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": {
|
2019-11-29 01:43:28 +00:00
|
|
|
"main": member.status.value,
|
|
|
|
"desktop": member.desktop_status.value,
|
|
|
|
"mobile": member.mobile_status.value,
|
|
|
|
"web": member.web_status.value,
|
2019-11-28 16:54:36 +00:00
|
|
|
},
|
2019-11-29 14:55:52 +00:00
|
|
|
"activities": [activity.to_dict() for activity in member.activities if activity is not None],
|
2019-11-28 16:54:36 +00:00
|
|
|
"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)
|
|
|
|
|
2019-11-29 01:43:28 +00:00
|
|
|
return {
|
|
|
|
"guild": {
|
|
|
|
"id": guild.id,
|
|
|
|
"name": guild.name,
|
|
|
|
"members": results,
|
|
|
|
}
|
|
|
|
}
|