Esempio n. 1
0
def handler(rate_option: str, meme_id: id, query_id: str, answer_query,
            inliner: User):
    try:
        meme = Meme.objects.get(id=meme_id)
    except (Meme.DoesNotExist, ValueError):
        inliner.database.save()
        raise RequestInterruption()
    if rate_option == 'up':
        if meme.voters.filter(user_id=inliner.database.user_id).exists():
            answer_query(
                query_id, user_messages['voted_before'].format(
                    user_messages[meme.type_string]), True)
        else:
            inliner.add_voter(meme)
            meme.votes = F('votes') + 1
            meme.save()
            answer_query(
                query_id, user_messages['meme_voted'].format(
                    user_messages[meme.type_string]), False)
    else:
        if meme.voters.filter(user_id=inliner.database.user_id).exists():
            inliner.remove_voter(meme)
            meme.votes = F('votes') - 1
            meme.save()
            answer_query(query_id, user_messages['took_vote_back'], False)
        else:
            answer_query(query_id, user_messages['not_voted'], True)
Esempio n. 2
0
def handler(chat_id: int, query_id: str, answer_query, inliner: User):
    inliner.send_message(
        admin_messages['user_profile'].format(chat_id),
        admin,
        parse_mode='Markdown'
    )
    answer_query(query_id, admin_messages['user_profile_sent'], False)
Esempio n. 3
0
def handler(target_meme: Meme, user: UserClass):
    target_meme.delete_vote(user.session)
    target_meme.deny(user.session)
    user.database.menu = User.Menu.ADMIN_MAIN
    user.send_message(
        user.translate('admin_meme_denied',
                       user.translate(target_meme.type_string)), admin)
Esempio n. 4
0
def handler(message_id: int, user: UserClass):
    user.database.menu = User.Menu.ADMIN_MAIN
    user.copy_message(message_id,
                      keyboards.admin_message,
                      chat_id=user.database.temp_user_id,
                      protect_content=True)
    user.send_message(user.translate('sent'), keyboards.admin)
Esempio n. 5
0
def handler(target_vote: Meme, user: UserClass):
    target_vote.delete_vote(user.session)
    target_vote.sender.status = target_vote.sender.Status.BANNED
    target_vote.sender.save()
    target_vote.deny(user.session)
    user.database.menu = User.Menu.ADMIN_MAIN
    user.send_message(user.translate('ban_voted'), admin)
Esempio n. 6
0
def handler(user: UserClass):
    user.database.menu = User.Menu.USER_SUGGEST_MEME
    if user.database.temp_meme_type == MemeType.VOICE:
        user.database.back_menu = 'suggest_voice_tags'
        user.send_message(user_messages['send_meme'].format(user.temp_meme_translation))
    else:
        user.database.back_menu = 'suggest_video_tags'
        user.send_message(user_messages['send_a_video'])
Esempio n. 7
0
def handler(text: str, user: UserClass):
    user.database.menu = User.Menu.USER_SUGGEST_MEME_TAGS
    user.database.temp_meme_name = text
    user.database.back_menu = 'suggest_voice_name' \
        if user.database.temp_meme_type == MemeType.VOICE \
        else 'suggest_video_name'
    user.send_message(
        user.translate('send_meme_tags', user.temp_meme_translation))
Esempio n. 8
0
def handler(file_unique_id: str, message_id: int, user: User):
    if user.add_voice_to_playlist(file_unique_id):
        user.send_message(user.translate('added_to_playlist'))
        user.go_back()
    else:
        user.send_message(user.translate('meme_is_not_yours',
                                         user.translate('voice')),
                          reply_to_message_id=message_id)
Esempio n. 9
0
def handler(message_id: int, target_meme: Meme, user: UserClass):
    owner = classes.User(user.session,
                         classes.User.Mode.NORMAL,
                         instance=User.objects.filter(rank='o').first())
    user.database.menu = User.Menu.USER_MAIN
    user.send_message(user.translate('request_created'), user_keyboard,
                      message_id)
    user.delete_request(target_meme)
    owner.send_message(admin_messages['new_delete_request'])
