Exemplo n.º 1
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)
            )
Exemplo n.º 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', '')))
Exemplo n.º 3
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
Exemplo n.º 4
0
def formatter_search(request, result):
    total, results = result['search_result']
    if not results:
        return 'No results found.'
    info = 'Found %d results' % total
    if total > 10:
        info += ' (displaying first 10)'
    print repr(info)
    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)
Exemplo n.º 5
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)
Exemplo n.º 6
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
Exemplo n.º 7
0
def postMessage(request, tags, clubs, text, anon=False, anoncomments=False):
        post_throttle = yield throttle_check(request.user['name'])
        sfrom = request.to.userhost() if request.to else None
        ok, rest = yield bnw_core.post.postMessage(
            request.user, tags, clubs, text, anon, anoncomments, sfrom=sfrom)
        _ = yield throttle_update(request.user['name'], post_throttle)
        if ok:
            msgid, qn, recepients = rest
            defer.returnValue(
                dict(ok=True,
                     desc='Message #%s has been delivered '
                          'to %d users. %s/p/%s' % (
                     msgid, recepients, get_webui_base(request.user),
                     msgid),
                     id=msgid))
        else:
            defer.returnValue(
                dict(ok=False, desc=rest)
            )
Exemplo n.º 8
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
Exemplo n.º 9
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