def save_freshman(identifier: ID) -> bool: """ Save freshman ID in a text file for the robot file path: '.dim/freshmen.txt' """ path = os.path.join(Storage.root, 'freshmen.txt') # check text = Storage.read_text(path=path) if text is None: lines = [] else: lines = text.splitlines() for item in lines: if item == identifier: # already exists return False # append line = str(identifier) + '\n' Storage.info('Saving freshman: %s' % identifier) return Storage.append_text(text=line, path=path)
def load_freshmen() -> List[ID]: freshmen = [] text = Storage.read_text(path=freshmen_file) if text is None: return freshmen array = text.splitlines() for item in array: identifier = ID.parse(identifier=item) if identifier is None: Log.error('ID error: %s' % item) elif identifier.type == NetworkType.MAIN: freshmen.append(identifier) else: # Log.error('Not a user ID: %s' % identifier) pass return freshmen
def load_freshmen() -> list: text = Storage.read_text(freshmen_file) if text is not None: return text.splitlines()
def load_robot_info(identifier: ID, filename: str) -> dict: return Storage.read_json(path=os.path.join(etc, identifier.address, filename))
Chat Bots Configuration ~~~~~~~~~~~~~~~~~~~~~~~ Secret keys for AI chat bots """ import os from dimp import ID from libs.common import Storage etc = os.path.abspath(os.path.dirname(__file__)) # chat bot: Tuling tuling_keys = Storage.read_json(path=os.path.join(etc, 'tuling', 'secret.js')) tuling_ignores = [4003] # chat bot XiaoI xiaoi_keys = Storage.read_json(path=os.path.join(etc, 'xiaoi', 'secret.js')) xiaoi_ignores = ['默认回复', '重复回复'] # # DIM chat bots # lingling_id = 'lingling@2PemMVAvxpuVZw2SYwwo11iBBEBb7gCvDHa' xiaoxiao_id = 'xiaoxiao@2PhVByg7PhEtYPNzW5ALk9ygf6wop1gTccp'
def load_station_info(identifier: ID, filename: str): return Storage.read_json( path=os.path.join(etc, identifier.address, filename))