ALIAS_RE = '[a-zA-Z0-9_-]+'
def cmd_alias(request, set="", delete="", value=""): def bl_internal(user, what, delete, text):
def cmd_blacklist(request, user="", tag="", club="", delete=""): def cmd_clubs(request):
def cmd_tags(request): def _(s, user):
def cmd_delete(request, message="", last=False): def _(s, user):
    def handleRedeye(self, options, rest, msg):
class ExceptCommand(BaseCommand): def de_yo(s):
def formatCommand(command):
def cmd_help_simple(request):
def cmd_help_redeye(request):
HELP_BASE = 'http://hive.blasux.ru/u/Stiletto/BnW/help_' def cmd_interface(request, iface=None):  # TODO: asynchronize def cmd_jids(request, add="", delete="", select=""):
def cmd_confirm(request, code): def cmd_login(request,reset=""):
def cmd_passlogin(request, user=None, password=None): def cmd_pm(request, text, user=""): def cmd_search(request, query='', page='0'): def _(s, user):
def normalize_format(fmt):
def postMessage(request, tags, clubs, text, anon=False, anoncomments=False,
                format=None):
def cmd_post(request, tags="", clubs="", anonymous="", anoncomments="", format="", text=""):
def cmd_post_simple(request, text, tag1=None, tag2=None, tag3=None, tag4=None, tag5=None):
def cmd_comment(request, message="", anonymous="", format="", text=""):
def cmd_recommend(request, message="", comment="", unrecommend=""): def _(s, user):
def cmd_register(request, name=""): class SimpleSetting(object):
class BooleanSetting(object):
class ServiceJidSetting(SimpleSetting):
class DefaultFormatSetting(SimpleSetting):
    def __init__(self, default=None):
    def get(self, request, name):
    def write(self, request, name, value):
    def __init__(self, default=False):
    def get(self, request, name):
    def write(self, request, name, value):
    def get(self, request, name):
    def write(self, request, name, value):
    def write(self, request, name, value):
def cmd_set(request, **kwargs): def get_user_bl(request, use_bl=False):
def set_subscriptions_info(request, messages):
def replace_banned(regions, message, kind='message'):
def showSearch(parameters, page, request):
def showComment(commentid, request):
def showComments(msgid, request, bl=None, after=''):
def cmd_show(request, message='', user='', tag='', club='', page='0',
             show='messages', replies=None, use_bl=False, after='', before=''):
def cmd_feed(request, page="0"):
def cmd_today(request, use_bl=False):
def cmd_today2(request): def cmd_vcard(request, safe=None): def cmd_userlist(request, page=""): def _(s, user):
def update_internal(message, what, delete, text):
def update_message_internal(request, message='', text='', club=False,
            tag=False, delete=False, clubs=None, tags=None, api=False,
            format=None):
def update_comment_internal(request, comment='', text='', club=False,
            tag=False, delete=False, clubs=None, tags=None, api=False,
            format=None):
def cmd_update(request, message='', text='', club=False, tag=False,
               delete=False, clubs=None, tags=None, api=False, format=None):
from parser_redeye import RedEyeParser
from parser_regex import RegexParser
from bnw.handlers import command_alias
from bnw.handlers import command_bl
from bnw.handlers import command_clubs
from bnw.handlers import command_delete
from bnw.handlers import command_except
from bnw.handlers import command_help
from bnw.handlers import command_interface
from bnw.handlers import command_jids
from bnw.handlers import command_login
from bnw.handlers import command_onoff
from bnw.handlers import command_ping
from bnw.handlers import command_pm
from bnw.handlers import command_search
from bnw.handlers import command_post
from bnw.handlers import command_register
from bnw.handlers import command_settings
from bnw.handlers import command_show
from bnw.handlers import command_subscription
from bnw.handlers import command_vcard
from bnw.handlers import command_userlist
from bnw.handlers import command_update
import formatters_redeye
import formatters_simple
        ("post", post_args, command_post.cmd_post, "text", ),
        ("comment", comment_args, command_post.cmd_comment, "text", ),
        ("recommend", recommend_args, command_post.cmd_recommend, "comment", ),
        ("on", (), command_onoff.cmd_on, ),
        ("off", (), command_onoff.cmd_off, ),
        ("delete", delete_args, command_delete.cmd_delete, ),
        ("login",
            (
                ("r", "reset", False, u"Reset login key"),
            ),
            command_login.cmd_login, ),
        ("bl", bl_args, command_bl.cmd_blacklist, ),
        ("vcard", (), command_vcard.cmd_vcard, ),
        ("pm",
            (
                ("u", "user", True, u"Target user"),
            ),
            command_pm.cmd_pm,
            "text",
        ),
        ("userlist",
            (
                ("p", "page", True, u"Show nth results page (counting from 0)"),
            ),
            command_userlist.cmd_userlist,
        ),
        ("update", update_args, command_update.cmd_update, "text", ),
        ("set",
            (
                ("c", "usercss", True, u"User CSS"),
                ("p", "password", True, u"Password"),
                ("s", "servicejid", False, u"Set service's jid"),
                ("b", "baseurl", True, u"Set base url for links"),
                ("a", "about", True, u'Set "about me"'),
                ("", "notify_on_recommendation", True, u'Set "notify_on_recommendation"'),
                ("f", "default_format", True, u"Default formatting for posts and comments (one of: %s)" % command_post.acceptable_formats_str),
            ),
            command_settings.cmd_set,
        ),
        ("clubs", (), command_clubs.cmd_clubs, ),
        ("jids",
            (
                ("a", "add", True, u"JID to add"),
                ("d", "delete", True, u"JID to delete"),
                ("s", "select", True, u"JID to select"),
            ),
            command_jids.cmd_jids,
        ),
        ("confirm", (), command_jids.cmd_confirm, "code", ),
        ("alias",
            (
                ("d", "delete", True, u"Delete an alias"),
                ("s", "set", True, u"Update an alias"),
            ),
            command_alias.cmd_alias,
            'value',
        ),
)

