示例#1
0
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))
示例#2
0
def cmd_login(request):
    """ Логин-ссылка """
    return dict(
        ok=True,
        desc='%s/login?key=%s' % (
            get_webui_base(request.user),
            request.user.get('login_key', '')))
示例#3
0
def format_comment(request, msg, short=False):
    args = {
        'id':
        msg['id'].split('/')[1].upper(),
        'author':
        msg['user'],
        'message':
        msg['message'].upper(),
        'replyto':
        msg['replyto'],
        'replytotext':
        msg['replytotext'],
        'rc':
        msg.get('num', -1),
        'text':
        msg['text'],
        'date':
        datetime.datetime.utcfromtimestamp(
            msg['date']).strftime('%d.%m.%Y %H:%M:%S'),
        'web':
        get_webui_base(request.user),
    }
    formatstring = ('' if short else 'Reply by ') + '@%(author)s:\n'
    if not short:
        formatstring += '>%(replytotext)s\n\n'
    formatstring += '%(text)s\n'
    if not short:
        formatstring += '\n'
    formatstring += '#%(message)s/%(id)s (%(rc)d)'
    if not short:
        formatstring += ' %(web)s/p/%(message)s#%(id)s'
    return formatstring % args
示例#4
0
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))
示例#5
0
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)
            )
示例#6
0
def cmd_comment(request, message="", anonymous="", text=""):
        """ Отправка комментария """
        message = canonic_message_comment(message).upper()
        message_id = message.split('/')[0]
        comment_id = message if '/' in message else None
        post_throttle = 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, sfrom=sfrom)
        _ = yield throttle_update(request.user['name'], post_throttle)
        if ok:
            msgid, num, qn, recepients = rest
            defer.returnValue(
                dict(ok=True,
                     desc='Comment #%s (%d) has been delivered '
                          'to %d users. %s/p/%s' % (
                     msgid, num, recepients, get_webui_base(
                     request.user),
                     msgid.replace('/', '#')),
                     id=msgid,
                     num=num))
        else:
            defer.returnValue(
                dict(ok=False, desc=rest)
            )
示例#7
0
def format_message(request, msg, short=False):
    result = ('@%(author)s: %(tags)s %(clubs)s\n%(text)s\n' + ('\n' if not short else '') + '#%(id)s (%(rc)d) %(web)s/p/%(id)s') % \
        {'id': msg['id'].upper(),
         'author': msg['user'],
         'tags': ' '.join('*' + tag for tag in msg['tags']),
         'clubs': ' '.join('!' + tag for tag in msg['clubs']),
         'rc': msg['replycount'],
         'text': msg['text'],
         'web': get_webui_base(request.user),
         }
    return result
示例#8
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', ''))))
示例#9
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', ''))))
示例#10
0
def formatter_search(request, search_result):
    estimated = search_result['estimated']
    results = search_result['results']
    results.reverse()  # Most relevant items should be at the bottom
    if not results:
        return 'No results found.'
    info = 'Found %d results' % estimated
    if estimated > 20:
        info += ' (displaying first 20)'
    out = [info + ':']
    for res in results:
        out.append('@%s: %s (%s%%)\n%s\n\n#%s %s/p/%s' % (
            res['user'], res['tags_info'], res['percent'], res['text'],
            res['id'], get_webui_base(request.user),
            res['id'].replace('/', '#')))
    return '\n\n'.join(out)
示例#11
0
def format_message(request, msg):
    result = '+++ [%s] %s:\n' % (
        datetime.datetime.utcfromtimestamp(
            msg['date']).strftime('%d.%m.%Y %H:%M:%S'),
        msg['user'],)
    if msg['tags']:
        result += 'Tags: %s\n' % (', '.join(msg['tags']),)
    if msg['clubs']:
        result += 'Clubs: %s\n' % (', '.join(msg['clubs']),)
    result += '\n%s\n' % (msg['text'],)
    result += '--- %(id)s (%(rc)d) %(base_url)s/p/%(id)s' % {
        'base_url': get_webui_base(request.user),
        'id': msg['id'].upper(),
        'rc': msg['replycount'],
    }
    return result
示例#12
0
def format_comment(request, msg, short=False):
    args = {'id': msg['id'].split('/')[1].upper(),
            'author': msg['user'],
            'message': msg['message'].upper(),
            'replyto': None if msg['replyto'] is None else msg['replyto'].upper(),
            'replytotext': msg['replytotext'],
            'text': msg['text'],
            'num': msg.get('num', -1),
            'date': datetime.datetime.utcfromtimestamp(msg['date']).strftime('%d.%m.%Y %H:%M:%S'),
            'web': get_webui_base(request.user),
            }
    formatstring = '+++ [ %(date)s ] %(author)s'
    if msg['replyto']:
        formatstring += ' (in reply to %(replyto)s):\n'
    else:
        formatstring += ' (in reply to %(message)s):\n'
    if not short:
        formatstring += '>%(replytotext)s\n'
    formatstring += '\n%(text)s\n--- %(message)s/%(id)s (%(num)d) %(web)s/p/%(message)s#%(id)s'
    return formatstring % args
示例#13
0
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)
            )