Exemplo n.º 1
0
 def send(self, qqNum, sendObj):
     """
     发送微语\n
     args:\n
         qqNum:发送者QQ号码
         sendObj:发送对象
     """
     if not isinstance(sendObj, SendObj):
         raise TypeError('sendObj should be SendObj Type,not ' +
                         type(sendObj))
     bot.Login(['-q', '%s' % qqNum])
     mes = self.get_content()
     for bu in sendObj.buddy:
         bl = bot.List('buddy', str(bu))
         if bl:
             b = bl[0]
             bot.SendTo(b, mes)
     for gr in sendObj.group:
         bl = bot.List('group', str(gr))
         if bl:
             b = bl[0]
             bot.SendTo(b, mes)
     for dis in sendObj.discuss:
         bl = bot.List('discuss', str(dis))
         if bl:
             b = bl[0]
             bot.SendTo(b, mes)
Exemplo n.º 2
0
    def find_group_discuss(self,name):
        groups = bot.List('group', name)
        if groups is not None and len(groups)>0:
            return groups[0]

        discusses = bot.List('discuss', name)
        if discusses is not None and len(discusses)>0:
            return discusses[0]

        return None
Exemplo n.º 3
0
def main(bot):
    # bot.SendTo('2861451012','dd')
    friends = bot.List('buddy')
    groups = bot.List('group')
    # print(friends)
    # print('-========')
    # print(groups)
    zhouwei = bot.List('buddy', '周巍')
    if zhouwei:
        zw = zhouwei[0]
        bot.SendTo(zw, 'hello')
Exemplo n.º 4
0
def getgroup():
    result = {}
    try:
        groups = bot.List('group')
    except:
        bot.Login()
        groups = bot.List('group')
    if groups != [] and groups != 'None':
        for group in groups:
            group_name = group.name
            group_number = group.qq
            result[group_number] = group_name
    return result
Exemplo n.º 5
0
def send_msg_by_qq(msg):
    if msg:
        print('发送消息给 %s ' % QQ_TARGET_BTR) 
        bl = bot.List('buddy', QQ_TARGET_BTR)
        if bl:
            b = bl[0]
            bot.SendTo(b, msg)
Exemplo n.º 6
0
def SendMessage(content, member=None):
    # from * import * # 消息过滤
    try:
        from qqbot import _bot as bot
        bot.Login(['-q', '549537094'])  # change
    except BaseException:
        SendEmail('SendMessage', BaseException)
        # 日志记录
        return 0

    try:
        from time import sleep
        if member:
            for group in member:
                message = bot.SendTo(group, content)
                if '失败' in message:
                    pass  # 日志记录
                sleep(0.5)
        else:
            for group in bot.List('group'):
                message = bot.SendTo(group, content)
                if '失败' in message:
                    pass  # 日志记录
                sleep(0.5)
            # 日志记录
    except Exception as e:
        pass
Exemplo n.º 7
0
    def parse_member_weibo(self, response, limit=5):
        response = filter(lambda x: x["card_type"] == 9,
                          response.json()["cards"])[:limit]
        for i in response:
            is_top = 0
            message = ''
            id = i["mblog"]["id"]
            if "isTop" in i["mblog"].keys():
                is_top = i["mblog"]["isTop"]
            created_at = i["mblog"]["created_at"]
            name = i["mblog"]["user"]["screen_name"]
            text = re.compile(r'<[^>]+>', re.S).sub('', i["mblog"]["text"])

            is_top_str = "【置顶】" if is_top == 1 else ""
            message += "%s【%s】\n%s: %s\n" % (is_top_str, created_at, name,
                                             text)

            if "data-url" in i["mblog"]["text"]:
                match = re.compile(r'data-url="(.*?)"', re.I).search(text)
                if match:
                    video_url = match.groups()[0]
                    message += "%s\n" % video_url

            if "pics" in i["mblog"].keys():
                for pic in i["mblog"]["pics"]:
                    message += "%s\n" % (pic["url"])

            bot.SendTo(bot.List('group', self.group_id)[0], message)
            time.sleep(0.05)
Exemplo n.º 8
0
def QQBotTest():
    from qqbot import _bot as bot
    qqID = '761282619'  # QQ号
    group_name = 'hxr粉丝群'  # 监听的群s
    bot.Login(['-q', qqID])
    group = bot.List('group', group_name)[0]
    bot.SendTo(group, '测试一下Bot')
