예제 #1
0
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)
예제 #2
0
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
예제 #3
0
def load_freshmen() -> list:
    text = Storage.read_text(freshmen_file)
    if text is not None:
        return text.splitlines()
예제 #4
0
def load_robot_info(identifier: ID, filename: str) -> dict:
    return Storage.read_json(path=os.path.join(etc, identifier.address, filename))
예제 #5
0
    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'
예제 #6
0
def load_station_info(identifier: ID, filename: str):
    return Storage.read_json(
        path=os.path.join(etc, identifier.address, filename))