示例#1
0
    async def mentions(self):
        try:
            mentions = self._data["mentions"]
            members = []
            guild = self.guild
            state = self._state

            if guild is not None:
                members = [state.store_user(m) for m in mentions]
            else:
                for mention in filter(None, mentions):
                    id_search = int(mention["id"])
                    member = await guild.get_member(id_search)

                    if member is not None:
                        members.append(member)
                    else:
                        members.append(
                            Member._try_upgrade(data=mention,
                                                guild=guild,
                                                state=state))

            return members
        except KeyError:
            return []
示例#2
0
    async def parse_message_reaction_add(self, data, old):
        emoji = PartialEmoji.with_state(
            self,
            id=utils._get_as_snowflake(data["emoji"], "id"),
            animated=data["emoji"].get("animated", False),
            name=data["emoji"]["name"],
        )

        raw = RawReactionActionEvent(data, emoji, "REACTION_ADD")

        member = data.get("member")
        if member:
            guild = await self._get_guild(raw.guild_id)
            if guild:
                raw.member = Member(guild=guild, state=self, data=member)

        self.dispatch("raw_reaction_add", raw)

        message = await self._get_message(raw.message_id)
        if message:
            reaction = Reaction(message=message,
                                data=data,
                                emoji=await self._upgrade_partial_emoji(emoji))
            user = raw.member or await self._get_reaction_user(
                message.channel, raw.user_id)

            if user:
                self.dispatch("reaction_add", reaction, user)
    async def get_member(self, user_id):
        member = await self._state.get(f"member:{self.id}:{user_id}")

        if member:
            return Member(guild=self, state=self._state, data=member)

        return None
示例#4
0
    def __init__(self, space=10, population=None, action=None):

        self.pop = population
        self.space = space
        if self.pop is None:
            self.pop = [Member() for i in xrange(space)]
        self.action = action
        if self.action == None:
            self.action = ['actions']
示例#5
0
    async def convert(self, ctx, argument):
        match = self._get_id_match(argument) or re.match(r"<@!?([0-9]+)>$", argument)
        if match:
            try:
                return await ctx.guild.fetch_member(int(match.group(1)))
            except discord.NotFound:
                pass

        members = await ctx.bot.http.request_guild_members(ctx.guild.id, argument)
        if len(members) > 0:
            return Member(guild=ctx.guild, state=ctx.bot.state, data=members[0])

        raise MemberNotFound(argument)
示例#6
0
文件: message.py 项目: zKryp/modmail
    def __init__(self, *, state, channel, data):
        self._state = state
        self._data = data
        self.id = int(data["id"])
        self.webhook_id = utils._get_as_snowflake(data, "webhook_id")
        self.reactions = [
            Reaction(message=self, data=x, emoji="x")
            for x in data.get("reactions", [])
        ]
        self.attachments = [
            Attachment(data=x, state=self._state) for x in data["attachments"]
        ]
        self.embeds = [Embed.from_dict(x) for x in data["embeds"]]
        self.application = data.get("application")
        self.activity = data.get("activity")
        self.channel = channel
        self._edited_timestamp = utils.parse_time(data["edited_timestamp"])
        self.type = try_enum(MessageType, data["type"])
        self.pinned = data["pinned"]
        self.flags = MessageFlags._from_value(data.get("flags", 0))
        self.mention_everyone = data["mention_everyone"]
        self.tts = data["tts"]
        self.content = data["content"]
        self.nonce = data.get("nonce")

        ref = data.get("message_reference")
        self.reference = MessageReference.with_state(
            state, ref) if ref is not None else None

        try:
            self._author = self._state.store_user(self._data["author"])
        except KeyError:
            self._author = None

        try:
            author = self._author
            try:
                author._update_from_message(self._data["member"])
            except AttributeError:
                author = Member._from_message(message=self,
                                              data=self._data["member"])
            self._member = author
        except KeyError:
            self._member = None

        for handler in ("call", "flags"):
            try:
                getattr(self, f"_handle_{handler}")(data[handler])
            except KeyError:
                continue
示例#7
0
    async def parse_guild_member_update(self, data, old):
        guild = await self._get_guild(int(data["guild_id"]))
        if old and guild:
            member = await guild.get_member(int(data["user"]["id"]))
            if member:
                old_member = Member._copy(member)
                old_member._update(old)
                user_update = old_member._update_inner_user(data["user"])

                if user_update:
                    self.dispatch("user_update", user_update[1],
                                  user_update[0])

                self.dispatch("member_update", old_member, member)
示例#8
0
    async def parse_presence_update(self, data, old):
        guild = await self._get_guild(utils._get_as_snowflake(
            data, "guild_id"))

        if not guild:
            return

        old_member = None
        member = await guild.get_member(int(data["user"]["id"]))
        if member and old:
            old_member = Member._copy(member)
            user_update = old_member._presence_update(data=old,
                                                      user=old["user"])

            if user_update:
                self.dispatch("user_update", user_update[1], user_update[0])

        self.dispatch("member_update", old_member, member)
示例#9
0
 async def parse_guild_member_remove(self, data, old):
     if old:
         guild = await self._get_guild(int(data["guild_id"]))
         if guild:
             member = Member(guild=guild, data=old, state=self)
             self.dispatch("member_remove", member)
示例#10
0
 async def parse_guild_member_add(self, data, old):
     guild = await self._get_guild(int(data["guild_id"]))
     if guild:
         member = Member(guild=guild, data=data, state=self)
         self.dispatch("member_join", member)
示例#11
0
 async def _members(self):
     return [
         Member(guild=self, state=self._state, data=x)
         for x in await self._state._members_get_all("guild", key_id=self.id, name="member")
     ]
示例#12
0
 async def fetch_member(self, member_id):
     data = await self._state.http.get_member(self.id, member_id)
     return Member(data=data, state=self._state, guild=self)