-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from wj-Mcat/master
add quick test
- Loading branch information
Showing
12 changed files
with
410 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
overrides | ||
flake8 | ||
mypy | ||
mypy_extensions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
docstring | ||
""" | ||
from abc import ABCMeta | ||
from typing import Optional | ||
from wechaty_puppet.puppet import Puppet | ||
from .config import LOG | ||
from .wechaty import Wechaty | ||
|
||
|
||
class Accessory: | ||
""" | ||
docstring | ||
""" | ||
__metaclass__ = ABCMeta | ||
_puppet: Optional[Puppet] = None | ||
# static _wechaty property to doing ... | ||
_wechaty: Optional[Wechaty] = None | ||
_counter: int = 0 | ||
|
||
def __init__(self, name: str = "accessory"): | ||
""" | ||
initialize the accessory instance | ||
""" | ||
self.name: str = name | ||
# increase when Accessory is initialized | ||
self._counter += 1 | ||
|
||
def __str__(self) -> str: | ||
""" | ||
docstring | ||
:return: the base accessory class name | ||
""" | ||
return "Accessory instance : %s" % self.name | ||
|
||
@classmethod | ||
def puppet(cls, value: Optional[Puppet] = None) -> Optional[Puppet]: | ||
""" | ||
get/set global single instance of the puppet | ||
:return: | ||
""" | ||
if value is None: | ||
if cls._puppet is None: | ||
raise AttributeError("static puppet instance not found ...") | ||
LOG.info("get puppet instance %s ...", | ||
cls._puppet.name) | ||
return cls._puppet | ||
|
||
if cls._puppet is not None: | ||
raise AttributeError("can't set puppet instance %s twice" % | ||
cls._puppet.name) | ||
LOG.info("set puppet instance %s ...", | ||
value.name) | ||
cls._puppet = value | ||
return None | ||
|
||
@classmethod | ||
def wechaty(cls, value: Optional[Wechaty] = None) -> Optional[Wechaty]: | ||
""" | ||
get/set wechaty instance | ||
If the param of value is None, then the function will return the | ||
instance of wechaty.Otherwise, the function will check the type | ||
of the value, and set as wechaty instance | ||
:param value: | ||
:return: | ||
""" | ||
if value is None: | ||
if cls._wechaty is None: | ||
raise AttributeError("wechaty instance not found") | ||
LOG.info("get wechaty instance %s", | ||
cls._wechaty.name) | ||
return cls._wechaty | ||
if not isinstance(value, Wechaty): | ||
raise NameError( | ||
"expected wechaty instance type is Wechaty, " | ||
"but got %s" % value.__class__ | ||
) | ||
if cls._wechaty is not None: | ||
raise AttributeError("can't set wechaty instance %s twice" % | ||
cls._wechaty.name) | ||
cls._wechaty = value | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
docstring | ||
""" | ||
from enum import IntEnum | ||
from typing import Type, TypeVar | ||
from wechaty_puppet.file_box import FileBox | ||
from .accessory import Accessory | ||
from .config import LOG | ||
|
||
|
||
class ImageType(IntEnum): | ||
""" | ||
docstring ... | ||
""" | ||
Thumbnail = 0 | ||
HD = 1 | ||
Artwork = 2 | ||
|
||
|
||
T = TypeVar("T", bound="Image") | ||
|
||
|
||
class Image(Accessory): | ||
""" | ||
docstring ... | ||
""" | ||
|
||
def __str__(self): | ||
return "image instance : %d" % self.image_id | ||
|
||
def __init__(self, image_id: str) -> None: | ||
""" | ||
:param image_id: | ||
""" | ||
super(Image, self).__init__() | ||
self.image_id = image_id | ||
LOG.info("create image : %d", self.image_id) | ||
if self.puppet is None: | ||
raise NotImplementedError("Image class can not be instanced" | ||
" without a puppet!") | ||
|
||
@classmethod | ||
def create(cls: Type[T], image_id: str) -> T: | ||
""" | ||
create image instance by image_id | ||
:param cls: | ||
:param image_id: | ||
:return: | ||
""" | ||
LOG.info("create static image : %d", image_id) | ||
return cls(image_id) | ||
|
||
async def thumbnail(self) -> FileBox: | ||
""" | ||
docstring | ||
:return: | ||
""" | ||
LOG.info("image thumbnail for %d", self.image_id) | ||
puppet = self.puppet() | ||
if puppet is None: | ||
raise AttributeError | ||
file_box = await puppet.message_image(self.image_id, | ||
ImageType.Thumbnail) | ||
return file_box | ||
|
||
async def hd(self) -> FileBox: | ||
""" | ||
docstring | ||
:return: | ||
""" | ||
LOG.info("image hd for %d", self.image_id) | ||
puppet = self.puppet() | ||
if puppet is None: | ||
raise AttributeError | ||
file_box = await puppet.message_image(self.image_id, ImageType.HD) | ||
return file_box | ||
|
||
async def artwork(self) -> FileBox: | ||
""" | ||
docstring | ||
:return: | ||
""" | ||
LOG.info("image artwork for %d", self.image_id) | ||
puppet = self.puppet() | ||
if puppet is None: | ||
raise AttributeError | ||
file_box = await puppet.message_image(self.image_id, ImageType.Artwork) | ||
return file_box |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
""" | ||
python-implementation for room | ||
""" | ||
from threading import Event, Thread | ||
from src.wechaty.accessory import Accessory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
wechaty instance | ||
""" | ||
from typing import Optional | ||
from .config import LOG | ||
|
||
|
||
# pylint: disable=R0903 | ||
class WechatyOptions: | ||
""" | ||
WechatyOptions instance | ||
""" | ||
def __init__(self): | ||
""" | ||
WechatyOptions constructor | ||
""" | ||
self.io_token: str = None | ||
self.name: str = None | ||
self.profile: Optional[None or str] = None | ||
|
||
|
||
# pylint: disable=R0903 | ||
class Wechaty: | ||
""" | ||
docstring | ||
""" | ||
def __init__(self, name: str = "wechaty"): | ||
""" | ||
docstring | ||
""" | ||
self.name = name | ||
|
||
_global_instance: Optional["Wechaty"] = None | ||
|
||
async def start(self) -> None: | ||
""" | ||
start the wechaty | ||
:return: | ||
""" | ||
LOG.info("wechaty is starting ...") | ||
|
||
async def stop(self) -> None: | ||
""" | ||
stop the wechaty | ||
""" | ||
LOG.info("wechaty is stoping ...") |
Empty file.
Oops, something went wrong.