コード例 #1
0
def handle_group_sticker(bot, update, session, chat, user):
    """Read all stickers.

    - Handle initial sticker addition.
    - Detect whether a sticker set is used in a chat or not.
    """
    tg_sticker = update.message.sticker
    set_name = tg_sticker.set_name

    # The sticker is no longer associated to a sticker set
    if set_name is None:
        return

    # Handle maintenance and newsfeed sticker sets
    if chat.is_maintenance or chat.is_newsfeed:
        sticker_set = StickerSet.get_or_create(session, set_name, chat, user)
        if not sticker_set.complete:
            return "Sticker set is not yet reviewed"

        message = f'StickerSet "{sticker_set.title}" ({sticker_set.name})'
        keyboard = get_nsfw_ban_keyboard(sticker_set)
        call_tg_func(
            update.message.chat, "send_message", [message], {"reply_markup": keyboard}
        )

        return

    # Handle replies to #request messages and tag those stickers with the request tags
    handle_request_reply(tg_sticker.file_id, update, session, chat, user)

    # Right now we only want to add animated stickers
    if not tg_sticker.is_animated:
        return

    sticker_set = StickerSet.get_or_create(session, set_name, chat, user)

    if sticker_set not in chat.sticker_sets:
        chat.sticker_sets.append(sticker_set)

    # Stickerset is not yet completed
    if not sticker_set.complete:
        return

    # Set the send sticker to the current sticker for tagging or report.
    sticker = session.query(Sticker).get(tg_sticker.file_id)
    if sticker is None:
        sticker_set.scan_scheduled = True
        return

    chat.current_sticker = sticker

    return
コード例 #2
0
def handle_private_sticker(bot, update, session, chat, user):
    """Read all stickers.

    - Handle initial sticker addition.
    - Handle sticker tagging
    """
    incoming_sticker = update.message.sticker
    set_name = incoming_sticker.set_name

    # The sticker is no longer associated to a sticker set
    if set_name is None:
        call_tg_func(update.message.chat,
                     'send_message',
                     args=["This sticker doesn't belong to a sticker set."])
        return

    sticker_set = StickerSet.get_or_create(session, set_name, chat, user)
    if sticker_set.reviewed is False:
        call_tg_func(
            update.message.chat,
            'send_message',
            args=[
                f'Set {sticker_set.name} is going to be reviewed soon. Please bear with us :).'
            ])

        return

    else:
        # Notify if they are still in a tagging process
        if chat.tag_mode in [TagMode.STICKER_SET, TagMode.RANDOM]:
            chat.cancel(bot)
            pass

        sticker = session.query(Sticker).get(incoming_sticker.file_id)
        if sticker is None:
            call_tg_func(
                update.message.chat,
                'send_message',
                args=[
                    f"I don't know this specific sticker yet. I'll just trigger a rescan of this set. Please wait a minute and try again."
                ])
            refresh_stickers(session, sticker_set, bot)
            return

        chat.current_sticker = sticker
        chat.tag_mode = TagMode.SINGLE_STICKER

        sticker_tags_message = current_sticker_tags_message(sticker, user)
        # Send inline keyboard to allow fast tagging of the sticker's set
        keyboard = get_tag_this_set_keyboard(sticker.sticker_set, user)
        call_tg_func(
            update.message.chat,
            'send_message',
            [
                f'Just send the new tags for this sticker.\n{sticker_tags_message}'
            ],
            {'reply_markup': keyboard},
        )

    return
コード例 #3
0
ファイル: tag.py プロジェクト: drmhdh/sticker-finder
def initialize_set_tagging(bot, tg_chat, session, name, chat, user):
    """Initialize the set tag functionality of a chat."""
    sticker_set = StickerSet.get_or_create(session, name, chat, user)
    if sticker_set.complete is False:
        return "Sticker set {name} is currently being added."

    # Chat now expects an incoming tag for the next sticker
    chat.tag_mode = TagMode.STICKER_SET
    chat.current_sticker = sticker_set.stickers[0]

    call_tg_func(tg_chat, 'send_message', [tag_text])
    send_tag_messages(chat, tg_chat, user)
コード例 #4
0
def initialize_set_tagging(session, bot, tg_chat, name, chat, user):
    """Initialize the set tag functionality of a chat."""
    sticker_set = StickerSet.get_or_create(session, name, chat, user)
    if sticker_set.complete is False:
        return "Sticker set {name} is currently being added."

    # Chat now expects an incoming tag for the next sticker
    chat.tag_mode = TagMode.sticker_set.value
    chat.current_sticker = sticker_set.stickers[0]

    tg_chat.send_message(i18n.t("text.tagging.send_tags"))
    send_tag_messages(chat, tg_chat, user)
コード例 #5
0
def add_sets(bot, update, session, chat, user):
    """Get random sticker_set."""
    text = update.message.text[9:]

    count = 0
    names = text.split("\n")
    for name in names:
        set_name = name.strip()
        try:
            tg_sticker_set = bot.get_sticker_set(set_name)
        except:
            return f"Couldn't find set {set_name}"

        sticker_set = session.query(StickerSet).get(tg_sticker_set.name)
        if sticker_set is None:
            try:
                StickerSet.get_or_create(session, set_name, chat, user)
                count += 1
            except:
                pass

    return f"Added {count} new sticker sets."
コード例 #6
0
ファイル: admin.py プロジェクト: drmhdh/sticker-finder
def add_sets(bot, update, session, chat, user):
    """Get random sticker_set."""
    text = update.message.text[9:]

    count = 0
    names = text.split('\n')
    for name in names:
        set_name = name.strip()
        try:
            tg_sticker_set = call_tg_func(bot, 'get_sticker_set', args=[set_name])
        except BaseException:
            return f"Couldn't find set {set_name}"

        sticker_set = session.query(StickerSet).get(tg_sticker_set.name)
        if sticker_set is None:
            try:
                StickerSet.get_or_create(session, set_name, chat, user)
                count += 1
            except BaseException:
                pass

    return f'Added {count} new sticker sets.'
コード例 #7
0
def handle_private_sticker(bot, update, session, chat, user):
    """Read all stickers.

    - Handle initial sticker addition.
    - Handle sticker tagging
    """
    incoming_sticker = update.message.sticker
    set_name = incoming_sticker.set_name

    # The sticker is no longer associated to a sticker set
    if set_name is None:
        return "This sticker doesn't belong to a sticker set."

    sticker_set = StickerSet.get_or_create(session, set_name, chat, user)
    if sticker_set.reviewed is False:
        sticker_set.furry = user.furry
        return f"Set {sticker_set.name} is going to be added soon ☺️"

    # Notify if they are still in a tagging process
    if chat.tag_mode in [TagMode.STICKER_SET, TagMode.RANDOM]:
        chat.cancel(bot)
        pass

    sticker = session.query(Sticker).get(incoming_sticker.file_id)
    if sticker is None:
        sticker_set.scan_scheduled = True
        return f"I don't know this specific sticker yet. Please wait a few minutes and try again ☺️"

    chat.current_sticker = sticker
    chat.tag_mode = TagMode.SINGLE_STICKER

    sticker_tags_message = current_sticker_tags_message(sticker, user)
    # Send inline keyboard to allow fast tagging of the sticker's set
    keyboard = get_tag_this_set_keyboard(sticker.sticker_set, user)
    update.message.chat.send_message(
        f"Just send the new tags for this sticker.\n{sticker_tags_message}",
        reply_markup=keyboard,
    )