Exemplo n.º 9
0
def sendMsgToGroup(msg, groupList, bot):
    for group in groupList:
        if group != None and group != "":
            print("group", group)
            bg = bot.List('group', group)
            print(bg)
            if bg is not None:
                bot.SendTo(bg[0], msg)
Exemplo n.º 10
0
 def get_group_number(cls, group_number):
     """
     获取对应群的成员人数
     :param group_number:
     :return:
     """
     number = 0
     if group_number:
         group = bot.List('group', group_number)
         if group:
             g = group[0]
             member_list = bot.List(g)
             # DEBUG(member_list)
             number = len(member_list)
         else:
             ERROR('没有搜索到对应的群号: %s', group_number)
             raise Exception('没有group number对应的群号')
     return number
Exemplo n.º 11
0
def tuling_reply(bot, contact, member, content):
    # 为了保证在图灵Key出现问题的时候仍旧可以回复,这里设置一个默认回复
    # print(msg["Text"][0:4])
    print(content)
    b1 = bot.List('buddy','任')
    b = b1[0]
    reply = get_response(content)
    reply = reply + '\n<自动回复>'
    bot.SendTo(b,reply)
Exemplo n.º 12
0
    def parse_memberLive_msg(self, response):
        message = ""
        if "liveList" in response["content"].keys():
            DEBUG("获得直播列表")
            live_list = response["content"]["liveList"]
            message = message + "当前共有%s人在直播:\n\n" % (len(live_list))
            for live_info in live_list:
                idol_name = live_info["title"]
                subtitle = live_info["subTitle"]
                streamPath = live_info["streamPath"]
                live_id = live_info["liveId"]
                member_id = live_info["memberId"]
                live_url = 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=%s' % live_id
                message += ('%s : %s\n %s\n\n' %
                            (idol_name, subtitle, live_url))

            bot.SendTo(bot.List('group', self.group_id)[0], message)
        else:
            bot.SendTo(bot.List('group', self.group_id)[0], "当前没有小偶像在直播~~")
Exemplo n.º 13
0
def send_g(bot):
    # 盟主你醒一醒啊!!
    bg = bot.List('group', "盟主你醒一醒啊!!")
    print(bg)
    while True:
        str = input()
        if str is not None and str != "":
            if bg is not None:
                tuling(str)
                bot.SendTo(bg[0], str)
Exemplo n.º 14
0
    def parse_watchMemberLive_msg(self, response, by_hand=False):
        all_live_ids = []
        if "liveList" in response["content"].keys():
            live_list = response["content"]["liveList"]
            for live_info in live_list:
                member_id = str(live_info["memberId"])
                idol_name = live_info["title"]
                subtitle = live_info["subTitle"]
                streamPath = live_info["streamPath"]
                live_id = live_info["liveId"]
                live_url = 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=%s' % live_id
                all_live_ids.append(member_id)

                if member_id in self.liveWatch_ids:
                    if member_id not in self.member_live_msg_ids:
                        DEBUG("%s开始直播!" % member_id)
                        message = '你关注的小偶像正在直播!\n\n'
                        message += ('%s : %s\n %s' %
                                    (idol_name, subtitle, live_url))
                        bot.SendTo(
                            bot.List('group', self.group_id)[0], message)
                        self.member_live_msg_ids.append(member_id)
                    elif by_hand:
                        message = '你关注的小偶像正在直播!\n\n'
                        message += ('%s : %s\n %s' %
                                    (idol_name, subtitle, live_url))
                        bot.SendTo(
                            bot.List('group', self.group_id)[0], message)
                    else:
                        DEBUG("%s在直播列表中!" % member_id)
        if not self.member_live_msg_ids:
            DEBUG("没有关注的小偶像在直播!")

        for member_id in self.member_live_msg_ids:
            if member_id not in all_live_ids:
                self.member_live_msg_ids.remove(member_id)
                DEBUG('%s关掉了直播' % member_id)
        return self.member_live_msg_ids