Esempio n. 10
0
def handler(text: str, user: UserClass):
    if user.process_meme_tags(text):
        user.database.menu = User.Menu.ADMIN_NEW_MEME
        if user.database.temp_meme_type == MemeType.VOICE:
            user.database.back_menu = 'voice_tags'
            meme_translation = admin_messages['voice']
        else:
            user.database.back_menu = 'video_tags'
            meme_translation = admin_messages['video']
        user.send_message(user.translate('send_meme', meme_translation))
Esempio n. 11
0
def handler(vote_option: str, query_id: str, meme_id: int, answer_query, inliner: UserClass):
    try:
        meme = Meme.objects.get(id=meme_id, status=Meme.Status.PENDING)
    except Meme.DoesNotExist:
        raise RequestInterruption()
    match vote_option:
        case 'a':
            if inliner.database.rank in BOT_ADMINS and inliner.database.menu == User.Menu.ADMIN_GOD_MODE:
                answer_query(
                    query_id, admin_messages['admin_meme_accepted'].format(admin_messages[meme.type_string]), True
                )
                meme.accept(inliner.session)
            elif not inliner.like_meme(meme):
                answer_query(query_id, inliner.translate('vote_before', inliner.translate(
                    meme.type_string
                )), True)
            else:
                answer_query(query_id, inliner.translate('voted'), False)
        case 'd':
            if inliner.database.rank in BOT_ADMINS and inliner.database.menu == User.Menu.ADMIN_GOD_MODE:
                answer_query(
                    query_id, admin_messages['admin_meme_denied'].format(admin_messages[meme.type_string]), True
                )
                meme.deny(inliner.session)
            elif not inliner.dislike_meme(meme):
                answer_query(query_id, inliner.translate('vote_before', inliner.translate(
                    meme.type_string
                )), True)
            else:
                answer_query(query_id, inliner.translate('voted'), False)
        case _:
            answer_query(query_id, inliner.translate(
                'voting_results', meme.accept_vote.count(), meme.deny_vote.count()
            ), True, 180)
Esempio n. 12
0
def handler(message: dict, text: str, user: UserClass):
    if user.validate_meme_name(message, text, user.database.temp_meme_type):
        user.database.menu = User.Menu.ADMIN_MEME_TAGS
        user.database.temp_meme_name = text
        if user.database.temp_meme_type == MemeType.VOICE:
            user.database.back_menu = 'voice_name'
            meme_translation = admin_messages['voice']
        else:
            user.database.back_menu = 'video_name'
            meme_translation = admin_messages['video']
        user.send_message(user.translate('send_meme_tags', meme_translation))
Esempio n. 13
0
def handler(text: str, message_id: int, user: User):
    if text and len(text) <= 60:
        user.send_message(
            user.translate('playlist_created',
                           (user.create_playlist(text)).get_link()))
        user.go_back()
    else:
        user.send_message(user.translate('invalid_playlist_name'),
                          reply_to_message_id=message_id)
Esempio n. 14
0
def handler(message: dict, text: str, message_id: int, user: UserClass):
    match user.database.menu:
        case User.Menu.USER_MAIN:
            main.handler(message, text, message_id, user)
        case User.Menu.USER_CONTACT_ADMIN:
            contact_admin.handler(message_id, user)
        case User.Menu.USER_SUGGEST_MEME_NAME if user.validate_meme_name(message, text, user.database.temp_meme_type):
            suggest_meme_name.handler(text, user)
        case User.Menu.USER_SETTINGS:
            settings_menu.handler(text, message_id, user)
        case User.Menu.USER_SUGGEST_MEME_TAGS if user.process_meme_tags(text):
            suggest_meme_tags.handler(user)
        case User.Menu.USER_SUGGEST_MEME if target_meme := user.add_meme(message, Meme.Status.PENDING):
            suggest_meme.handler(target_meme, user)
Esempio n. 15
0
def handler(playlist_id: int, query_id: str, answer_query, inliner: UserClass):
    try:
        inliner.database.current_playlist = Playlist.objects.get(
            id=playlist_id, creator=inliner.database
        )
    except (Playlist.DoesNotExist, ValueError):
        inliner.database.save()
        raise RequestInterruption()
    inliner.menu_cleanup()
    inliner.database.menu_mode = inliner.database.MenuMode.USER
    inliner.database.menu = User.Menu.USER_MANAGE_PLAYLIST
    inliner.database.back_menu = 'manage_playlists'
    answer_query(query_id, user_messages['managing_playlist'], False)
    inliner.send_message(user_messages['manage_playlist'], manage_playlist)
