# Path: bnw/core/base.py
# class BnwResponse(Exception):  # we do it idiotic way!
#     pass
# 
# def get_webui_base(user):
#     """Get base url for links in accordance with baseurl user setting.
#     baseurl can be one of:
#         "http": return http base url
#         "https": return https base url
#         "random string": return this string
#         None: return http base url
#     """
#     baseurl = user.get('settings', {}).get('baseurl', None) if user else None
#     if not baseurl:
#         return get_http_webui_base()
#     else:
#         if baseurl == 'http':
#             return get_http_webui_base()
#         elif baseurl == 'https':
#             return get_https_webui_base()
#         else:
#             return baseurl


from base import *
from bnw.core.base import BnwResponse, get_webui_base
from bnw.core.post import publish
from twisted.python import log
from throttle import throttle_check
import random
import time
import bnw.core.bnw_objects as objs
import bnw.core.post
#            command_post.cmd_post_simple),
    """ Отправка псто """
    raw_tags = [t for t in (tag1, tag2, tag3, tag4, tag5) if t]
    clubs = ','.join([x[1:] for x in raw_tags if x.startswith('!')])
    tags = ','.join([x[1:] for x in raw_tags if x.startswith('*')])
    defer.returnValue((yield cmd_post(request, tags=tags, clubs=clubs, text=text)))


@require_auth
@check_arg(message=MESSAGE_COMMENT_RE)
@defer.inlineCallbacks
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' % (

# Path: bnw/core/base.py
# class BnwResponse(Exception):  # we do it idiotic way!
#     pass
# 
# def get_webui_base(user):
#     """Get base url for links in accordance with baseurl user setting.
#     baseurl can be one of:
#         "http": return http base url
#         "https": return https base url
#         "random string": return this string
#         None: return http base url
#     """
#     baseurl = user.get('settings', {}).get('baseurl', None) if user else None
#     if not baseurl:
#         return get_http_webui_base()
#     else:
#         if baseurl == 'http':
#             return get_http_webui_base()
#         elif baseurl == 'https':
#             return get_https_webui_base()
#         else:
#             return baseurl


# Path: bnw/handlers/command_post.py
from base import *
from bnw.core.base import BnwResponse, get_webui_base
from bnw.core.post import publish
from twisted.python import log
from throttle import throttle_check
import random
import time
import bnw.core.bnw_objects as objs
import bnw.core.post

#            command_post.cmd_post_simple),
    """ Отправка псто """
    raw_tags = [t for t in (tag1, tag2, tag3, tag4, tag5) if t]
    clubs = ','.join([x[1:] for x in raw_tags if x.startswith('!')])
    tags = ','.join([x[1:] for x in raw_tags if x.startswith('*')])
    defer.returnValue((yield cmd_post(request, tags=tags, clubs=clubs, text=text)))


@require_auth
@check_arg(message=MESSAGE_COMMENT_RE)
@defer.inlineCallbacks
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(