Exemplo n.º 15
0
    def parse_name_wdsList(self, response):
    	if response["status"] == "-1":
            DEBUG("fail to get wds list")
            bot.SendTo(bot.List('group', self.group_id)[0], "查不到小偶像的集资链接~~")
            return 

    	current_timestamps = int(time.time())
    	wds_cnt = 0
    	message = ''

    	for des in response["des"]:
    		id = des["id"]
    		name = des["name"]
    		goal = des["goal"]
    		all_amount = des["all_amount"]
    		end_timestamps = convert_timestr_to_timestamp(des["end_time"])
    		url = "https://wds.modian.com/show_weidashang_pro/%s"%id

    		if current_timestamps < end_timestamps:
    			wds_cnt += 1
    			message += ("%s: \n目标:%s,已集:%s \n链接:%s\n\n")%(name, goal, all_amount, url)

    	message = "你查询的小偶像有%s个进行中的集资:\n\n"%(wds_cnt) + message
    	bot.SendTo(bot.List('group', self.group_id)[0], message)
Exemplo n.º 16
0
def onQQMessage(bot, contact, member, content):
    print(contact, member, content)

    if bot.isMe(contact, member):
        print('自己发送的')
        return

    toUsers = bot.List('buddy', '*****')

    print('收到消息' + content)
    if toUsers:
        toUser = toUsers[0]
        bot.SendTo(toUser, u'[%s]:%s' % (contact, content))
        itchat.send_msg(u"收到好友@%s 的信息:%s\n" % (contact, content),
                        toUserName='******')
Exemplo n.º 17
0
 def list_group(cls, groups):
     """
     根据群号查询对应的QContact对象
     :param groups:
     :return: list of QContact
     """
     result = []
     for group_number in groups:
         if group_number:
             group = bot.List('group', group_number)
             if group:
                 result.append(group[0])
             else:
                 ERROR('没有搜索到对应的群号: %s', group_number)
                 raise Exception('没有group number对应的群号')
     return result
Exemplo n.º 18
0
 def Notice(self, nickname='jack', content='Hello World'):
     try:
         bot.Login([
             '-q', self.qq_num_sender, '-ip', self.ip, '-hp', self.port,
             '--daemon', '-r'
         ])
         nickname = 'jack' if nickname == '' else nickname
         content = 'Hello World' if content == '' else content
         bl = bot.List('buddy', nickname)
         if bl:
             b = bl[0]
             bot.SendTo(b, content)
             return "Notice '{ct}' sent to {nickname} successfully!".format(
                 ct=content, nickname=nickname)
         return 'Get buddy error!'
     except:
         return 'Notice Error!'
Exemplo n.º 19
0
 def parse_memberReviewLive_msg(self, response, limit=5):
     message = ""
     if "reviewList" in response["content"].keys():
         DEBUG("获得录播列表")
         live_list = response["content"]["reviewList"]
         live_list = live_list[:limit]
         message += "小偶像的录播:\n\n"
         for live_info in live_list:
             idol_name = live_info["title"]
             subtitle = live_info["subTitle"]
             streamPath = live_info["streamPath"]
             startTime = convert_timestamp_to_timestr(
                 live_info["startTime"])
             live_id = live_info["liveId"]
             member_id = live_info["memberId"]
             message += ('%s : %s [%s]\n %s\n\n' %
                         (idol_name, subtitle, startTime, streamPath))
         bot.SendTo(bot.List('group', self.group_id)[0], message)
Exemplo n.º 20
0
def sendMessageOnline():
    while True:
        time.sleep(2)
        #print (friendDict)
        #print (players_list)
        for qqNickName in friendDict:
            for friend in friendDict[qqNickName]:
                if friend[0] in players_list:
                    if friend[1] == 0:
                        last_players_list = players_list
                        myQQId = bot.List('buddy', qqNickName)[0]
                        #print(myQQId)
                        bot.SendTo(myQQId, "你的好友{}上线了。".format(friend[0]))
                        friend[1] = 1
                    else:
                        pass
                else:
                    if friend[1] == 1:
                        bot.SendTo(myQQId, "你的好友{}下线了。".format(friend[0]))
                    friend[1] = 0