Esempio n. 16
0
def handler(text: str, user: UserClass):
    matched = True
    match text:
        case "Video":
            user.database.temp_meme_type = MemeType.VIDEO
            meme_translation = user.translate('video')
        case "Voice":
            user.database.temp_meme_type = MemeType.VOICE
            meme_translation = user.translate('voice')
        case _:
            matched = False
    if matched:
        user.database.back_menu = 'meme_type'
        user.database.menu = User.Menu.ADMIN_MEME_NAME
        user.send_message(user.translate('meme_name', meme_translation), en_back)
Esempio n. 17
0
def handler(text: str, message_id: int, user: UserClass):
    matched = True
    match text:
        case 'ویس ها 🔊':
            user.database.search_items = User.SearchItems.VOICES
            user.send_message(user_messages['search_item_voices'], reply_to_message_id=message_id)
        case 'ویدئو ها 📹':
            user.database.search_items = User.SearchItems.VIDEOS
            user.send_message(user_messages['search_item_videos'], reply_to_message_id=message_id)
        case 'ویس ها 🔊 و ویدئو ها 📹':
            user.database.search_items = User.SearchItems.BOTH
            user.send_message(user_messages['search_item_videos_and_voices'], reply_to_message_id=message_id)
        case _:
            matched = False
            user.send_message(user_messages['unknown_command'], reply_to_message_id=message_id)
    if matched:
        user.go_back()
Esempio n. 18
0
def handler(command: str, query_id: str, message_id: int, answer_query,
            report: Report, inliner: UserClass):
    if command == 'rep_accept':
        if report.meme.status == Meme.Status.PENDING:
            report.meme.delete_vote(inliner.session)
        report.meme.previous_status = report.meme.status
        report.meme.status = Meme.Status.REPORTED
        report.meme.save()
        report.meme.sender.report_violation_count = F(
            'report_violation_count') + 1
        report.meme.sender.save()
        report.meme.sender.refresh_from_db()
        sender = UserClass(inliner.session,
                           UserClass.Mode.NORMAL,
                           instance=report.meme.sender)
        if sender.database.report_violation_count >= settings.VIOLATION_REPORT_LIMIT:
            sender.database.status = User.Status.BANNED
            sender.database.save()
            sender.send_message(translations.user_messages['you_are_banned'])
        else:
            sender.send_message(
                translations.user_messages['meme_violated'].format(
                    translations.user_messages[report.meme.type_string],
                    report.meme.name, sender.database.report_violation_count,
                    settings.VIOLATION_REPORT_LIMIT),
                parse_mode='HTML')
        answer_query(query_id, translations.admin_messages['deleted'], True)
        edit_message_reply_markup(settings.MEME_REPORTS_CHANNEL,
                                  deleted,
                                  message_id,
                                  session=inliner.session)
    else:
        if report.meme.status == Meme.Status.REPORTED:
            if report.meme.previous_status == Meme.Status.PENDING:
                report.meme.send_vote(inliner.session)
            report.meme.status = report.meme.previous_status
            report.meme.save()
        answer_query(query_id, translations.admin_messages['report_dismissed'],
                     False)
        edit_message_reply_markup(settings.MEME_REPORTS_CHANNEL,
                                  dismissed,
                                  message_id,
                                  session=inliner.session)
    report.status = Report.Status.REVIEWED
    report.review_date = now()
    report.save()
Esempio n. 19
0
def handler(text: str, message_id: int, user: UserClass):
    match text:
        case 'روشن 🔛' | 'خاموش 🔴':
            user.database.back_menu = 'main'
            user.database.menu = User.Menu.USER_SETTINGS
            if text == 'روشن 🔛':
                user.database.vote = True
                user.send_message(user.translate('voting_on'), settings)
            else:
                user.database.vote = False
                user.send_message(user.translate('voting_off'), settings)
        case _:
            user.send_message(
                user.translate('unknown_command'), reply_to_message_id=message_id
            )
