def batchSend(): global _IMAGE_LIST_CACHE _IMAGE_LIST_CACHE = None logger.debug("Begin to start daily greeting") groupsList = [i["group_id"] for i in callModuleAPI("get_group_list")] successSend = 0 for groupID in groupsList: enabled = PluginManager._getSettings(__plugin_name__, type="group", id=groupID).status if not enabled: continue try: callModuleAPI( "send_msg", params={ "group_id": groupID, "message": timeTelling() }, ) except Exception: eid = ExceptionProcess.catch() logger.exception( f"Failed to greeting in group {groupID},traceback id:{eid}") else: successSend += 1 logger.info( f"Daily greeting finished,total send:{len(groupsList)},success:{successSend}" )
def wrapper(*args, **kwargs): try: return function(*args, **kwargs) except (KeyError, AttributeError): raise BotProgramError( reason="处理RSS订阅数据失败:缺失关键数据", trace=ExceptionProcess.catch() )
def catch(session: CommandSession): stackID: str = session.get("id") returnData = """ 追踪ID:{stack_id} 出错时间:{time_format}(时间戳{time}) 错误堆栈:\n{stack}""".format(**ExceptionProcess.read(stackID.upper())) return returnData
def recordChat(session: NLPSession): content = extract_text(session.ctx["message"]) ctx = session.ctx.copy() sender = session.ctx["user_id"] group = session.ctx.get("group_id") data = models.RecordsCreate(sender=sender, group=group, content=content, ctx=ctx) try: result = DatabaseIO.recordCreate(data) except Exception as e: traceID = ExceptionProcess.catch() logger.warning( f"Chat record {data} failed to storage due to {e} (Traceback ID:{traceID})." ) else: logger.debug( f"Chat record {result} has been storaged to database successfully." )
def rssParser(feed: str) -> dict: """Functions for handling RSS pushes Parameters ---------- feed : str Downloaded RSS file content Returns ------- dict A dictionary containing RSS information Raises ------ BotProgramError Thrown when RSS processing fails """ try: parsedData: FeedParserDict = parseFeed(feed) if parsedData.get("bozo") != 0: raise parsedData["bozo_exception"] except Exception: traceID = ExceptionProcess.catch() raise BotProgramError(reason="处理RSS订阅数据失败", trace=traceID) logger.debug(f"The RSS feed information is as follows: {str(parsedData)[:100]}...") feedInfo: dict = parsedData.feed returnInfo = { "title": feedInfo["title"], "subtitle": feedInfo.get("subtitle"), "link": feedInfo.get("link"), "last_update": feedInfo.get("updated"), "last_update_stamp": _parseTime(feedInfo.get("updated_parsed")), "published": feedInfo.get("published"), "published_stamp": _parseTime(feedInfo.get("published_parsed")), "version": parsedData.get("version"), "token": _generateToken(feedInfo["link"]), } feedContent: dict feedContents = [ { "title": feedContent["title"], "link": feedContent["link"], "id": feedContent.get("id"), "published": feedContent.get("published"), "published_stamp": _parseTime(feedContent.get("published_parsed")), "author": feedContent.get("author"), "all_author": "/".join(i["name"] for i in feedContent.get("authors", [])), "summary": feedContent.get("summary"), } for feedContent in parsedData.entries ] feedContents.sort(key=lambda x: x["published_stamp"], reverse=True) returnInfo.update({"content": feedContents, "size": len(feedContents)}) return returnInfo