def check(self): '''检查是否更新''' j = self.Getaweme() if not self.vid and len(j) != 1: for v in j: self.vid.append(v.get('video', {}).get('vid')) return False if j: for v in j: video = v.get('video', {}) vid = video.get('vid') if vid in self.vid: #当前视频在本地记录过,直接跳出循环既可 pass else: #未记录,表示为新视频 INFO(f'用户{self.conf.get("showname",self.name)}有新作品了') self.msg = MsgChain() self.msg.joinPlain( f'【抖音】{self.conf.get("showname",self.name)}更新视频啦~\n{v.get("desc")}' ) self.msg.joinImg(Url=video.get('origin_cover', {}).get( 'url_list', ['1'])[0]) self.msg.joinPlain( video.get('play_addr', {}).get('url_list', ['1'])[1]) self.video = MsgChain().joinVideo(Url=video.get( 'play_addr', {}).get('url_list', ['1'])[1]) self.vid.append(vid) return True return False
def OnLIVE(self, data): '''开播调用''' INFO( f'{self.roomid}[{self.info.get("showname",self.info.get("name"))}]收到开播推送' ) if not self.status: for group in self.info['Group']: msg = MsgChain() if group['ATall']: msg.joinAT(-1) msg.joinPlain( f'你的小可爱{self.info.get("showname",self.info.get("name"))}开播啦~' ) if self.title: msg.joinPlain(f'\n【{self.title}】') if group['sendPic']: '''''' if group['sendUrl']: msg.joinPlain(f'\nhttps://live.bilibili.com/{self.roomid}') Send['sendGroupMsg'](group['id'], msg) time.sleep(0.2) self.status = True #保存开播日志在弹幕表中 if self.info.get('savedanmu'): self.SQL.savedanmu( time.time() * 1000, #时间 'null', #用户名 'null', #用户uid 'LIVE' #弹幕 )
def on_GroupMessage(Message: MsgChain, sender: GroupInfo): mesg = Message.GetCQ() try: if mesg.startswith('点歌'): msg = MsgChain() msg.joinApp(WangYiYunD(mesg.replace('点歌',''))) Send['sendGroupMsg'](sender.GroupId,msg) except: print('点歌异常!')
def on_GroupMessage(Message: MsgChain, sender: GroupInfo): if Message.GetCQ().startswith('我想吃'): try: INFO('出现食谱查询指令:'+Message.GetCQ()) name = Message.GetCQ()[3:] if name.isnumeric(): Send['sendGroupMsg'](sender.GroupId,MsgChain().joinPlain(Getfangfa(name))) else: Send['sendGroupMsg'](sender.GroupId,MsgChain().joinImg(Path=合成图片(Getname(name)))) except: ERROR('食谱查询异常')
def OnVOICE_JOIN_STATUS(self, data): '''连麦''' #因为未知bug,会重复推送 if self.VOICE_name != data['data']['user_name']: self.VOICE_name = data['data']['user_name'] self.SendMSG( MsgChain().joinPlain(f'直播间连麦,当前语音接入:{self.VOICE_name}'))
def OnWARNING(self, data): '''收到警告''' self.SendMSG(MsgChain().joinPlain(f'{self.roomid}收到警告\n{data}')) #保存房间被警告日志在弹幕表中 if self.info.get('savedanmu'): self.SQL.savedanmu( time.time() * 1000, #时间 'null', #用户名 'null', #用户uid str(data) #弹幕 )
def OnGUARD_BUY(self, data): '''舰队''' self.SendMSG(MsgChain().joinPlain( f'{self.info.get("showname",self.info.get("name"))}的舰队消息:{data["data"]["username"]}在本房间开通了{data["data"]["gift_name"]}*{data["data"]["num"]}' )) #保存舰队日志 if self.info.get('savegift'): d = data['data'] self.SQL.saveguard(d.get('timestamp', time.time() * 1000), d['username'], d['uid'], d['gift_name'], d['num'], d['price'])
def OnCUT_OFF(self, data): '''房间被切''' self.SendMSG(MsgChain().joinPlain(f'{data}')) #保存房间被切日志在弹幕表中 if self.info.get('savedanmu'): self.SQL.savedanmu( time.time() * 1000, #时间 'null', #用户名 'null', #用户uid str(data) #弹幕 )
def OnANCHOR_LOT_AWARD(self, data): '''天选时刻中间信息''' msg = MsgChain() msg.joinPlain(f'天选时刻中奖信息 [{data["data"]["id"]}]\n中奖用户:') users = [].copy() for user in data['data']['award_users']: users.append(user['uname'] + '[' + user['uid'] + ']') msg.joinPlain('、'.join(users) + f'\n中奖奖品:{data["data"]["award_name"]}') self.SendMSG(msg)
def on_GroupMessage(Message: MsgChain, sender: GroupInfo): if Message.GetCQ().startswith('./'): try: s = Message.GetCQ().split('/') if s[0] == '.' and len(s) >= 2 and is_number(s[1]): line = int(s[1]) try: m = s[2] except: m = 0 ll = bus.GETLinePIC(str(line), int(m)) l = None if len(ll) > 1: l = bus.pastepic(ll, int(m)) elif len(ll) == 1: l = ll[0] if l: Send['sendGroupMsg'](sender.GroupId, MsgChain().joinImg(Path=l)) else: Send['sendGroupMsg'](sender.GroupId, MsgChain().joinPlain('查询失败!')) except: ERROR('公交查询异常!')
def OnPREPARING(self, data): '''下播调用''' INFO( f'{self.roomid}[{self.info.get("showname",self.info.get("name"))}]收到下播推送' ) #self.SendMSG(f'你的小可爱{self.info.get("showname","None")}开播啦~\nhttps://live.bilibili.com/{self.roomid}') self.status = False self.SendMSG(MsgChain().joinPlain( f'你的小可爱{self.info.get("showname",self.info.get("name"))}下播啦~')) #保存下播日志在弹幕表中 if self.info.get('savedanmu'): self.SQL.savedanmu( time.time() * 1000, #时间 'null', #用户名 'null', #用户uid 'PREPARING' #弹幕 )
def OnGIFT(self, data): '''收到礼物''' gift_uname = data['data']['uname'] gift_num = data['data']['num'] gift_giftname = data['data']['giftName'] gift_price = data['data']['price'] gift_coin_type = data['data']['coin_type'] if int(gift_price ) >= 80000 and gift_coin_type == 'gold': #默认屏蔽80元以下的礼物和默认屏蔽银瓜子 self.SendMSG(MsgChain().joinPlain( f'你的小可爱{self.info.get("showname",self.info.get("name"))}收到礼物:{gift_giftname}*{gift_num} From {gift_uname}' )) #保存礼物日志 if self.info.get('savegift'): d = data['data'] self.SQL.savegift(d['timestamp'], d['uname'], d['uid'], d['giftName'], d['num'], d['price'], d['coin_type'])
def OnANCHOR_LOT_START(self, data): '''天选时刻抽奖开始''' msg = MsgChain() msg.joinPlain( f'天选时刻抽奖开始 [{data["data"]["id"]}]\n奖品:{data["data"]["award_name"]}*{data["data"]["award_num"]}' ) if data['data'].get('danmu'): msg.joinPlain(f'\n弹幕:{data["data"].get("danmu")}') if data['data'].get('gift_name'): msg.joinPlain(f'\n赠送礼物:{data["data"].get("gift_name")}') if data['data'].get('require_text'): msg.joinPlain(f'\n抽奖限制:{data["data"].get("require_text")}') if data['data'].get('award_image'): msg.joinImg(Url=data['data'].get('award_image')) self.SendMSG(msg)
def OnCHANGE(self, data): '''房间信息:修改标题,修改分区''' self.title = data['data']['title'] self.area = f'{data["data"]["area_name"]}·{data["data"]["parent_area_name"]}' INFO(f'{self.roomid}修改分区或标题 【{self.title}】 {self.area}') self.SendMSG(MsgChain().joinPlain(f'{self.title}\n{self.area}'))
class dy: def __init__(self, conf: dict): self.conf = conf self.sec_uid = conf['sec_uid'] self.name = conf['showname'] if not self.GetInfo(): '''secuid验证失败''' ERROR(f'{conf}:的sec_uid无效') self.vid = [].copy() def GetInfo(self): try: r = requests.get( 'https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid=' + self.sec_uid) if r.status_code == 200: j = r.json() if j['status_code'] == 0: self.name = j['user_info']['nickname'] return True return False except: ERROR(f'获取用户信息时发生异常') return False def Getaweme(self): '''获取作品列表''' url = 'https://www.iesdouyin.com/web/api/v2/aweme/post/?count=10&sec_uid=' + self.sec_uid try: r = requests.get(url) if r.status_code == 200: j = r.json() return j['aweme_list'] return [] except: ERROR(f'获取用户视频列表时发生异常') return [] def check(self): '''检查是否更新''' j = self.Getaweme() if not self.vid and len(j) != 1: for v in j: self.vid.append(v.get('video', {}).get('vid')) return False if j: for v in j: video = v.get('video', {}) vid = video.get('vid') if vid in self.vid: #当前视频在本地记录过,直接跳出循环既可 pass else: #未记录,表示为新视频 INFO(f'用户{self.conf.get("showname",self.name)}有新作品了') self.msg = MsgChain() self.msg.joinPlain( f'【抖音】{self.conf.get("showname",self.name)}更新视频啦~\n{v.get("desc")}' ) self.msg.joinImg(Url=video.get('origin_cover', {}).get( 'url_list', ['1'])[0]) self.msg.joinPlain( video.get('play_addr', {}).get('url_list', ['1'])[1]) self.video = MsgChain().joinVideo(Url=video.get( 'play_addr', {}).get('url_list', ['1'])[1]) self.vid.append(vid) return True return False
def LiveLoad(self) -> MsgChain: '''开播推送信息''' if self.Live == False: #为开播,不发送 ERROR("主播未开播,无法载入相关信息") return MsgChain() Msg = MsgChain() if self.user.get('ATall'): Msg.joinAT(-1) Msg.joinPlain(" \n") Msg.joinPlain( f'你的小可爱[{self.Name}]开播啦~\n{self.LiveInfo.get("title","")}\n{self.LiveInfo.get("type",{}).get("name","")}\nhttps://live.acfun.cn/live/{self.Uid}' ) Msg.joinImg(Url=self.LiveInfo.get('coverUrls', [""])[0]) return Msg
def DynamincLoad(self) -> MsgChain: '''载入将要推送的动态信息为MsgChain消息格式''' Msg = MsgChain() #判断一下是否有数据 if self.OldDynamic.get('resourceId') == None: ERROR("获取到的数据有问题,无法正常推送。") return Msg Type = self.OldDynamic.get('moment', {}).get('originResourceType') if self.user.get('ATall'): Msg.joinAT(-1) Msg.joinPlain(" \n") if not Type: Msg.joinPlain(f'你的小可爱{self.Name}发布一条新动态了哦,快来看看吧~\n') else: Msg.joinPlain(f'你的小可爱{self.Name}转发一条新动态了\n') Msg = Msg + self.DynamicOriginalLoad(self.OldDynamic) Msg.joinPlain('\n' + self.OldDynamic['shareUrl']) return Msg
def DynamicOriginalLoad(self, Dynamic) -> MsgChain: #将动态数据交给我解析,不要外部调用 Msg = MsgChain() #print(Dynamic['resourceType'] , Dynamic['tagResourceType']) if int(Dynamic['resourceType']) == 10 and int( Dynamic['tagResourceType']) == 3: #纯动态(原创、转发) moment = Dynamic['moment'] Msg.joinPlain(moment.get('replaceUbbText') ) #当为纯动态时,此条数据好像是必有的,动态的详细文本内容,无论是含图片动态还是转发动态,都会有的 if int(moment['originResourceType'] ) == 0: #originResourceType=0为原创,否则为转发 momentType = moment['momentType'] if int( momentType ) == 2: #2是含图片动态,1是纯文本内容。因为无论类型为1还是2文本都会存在,这里就只判断类型为2的时候取出图片了 for img in moment['imgs']: Msg.joinImg(Url=img['originUrl']) else: #为转发动态,将转发的内容repostSource再次解析,这里的套娃只有一次 Msg.joinPlain('\n------------------------------\n') #转发分割线 Msg = Msg + self.DynamicOriginalLoad(Dynamic['repostSource']) elif int(Dynamic['resourceType']) == 2 and int( Dynamic['tagResourceType']) == 2: #视频动态 Msg.joinPlain( f'{Dynamic["caption"]}\n{Dynamic["channel"]["parentName"]}·{Dynamic["channel"]["name"]}' ) Msg.joinImg(Url=Dynamic['coverUrl']) elif int(Dynamic['resourceType']) == 3 and int( Dynamic['tagResourceType']) == 1: #文章动态 #略略略 Msg.joinPlain( f'分类:{Dynamic["channel"]["parentName"]}·{Dynamic["channel"]["name"]}\n{Dynamic["articleTitle"]}\n{Dynamic["articleBody"]}' ) articleBodyImgsWithFormat = Dynamic.get( 'articleBodyImgsWithFormat') if len(articleBodyImgsWithFormat) > 0: for imgs in articleBodyImgsWithFormat: if imgs['size'] > 2000000: #当图片大于2M时选择发送压缩后的图,否则发送原图 Msg.joinImg(Url=imgs['expandedUrl']) else: Msg.joinImg(Url=imgs['originUrl']) #当都不符合要求是,看来又他妈的出现新的动态类型 return Msg
def VideoLoad(self) -> MsgChain: '''载入将要推送的视频信息为MsgChain消息格式''' Msg = MsgChain() if self.user.get('ATall'): Msg.joinAT(-1) Msg.joinPlain(" \n") times = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(float( int(self.OldVideo['createTimeMillis']) / 1000))) tags = [] for tag in self.OldVideo['tagList']: tags.append(f'#{tag["name"]}#') Msg.joinPlain( f'你的小可爱{self.Name}有新作品了哦,快来看看吧~\n{self.OldVideo["title"]}\n{self.OldVideo["channel"]["parentName"]}·{self.OldVideo["channel"]["name"]} {times}' ) Msg.joinImg(Url=self.OldVideo['coverUrl']) Msg.joinPlain( f'{self.OldVideo["description"]}\n{" ".join(tags)}\n{self.OldVideo["shareUrl"]}' ) return Msg