Exemple #1
0
def get_cave(id: int) -> Optional[CaveDict]:
    entry: CaveEntry = CaveEntry.get_or_none(CaveEntry.id == id)
    if entry is None:
        return None
    entry_dict: CaveDict = CaveDict(
        name=entry.name,
        chain=MessageChain.fromPersistentString(entry.content),
        create_time=entry.time.strftime("%Y-%m-%d %H:%M:%S"),
        query_time=str(entry.query_time),
        id=str(entry.id),
    )
    return entry_dict
Exemple #2
0
def random_cave() -> Optional[CaveDict]:
    if CaveEntry.select().count() == 0:
        return None
    entries: List[CaveEntry] = CaveEntry.select().order_by(fn.Random())[:5]
    entry: CaveEntry = random.choice(entries)
    entry_dict: CaveDict = CaveDict(
        name=entry.name,
        chain=MessageChain.fromPersistentString(entry.content),
        create_time=entry.time.strftime("%Y-%m-%d %H:%M:%S"),
        query_time=str(entry.query_time),
        id=str(entry.id),
    )
    CaveEntry.update(query_time=entry.query_time +
                     1).where(CaveEntry.id == entry.id).execute()
    return entry_dict