Exemplo n.º 21
0
def film_name(a):
    s_words = etree.HTML(a)
    for num_list in range(25):
        num_list += 1
        cn_name = s_words.xpath('//*[@id="content"]/div/div[1]/ol/li[' +
                                str(num_list) +
                                ']/div/div[2]/div[1]/a/span[1]/text()')  # 电影名
        words = s_words.xpath('//*[@id="content"]/div/div[1]/ol/li[' +
                              str(num_list) +
                              ']/div/div[2]/div[2]/p[2]/span/text()')  # 一句话
        str_name_not = str(cn_name)  #同下
        str_name_yes = str_name_not[2:-2]  #参考下面
        str_words_not = str(words)  #转换类型
        str_words_yes = str_words_not[2:-2]  #去掉多余的东西
        str_sent = str_name_yes + '——' + str_words_yes  #拼接字符串
        for qqfriend in sent_list:
            bl = bot.List('buddy', qqfriend)  #发送给谁
            if bl:  #不知道在这里判断了什么 (-‸ლ)无语
                b = bl[0]
                bot.SendTo(b, str_sent)
        time.sleep(5400)  #休眠,三小时发送一次   休眠到底加在哪里!!!!!
Exemplo n.º 22
0
def sendMessage(bot, group, content):
    bot.Update('group')
    gl = bot.List('group', group)
    print gl[0].qq
    if gl:
        qq_item = {
            'xnr_qq_number': bot.session.qq,
            'xnr_nickname': bot.session.nick,
            'timestamp': int(round(time.time())),
            'speaker_qq_number': bot.session.qq,
            'text': content,
            'speaker_nickname': bot.session.nick,
            'qq_group_number': gl[0].qq,
            'qq_group_nickname': group
        }
        qq_json = json.dumps(qq_item)
        print qq_json

        conMD5 = string_md5(content)

        nowDate = datetime.datetime.now().strftime('%Y-%m-%d')
        index_name = sent_group_message_index_name_pre + str(nowDate)
        index_id = bot.conf.qq + '_' + gl[0].qq + '_' + str(
            int(round(time.time()))) + '_' + conMD5
        # 将发送的信息存入es
        if not es.indices.exists(index=index_name):
            group_message_mappings(bot.session.qq, nowDate)

        es.index(index=index_name,
                 doc_type=group_message_index_type,
                 id=index_id,
                 body=qq_item)

        bot.SendTo(gl[0], content)
        return 1
    else:
        print 'you no own this group', group
        return 0
Exemplo n.º 23
0
def list():
    """
    bot.List('buddy')        # 返回 好友列表:
    bot.List('buddy', 'jack')   # 返回名为 'jack' 的好友的列表:
    bot.List('group')              # 返回 群列表:
    bot.List('group', '机器人测试')  # 返回名为 “机器人测试” 的群的列表:
    g = bot.List('group', "456班")[0]   # g 是一个 Group 对象(群“456班”)
    bot.List(g)                         # 返回 群“456班” 的成员列表
    bot.List(g, 'card=jack')          # 返回 群“456班” 中名片为 “jack” 的成员列表
    bot.Update('buddy') # 更新 好友列表 :
    bot.Update('group') # 更新 群列表 :
    gl = bot.List('group', "456班")  # 更新 某个群的成员列表 :
    if gl:
      g = gl[0]
      bot.Update(g)
    """
    l = bot.List('buddy')  # l 是一个 list 对象
    m = 1
    for i in l:
        print i, i.qq, i.uin, i.nick, i.mark, i.name
        print '成功获取第%s个好友------------------' % (m), '\n'
        m += 1
        time.sleep(0.5)
