def localSetu(self): if self.config['count'] == sum( self.getCountList): # 如果上面的api已经获取了足够的数量 return res = database.LocalSetu.getSetu(self.ctx.QQG, self.config['setuLevel'], self.config['count'], self.tags) for data in res: if database.Setu.ifSent(self.config['callid'], data['original'], self.config['refreshSent']): # 判断是否发送过 continue msg = self.build_msg(data['title'], data['artwork'], data['author'], data['artist'], data['page'], self.replaceLink(data['original'])) # 组装消息 if self.config['original']: # 是否发送原图 send.picture( self.ctx, msg, self.replaceLink(data['original']) if config.proxy else data['original'], False, self.config['at']) else: send.picture( self.ctx, msg, self.replaceLink(data['large']) if config.proxy else data['large'], False, self.config['at']) self.getCountList[0] += 1 logger.info('从本地数据库获取到{}张关于{}的setu 实际发送{}张'.format( len(res), self.tags, self.getCountList[0])) # 打印获取到多少条
def processing_and_inspect(self): # 处理消息+调用 # ----------------------------------------------- if self.SetuCount != '': # 如果指定了数量 try: self.config['count'] = int(self.SetuCount) except: # 出错就说明不是数字 send.text(self.ctx, self.config['msg_inputError'], self.config['at_warning']) return if self.config['count'] <= 0: # ????? send.text(self.ctx, self.config['msg_lessThan0'], self.config['at_warning']) return else: # 未指定默认1 self.config['count'] = 1 # ----------------------------------------------- if self.config['type'] in ['group', 'temp']: # 群聊和临时会话 if not self.config['setu']: # 如果没开启色图 send.text(self.ctx, self.config['msg_setuClosed'], self.config['at_warning']) return if self.config['count'] > self.config['maxnum']: # 大于单次最大数量 send.text(self.ctx, self.config['msg_tooMuch'], self.config['at_warning']) return if self.r18Keyword != '': # 正则匹配到开启r18的关键字 if self.config['r18']: # 开启了r18 self.config['setuLevel'] = 2 else: send.text(self.ctx, self.config['msg_r18Closed'], self.config['at_warning']) return if self.freq(): # 频率控制,仅群聊和临时会话 return elif self.config['type'] == 'friend': if self.r18Keyword != '': # 好友会话无限制 self.config['setuLevel'] = 2 self.send()
def main(self): logger.info('解析Pixiv:{}'.format(self.msg)) raw_info = re.match(r'.*pixiv.net/artworks/(.*)', self.msg) info_list = raw_info[1].split() if len(info_list) > 2: pass return elif len(info_list) == 1: try: pid = int(info_list[0]) page = 0 except: return elif len(info_list) == 2: try: pid = int(info_list[0]) page = int(re.match('p(\d+)', info_list[1])[1]) except: return else: return if data := self.getSetuInfo(pid): # print(self.buildMsg(data, page)) if picurl := self.choosePicUrl(data['body']['illust_details'], page): pic_base64 = self.pictureProcess(picurl[1]) msg = self.buildMsg( data['body']['illust_details']['title'], data['body'] ['illust_details']['author_details']['user_name'], data['body']['illust_details']['user_id'], page, picurl[0].replace('i.pximg.net', 'i.pixiv.cat')) send.picture(self.ctx, msg, '', False, False, pic_base64)
def api_0(self): if not config.api_yuban10703: return if self.config['count'] == sum(self.getCountList): # 如果上面的api已经获取了足够的数量 return url = 'http://api.yuban10703.xyz:2333/setu_v4' params = {'level': self.config['setuLevel'], 'num': self.config['count'] - sum(self.getCountList), 'tag': self.tags} if self.config['count'] > 10: # api限制不能大于10 params['num'] = 10 try: res = requests.get(url, params, timeout=5) setu_data = res.json() except Exception as e: logger.warning('api0 boom~ :{}'.format(e)) else: if res.status_code == 200: for data in setu_data['data']: if database.Setu.ifSent(self.config['callid'], data['original'], self.config['refreshSent']): # 判断是否发送过 continue url_original = self.replaceLink(data['original']) if config.proxy else data['original'] # 原图链接 url_large = self.replaceLink(data['large']) if config.proxy else data['large'] # 高清链接 msg = self.build_msg(data['title'], data['artwork'], data['author'], data['artist'], data['page'], self.replaceLink(data['original'])) # 组装消息 if self.config['original']: # 是否发送原图 send.picture(self.ctx, msg, url_original, False, self.config['at']) else: send.picture(self.ctx, msg, url_large.replace('600x1200_90_webp', '600x1200_90'), False, self.config['at']) self.getCountList[1] += 1 logger.info( '从yubanのapi获取到{}张关于{}的setu 实际发送{}张'.format(setu_data['count'], self.tags, self.getCountList[1])) # 打印获取到多少条
def receive_group_msg(ctx: GroupMsg): if delay := re.findall(r'REVOKE\[(\d+)]', ctx.Content): if delay: delay = min(int(delay[0]), 90) else: delay = random.randint(30, 60) time.sleep(delay) send.revoke(ctx)
def api_1(self): if not config.api_lolicon: return if self.config['count'] == sum( self.getCountList): # 如果上面的api已经获取了足够的数量 return # 兼容api0 if self.config['setuLevel'] == 1: r18 = 0 elif self.config['setuLevel'] == 3: r18 = 2 elif self.config['setuLevel'] == 2: r18 = 1 else: r18 = 0 url = 'https://api.lolicon.app/setu' params = { 'r18': r18, 'apikey': config.loliconApiKey, 'num': self.config['count'] - sum(self.getCountList), 'size1200': not bool(self.config['original']) } if self.config['count'] > 10: params['num'] = 10 if len(self.tags) != 1 or ( len(self.tags[0]) != 0 and not self.tags[0].isspace()): # 如果tag不为空(字符串字数不为零且不为空) params['keyword'] = self.tags if not config.proxy: # 不开启反代 params['proxy'] = 'disable' try: with requests.session() as s: res = s.get(url, params=params, timeout=8) setu_data = res.json() except Exception as e: logger.warning('api1 boom~ :{}'.format(e)) else: if res.status_code == 200: for data in setu_data['data']: if database.Setu.ifSent( self.config['callid'], data['url'], self.config['refreshSent']): # 判断是否发送过 continue msg = self.build_msg( data['title'], data['pid'], data['author'], data['uid'], data['p'], 'https://i.pixiv.cat/img-original/img/{}'.format( re.findall('img/(.*)', data['url'])[0].replace( '_master1200', ''))) send.picture(self.ctx, msg, data['url'], False, self.config['at']) self.getCountList[2] += 1 logger.info('从loliconのapi获取到{}张关于{}的setu 实际发送{}张'.format( setu_data['count'], self.tags, self.getCountList[2])) # 打印获取到多少条 else: logger.warning('api1:{}'.format(res.status_code))
def freq(self): if freqinfo := database.Setu.freq(self.ctx.QQG, self.config['count'], self.config['refreshTime'], self.config['freq']): msg = self.config['msg_frequency'].format( time=self.config['refreshTime'], num=self.config['freq'], num_call=freqinfo[0], r_time=round(self.config['refreshTime'] - (time.time() - freqinfo[1])) ) send.text(self.ctx, msg, self.config['at_warning']) return True
def api_pixiv(self): # p站热度榜 if not config.api_pixiv: return if self.config['count'] == sum( self.getCountList): # 如果上面的api已经获取了足够的数量 return # 兼容api0 if self.config['setuLevel'] == 1: r18 = 0 elif self.config['setuLevel'] == 3: r18 = random.choice([0, 1]) elif self.config['setuLevel'] == 2: r18 = 1 else: r18 = 0 data = pixiv.pixivSearch(self.tags, bool(r18)) for setu in data['illusts']: if sum(self.getCountList) == self.config['count']: break if setu['page_count'] != 1: # 多页画廊 continue if setu['x_restrict'] == 2: # R18G continue if self.config['setuLevel'] in [ 0, 1 ] and setu['x_restrict'] == 1: # R18 continue if database.Setu.ifSent( self.config['callid'], setu['meta_single_page']['original_image_url'], self.config['refreshSent']): continue url_original = self.replaceLink(setu['meta_single_page']['original_image_url']) if config.proxy else \ setu['meta_single_page']['original_image_url'] # 原图链接 url_large = self.replaceLink( setu['image_urls']['large'] ) if config.proxy else setu['image_urls']['large'] # 高清链接 msg = self.build_msg( setu['title'], setu['id'], setu['user']['name'], setu['user']['id'], 1, self.replaceLink( setu['meta_single_page']['original_image_url'])) if self.config['original']: # 原图 send.picture(self.ctx, msg, url_original, False, self.config['at']) else: url_large.replace('600x1200_90_webp', '600x1200_90') # 更换为非webp的链接 send.picture(self.ctx, msg, url_large, False, self.config['at']) self.getCountList[3] += 1 logger.info('从Pixiv热度榜获取到{}张setu 实际发送{}张'.format( len(data['illusts']), self.getCountList[3])) # 打印获取到多少条
def main(self): content = json.loads(self.ctx.Content) if content['Tips'] == '[群图片]': picurl = content['GroupPic'][0]['Url'] # elif content['Tips'] == '[好友图片]': # picurl = content['FriendPic'][0]['Url'] else: return if res := self.saucenao(picurl): msg = self.buildmsg(res['results'][0]) send.picture(self.ctx, msg, res['results'][0]['header']['thumbnail']) return
def send(self): apis = [self.localSetu, self.api_0] func = random.choice(apis) apis.remove(func) func() apis[0]() if len(self.tags) in [0, 1]: # api1不支持多tag self.api_1() if len(self.tags) != 0: self.api_pixiv() if sum(self.getCountList) == 0: send.text(self.ctx, self.config['msg_notFind'], self.config['at_warning']) return elif sum(self.getCountList) < self.config['count']: send.text(self.ctx, self.config['msg_insufficient'].format( tag=self.tags, num=sum(self.getCountList) ), self.config['at_warning'])
def main(self): if self.count > 10: send.text(self.ctx, '不能>10') return for i in range(self.count): self.userconf['allCount'] += 1 self.userconf['farFiveStarFloors'] -= 1 self.userconf['farFourStarFloors'] -= 1 if self.userconf['farFiveStarFloors'] <= 0: # 5星保底 # print('5星保底') self.userconf['farFiveStarFloors'] = self.config['fiveStarFloorsCount'] self.floors(('Five', 'five', '5')) continue if self.userconf['farFourStarFloors'] <= 0: # 4星保底 # print('4星保底') self.userconf['farFourStarFloors'] = self.config['fourStarFloorsCount'] random.choices([lambda: self.floors(('Four', 'four', '4')), lambda: self.floors(('Four', 'four', '4'))], [self.config['fourStarFloorsProbability']['fourStar'], self.config['fourStarFloorsProbability']['fiveStar']])[0]() continue res = random.choices([5, 4, 3], [ self.config['probability']['fiveStarRole'] + self.config['probability']['fiveStarArms'], self.config['probability']['fourStarRole'] + self.config['probability']['fourStarArms'], 100 - self.config['probability']['fiveStarRole'] + self.config['probability']['fiveStarArms'] + self.config['probability']['fourStarRole'] + self.config['probability']['fourStarArms'] ])[0] # print('抽到{}星'.format(res)) if res == 3: # 3星 # self.articleList.append(random.choice(os.listdir('./config/yuanShenPools/arms_3'))) self.articleList.append( random.choice([str(i) for i in Path('./config/yuanShenPools/arms_3').rglob('*.png')])) elif res == 4: self.floors(('Four', 'four', '4')) else: # 5星 self.floors(('Five', 'five', '5')) database.Lottery.updateUserinfo(self.qq, self.pool, self.userconf) # print(self.userconf) # print(self.articleList) random.shuffle(self.articleList) pic_base64 = self.draw() send.picture(self.ctx, '', '', '', False, pic_base64)
def delsetu(self, pid: int, groupid: int, page: int = None): if database.LocalSetu.delSetu(pid, groupid, page): if page == None: send.text(self.ctx, '已删除pid{}的所有p'.format(pid)) else: send.text(self.ctx, '已删除pid{}的p{}'.format(pid, page)) else: send.text(self.ctx, '不存在pid:{}的setu'.format(pid))
def addsetu(self, pid, groupid, level, page=None): data = self.getSetuInfo(pid) if page != None: try: database.LocalSetu.addSetu(data[page], level, groupid) except: send.text(self.ctx, 'page错误????') return send.text(self.ctx, 'addsetu:\npid:{} p{} \n{}'.format(data[page]['artwork'], data[page]['page'], data[page]['original'].replace('i.pximg.net', 'i.pixiv.cat'))) else: msg = 'addsetu:\npid:{}\n'.format(data[0]['artwork']) for d in data: database.LocalSetu.addSetu(d, level, groupid) msg += 'p{}\n{}\n'.format(d['page'], d['original'].replace('i.pximg.net', 'i.pixiv.cat')) send.text(self.ctx, msg)
def receive_group_msg(ctx): send.text(ctx, Sysinfo.allInfo())
return else: return if data := self.getSetuInfo(pid): # print(self.buildMsg(data, page)) if picurl := self.choosePicUrl(data['body']['illust_details'], page): pic_base64 = self.pictureProcess(picurl[1]) msg = self.buildMsg( data['body']['illust_details']['title'], data['body'] ['illust_details']['author_details']['user_name'], data['body']['illust_details']['user_id'], page, picurl[0].replace('i.pximg.net', 'i.pixiv.cat')) send.picture(self.ctx, msg, '', False, False, pic_base64) else: send.text(self.ctx, '{}无P{}~'.format(pid, page)) re_expression = r'.*pixiv.net/artworks/.*' @deco.ignore_botself @deco.with_pattern(re_expression) def receive_group_msg(ctx: GroupMsg): PixivResolve(ctx).main() @deco.ignore_botself @deco.with_pattern(re_expression) def receive_friend_msg(ctx: FriendMsg): PixivResolve(ctx).main()
def receive_friend_msg(ctx): send.text(ctx, Sysinfo.allInfo())
def group_or_temp(self): # 读数据库+鉴权+判断开关 if self.ctx.__class__.__name__ == 'GroupMsg': # 群聊 self.config['type'] = 'group' self.config['callqq'] = self.ctx.FromUserId self.config['callid'] = self.ctx.FromGroupId elif self.ctx.MsgType == 'TempSessionMsg': # 临时会话 self.config['callqq'] = self.ctx.FromUin self.config['callid'] = self.ctx.TempUin self.config['type'] = 'temp' if data := database.Setu.getGroupConf(self.ctx.QQG, self.ctx.type): # 查询group数据库数据 self.config.update(data) self.processing_and_inspect() else: send.text(self.ctx, '数据库无群:{}信息,请联系管理员~'.format(self.config['callid'])) logger.error('数据库无群:{} 信息'.format(self.config['callid'])) return def friend(self): self.config['type'] = 'friend' self.config['callqq'] = self.ctx.FromUin self.config['callid'] = self.ctx.FromUin self.config.update(database.Setu.getUserconf(self.ctx.QQ)) # 载入自定义数据 self.processing_and_inspect() def main(self): # 判断消息类型给对应函数处理 if self.ctx.type == 'friend': # 好友会话 self.friend() else: # 群聊or临时会话 self.group_or_temp()