async def create_dice(cls, character_id: int, episode_id: int, dice_type: DiceType, expression: str, detail: str, result: DiceValue_T, reason: Optional[str] = '') -> Dice: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, character_id=character_id, episode_id=episode_id, type=int(dice_type), expression=expression, detail=detail, reason=reason if reason else '', result=result, created=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid dice = _format_dice(values) return dice
async def create_message(cls, campaign_id: int, episode_id: int, character_id: int, message_type: MessageType, content: dict, is_gm: bool, created: Optional[int] = None) -> Message: url_token = base62.encode(get_id()) if not created: created = int(time.time()) values = ObjectDict( url_token=url_token, campaign_id=campaign_id, episode_id=episode_id, character_id=character_id, type=int(message_type), is_removed=0, is_gm=int(is_gm), content=content, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid message = _format_message(values) return message
async def main(): query = "SELECT * FROM chat" r = await dndlog.execute(query) rs = await r.fetchall() for row in rs: created = int(row.time.replace(tzinfo=timezone.utc).timestamp()) dt = datetime.datetime.fromtimestamp(created) if row.type not in ('dice', 'chat'): continue _type = MessageType[row.type.upper()] await MessageDAO.create_message( row.ep_id, row.qq_id, _type, row.chat_text, get_id() if _type is MessageType.DICE else None, created, ) print(f'{dt}\t{row.ep_id}\t{row.name}\t{row.chat_text}')
async def create_member(cls, name: str, email: str, passhash: str, headline: str='', avatar: str='') -> Member: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, name=name, email=email, passhash=passhash, headline=headline, avatar=avatar, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid member = _format_member(values) return member
async def create_combat(cls, room_id: int) -> Combat: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, room_id=room_id, state=int(CombatState.INITIATING), is_removed=0, tokens={}, order={}, data={}, started_at=created, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid combat = _format_combat(values) return combat
async def create_character(cls, member_id: int, name: str, avatar: str, description: str, raw_data: dict) -> Character: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, member_id=member_id, name=name, avatar=avatar, description=description, is_removed=0, data=raw_data, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid character = _format_character(values) return character
async def create_episode(cls, room_id: int, campaign_id: int, title: str, state: EpisodeState) -> Episode: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, room_id=room_id, campaign_id=campaign_id, title=title, state=int(state), is_removed=0, started_at=created, ended_at=None, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid episode = _format_episode(values) return episode
async def create_campaign(cls, room_id: int, name: str, description: str, owner_id: int) -> Campaign: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, room_id=room_id, name=name, description=description, owner_id=owner_id, state=int(CampaignState.PREPARING), is_removed=0, last_episode_id=0, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid campaign = _format_campaign(values) return campaign
async def create_room(cls, name: str, description: str, owner_id: int, avatar: str = '') -> Room: created = int(time.time()) url_token = base62.encode(get_id()) values = ObjectDict( url_token=url_token, name=name, description=description, owner_id=owner_id, is_removed=0, current_campaign_id=0, avatar=avatar, created=created, updated=created, ) query = cls.t.insert().values(values) result = await table.execute(query) values.id = result.lastrowid room = _format_room(values) return room