Beispiel #1
0
    def remove_members(self, members):
        """
        从群聊中移除用户

        :param members: 待移除的用户列表或单个用户
        """

        return self.robot.core.delete_member_from_chatroom(
            self.user_name, ensure_list(wrap_user_name(members)))
Beispiel #2
0
    def add_members(self, users, use_invitation=False):
        """
        向群聊中加入用户

        :param users: 待加入的用户列表或单个用户
        :param use_invitation: 使用发送邀请的方式
        """

        return self.robot.core.add_member_into_chatroom(
            self.user_name, ensure_list(wrap_user_name(users)), use_invitation)
Beispiel #3
0
 def chat(self):
     """
     来自的聊天对象
     """
     user_name = self.get('FromUserName')
     if user_name:
         for _chat in self.robot.chats():
             if _chat.user_name == user_name:
                 return _chat
         _chat = Chat(wrap_user_name(user_name))
         _chat.robot = self.robot
         return _chat
Beispiel #4
0
    def __init__(self,
                 save_path=None,
                 console_qr=False,
                 qr_path=None,
                 qr_callback=None,
                 login_callback=None,
                 logout_callback=None):
        # 在初始化时便会执行登陆操作,需要手机扫描登陆。
        """
        :param save_path:
            | 用于保存或载入登陆状态的文件路径,例如: 'wxpy.pkl',为空则不尝试载入。
            | 填写本参数后,可在短时间内重新载入登陆状态,避免重复扫码,失效时会重新要求登陆
        :param console_qr: 在终端中显示登陆二维码,需要安装 Pillow 模块
        :param qr_path: 保存二维码的路径
        :param qr_callback: 获得二维码时的回调,接收参数: uuid, status, qrcode
        :param login_callback: 登陆时的回调,接收参数同上
        :param logout_callback: 登出时的回调,接收参数同上
        """

        self.core = itchat.Core()
        itchat.instanceList.append(self)

        self.core.auto_login(hotReload=bool(save_path),
                             statusStorageDir=save_path,
                             enableCmdQR=console_qr,
                             picDir=qr_path,
                             qrCallback=qr_callback,
                             loginCallback=login_callback,
                             exitCallback=logout_callback)

        self.message_configs = MessageConfigs(self)
        self.messages = Messages(robot=self)

        self.file_helper = Chat(wrap_user_name('filehelper'))
        self.file_helper.robot = self
        self.file_helper.nick_name = '文件传输助手'

        self.self = Chat(self.core.loginInfo['User'])
        self.self.robot = self

        self.save_path = save_path
Beispiel #5
0
Datei: bot.py Projekt: vanxv/wxpy
 def request():
     return self.core.create_chatroom(memberList=wrap_user_name(users),
                                      topic=topic or '')
Beispiel #6
0
 def __contains__(self, user):
     user = wrap_user_name(user)
     for member in self.members:
         if member == user:
             return member