Exemplo n.º 24
0
    def parse_roomChat_msg(self, response, room_id):
        # DEBUG('Room: %s exit msg ids: %s'%(room_id,  \
        #         '\t'.join(self.member_room_msg_ids[room_id])))

        msgs = response["content"]["data"]
        msgs.reverse()

        for msg in msgs:
            message = ''
            extInfo = json.loads(msg["extInfo"])
            msg_id = msg["msgidClient"]

            if msg_id in self.member_room_msg_ids[room_id]:
                continue

            DEBUG("小偶像的房间%s有新消息了!" % room_id)

            if len(self.member_room_msg_ids[room_id]) > 1:
                self.member_room_msg_ids[room_id].insert(0, msg_id)
                self.member_room_msg_ids[room_id].pop(-1)

            msg_object = extInfo["messageObject"]
            idol_name = extInfo["senderName"]
            msg_time = msg["msgTimeStr"]

            if msg['msgType'] == 0:  #文字
                if msg_object == "text":
                    DEBUG("普通消息")
                    message = ('【%s的口袋房间】[%s]\n %s:%s' %
                               (idol_name, msg_time, idol_name,
                                extInfo["text"])) + message
                elif msg_object == "faipaiText":
                    DEBUG("翻牌消息")
                    member_msg = extInfo['messageText']
                    gl_msg = extInfo['faipaiContent']
                    gl_name = extInfo['faipaiName']
                    message = ('【%s的口袋房间】[%s]\n gl(%s) : %s\n %s :%s' %
                               (idol_name, msg_time, gl_name, gl_msg,
                                idol_name, member_msg)) + message
            elif msg["msgType"] == 1:  #图片
                DEBUG("图片消息")
                if msg["bodys"] == "":
                    DEBUG("skip pic")
                    continue
                bodys = json.loads(msg["bodys"])
                if "url" in bodys.keys():
                    url = bodys["url"]
                    message = ('【%s的口袋房间】[%s]\n 小偶像发图片啦!:\n%s' %
                               (idol_name, msg_time, url)) + message
            elif msg["msgType"] == 2:  #语音
                DEBUG("语音消息")
                if msg["bodys"] == "":
                    DEBUG("skip voice")
                    continue
                bodys = json.loads(msg["bodys"])
                if "url" in bodys.keys():
                    url = bodys["url"]
                    message = ('【%s的口袋房间】[%s]\n 小偶像发语音啦!:\n%s' %
                               (idol_name, msg_time, url)) + message
            elif msg["msgType"] == 3:  #小视频
                DEBUG("小视频消息")
                if msg["bodys"] == "":
                    DEBUG("skip video")
                    continue
                bodys = json.loads(msg["bodys"])
                if "url" in bodys.keys():
                    url = bodys["url"]
                    message = ('【%s的口袋房间】[%s]\n 小偶像发小视频啦!:\n%s' %
                               (idol_name, msg_time, url)) + message
            else:
                DEBUG("unknown msgType")
                continue

            # QQHandler.send_to_groups(group_id, message)
            bot.SendTo(bot.List('group', self.group_id)[0], message)
            time.sleep(2)
Exemplo n.º 25
0
def senMsgToBuddy(msg, buddyList, bot):
    for buddy in buddyList:
        bg = bot.List('buddy', buddy)
        if bg is not None:
            bot.SendTo(bg[0], msg)
Exemplo n.º 26
0
def sendMsgToGroup(msg, groupList, bot):
    for group in groupList:
        bg = bot.List('group', group)
        if bg is not None:
            bot.SendTo(bg[0], msg)
Exemplo n.º 27
0
    def update(cls):
        bot.Update('buddy')
        bot.Update('group')

    @classmethod
    def restart(cls):
        DEBUG('RESTART')
        bot.Restart()

    @classmethod
    def fresh_restart(cls):
        bot.FreshRestart()

    @classmethod
    def stop(self):
        bot.Stop()

    @classmethod
    def send(cls, receiver, message):
        bot.SendTo(receiver, message)

    @classmethod
    def send_to_groups(cls, groups, message):
        for group in groups:
            bot.SendTo(group, message)
            time.sleep(2)


if __name__ == '__main__':
    print bot.List('buddy')
    print bot.conf.qq
Exemplo n.º 28
0
from qqbot import _bot as bot

bl = bot.List('buddy', '梅海洋')
if bl:
    b = bl[0]
    bot.SendTo(b, '我说我世界第二帅,恐怕没人敢说第一了吧?')
Exemplo n.º 29
0
    def Unplug(self, moduleName):
        if moduleName not in self.plugins:
            result = '警告:试图卸载未安装的插件 %s' % moduleName
            WARN(result)
            return result
        else:
            module = self.plugins[moduleName]
            self.unplug(moduleName)
            if hasattr(module, 'onUnplug'):
                _call(module.onUnplug, self)
            result = '成功:卸载插件 %s' % moduleName
            INFO(result)
            return result

    def Plugins(self):
        return list(self.plugins.keys())


_bot = QQBot()
QQBot._bot = _bot
QQBotSlot = _bot.AddSlot
QQBotSched = _bot.AddSched
QQBot.__init__ = None

if __name__ == '__main__':
    from qqbot import _bot as bot
    bot.Login()
    gl = bot.List('group')
    ml = bot.List(gl[0])
    m = ml[0]
Exemplo n.º 30
0
#coding:utf-8

import Kia
from qqbot import _bot as bot
bot.Login(['-q', '2352341722'])
s = bot.List('buddy')
print(s[0])
s = bot.List('group', '小开测试群')[0]
print(s, type(s), s.qq, s.name, s.uin, s.mark)