Skip to content

Commit

Permalink
support: for image component attr url
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenwe_i_lin committed Mar 1, 2020
1 parent d4709f0 commit 21846a6
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions mirai/message/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mirai.misc import findKey, printer, ImageRegex, getMatchedString, randomRangedNumberString as rd
from mirai.face import QQFaces
from mirai.message.base import BaseMessageComponent, MessageComponentTypes
from pydantic import Field, validator
from pydantic import Field, validator, HttpUrl
from pydantic.generics import GenericModel
from mirai.network import fetch, session
from mirai.misc import ImageType
Expand Down Expand Up @@ -62,6 +62,7 @@ def toString(self):
class Image(BaseMessageComponent):
type: MessageComponentTypes = "Image"
imageId: UUID
url: HttpUrl

@validator("imageId", always=True, pre=True)
@classmethod
Expand All @@ -80,10 +81,6 @@ def imageId_formater(cls, v):
def toString(self):
return f"[Image::{self.imageId}]"

@property
def url(self):
return f"http://gchat.qpic.cn/gchatpic_new/{rd()}/{rd()}-{rd()}-{self.imageId.hex.upper()}/0"

def asGroupImage(self) -> str:
return f"{{{str(self.imageId).upper()}}}.jpg"

Expand Down Expand Up @@ -126,11 +123,4 @@ class ComponentTypes(Enum):
"Image": Image,
"Source": Source,
"Unknown": Unknown
}

from ..context import message, event
from mirai.prototypes.context import (
MessageContextBody,
EventContextBody
)
from mirai.protocol import MiraiProtocol
}

0 comments on commit 21846a6

Please sign in to comment.