예제 #1
0
파일: command_post.py 프로젝트: UndeRus/bnw
def cmd_comment(request, message="", anonymous="", format="", text=""):
        """ Отправка комментария """
        if format and not format in acceptable_formats:
            defer.returnValue(dict(ok=False, desc=u"'%s' is not a valid format! Choose one of: %s" % (format, acceptable_formats_str)))
        else:
            format = normalize_format(format)
        message = canonic_message_comment(message).upper()
        message_id = message.split('/')[0]
        comment_id = message if '/' in message else None
        yield throttle_check(request.user['name'])
        sfrom = request.to.userhost() if request.to else None
        ok, rest = yield bnw.core.post.postComment(
            message_id, comment_id, text, request.user, anonymous, format, sfrom=sfrom)
        if ok:
            msgid, num, qn, recipients = rest
            defer.returnValue(
                dict(ok=True,
                     desc='Comment #%s (%d) has been delivered '
                          'to %d users. %s/p/%s' % (
                     msgid, num, recipients, get_webui_base(
                     request.user),
                     msgid.replace('/', '#')),
                     id=msgid,
                     num=num))
        else:
            defer.returnValue(
                dict(ok=False, desc=rest)
            )
예제 #2
0
파일: command_post.py 프로젝트: UndeRus/bnw
def postMessage(request,
                tags,
                clubs,
                text,
                anon=False,
                anoncomments=False,
                format=None):
    yield throttle_check(request.user['name'])
    sfrom = request.to.userhost() if request.to else None
    start = text[:10].lower()
    if start.startswith('?otr'):
        defer.returnValue(
            dict(ok=False, desc='?OTR Error: F**k your OTR, srsly'))
    ok, rest = yield bnw.core.post.postMessage(request.user,
                                               tags,
                                               clubs,
                                               text,
                                               anon,
                                               anoncomments,
                                               format,
                                               sfrom=sfrom)
    if ok:
        msgid, qn, recipients = rest
        defer.returnValue(
            dict(ok=True,
                 desc='Message #%s has been delivered '
                 'to %d users. %s/p/%s' %
                 (msgid, recipients, get_webui_base(request.user), msgid),
                 id=msgid))
    else:
        defer.returnValue(dict(ok=False, desc=rest))
예제 #3
0
파일: command_post.py 프로젝트: UndeRus/bnw
def cmd_comment(request, message="", anonymous="", format="", text=""):
    """ Отправка комментария """
    if format and not format in acceptable_formats:
        defer.returnValue(
            dict(ok=False,
                 desc=u"'%s' is not a valid format! Choose one of: %s" %
                 (format, acceptable_formats_str)))
    else:
        format = normalize_format(format)
    message = canonic_message_comment(message).upper()
    message_id = message.split('/')[0]
    comment_id = message if '/' in message else None
    yield throttle_check(request.user['name'])
    sfrom = request.to.userhost() if request.to else None
    ok, rest = yield bnw.core.post.postComment(message_id,
                                               comment_id,
                                               text,
                                               request.user,
                                               anonymous,
                                               format,
                                               sfrom=sfrom)
    if ok:
        msgid, num, qn, recipients = rest
        defer.returnValue(
            dict(ok=True,
                 desc='Comment #%s (%d) has been delivered '
                 'to %d users. %s/p/%s' %
                 (msgid, num, recipients, get_webui_base(
                     request.user), msgid.replace('/', '#')),
                 id=msgid,
                 num=num))
    else:
        defer.returnValue(dict(ok=False, desc=rest))
예제 #4
0
파일: command_pm.py 프로젝트: q587p/bnw
def cmd_pm(request, text, user=""):
    """ Отправка приватного сообщения """
    yield throttle_check(request.user['name'])
    user = canonic_user(user).lower()
    if len(text) > 2048:
        defer.returnValue(dict(ok=False, desc='Too long.'))
    target_user = yield objs.User.find_one({'name': user})
    if not target_user:
        defer.returnValue(dict(ok=False, desc='No such user.'))
    target_user.send_plain('PM from @%s:\n%s' % (request.user['name'], text))
    defer.returnValue(dict(ok=True, desc='PM sent.'))
예제 #5
0
def cmd_login(request,reset=""):
    """ Логин-ссылка """
    user = request.user
    if reset:
        yield throttle_check(request.user['name'])
        user = yield objs.User.find_and_modify({'name': request.user['name']}, {'$set': {'login_key': uuid4().hex}}, new=True)
    defer.returnValue(dict(
        ok=True,
        desc='%s/login?key=%s' % (
            get_webui_base(user),
            user.get('login_key', ''))))
