# Stocking. Dec 4, 2019 from utils.common import getLogger logger = getLogger('stocking')
#coding: utf-8 import sys,os from utils import common if __name__ == "__main__": print sys.path filename = os.path.abspath(__file__) print os.path.dirname(filename) print os.path.realpath('aa') filename = os.path.abspath(__file__) dirname = os.path.dirname(filename) utils = os.path.join(dirname,'utils') sys.path.insert(0,utils) print 'utils',utils logger = common.getLogger('sender') logger.debug('debug...') logger.warn('warnning...') logger.error('error!!!') logger.critical('critical...')
import modules, re, time import asyncio from .container import Queue, TTLCheck from utils import common, exceptions from utils.cache import cachedRun as cache from bilibili_api import Verify, user, live, Danmaku from pathlib import Path logger = common.getLogger('live') cfgPath = common.getRunningPath(False) / 'config' / 'live_reply.json' config = common.loadConfig(cfgPath, logger) # if config.get('disable', False): raise exceptions.PluginExit('reply', '直播回复') if config.get('disable', False): logger.warning('直播弹幕回复模块已禁用') conf = {} verify = common.getVerify() bot_uid = user.get_self_info(verify=verify).get('mid') msgCheck = TTLCheck(ttl=5) msgQueue = Queue(maxsize=128) @modules.live.receiver('reply', 'DANMU_MSG') async def on_danmu(msg): if config.get('disable', False): return rid = msg['room_display_id'] info = msg['data']['info'] if info[2][0] == bot_uid: logger.debug('检测到自己的消息,已忽略') return text = info[1] logger.debug(f'收到{rid}房间的弹幕——{text}')
import modules, time from pathlib import Path from utils import common, exceptions from bilibili_api import live, user, Verify from utils.cache import cachedRun as cache logger = common.getLogger('live_debug') @modules.live.receiver('debug', 'ALL') async def on_all(msg): Filter = [ 'ROOM_REAL_TIME_MESSAGE_UPDATE', 'DANMU_MSG', 'COMBO_SEND', 'ROOM_BANNER', 'SEND_GIFT', 'WELCOME', 'INTERACT_WORD', 'VIEW', 'ENTRY_EFFECT', 'NOTICE_MSG', 'PANEL', 'USER_TOAST_MSG', 'ONLINERANK', 'ROOM_RANK', 'WELCOME_GUARD', 'ACTIVITY_BANNER_UPDATE_V2' ] path = Path(common.getRunningPath()) / 'debug' / 'live' / msg['type'] if path.exists(): if msg['type'] in Filter: return if msg['type'] == 'SEND_GIFT' and msg['data']['data'][ 'coin_type'] == 'silver': return if msg['type'] == 'SEND_GIFT' and msg['data']['data'][ 'total_coin'] < 10000: return upinfo = cache( user.get_user_info, cache(live.get_room_play_info, msg['room_display_id'], verify=None).get('uid')) upname = upinfo.get('name')
import importlib, asyncio from pathlib import Path from utils import exceptions, common logger = common.getLogger('bot') async def load_modules(): modules = [] module_dir = Path(__file__).parent module_prefix = module_dir.name for module in module_dir.iterdir(): if module.is_dir() \ and not module.name.startswith('_') \ and module.joinpath('__init__.py').exists() \ and not module.joinpath('.disable').exists(): logger.info(f'加载{module.name}模块') run = importlib.import_module(f'{module_prefix}.{module.name}') modules.append(run.main()) if not modules: logger.warning('无可用模块') return await asyncio.gather(*modules)