def __init__(self, options: Optional[WechatyOptions] = None): """ docstring """ super().__init__() if options is None: options = WechatyOptions(puppet='wechaty-puppet-hostie') if options.puppet_options is None: options.puppet_options = PuppetOptions() self.Tag = Tag self.Contact = Contact self.Friendship = Friendship self.Message = Message self.Room = Room self.Image = Image self.RoomInvitation = RoomInvitation self.Favorite = Favorite self.MiniProgram = MiniProgram # TODO -> url-link, miniprogram self.started: bool = False self.puppet: Puppet = self._load_puppet(options) self._name: Optional[str] = None self.state = StateSwitch() self._ready_state = StateSwitch() self._watchdog = Watchdog(DEFAULT_TIMEOUT)
def __init__(self, options: Optional[WechatyOptions] = None): """ init Wechaty instance Args: options: WechatyOptions Examples: >>> from wechaty import Wechaty >>> bot = Wechaty() """ super().__init__() # 1. int the puppet options if options is None: options = WechatyOptions(puppet='wechaty-puppet-service') if options.puppet_options is None: options.puppet_options = PuppetOptions() options.puppet_options.token = options.puppet_options.token or options.token options.puppet_options.end_point = options.puppet_options.end_point or options.endpoint options.puppet = self._load_puppet(options) # 2. init the scheduler options self._options = options # pylint: disable=C0103 self.Tag: Type[Tag] = Tag # pylint: disable=C0103 self.Contact: Type[Contact] = Contact # pylint: disable=C0103 self.ContactSelf: Type[ContactSelf] = ContactSelf # pylint: disable=C0103 self.Friendship: Type[Friendship] = Friendship # pylint: disable=C0103 self.Message: Type[Message] = Message # pylint: disable=C0103 self.Room: Type[Room] = Room # pylint: disable=C0103 self.Image: Type[Image] = Image # pylint: disable=C0103 self.RoomInvitation: Type[RoomInvitation] = RoomInvitation self.Favorite: Type[Favorite] = Favorite self.MiniProgram: Type[MiniProgram] = MiniProgram self.UrlLink: Type[UrlLink] = UrlLink # TODO -> url-link, miniprogram self.started: bool = False self._name: Optional[str] = None self.state = StateSwitch() self._ready_state = StateSwitch() self._puppet: Puppet = options.puppet self._plugin_manager: WechatyPluginManager = WechatyPluginManager( self, (options.host, options.port))
class WechatyOptions: """ WechatyOptions instance """ name: str = 'Python Wechaty' puppet: Union[PuppetModuleName, Puppet] = 'wechaty-puppet-service' puppet_options: PuppetOptions = PuppetOptions() host: str = '0.0.0.0' port: int = 5000
async def test_bot() -> Wechaty: """Initialize a Wechaty instance and return it""" puppet = FakePuppet(options=PuppetOptions()) puppet.add_contact(ContactPayload("wechaty_user", name="Wechaty User")) puppet.add_contact(ContactPayload("fake_user", name="Fake User")) puppet.add_contact(ContactPayload("test_user", name="Test User")) puppet.add_room( RoomPayload("fake_room", "fake_room", member_ids=["wechaty_user", "fake_user", "test_user"])) puppet.add_room_member("fake_room", RoomMemberPayload("wechaty_user")) puppet.add_room_member( "fake_room", RoomMemberPayload("fake_user", room_alias="Fake Alias")) puppet.add_room_member("fake_room", RoomMemberPayload("test_user")) puppet.add_message( MessagePayload('no_mention', text='foo bar asd', type=MessageType.MESSAGE_TYPE_TEXT)) puppet.add_message( MessagePayload('room_no_mention', text='beep', room_id="fake_room", type=MessageType.MESSAGE_TYPE_TEXT)) puppet.add_message( MessagePayload('room_with_mentions', text='@Wechaty User @Test User test message asd', room_id="fake_room", type=MessageType.MESSAGE_TYPE_TEXT, mention_ids=["wechaty_user", "test_user"])) puppet.add_message( MessagePayload( 'room_with_mentions_and_alias', text='123123 @Wechaty User @Test User @Fake Alias kkasd', room_id="fake_room", type=MessageType.MESSAGE_TYPE_TEXT, mention_ids=["wechaty_user", "test_user", "fake_user"])) puppet.add_message( MessagePayload('room_with_mentions_and_alias_mismatched', text='123123@Wechaty User @Test User @Fake User beep', room_id="fake_room", type=MessageType.MESSAGE_TYPE_TEXT, mention_ids=["wechaty_user", "test_user", "fake_user"])) puppet.add_message( MessagePayload('room_with_text_mentions', text='@Wechaty User @Test User @Fake Alias beep!!', room_id="fake_room", type=MessageType.MESSAGE_TYPE_TEXT)) bot = Wechaty(WechatyOptions(puppet=puppet)) await bot.init_puppet() return bot
def __init__(self, options: Optional[WechatyOptions] = None): """ docstring """ super().__init__() if options is None: options = WechatyOptions(puppet='wechaty-puppet-service') if options.puppet_options is None: options.puppet_options = PuppetOptions() self._options = options # pylint: disable=C0103 self.Tag: Type[Tag] = Tag # pylint: disable=C0103 self.Contact: Type[Contact] = Contact # pylint: disable=C0103 self.ContactSelf: Type[ContactSelf] = ContactSelf # pylint: disable=C0103 self.Friendship: Type[Friendship] = Friendship # pylint: disable=C0103 self.Message: Type[Message] = Message # pylint: disable=C0103 self.Room: Type[Room] = Room # pylint: disable=C0103 self.Image: Type[Image] = Image # pylint: disable=C0103 self.RoomInvitation: Type[RoomInvitation] = RoomInvitation self.Favorite: Type[Favorite] = Favorite self.MiniProgram: Type[MiniProgram] = MiniProgram self.UrlLink: Type[UrlLink] = UrlLink # TODO -> url-link, miniprogram self.started: bool = False self._name: Optional[str] = None self.state = StateSwitch() self._ready_state = StateSwitch() self._puppet: Optional[Puppet] = None # Create watchdog on start, and allow to shutdown the watchdog by # setting it to None self._watchdog: Optional[Watchdog] = None self._watchdog_task: Optional[asyncio.Task] = None self._plugin_manager: WechatyPluginManager = WechatyPluginManager(self)
class WechatyOptions: """ WechatyOptions instance """ name: str = 'Python Wechaty' puppet: Union[PuppetModuleName, Puppet] = 'wechaty-puppet-service' puppet_options: PuppetOptions = PuppetOptions() host: str = '0.0.0.0' port: int = 5000 # expose the puppet options at here to make it easy to user token: Optional[str] = None endpoint: Optional[str] = None scheduler: Optional[Union[WechatySchedulerOptions, BaseScheduler]] = None