예제 #6
0
파일: command_login.py 프로젝트: q587p/bnw
def cmd_login(request, reset=""):
    """ Логин-ссылка """
    user = request.user
    if reset:
        yield throttle_check(request.user['name'])
        user = yield objs.User.find_and_modify(
            {'name': request.user['name']},
            {'$set': {
                'login_key': uuid4().hex
            }},
            new=True)
    defer.returnValue(
        dict(ok=True,
             desc='%s/login?key=%s' %
             (get_webui_base(user), user.get('login_key', ''))))
예제 #7
0
파일: command_post.py 프로젝트: UndeRus/bnw
def cmd_recommend(request, message="", comment="", unrecommend=""):
        """Recommend or unrecommend message."""
        message_id = canonic_message(message).upper()
        message_obj = yield objs.Message.find_one({'id': message_id})
        if not message_obj:
            defer.returnValue(dict(
                ok=False,
                desc='No such message.'))
        if unrecommend:
            if request.user['name'] in message_obj['recommendations']:
                yield objs.Message.mupdate(
                    {'id': message_id},
                    {'$pull': {'recommendations': request.user['name']}})
                rcount = len(message_obj['recommendations']) - 1
                all_recos = list(message_obj['recommendations'])
                all_recos.remove(request.user['name'])
                publish('upd_recommendations_count',
                        message_id, rcount, all_recos)
                publish('upd_recommendations_count_in_' + message_id,
                        message_id, rcount, all_recos)
                defer.returnValue(dict(
                    ok=True,
                    desc='Message deleted from your recommendations list.'))
            else:
                defer.returnValue(dict(
                    ok=False,
                    desc='You haven\'t recommended this message.'))

        yield throttle_check(request.user['name'])
        ok, rest = yield bnw.core.post.recommendMessage(
            request.user, message_obj, comment)
        if ok:
            qn, recipients, replies = rest
            defer.returnValue(dict(
                ok=True,
                desc='Recommended and delivered to %d users (%d replies).' % (
                    recipients, replies)))
        else:
            defer.returnValue(dict(
                ok=False,
                desc=rest))
예제 #8
0
파일: command_post.py 프로젝트: UndeRus/bnw
def cmd_recommend(request, message="", comment="", unrecommend=""):
    """Recommend or unrecommend message."""
    message_id = canonic_message(message).upper()
    message_obj = yield objs.Message.find_one({'id': message_id})
    if not message_obj:
        defer.returnValue(dict(ok=False, desc='No such message.'))
    if unrecommend:
        if request.user['name'] in message_obj['recommendations']:
            yield objs.Message.mupdate(
                {'id': message_id},
                {'$pull': {
                    'recommendations': request.user['name']
                }})
            rcount = len(message_obj['recommendations']) - 1
            all_recos = list(message_obj['recommendations'])
            all_recos.remove(request.user['name'])
            publish('upd_recommendations_count', message_id, rcount, all_recos)
            publish('upd_recommendations_count_in_' + message_id, message_id,
                    rcount, all_recos)
            defer.returnValue(
                dict(ok=True,
                     desc='Message deleted from your recommendations list.'))
        else:
            defer.returnValue(
                dict(ok=False, desc='You haven\'t recommended this message.'))

    yield throttle_check(request.user['name'])
    ok, rest = yield bnw.core.post.recommendMessage(request.user, message_obj,
                                                    comment)
    if ok:
        qn, recipients, replies = rest
        defer.returnValue(
            dict(ok=True,
                 desc='Recommended and delivered to %d users (%d replies).' %
                 (recipients, replies)))
    else:
        defer.returnValue(dict(ok=False, desc=rest))
예제 #9
0
파일: command_post.py 프로젝트: UndeRus/bnw
def postMessage(request, tags, clubs, text, anon=False, anoncomments=False,
                format=None):
        yield throttle_check(request.user['name'])
        sfrom = request.to.userhost() if request.to else None
        start = text[:10].lower()
        if start.startswith('?otr'):
            defer.returnValue(
                dict(ok=False, desc='?OTR Error: F**k your OTR, srsly')
            )
        ok, rest = yield bnw.core.post.postMessage(
            request.user, tags, clubs, text, anon, anoncomments, format, sfrom=sfrom)
        if ok:
            msgid, qn, recipients = rest
            defer.returnValue(
                dict(ok=True,
                     desc='Message #%s has been delivered '
                          'to %d users. %s/p/%s' % (
                     msgid, recipients, get_webui_base(request.user),
                     msgid),
                     id=msgid))
        else:
            defer.returnValue(
                dict(ok=False, desc=rest)
            )