Esempio n. 20
0
def handler(text: str, message_id: int, user: User):
    match text:
        case 'ویس 🔊':
            user.suggest_meme(MemeType.VOICE)
        case 'ویدئو 📹':
            user.suggest_meme(MemeType.VIDEO)
        case _:
            user.send_message(user.translate('unknown_command'), reply_to_message_id=message_id)
Esempio n. 21
0
def handler(request, chosen_inline_result, user_chat_id):
    try:
        used_meme = Meme.objects.get(id=chosen_inline_result['result_id'])
    except Meme.DoesNotExist:
        pass
    else:
        if (user := User(request.http_session, User.Mode.NORMAL,
                         user_chat_id)).database.use_recent_memes:
            user.add_recent_meme(used_meme)
        if used_meme.visibility == Meme.Visibility.NORMAL:
            used_meme.usage_count = F('usage_count') + 1
            used_meme.save()
Esempio n. 22
0
def handler(text: str, message_id: int, user: UserClass):
    match text:
        case (
            'جدید به قدیم' |
            'قدیم به جدید' |
            'بهترین به بدترین' |
            'بدترین به بهترین' |
            'پر استفاده به کم استفاده' |
            'کم استفاده به پر استفاده'
        ):
            user.database.back_menu = 'main'
            user.database.menu = User.Menu.USER_SETTINGS
            user.send_message(user.translate('ordering_changed'), settings)
            match text:
                case 'جدید به قدیم':
                    user.database.meme_ordering = user.database.Ordering.new_meme_id
                case 'قدیم به جدید':
                    user.database.meme_ordering = user.database.Ordering.meme_id
                case 'بهترین به بدترین':
                    user.database.meme_ordering = user.database.Ordering.high_votes
                case 'بدترین به بهترین':
                    user.database.meme_ordering = user.database.Ordering.votes
                case 'پر استفاده به کم استفاده':
                    user.database.meme_ordering = user.database.Ordering.high_usage
                case 'کم استفاده به پر استفاده':
                    user.database.meme_ordering = user.database.Ordering.low_usage
        case _:
            user.send_message(user.translate('unknown_command'), reply_to_message_id=message_id)
Esempio n. 23
0
def handler(meme_id: int, query_id: str, answer_query, inliner: UserClass):
    try:
        meme = Meme.objects.get(id=meme_id, status=Meme.Status.PENDING)
    except (Meme.DoesNotExist, ValueError):
        inliner.database.save()
        raise RequestInterruption()
    match inliner.report_meme(meme):
        case ReportResult.REPORTED:
            answer_query(query_id, user_messages['report_submitted'], True)
        case ReportResult.REPORTED_BEFORE:
            answer_query(query_id, user_messages['reported_before'].format(user_messages[meme.type_string]), True)
        case ReportResult.REPORT_FAILED:
            answer_query(query_id, user_messages['report_reviewed'].format(user_messages[meme.type_string]), True)
Esempio n. 24
0
def handler(command: str, meme_id: int, message_id: int, query_id: str,
            answer_query, inliner: User):
    try:
        deleted_meme = Meme.objects.get(id=meme_id, status=Meme.Status.DELETED)
    except Meme.DoesNotExist:
        raise RequestInterruption()
    user = User(inliner.session,
                User.Mode.NORMAL,
                instance=deleted_meme.sender)
    if command == 'r':
        deleted_meme.status = Meme.Status.ACTIVE
        assigned_admin = User(inliner.session,
                              User.Mode.NORMAL,
                              instance=deleted_meme.assigned_admin)
        deleted_meme.assigned_admin = None
        deleted_meme.save()
        assigned_admin.send_message(assigned_admin.translate(
            'deleted_meme_recovered',
            assigned_admin.translate(deleted_meme.type_string),
            deleted_meme.name),
                                    parse_mode='HTML')
        answer_query(
            query_id, translations.admin_messages['meme_recovered'].format(
                translations.admin_messages[deleted_meme.type_string]), True)
        edit_message_reply_markup(settings.MEME_LOGS,
                                  recovered,
                                  message_id=message_id,
                                  session=inliner.session)
    else:
        deleted_meme.delete()
        user.send_message(
            translations.user_messages['deleted_by_admins'].format(
                translations.user_messages[deleted_meme.type_string],
                deleted_meme.name))
        edit_message_reply_markup(settings.MEME_LOGS,
                                  deleted,
                                  message_id=message_id,
                                  session=inliner.session)
