コード例 #1
0
ファイル: bot.py プロジェクト: zeteticl/PlayTRPGBot
def finish_gm_mode(message: telegram.Message, chat: Chat):
    _ = partial(get_by_user, user=message.from_user)
    if chat.gm_mode:
        if chat.gm_mode_notice:
            delete_message(chat.chat_id, chat.gm_mode_notice, 20)
        chat.gm_mode = False
        chat.gm_mode_notice = None
        chat.save()

    send_message(chat.chat_id, _(Text.FINISH_GM_MODE), delete_after=20)
    delete_message(message.chat_id, message.message_id)
コード例 #2
0
    def resolve_log_list(chat: archive.Chat, info, password=''):
        log_list_cache_time_key = 'api:chat:{}:log:cache_time'.format(chat.id)
        log_list_key = 'api:chat:{}:log'.format(chat.id)
        log_list_cache_time: datetime.datetime = cache.get(
            log_list_cache_time_key, datetime.datetime.min)
        log_list: Optional[List[archive.Log]] = cache.get(log_list_key)

        if not chat.validate(password):
            return None

        if log_list and log_list_cache_time > chat.modified:
            return log_list
        log_list = list(chat.query_log().all())

        cache.set(log_list_key, log_list, 5 * 24 * 60 * 60)
        cache.set(log_list_cache_time_key, datetime.datetime.now())
        return log_list
コード例 #3
0
ファイル: roll.py プロジェクト: sunyi00/PlayTRPGBot
def handle_roll(job_queue: JobQueue,
                message: telegram.Message,
                name: str,
                entities: Entities,
                chat: Chat,
                hide=False):
    _ = partial(get_by_user, user=message.from_user)
    kind = LogKind.ROLL.value
    result_text = entities.telegram_html()
    if hide:
        hide_roll = HideRoll(message.chat_id, result_text)
        hide_roll.set()
        keyboard = [[
            InlineKeyboardButton(_(Text.GM_LOOKUP),
                                 callback_data=hide_roll.key())
        ]]

        reply_markup = InlineKeyboardMarkup(keyboard)
        text = '<b>{}</b> {}'.format(name, _(Text.ROLL_HIDE_DICE))
        kind = LogKind.HIDE_DICE.value
    else:
        text = '{} 🎲 {}'.format(name, result_text)
        reply_markup = None
    if not chat.recording:
        text = '[{}] '.format(_(Text.NOT_RECORDING)) + text
    sent = message.chat.send_message(text,
                                     reply_markup=reply_markup,
                                     parse_mode='HTML')
    user = message.from_user
    assert isinstance(user, telegram.User)
    if chat.recording:
        Log.objects.create(
            user_id=user.id,
            message_id=sent.message_id,
            chat=chat,
            content=result_text,
            entities=entities.to_object(),
            user_fullname=user.full_name,
            character_name=name,
            gm=is_gm(message.chat_id, user.id),
            kind=kind,
            created=message.date,
        )
        chat.save()
    delete_message(job_queue, message.chat_id, message.message_id, 25)
コード例 #4
0
ファイル: say.py プロジェクト: zeteticl/PlayTRPGBot
def on_edit(chat: Chat, edit_log: Log, kind, message, rpg_message: RpgMessage,
            send_text, text, with_photo):
    assert isinstance(edit_log, Log)
    chat_id = message.chat_id
    message_id = edit_log.message_id
    if edit_log.media:
        if isinstance(with_photo, telegram.PhotoSize):
            edit_message_photo(chat_id, message_id, with_photo.file_id)
            set_photo(edit_log.id, with_photo.file_id)
        edit_message_caption(chat_id, message_id, send_text)
    else:
        edit_message(chat_id, message_id, send_text)
    edit_log.tag.clear()
    for tag_name in rpg_message.tags:
        tag = get_tag(chat, tag_name)
        edit_log.tag.add(tag)
    edit_log.content = text
    edit_log.entities = rpg_message.entities.to_object()
    edit_log.kind = kind
    edit_log.save()
    delete_message(message.chat_id, message.message_id, 25)
    chat.save()
    return
コード例 #5
0
ファイル: bot.py プロジェクト: zeteticl/PlayTRPGBot
def start_gm_mode(bot: telegram.Bot, message: telegram.Message, chat: Chat):
    _ = partial(get_by_user, user=message.from_user)
    if chat.gm_mode:
        return
    chat.gm_mode = True
    chat.save()
    sent = bot.send_message(chat.chat_id, _(Text.START_GM_MODE), parse_mode='HTML')
    chat.gm_mode_notice = sent.message_id
    chat.save()
コード例 #6
0
 def resolve_counter(chat: archive.Chat, info):
     return chat.log_count()