예제 #1
0
def rename_chapter(call):
    user_context = mem.UserContext(call.from_user.id)
    _chapter = chapter.Chapter(
        int(user_context.get_context('story_id')),
        int(user_context.get_context('chapter_id')),
    )
    _chapter.get_new_name(call.from_user.id)
예제 #2
0
def wait_line_rename(message):
    user_context = mem.UserContext(message.from_user.id)
    user_context.rm_status()
    _chapter = chapter.Chapter(
        user_context.get_context('story_id'),
        user_context.get_context('chapter_id'),
    )
    _chapter.rename(message.from_user.id, message.text)
예제 #3
0
def show_chapter(call):
    params = tools.get_call_back_params(call.data)
    user_context = mem.UserContext(call.from_user.id)
    _chapter = chapter.Chapter(
        int(user_context.get_context('story_id')),
        params.get('chapter_id') or user_context.get_context('chapter_id'),
    )
    _chapter.show(call.from_user.id)
예제 #4
0
def down_chapter(call):
    user_context = mem.UserContext(call.from_user.id)
    params = tools.get_call_back_params(call.data)
    _chapter = chapter.Chapter(
        int(user_context.get_context('story_id')),
        params.get('chapter_id'),
    )
    _chapter.replace(_chapter.number + 1, call.from_user.id)
예제 #5
0
def rm_chapter(call):
    params = tools.get_call_back_params(call.data)
    user_context = mem.UserContext(call.from_user.id)
    _chapter = chapter.Chapter(
        int(user_context.get_context('story_id')),
        int(user_context.get_context('chapter_id')),
    )
    if params.get('is_sure'):
        _chapter.rm(call.from_user.id)
    else:
        _chapter.make_sure_rm(call.from_user.id)
예제 #6
0
 def rm(self, tg_id: int):
     req_data = {
         'msg_id': self.id,
         'tg_id': tg_id,
     }
     rm_msg_resp = json.loads(
         requests.post(
             DB_URL.format(item='message', cmd='rm'),
             json=req_data,
         ).text)
     if rm_msg_resp.get('error'):
         msg = rm_msg_resp.get('error')
         tools.send_menu_msg(tg_id, msg)
     else:
         chapter.Chapter(self.story_id, self.chapter_id).show(tg_id)
예제 #7
0
def start_message(msg):
    link_data = extract_link_data(msg.text)
    user = tg_user.TelegramUser(msg.chat.id)
    user_context = mem.UserContext(user.telegram_id)
    user_context.flush_all()
    if link_data and link_data.get('edit_message_id') and link_data.get(
            'story_id'):
        if int(link_data.get('story_id')) in [
                story.id for story in user.stories
        ]:
            _message = message.Message(link_data.get('edit_message_id'))
            user_context.update_context('story_id', link_data.get('story_id'))
            try:
                chapter.Chapter(link_data.get('story_id'), _message.chapter_id)
            except Exception:
                user.show_stories()
                return
            user_context.update_context('chapter_id', _message.chapter_id)
            _message.show(user.telegram_id)
    else:
        user.show_stories()