Esempio n. 25
0
def handler(message: dict, message_id: int, user: UserClass):
    if message.get('document'):
        user.database.menu = User.Menu.ADMIN_MAIN
        user.send_message(
            user.translate('file_id', message['document']['file_id']), admin,
            message_id)
    else:
        user.send_message(user.translate('no_document'),
                          reply_to_message_id=message_id)
Esempio n. 26
0
def handler(user: User):
    user.edit_meme_tags()
    user.database.current_meme.description = create_description(
        user.database.current_meme.tags.all())
    user.database.current_meme.save()
    user.send_message(
        admin_messages['meme_tags_and_description_edited'].format(
            user.current_meme_translation))
    user.go_back()
Esempio n. 27
0
def handler(text: str, user: UserClass):
    try:
        user.database.temp_user_id = int(text)
    except (ValueError, TypeError):
        user.send_message(user.translate('invalid_user_id'))
    else:
        user.database.menu = User.Menu.ADMIN_MESSAGE_USER
        user.database.back_menu = 'chat_id'
        user.send_message(user.translate('message'))
Esempio n. 28
0
def handler(text: str, user: UserClass, ban_mode: User.Status):
    try:
        user_id = int(text)
    except (ValueError, TypeError):
        user.send_message(user.translate('invalid_user_id'))
    else:
        user.database.menu = User.Menu.ADMIN_MAIN
        change_user_status(user_id, ban_mode)
        user.send_message(user.translate('unbanned' if ban_mode is User.Status.ACTIVE else 'banned', user_id), admin)
Esempio n. 29
0
def handler(message: dict, text: str, message_id: int, user: UserClass):
    match user.database.menu:
        case User.Menu.ADMIN_MAIN:
            main.handler(message, text, user, message_id)
        case User.Menu.ADMIN_MEME_NAME if text:
            meme_name.handler(message, text, user)
        case User.Menu.ADMIN_MEME_TAGS:
            meme_tags.handler(text, user)
        case User.Menu.ADMIN_NEW_MEME:
            new_meme.handler(message, user)
        case User.Menu.ADMIN_DELETE_MEME:
            delete_meme.handler(message, user, message_id)
        case User.Menu.ADMIN_BAN_USER:
            ban_user.handler(text, user, User.Status.BANNED)
        case User.Menu.ADMIN_UNBAN_USER:
            ban_user.handler(text, user, User.Status.ACTIVE)
        case User.Menu.ADMIN_FULL_BAN_USER:
            ban_user.handler(text, user, User.Status.FULL_BANNED)
        case User.Menu.ADMIN_MESSAGE_USER_ID:
            message_user_id.handler(text, user)
        case User.Menu.ADMIN_MESSAGE_USER:
            message_user.handler(message_id, user)
        case User.Menu.ADMIN_ADD_AD:
            add_ad.handler(message_id, user)
        case User.Menu.ADMIN_DELETE_AD:
            delete_ad.handler(text, message_id, user)
        case User.Menu.ADMIN_GET_USER:
            get_user.handler(text, user, message_id)
        case User.Menu.ADMIN_BROADCAST:
            broadcast.handler(message_id, user)
        case User.Menu.ADMIN_EDIT_AD_ID:
            edit_ad_id.handler(text, message_id, user)
        case User.Menu.ADMIN_EDIT_AD:
            edit_ad.handler(message_id, user)
        case User.Menu.ADMIN_BAN_VOTE if target_vote := user.get_vote(message):
            ban_vote.handler(target_vote, user)
Esempio n. 30
0
def handler(text: str, message_id: int, user: UserClass):
    try:
        user.database.current_ad = Ad.objects.get(ad_id=text)
    except (Ad.DoesNotExist, ValueError):
        user.send_message(user.translate('invalid_ad_id'),
                          reply_to_message_id=message_id)
    else:
        user.database.back_menu = 'edit_ad'
        user.database.menu = User.Menu.ADMIN_EDIT_AD
        user.send_message(user.translate('replace_ad'), en_back)