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') rq = time.strftime('%H-%M-%S', time.localtime(time.time())) savePath = Path(common.getRunningPath()) / 'debug' / 'live' / msg[ 'type'] / f'{upname}-{msg["type"]}-{rq}-{int(time.mktime(time.localtime(time.time())))}.json' savePath = str(savePath) logger.info(f'保存了一条{upname}的{msg["type"]}消息') common.saveConfig(msg, savePath, logger=logger)
def sendMsg(rid, msg): upinfo = cache(user.get_user_info, cache(live.get_room_play_info, rid, verify=None).get('uid')) upname = upinfo.get('name') danmu = Danmaku(text=str(msg), mode=1) try: live.send_danmaku(rid, danmaku=danmu, verify=verify) except exceptions.BilibiliException as e: logger.error(f'{upname}的直播间--' + msg + f'--{str(e)}') else: logger.info(f'{upname}的直播间--' + msg + '--已发送')
def load_cached(cache_path, in_dir): """ Wrapper-function for creating a DataSet-object, which will be loaded from a cache-file if it already exists, otherwise a new object will be created and saved to the cache-file. This is useful if you need to ensure the ordering of the filenames is consistent every time you load the data-set, for example if you use the DataSet-object in combination with Transfer Values saved to another cache-file, see e.g. Tutorial #09 for an example of this. :param cache_path: File-path for the cache-file. :param in_dir: Root-dir for the files in the data-set. This is an argument for the DataSet-init function. :return: The DataSet-object. """ print("Creating dataset from the files in: " + in_dir) # If the object-instance for DataSet(in_dir=data_dir) already # exists in the cache-file then reload it, otherwise create # an object instance and save it to the cache-file for next time. dataset = cache(cache_path=cache_path, fn=DataSet, in_dir=in_dir) return dataset ########################################################################
async def sendMsg(): if config.get('disable', False): return lastSend = time.time() interval = config.get('reply_interval', 2) while True: MSG = await msgQueue.get() rid = MSG[0] msg = MSG[1] now = time.time() if now - lastSend < interval: await asyncio.sleep(interval) lastSend = time.time() upinfo = cache( user.get_user_info, cache(live.get_room_play_info, rid, verify=None).get('uid')) upname = upinfo.get('name') danmu = Danmaku(text=str(msg), mode=1) live.send_danmaku(rid, danmaku=danmu, verify=verify) logger.info(f'{upname}的直播间--' + msg + '--已发送') msgQueue.task_done()
config = ConfigParser() config.read("config.ini") t = config["Main"]["Token"] config_channels = config["Channels"] if "key" not in config["Main"]: key = Fernet.generate_key() config["Main"]["key"] = str(key) with open("cache.json", "wb") as cachefile: cachefile.write(Fernet(key).encrypt(b"{}")) with open("config.ini", "w") as configfile: config.write(configfile) cache_key_str = config["Main"]["key"][2:-1] cache_key_bytes = str.encode(cache_key_str) cache = cache(cache_key_bytes) # Define random variables BOT_PREFIX = "-" before = monotonic() NoneType = type(None) to_enabled = {True: "Enabled", False: "Disabled"} with open("langs.json") as lang_file: tts_langs = json.load(lang_file) if exists("activity.txt"): with open("activity.txt") as f2, open("activitytype.txt") as f3, open( "status.txt") as f4: activity = f2.read() activitytype = f3.read()
user=config["PostgreSQL Info"]["name"], database=config["PostgreSQL Info"]["db"], password=config["PostgreSQL Info"]["pass"] ) ) bot.queue = dict() bot.channels = dict() bot.should_return = dict() bot.message_locks = dict() bot.currently_playing = dict() bot.session = ClientSession() bot.settings = settings.settings_class(pool) bot.setlangs = settings.setlangs_class(pool) bot.nicknames = settings.nickname_class(pool) bot.cache = cache.cache(cache_key_bytes, pool) bot.blocked_users = settings.blocked_users_class(pool) bot.trusted = basic.remove_chars(config["Main"]["trusted_ids"], "[", "]", "'").split(", ") for cog in listdir("cogs"): if cog.endswith(".py"): bot.load_extension(f"cogs.{cog[:-3]}") print(f"Successfully loaded: {cog}") @bot.event async def on_ready(): await bot.wait_until_ready() support_server_id = int(config["Main"]["main_server"]) bot.supportserver = bot.get_guild(support_server_id)