Exemple #1
0
    def test_calculate_ratios_raises(self, create_core):
        member = Member(
            1,
            1,
            messages=[Message(1, 2, 3, 4, "One"),
                      Message(2, 2, 3, 4, "Two")])

        m = Message(1, 2, 3, 4, "One")
        m.creation_time = member.messages[0].creation_time
        with pytest.raises(DuplicateObject):
            create_core._calculate_ratios(m, member, Guild(1))
Exemple #2
0
    def create_message_from_dict(message_data) -> Message:
        message = Message(
            id=message_data["id"],
            content=message_data["content"],
            guild_id=message_data["guild_id"],
            author_id=message_data["author_id"],
            channel_id=message_data["channel_id"],
        )
        message.is_duplicate = message_data["is_duplicate"]
        message.creation_time = datetime.datetime.strptime(
            message_data["creation_time"], "%f:%S:%M:%H:%d:%m:%Y")
        log.info("Created Message(id=%s) from dict", message.id)

        return message
Exemple #3
0
    async def get_guild(self, guild_id: int) -> Guild:
        log.debug("Attempting to return cached Guild(id=%s)", guild_id)
        guild: Guild = await self.guilds.find({"id": guild_id})

        # This is a dict here actually
        if not guild:
            raise GuildNotFound

        guild.options = Options(**guild.options)  # type: ignore
        members: List[Member] = await self.members.find_many_by_custom(
            {"guild_id": guild_id})
        for member in members:
            messages: List[Message] = []
            for dict_message in member.messages:
                dict_message: dict = dict_message
                msg = Message(**dict_message)
                msg.creation_time = msg.creation_time.replace(tzinfo=pytz.UTC)
                messages.append(msg)
            member.messages = messages
            guild.members[member.id] = member

        return guild
Exemple #4
0
    async def get_member(self, member_id: int, guild_id: int) -> Member:
        log.debug(
            "Attempting to return a cached Member(id=%s) for Guild(id=%s)",
            member_id,
            guild_id,
        )
        member: Member = await self.members.find({
            "id": member_id,
            "guild_id": guild_id
        })
        if not member:
            raise MemberNotFound

        messages: List[Message] = []
        for dict_message in member.messages:
            dict_message: dict = dict_message
            msg = Message(**dict_message)
            msg.creation_time = msg.creation_time.replace(tzinfo=pytz.UTC)
            messages.append(msg)
        member.messages = messages

        return member