async def search(keyword, result_num: int = 3): """ 搜索音乐 """ number = 5 song_list = [] params = {"w": keyword, "format": "json", "p": 0, "n": number} headers = {"referer": "http://m.y.qq.com", "User-Agent": USER_AGENT} try: resp = await aiorequests.get( url="http://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp", params=params, headers=headers, timeout=3) res_data = await resp.json() except Exception as e: logger.warning(f'Request QQ Music Timeout {e}') return None try: for item in res_data['data']['song']['list'][:result_num]: song_list.append({ 'name': item['songname'], 'id': item['songid'], 'artists': ' '.join(artist['name'] for artist in item['singer']), 'type': 'qq' }) return song_list except KeyError as e: logger.warning(f'No Result: {e}') return None
def gen_name2id(): NAME2ID.clear() for k, v in priconne_data._PriconneData.CHARA.items(): for s in v: if s not in NAME2ID: NAME2ID[normname(s)] = k else: logger.warning( f'Chara.__gen_name2id: 出现重名{s}于id{k}与id{NAME2ID[s]}')
async def search(keyword, result_num: int = 3): """ 搜索音乐 """ song_list = [] # ?rows=20&type=2&keyword=稻香&pgc=1 headers = { "referer": "https://m.music.migu.cn/v3", "User-Agent": USER_AGENT } try: resp = await aiorequests.get( url= f"https://m.music.migu.cn/migu/remoting/scr_search_tag?rows=20&type=2&keyword={keyword}&pgc=1", headers=headers, timeout=3) res_data = await resp.json() except Exception as e: logger.warning(f'Request Migu Music Timeout {e}') return None try: for item in res_data['musics'][:result_num]: song_list.append({ 'url': 'https://music.migu.cn/v3/music/song/' + item['copyrightId'], 'purl': item['mp3'], 'image': item['cover'], 'title': item['songName'], 'content': item['singerName'], 'name': item['songName'], 'artists': item['singerName'], 'type': 'custom', 'subtype': 'migu' }) return song_list except KeyError as e: logger.warning(f'No Results: {e}') return None
async def reload_pcrdata(): try: dataget = await aiorequests.get( 'http://api.akiraxie.me/pcr/priconne_data.py', timeout=5) datacon = await dataget.content except Exception as e: logger.error(f'连接服务器失败. {type(e)}') logger.exception(e) return 1 if 200 != dataget.status_code: logger.warning('连接服务器失败') return 1 with open(pcrdatapath, 'wb') as f: f.write(datacon) f.close() reload_data() logger.info('更新角色数据成功') return 0
def init(): logger.info(f'Initializing Database...') if TESTING_MODE: logger.warning("PAY ATTENTION!NOW UNDER TESTING MODE!") for db in BaseDatabase.__subclasses__(): try: db_name = db.__name__ db.bind(database(db_name)) if skip_database_initialize: continue database(db_name).connect() if not db.table_exists(): database(db_name).create_tables([db]) logger.info(f'Table <{db_name}> not exists, will be created in database <{get_database(db_name)}>.') database(db_name).close() except Exception as e: traceback.print_exc() logger.critical(f'Error <{e}> encountered while initializing database <{get_database(db_name)}>.')
async def reload_config(): try: dataget = await aiorequests.get( 'http://api.akiraxie.me/pcr/config.json', timeout=5) datacon = await dataget.content except Exception as e: logger.error(f'连接服务器失败. {type(e)}') logger.exception(e) return 1 if 200 != dataget.status_code: logger.warning('连接服务器失败') return 1 with open(jsonpath, 'wb') as f: f.write(datacon) f.close() importlib.reload(priconne_data) gen_name2id() logger.info('更新卡池配置成功') return 0
async def search(keyword, result_num: int = 3): """ 搜索音乐 """ number = 5 song_list = [] params = {"w": keyword, "format": "json", "p": "1", "n": number} headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset": "UTF-8,*;q=0.5", "Accept-Encoding": "gzip,deflate,sdch", "Accept-Language": "en-US,en;q=0.8", "referer": "http://m.y.qq.com", "User-Agent": USER_AGENT } try: resp = await aiorequests.get( url="https://c.y.qq.com/soso/fcgi-bin/client_search_cp", params=params, headers=headers, timeout=3) res_data = await resp.json() except Exception as e: logger.warning(f'Request QQ Music Timeout {e}') return None try: for item in res_data['data']['song']['list'][:result_num]: song_list.append({ 'name': item['songname'], 'id': item['songid'], 'artists': ' '.join(artist['name'] for artist in item['singer']), 'type': 'qq' }) return song_list except KeyError as e: logger.warning(f'No Result: {e}') return None
async def search(keyword: str, result_num: int = 3): n = NetEase() song_list = [] data = await n.search(keyword) if data and data['code'] == 200: try: for item in data['result']['songs'][:result_num]: song_list.append({ 'name': item['name'], 'id': item['id'], 'artists': ' '.join([artist['name'] for artist in item['artists']]), 'type': '163' }) return song_list except Exception as e: logger.warning(f'获取网易云歌曲失败, 返回数据data={data}, 错误信息error={e}') return song_list
from hoshino import R, logger ImageFile.LOAD_TRUNCATED_IMAGES = True session = requests.session() apikey = '435221525ed48358ebab15' _setu_quene_file = os.path.expanduser('~/.hoshino/setu_quene_config.json') _setu_list = [] try: with open(_setu_quene_file, encoding='utf8') as f: _setu_list = json.load(f) logger.info( f'initial {len(_setu_list)} setu is put into the setu list') except FileNotFoundError as e: logger.warning( 'setu_quene_config.json not found, will create when needed.') def dump_setu_config(): with open(_setu_quene_file, 'w', encoding='utf8') as f: json.dump(_setu_list, f, ensure_ascii=False) def get_setu(): url = 'https://api.lolicon.app/setu/' params = {'apikey': apikey, 'r18': 0, 'num': 5, 'size1200': True} try: r = session.get(url=url, params=params, timeout=10) except (requests.exceptions.RequestException) as e: logger.error(f'[lolicon.app connect failed]{e}') return []
sv = Service("custom_reply", manage_priv=SUPERUSER, enable_on_default=True, visible=True) custom_reply = {} # do not edit it, edit it in the json instead customReply = os.path.expanduser("~/.hoshino/customReply.json") try: with open(customReply, "r", encoding="UTF-8") as json_file: custom_reply = ujson.load(json_file) if not custom_reply.get("global"): custom_reply["global"] = {} except FileNotFoundError: if not custom_reply.get("global"): custom_reply["global"] = {} logger.warning("customReply.json not found, will create when needed.") @sv.on_message() async def migang_reply(bot, ev): msg = str(ev.message) group_id = str(ev.group_id) if custom_reply.get(group_id) and custom_reply.get(group_id).get(msg): await bot.send( ev, custom_reply.get(group_id)[msg]["content"], at_sender=custom_reply.get(group_id)[msg]["at_sender"], ) elif custom_reply["global"].get(msg): await bot.send( ev,
''' Database for arena likes & dislikes DB is a dict like: { 'md5_id': {'like': set(qq), 'dislike': set(qq)} } ''' DB_PATH = os.path.expanduser('~/.hoshino/arena_db.json') DB = {} try: with open(DB_PATH, encoding='utf8') as f: DB = json.load(f) for k in DB: DB[k] = { 'like': set(DB[k].get('like', set())), 'dislike': set(DB[k].get('dislike', set())) } except FileNotFoundError: logger.warning(f'arena_db.json not found, will create when needed.') def dump_db(): ''' Dump the arena databese. json do not accept set object, this function will help to convert. ''' j = {} for k in DB: j[k] = { 'like': list(DB[k].get('like', set())), 'dislike': list(DB[k].get('dislike', set())) } with open(DB_PATH, 'w', encoding='utf8') as f: json.dump(j, f, ensure_ascii=False)