redeye_formatters = {
    'comment': formatters_redeye.formatter_comment,
    'clubs': formatters_redeye.formatter_clubs,
    'message': formatters_redeye.formatter_message,
    'recommendation': formatters_redeye.formatter_recommendation,
    'message_with_replies': formatters_redeye.formatter_message_with_replies,
    'messages': formatters_redeye.formatter_messages,
    'subscriptions': formatters_redeye.formatter_subscriptions,
    'blacklist': formatters_redeye.formatter_blacklist,
    'search': formatters_redeye.formatter_search,
    'userlist': formatters_redeye.formatter_userlist,
    'settings': formatters_redeye.formatter_settings,
    'jids': formatters_redeye.formatter_jids,
}

simple_handlers = (
        (ur'(?i)(?:ping|зштп|пинг)', command_ping.cmd_ping),
        (ur'(?i)register (?P<name>\S+)',command_register.cmd_register),
        (ur'(?i)interface (?P<iface>\S+)',command_interface.cmd_interface),
        (ur'(?i)vcard', command_vcard.cmd_vcard),
        (ur'(?i)userlist(?: (?P<page>\S+))?', command_userlist.cmd_userlist),
        (ur'\? (?P<query>.+)',command_search.cmd_search),
        (ur'(?i)[DВ] [#№](?P<message>.+)',command_delete.cmd_delete),
        (ur'(?i)[DВ] L',command_delete.cmd_delete,{'last':True}),
        (ur'(?i)[SЫ]',command_subscription.cmd_subscriptions),
        (ur'(?i)[SЫ] [#№](?P<message>.+)',command_subscription.cmd_subscribe),
        (ur'(?i)[SЫ] @(?P<user>\S+)',command_subscription.cmd_subscribe),
        (ur'(?i)[SЫ] \*(?P<tag>\S+)',command_subscription.cmd_subscribe),
        (ur'(?i)[SЫ] !(?P<club>\S+)',command_subscription.cmd_subscribe),
        (ur'(?i)[UГ] [#№](?P<message>.+)',command_subscription.cmd_unsubscribe),
        (ur'(?i)[UГ] @(?P<user>\S+)',command_subscription.cmd_unsubscribe),
        (ur'(?i)[UГ] \*(?P<tag>\S+)',command_subscription.cmd_unsubscribe),
        (ur'(?i)[UГ] !(?P<club>\S+)',command_subscription.cmd_unsubscribe),
#        (ur'L @(?P<user>\S+)','not_implemented'),
        (ur'(?i)help',command_help.cmd_help_simple),
        (ur'(?i)login',command_login.cmd_login),
        (ur'(?i)on',command_onoff.cmd_on),
        (ur'(?i)off',command_onoff.cmd_off),
        (ur'(?i)pm +@(?P<user>\S+)\s+(?P<text>.+)',command_pm.cmd_pm),

        (ur'(?i)bl',command_bl.cmd_blacklist),
        (ur'(?i)bl \+?@(?P<user>\S+)',command_bl.cmd_blacklist),
        (ur'(?i)bl \+?\*(?P<tag>\S+)',command_bl.cmd_blacklist),
        (ur'(?i)bl \+?!(?P<club>\S+)',command_bl.cmd_blacklist),
        (ur'(?i)bl -@(?P<user>\S+)',command_bl.cmd_blacklist,{'delete':True}),
        (ur'(?i)bl -\*(?P<tag>\S+)',command_bl.cmd_blacklist,{'delete':True}),
        (ur'(?i)bl -!(?P<club>\S+)',command_bl.cmd_blacklist,{'delete':True}),

        (ur'(?i)jid \+(?P<add>\S+)',command_jids.cmd_jids),
        (ur'(?i)jid -(?P<delete>\S+)',command_jids.cmd_jids),
        (ur'(?i)jid !(?P<select>\S+)',command_jids.cmd_jids),
        (ur'(?i)jid',command_jids.cmd_jids),

        (ur'(?i)set',command_settings.cmd_set),
        (ur'(?i)set +(?P<name>\w+)(?: +(?P<value>.+))?',command_settings.cmd_set),

        (ur'(?i)today',command_show.cmd_today),
        (ur'[#№]',command_show.cmd_feed),
        (ur'[#№]\+',command_show.cmd_show),
        (ur'@(?P<user>\S+)',command_show.cmd_show),
        (ur'@(?P<user>\S+)',command_show.cmd_show),

        (ur'@(?P<user>\S+) \*(?P<tag>\S+)',command_show.cmd_show),